Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3408438
D11638.id39125.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.id39125.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,14 @@
import * as React from 'react';
+import { isLoggedIn } from 'lib/selectors/user-selectors.js';
+
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({});
@@ -38,6 +43,48 @@
],
);
+ const loggedIn = useSelector(isLoggedIn);
+ const persistSIWEBackupSecretsPromise = React.useRef<?Promise<void>>(null);
+
+ React.useEffect(() => {
+ if (persistSIWEBackupSecretsPromise.current) {
+ return;
+ }
+ const innerSiweBackupSecrets = cachedSelections.siweBackupSecrets;
+ if (!innerSiweBackupSecrets || !loggedIn) {
+ return;
+ }
+
+ persistSIWEBackupSecretsPromise.current = void (async () => {
+ try {
+ await commCoreModule.setSIWEBackupSecrets(innerSiweBackupSecrets);
+ } catch (e) {
+ console.log(e);
+ if (__DEV__) {
+ Alert.alert(
+ 'Failed to persist SIWE backup secrets to SQLite.',
+ e.message,
+ );
+ }
+ } finally {
+ setCachedSelections(oldUserSelections => ({
+ ...oldUserSelections,
+ siweBackupSecrets: undefined,
+ }));
+ persistSIWEBackupSecretsPromise.current = null;
+ }
+ })();
+ }, [cachedSelections.siweBackupSecrets, loggedIn]);
+
+ React.useEffect(() => {
+ if (!loggedIn) {
+ setCachedSelections(oldUserSelections => ({
+ ...oldUserSelections,
+ siweBackupSecrets: undefined,
+ }));
+ }
+ }, [loggedIn]);
+
return (
<RegistrationContext.Provider value={contextValue}>
{props.children}
diff --git a/native/account/registration/registration-types.js b/native/account/registration/registration-types.js
--- a/native/account/registration/registration-types.js
+++ b/native/account/registration/registration-types.js
@@ -5,7 +5,7 @@
ClientAvatar,
} from 'lib/types/avatar-types.js';
import type { NativeMediaSelection } from 'lib/types/media-types.js';
-import type { SIWEResult } from 'lib/types/siwe-types.js';
+import type { SIWEResult, SIWEBackupSecrets } from 'lib/types/siwe-types.js';
export type CoolOrNerdMode = 'cool' | 'nerd';
@@ -53,6 +53,7 @@
+avatarData?: ?AvatarData,
+ethereumAccount?: EthereumAccountSelection,
+farcasterID?: string,
+ +siweBackupSecrets?: ?SIWEBackupSecrets,
};
export const ensAvatarSelection: AvatarData = {
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 { setCachedSelections } = registrationContext;
+
const onSuccessfulWalletSignature = React.useCallback(
(result: SIWEResult) => {
- console.log(result);
+ const { message, signature } = result;
+ setCachedSelections(oldUserSelections => ({
+ ...oldUserSelections,
+ siweBackupSecrets: { message, signature },
+ }));
navigate<'RegistrationTerms'>({
name: RegistrationTermsRouteName,
params,
});
},
- [navigate, params],
+ [navigate, params, setCachedSelections],
);
let siwePanel;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 5, 11:15 AM (17 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2616886
Default Alt Text
D11638.id39125.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