Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3406075
D13839.id45502.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13839.id45502.diff
View Options
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
@@ -5,8 +5,10 @@
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
import { accountHasPassword } from 'lib/shared/account-utils.js';
import {
- type SIWEBackupData,
+ 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';
@@ -20,6 +22,7 @@
+uploadBackupProtocol: () => Promise<void>,
+restorePasswordUserBackupProtocol: () => Promise<void>,
+retrieveLatestSIWEBackupData: () => Promise<SIWEBackupData>,
+ +retrieveLatestBackupInfo: () => Promise<LatestBackupInfo>,
};
async function getBackupSecret(): Promise<string> {
@@ -105,11 +108,35 @@
);
}, [currentUserID, currentUserInfo, loggedIn]);
- return {
- uploadBackupProtocol,
- restorePasswordUserBackupProtocol,
- retrieveLatestSIWEBackupData,
- };
+ const retrieveLatestBackupInfo = React.useCallback(async () => {
+ if (!loggedIn || !currentUserID || !currentUserInfo?.username) {
+ throw new Error('Attempt to restore backup for not logged in user.');
+ }
+ const userIdentitifer = currentUserInfo?.username;
+
+ const response =
+ await commCoreModule.retrieveLatestBackupInfo(userIdentitifer);
+
+ return assertWithValidator<LatestBackupInfo>(
+ JSON.parse(response),
+ latestBackupInfoResponseValidator,
+ );
+ }, [currentUserID, currentUserInfo, loggedIn]);
+
+ return React.useMemo(
+ () => ({
+ uploadBackupProtocol,
+ restorePasswordUserBackupProtocol,
+ retrieveLatestSIWEBackupData,
+ retrieveLatestBackupInfo,
+ }),
+ [
+ restorePasswordUserBackupProtocol,
+ retrieveLatestBackupInfo,
+ retrieveLatestSIWEBackupData,
+ uploadBackupProtocol,
+ ],
+ );
}
export { getBackupSecret, useClientBackup };
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
@@ -39,6 +39,7 @@
uploadBackupProtocol,
restorePasswordUserBackupProtocol,
retrieveLatestSIWEBackupData,
+ retrieveLatestBackupInfo,
} = useClientBackup();
const uploadBackup = React.useCallback(async () => {
@@ -63,6 +64,25 @@
Alert.alert('Restore protocol result', message);
}, [restorePasswordUserBackupProtocol]);
+ const testLatestBackupInfo = React.useCallback(async () => {
+ let message;
+ try {
+ const backupInfo = await retrieveLatestBackupInfo();
+ const { backupID, userID } = backupInfo;
+ message =
+ `Success!\n` +
+ `Backup ID: ${backupID},\n` +
+ `userID: ${userID},\n` +
+ `userID check: ${currentUserInfo?.id === userID ? 'true' : 'false'}`;
+ } catch (e) {
+ message = `Latest backup info error: ${String(
+ getMessageForException(e),
+ )}`;
+ console.error(message);
+ }
+ Alert.alert('Latest backup info result', message);
+ }, [currentUserInfo?.id, retrieveLatestBackupInfo]);
+
const testRestoreForSIWEUser = React.useCallback(async () => {
let message = 'success';
try {
@@ -140,6 +160,19 @@
<Text style={styles.submenuText}>Test backup restore protocol</Text>
</Button>
</View>
+ <View style={styles.section}>
+ <Button
+ onPress={testLatestBackupInfo}
+ style={styles.row}
+ iosFormat="highlight"
+ iosHighlightUnderlayColor={colors.panelIosHighlightUnderlay}
+ iosActiveOpacity={0.85}
+ >
+ <Text style={styles.submenuText}>
+ Test retrieving latest backup info
+ </Text>
+ </Button>
+ </View>
</ScrollView>
);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 5, 12:29 AM (13 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2614092
Default Alt Text
D13839.id45502.diff (3 KB)
Attached To
Mode
D13839: [native] make it possible to test retrieving latest backup info
Attached
Detach File
Event Timeline
Log In to Comment