Skip to content

Commit

Permalink
[native_rust_library] update creating backup to return backupID
Browse files Browse the repository at this point in the history
Summary:
[ENG-9656](https://linear.app/comm/issue/ENG-9656/native-changes-for-minimal-version-of-backup).

We need to store `backupID` in the store, it's needed in e.g. [ENG-9616](https://linear.app/comm/issue/ENG-9616/clients-store-informations-if-using-backup-or-v1-login#comment-f937dae3).

Depends on D13936

Test Plan:
This is the final diff for this stack so testing this end-to-end, mostly uploading User Keys, but also getting the latest Backup Info and Uploading full backup to test if this still works.
I was testing using physical iOS and Android, and both password and wallet users.
I was confirming everything with investigating DDB content.

Reviewers: bartek, tomek

Reviewed By: bartek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D13937
  • Loading branch information
xsanm committed Nov 25, 2024
1 parent f2be17b commit 45497af
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions native/backup/use-client-backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { commCoreModule } from '../native-modules.js';
import { useSelector } from '../redux/redux-utils.js';

type ClientBackup = {
+createFullBackup: () => Promise<void>,
+createUserKeysBackup: () => Promise<void>,
+createFullBackup: () => Promise<string>,
+createUserKeysBackup: () => Promise<string>,
+retrieveLatestBackupInfo: () => Promise<LatestBackupInfo>,
};

Expand All @@ -33,7 +33,7 @@ function useClientBackup(): ClientBackup {
}

const backupSecret = await getBackupSecret();
await commCoreModule.createFullBackup(backupSecret);
return commCoreModule.createFullBackup(backupSecret);
}, [loggedIn, currentUserID, getBackupSecret]);

const createUserKeysBackup = React.useCallback(async () => {
Expand All @@ -42,7 +42,7 @@ function useClientBackup(): ClientBackup {
}

const backupSecret = await getBackupSecret();
await commCoreModule.createUserKeysBackup(backupSecret);
return commCoreModule.createUserKeysBackup(backupSecret);
}, [loggedIn, currentUserID, getBackupSecret]);

const retrieveLatestBackupInfo = React.useCallback(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::handle_void_result_as_callback;
use crate::handle_string_result_as_callback;
use lazy_static::lazy_static;
use std::{collections::HashMap, sync::Mutex};

Expand All @@ -20,5 +20,9 @@ pub fn resolve(backup_id: &str, result: Result<(), String>) {
let Some(promise_id) = backups_to_promises.remove(backup_id) else {
return;
};
handle_void_result_as_callback(result, promise_id);

let backup_id_result: Result<String, String> =
result.map(|_| backup_id.to_string());

handle_string_result_as_callback(backup_id_result, promise_id);
}
10 changes: 6 additions & 4 deletions native/profile/backup-menu.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ function BackupMenu(props: Props): React.Node {
useClientBackup();

const uploadBackup = React.useCallback(async () => {
let message = 'Success';
let message;
try {
await createFullBackup();
const backupID = await createFullBackup();
message = `Success!\n` + `Backup ID: ${backupID}`;
} catch (e) {
message = `Backup upload error: ${String(getMessageForException(e))}`;
console.error(message);
Expand All @@ -54,9 +55,10 @@ function BackupMenu(props: Props): React.Node {
}, [createFullBackup]);

const uploadUserKeys = React.useCallback(async () => {
let message = 'Success';
let message;
try {
await createUserKeysBackup();
const backupID = await createUserKeysBackup();
message = `Success!\n` + `Backup ID: ${backupID}`;
} catch (e) {
message = `User Keys upload error: ${String(getMessageForException(e))}`;
console.error(message);
Expand Down
4 changes: 2 additions & 2 deletions native/schema/CommCoreModuleSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ interface Spec extends TurboModule {
+clearCommServicesAccessToken: () => Promise<void>;
+startBackupHandler: () => void;
+stopBackupHandler: () => void;
+createUserKeysBackup: (backupSecret: string) => Promise<void>;
+createFullBackup: (backupSecret: string) => Promise<void>;
+createUserKeysBackup: (backupSecret: string) => Promise<string>;
+createFullBackup: (backupSecret: string) => Promise<string>;
+restoreBackup: (
backupSecret: string,
maxVersion: string,
Expand Down

0 comments on commit 45497af

Please sign in to comment.