Skip to content

Commit

Permalink
[native] Wait for backup before processing QR code
Browse files Browse the repository at this point in the history
Summary: Address [[ https://linear.app/comm/issue/ENG-9709/make-sure-qr-code-screen-waits-for-migration-to-new-flows | ENG-9709 ]].

Test Plan: Added artificial delay to backup creation and scanned QR code. Made sure that processing continued after backup creation finished.

Reviewers: kamil

Reviewed By: kamil

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D14202
  • Loading branch information
barthap committed Jan 14, 2025
1 parent c9327ed commit 11ddcd9
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions native/account/qr-auth/primary-device-qr-auth-context-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ function PrimaryDeviceQRAuthContextProvider(props: Props): React.Node {
const identityContext = React.useContext(IdentityClientContext);
invariant(identityContext, 'identity context not set');

const backupExists = useSelector(
state => !!state.backupStore.latestBackupInfo,
);
const [backupNotReady, setBackupNotReady] = React.useState(false);

React.useEffect(() => {
return () => {
if (timeout.current) {
Expand Down Expand Up @@ -258,11 +263,27 @@ function PrimaryDeviceQRAuthContextProvider(props: Props): React.Node {
return;
}

await processDeviceListUpdate();
if (backupExists) {
await processDeviceListUpdate();
} else {
setBackupNotReady(true);
}
},
[processDeviceListUpdate],
[processDeviceListUpdate, backupExists],
);

React.useEffect(() => {
if (backupExists && backupNotReady && connectingInProgress) {
void processDeviceListUpdate();
setBackupNotReady(false);
}
}, [
backupExists,
backupNotReady,
connectingInProgress,
processDeviceListUpdate,
]);

const onRemoveSecondaryDevice = React.useCallback(async () => {
if (!secondaryDeviceID.current) {
console.log('No secondary device to remove');
Expand Down

0 comments on commit 11ddcd9

Please sign in to comment.