Page MenuHomePhabricator

D13839.id45670.diff
No OneTemporary

D13839.id45670.diff

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

Mime Type
text/plain
Expires
Wed, Dec 4, 11:18 AM (22 m, 27 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2614092
Default Alt Text
D13839.id45670.diff (3 KB)

Event Timeline