Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3408294
D11638.id39150.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.id39150.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
@@ -1,10 +1,16 @@
// @flow
+import _isEmpty from 'lodash/fp/isEmpty.js';
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 +44,40 @@
],
);
+ const loggedIn = useSelector(isLoggedIn);
+ const clearCachedSelectionsPromise = React.useRef<?Promise<void>>(null);
+
+ React.useEffect(() => {
+ if (clearCachedSelectionsPromise.current) {
+ return;
+ }
+
+ if (_isEmpty(cachedSelections) || !loggedIn) {
+ return;
+ }
+
+ clearCachedSelectionsPromise.current = (async () => {
+ try {
+ if (cachedSelections.siweBackupSecrets) {
+ await commCoreModule.setSIWEBackupSecrets(
+ cachedSelections.siweBackupSecrets,
+ );
+ }
+ } catch (e) {
+ console.log(e);
+ if (__DEV__) {
+ Alert.alert(
+ 'Failed to persist SIWE backup secrets to SQLite.',
+ e.message,
+ );
+ }
+ } finally {
+ setCachedSelections({});
+ clearCachedSelectionsPromise.current = null;
+ }
+ })();
+ }, [cachedSelections, 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,6 +1,7 @@
// @flow
import Icon from '@expo/vector-icons/MaterialIcons.js';
+import invariant from 'invariant';
import * as React from 'react';
import { View, Text } from 'react-native';
@@ -10,6 +11,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,
@@ -69,15 +71,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, 10:49 AM (16 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2616795
Default Alt Text
D11638.id39150.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