Page MenuHomePhabricator

D11638.id39064.diff
No OneTemporary

D11638.id39064.diff

diff --git a/native/account/registration/registration-context-provider.react.js b/native/account/registration/registration-context-provider.react.js
--- a/native/account/registration/registration-context-provider.react.js
+++ b/native/account/registration/registration-context-provider.react.js
@@ -2,9 +2,14 @@
import * as React from 'react';
+import { isLoggedIn } from 'lib/selectors/user-selectors.js';
+import type { SIWEBackupSecrets } from 'lib/types/siwe-types';
+
import { RegistrationContext } from './registration-context.js';
import { useRegistrationServerCall } from './registration-server-call.js';
import type { CachedUserSelections } from './registration-types.js';
+import { commCoreModule } from '../../native-modules.js';
+import { useSelector } from '../../redux/redux-utils.js';
const emptyObj: CachedUserSelections = Object.freeze({});
@@ -20,6 +25,8 @@
const setSkipEthereumLoginOnce = React.useCallback((skip: boolean) => {
baseSetSkipEthereumLoginOnce(skip || undefined);
}, []);
+ const [siweBackupSecrets, setSIWEBackupSecrets] =
+ React.useState<?SIWEBackupSecrets>(undefined);
const registrationServerCall = useRegistrationServerCall();
const contextValue = React.useMemo(
@@ -29,14 +36,34 @@
setCachedSelections,
skipEthereumLoginOnce,
setSkipEthereumLoginOnce,
+ siweBackupSecrets,
+ setSIWEBackupSecrets,
}),
[
registrationServerCall,
cachedSelections,
skipEthereumLoginOnce,
setSkipEthereumLoginOnce,
+ siweBackupSecrets,
+ setSIWEBackupSecrets,
],
);
+ const storeLoaded = useSelector(state => state.storeLoaded);
+ const loggedIn = useSelector(isLoggedIn);
+ const lastPersistedBackupSecret = React.useRef<?SIWEBackupSecrets>(undefined);
+
+ React.useEffect(() => {
+ void (async () => {
+ if (!siweBackupSecrets || !storeLoaded || !loggedIn) {
+ return;
+ }
+ if (lastPersistedBackupSecret.current === siweBackupSecrets) {
+ return;
+ }
+ lastPersistedBackupSecret.current = siweBackupSecrets;
+ await commCoreModule.setSIWEBackupSecrets(siweBackupSecrets);
+ })();
+ }, [storeLoaded, siweBackupSecrets, loggedIn]);
return (
<RegistrationContext.Provider value={contextValue}>
diff --git a/native/account/registration/registration-context.js b/native/account/registration/registration-context.js
--- a/native/account/registration/registration-context.js
+++ b/native/account/registration/registration-context.js
@@ -3,6 +3,7 @@
import * as React from 'react';
import type { SetState } from 'lib/types/hook-types.js';
+import type { SIWEBackupSecrets } from 'lib/types/siwe-types.js';
import type {
RegistrationServerCallInput,
@@ -18,6 +19,8 @@
// skipping the login flow once, so that the user can back out and change it.
+skipEthereumLoginOnce?: ?true,
+setSkipEthereumLoginOnce: boolean => void,
+ +siweBackupSecrets?: ?SIWEBackupSecrets,
+ +setSIWEBackupSecrets: SetState<?SIWEBackupSecrets>,
};
const RegistrationContext: React.Context<?RegistrationContextType> =
diff --git a/native/account/registration/siwe-backup-message-creation.react.js b/native/account/registration/siwe-backup-message-creation.react.js
--- a/native/account/registration/siwe-backup-message-creation.react.js
+++ b/native/account/registration/siwe-backup-message-creation.react.js
@@ -1,5 +1,6 @@
// @flow
+import invariant from 'invariant';
import * as React from 'react';
import { Text } from 'react-native';
@@ -9,6 +10,7 @@
import RegistrationButton from './registration-button.react.js';
import RegistrationContainer from './registration-container.react.js';
import RegistrationContentContainer from './registration-content-container.react.js';
+import { RegistrationContext } from './registration-context.js';
import { type RegistrationNavigationProp } from './registration-navigator.react.js';
import type {
CoolOrNerdMode,
@@ -68,15 +70,23 @@
[panelState],
);
+ const registrationContext = React.useContext(RegistrationContext);
+ invariant(registrationContext, 'registrationContext should be set');
+ const { setSIWEBackupSecrets } = registrationContext;
+
const onSuccessfulWalletSignature = React.useCallback(
async (result: SIWEResult) => {
- console.log(result);
+ const { message, signature } = result;
+ setSIWEBackupSecrets({
+ message,
+ signature,
+ });
navigate<'RegistrationTerms'>({
name: RegistrationTermsRouteName,
params,
});
},
- [navigate, params],
+ [navigate, params, setSIWEBackupSecrets],
);
let siwePanel;

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 5, 10:56 AM (16 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2616832
Default Alt Text
D11638.id39064.diff (4 KB)

Event Timeline