Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3408335
D11638.id39077.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D11638.id39077.diff
View Options
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,15 @@
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';
+import Alert from '../../utils/alert.js';
const emptyObj: CachedUserSelections = Object.freeze({});
@@ -20,6 +26,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,15 +37,54 @@
setCachedSelections,
skipEthereumLoginOnce,
setSkipEthereumLoginOnce,
+ siweBackupSecrets,
+ setSIWEBackupSecrets,
}),
[
registrationServerCall,
cachedSelections,
skipEthereumLoginOnce,
setSkipEthereumLoginOnce,
+ siweBackupSecrets,
+ setSIWEBackupSecrets,
],
);
+ const loggedIn = useSelector(isLoggedIn);
+ const persistSIWEBackupSecretsPromise = React.useRef<?Promise<void>>(null);
+
+ React.useEffect(() => {
+ if (persistSIWEBackupSecretsPromise.current) {
+ return;
+ }
+ if (!siweBackupSecrets || !loggedIn) {
+ return;
+ }
+
+ persistSIWEBackupSecretsPromise.current = void (async () => {
+ try {
+ await commCoreModule.setSIWEBackupSecrets(siweBackupSecrets);
+ } catch (e) {
+ console.log(e);
+ if (__DEV__) {
+ Alert.alert(
+ 'Failed to persist SIWE backup secrets to SQLite.',
+ e.message,
+ );
+ }
+ } finally {
+ setSIWEBackupSecrets(undefined);
+ persistSIWEBackupSecretsPromise.current = null;
+ }
+ })();
+ }, [siweBackupSecrets, loggedIn]);
+
+ React.useEffect(() => {
+ if (!loggedIn) {
+ setSIWEBackupSecrets(undefined);
+ }
+ }, [loggedIn]);
+
return (
<RegistrationContext.Provider value={contextValue}>
{props.children}
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
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 5, 10:54 AM (16 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2616820
Default Alt Text
D11638.id39077.diff (4 KB)
Attached To
Mode
D11638: Persist SIWE backup secrets to SQLite after succesfull registration process
Attached
Detach File
Event Timeline
Log In to Comment