Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3111342
D13844.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D13844.id.diff
View Options
diff --git a/native/backup/restore-siwe-backup.react.js b/native/backup/restore-siwe-backup.react.js
--- a/native/backup/restore-siwe-backup.react.js
+++ b/native/backup/restore-siwe-backup.react.js
@@ -40,10 +40,10 @@
const { signature } = result;
let message = 'success';
try {
- await commCoreModule.restoreSIWEBackup(
+ await commCoreModule.restoreBackup(
signature,
- backupID,
persistConfig.version.toString(),
+ backupID,
);
} catch (e) {
message = `Backup restore error: ${String(
diff --git a/native/backup/use-client-backup.js b/native/backup/use-client-backup.js
--- a/native/backup/use-client-backup.js
+++ b/native/backup/use-client-backup.js
@@ -6,22 +6,17 @@
import { accountHasPassword } from 'lib/shared/account-utils.js';
import {
latestBackupInfoResponseValidator,
- siweBackupDataValidator,
type LatestBackupInfo,
- type SIWEBackupData,
} from 'lib/types/backup-types.js';
import type { SIWEBackupSecrets } from 'lib/types/siwe-types.js';
import { assertWithValidator } from 'lib/utils/validation-utils.js';
import { fetchNativeKeychainCredentials } from '../account/native-credentials.js';
import { commCoreModule } from '../native-modules.js';
-import { persistConfig } from '../redux/persist.js';
import { useSelector } from '../redux/redux-utils.js';
type ClientBackup = {
+uploadBackupProtocol: () => Promise<void>,
- +restorePasswordUserBackupProtocol: () => Promise<void>,
- +retrieveLatestSIWEBackupData: () => Promise<SIWEBackupData>,
+retrieveLatestBackupInfo: () => Promise<LatestBackupInfo>,
};
@@ -66,26 +61,6 @@
console.info('Backup uploaded.');
}, [currentUserID, loggedIn, currentUserInfo]);
- const retrieveLatestSIWEBackupData = React.useCallback(async () => {
- if (!loggedIn || !currentUserID) {
- throw new Error('Attempt to restore backup for not logged in user.');
- }
-
- if (accountHasPassword(currentUserInfo)) {
- throw new Error(
- 'Attempt to retrieve siwe backup data for password user.',
- );
- }
-
- const serializedBackupData =
- await commCoreModule.retrieveLatestSIWEBackupData();
-
- return assertWithValidator(
- JSON.parse(serializedBackupData),
- siweBackupDataValidator,
- );
- }, [currentUserID, currentUserInfo, loggedIn]);
-
const retrieveLatestBackupInfo = React.useCallback(async () => {
if (!loggedIn || !currentUserID || !currentUserInfo?.username) {
throw new Error('Attempt to restore backup for not logged in user.');
@@ -101,40 +76,12 @@
);
}, [currentUserID, currentUserInfo, loggedIn]);
- const restorePasswordUserBackupProtocol = React.useCallback(async () => {
- if (!accountHasPassword(currentUserInfo)) {
- throw new Error(
- 'Attempt to restore from password for non-password user.',
- );
- }
-
- const [latestBackupInfo, backupSecret] = await Promise.all([
- retrieveLatestBackupInfo(),
- getBackupSecret(),
- ]);
-
- console.info('Start restoring backup...');
- await commCoreModule.restoreBackup(
- backupSecret,
- persistConfig.version.toString(),
- latestBackupInfo.backupID,
- );
- console.info('Backup restored.');
- }, [currentUserInfo, retrieveLatestBackupInfo]);
-
return React.useMemo(
() => ({
uploadBackupProtocol,
- restorePasswordUserBackupProtocol,
- retrieveLatestSIWEBackupData,
retrieveLatestBackupInfo,
}),
- [
- restorePasswordUserBackupProtocol,
- retrieveLatestBackupInfo,
- retrieveLatestSIWEBackupData,
- uploadBackupProtocol,
- ],
+ [retrieveLatestBackupInfo, uploadBackupProtocol],
);
}
diff --git a/native/profile/backup-menu.react.js b/native/profile/backup-menu.react.js
--- a/native/profile/backup-menu.react.js
+++ b/native/profile/backup-menu.react.js
@@ -10,11 +10,16 @@
import { useDispatch } from 'lib/utils/redux-utils.js';
import type { ProfileNavigationProp } from './profile.react.js';
-import { useClientBackup } from '../backup/use-client-backup.js';
+import {
+ getBackupSecret,
+ useClientBackup,
+} from '../backup/use-client-backup.js';
import Button from '../components/button.react.js';
+import { commCoreModule } from '../native-modules.js';
import type { NavigationRoute } from '../navigation/route-names.js';
import { RestoreSIWEBackupRouteName } from '../navigation/route-names.js';
import { setLocalSettingsActionType } from '../redux/action-types.js';
+import { persistConfig } from '../redux/persist.js';
import { useSelector } from '../redux/redux-utils.js';
import { useColors, useStyles } from '../themes/colors.js';
import Alert from '../utils/alert.js';
@@ -35,12 +40,7 @@
state => state.localSettings.isBackupEnabled,
);
- const {
- uploadBackupProtocol,
- restorePasswordUserBackupProtocol,
- retrieveLatestSIWEBackupData,
- retrieveLatestBackupInfo,
- } = useClientBackup();
+ const { uploadBackupProtocol, retrieveLatestBackupInfo } = useClientBackup();
const uploadBackup = React.useCallback(async () => {
let message = 'Success';
@@ -56,13 +56,22 @@
const testRestoreForPasswordUser = React.useCallback(async () => {
let message = 'success';
try {
- await restorePasswordUserBackupProtocol();
+ const [latestBackupInfo, backupSecret] = await Promise.all([
+ retrieveLatestBackupInfo(),
+ getBackupSecret(),
+ ]);
+ await commCoreModule.restoreBackup(
+ backupSecret,
+ persistConfig.version.toString(),
+ latestBackupInfo.backupID,
+ );
+ console.info('Backup restored.');
} catch (e) {
message = `Backup restore error: ${String(getMessageForException(e))}`;
console.error(message);
}
Alert.alert('Restore protocol result', message);
- }, [restorePasswordUserBackupProtocol]);
+ }, [retrieveLatestBackupInfo]);
const testLatestBackupInfo = React.useCallback(async () => {
let message;
@@ -86,10 +95,14 @@
const testRestoreForSIWEUser = React.useCallback(async () => {
let message = 'success';
try {
- const siweBackupData = await retrieveLatestSIWEBackupData();
+ const backupInfo = await retrieveLatestBackupInfo();
+ const { siweBackupData, backupID } = backupInfo;
+
+ if (!siweBackupData) {
+ throw new Error('Missing SIWE message for Wallet user backup');
+ }
const {
- backupID,
siweBackupMsgNonce,
siweBackupMsgIssuedAt,
siweBackupMsgStatement,
@@ -108,7 +121,7 @@
message = `Backup restore error: ${String(getMessageForException(e))}`;
console.error(message);
}
- }, [navigation, retrieveLatestSIWEBackupData]);
+ }, [navigation, retrieveLatestBackupInfo]);
const onBackupToggled = React.useCallback(
(value: boolean) => {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 1, 1:50 PM (15 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2398744
Default Alt Text
D13844.id.diff (6 KB)
Attached To
Mode
D13844: [native] unify username and wallet backup restore
Attached
Detach File
Event Timeline
Log In to Comment