diff --git a/native/account/registration/missing-registration-data/missing-registration-data-handler.react.js b/native/account/registration/missing-registration-data/missing-registration-data-handler.react.js new file mode 100644 --- /dev/null +++ b/native/account/registration/missing-registration-data/missing-registration-data-handler.react.js @@ -0,0 +1,40 @@ +// @flow + +import { useNavigation } from '@react-navigation/native'; +import * as React from 'react'; + +import { isLoggedIn } from 'lib/selectors/user-selectors.js'; +import { accountHasPassword } from 'lib/shared/account-utils.js'; + +import { commCoreModule } from '../../../native-modules.js'; +import { CreateMissingSIWEBackupMessageRouteName } from '../../../navigation/route-names.js'; +import { useSelector } from '../../../redux/redux-utils.js'; + +function MissingRegistrationDataHandler(): React.Node { + const loggedIn = useSelector(isLoggedIn); + const navigation = useNavigation(); + const currentUserInfo = useSelector(state => state.currentUserInfo); + + React.useEffect(() => { + if (!loggedIn || accountHasPassword(currentUserInfo)) { + return; + } + + void (async () => { + const nativeSIWEBackupSecrets = + await commCoreModule.getSIWEBackupSecrets(); + + if (nativeSIWEBackupSecrets) { + return; + } + + navigation.navigate<'CreateMissingSIWEBackupMessage'>({ + name: CreateMissingSIWEBackupMessageRouteName, + }); + })(); + }, [currentUserInfo, loggedIn, navigation]); + + return null; +} + +export { MissingRegistrationDataHandler }; diff --git a/native/account/registration/missing-registration-data/missing-siwe-backup-message.react.js b/native/account/registration/missing-registration-data/missing-siwe-backup-message.react.js new file mode 100644 --- /dev/null +++ b/native/account/registration/missing-registration-data/missing-siwe-backup-message.react.js @@ -0,0 +1,61 @@ +// @flow + +import invariant from 'invariant'; +import * as React from 'react'; +import { SafeAreaView } from 'react-native-safe-area-context'; + +import { type SIWEResult } from 'lib/types/siwe-types.js'; + +import { type RootNavigationProp } from '../../../navigation/root-navigator.react.js'; +import { type NavigationRoute } from '../../../navigation/route-names.js'; +import { useStyles } from '../../../themes/colors.js'; +import { RegistrationContext } from '../registration-context.js'; +import { CreateSIWEBackupMessageBase } from '../siwe-backup-message-creation.react.js'; + +type Props = { + +navigation: RootNavigationProp<'CreateMissingSIWEBackupMessage'>, + +route: NavigationRoute<'CreateMissingSIWEBackupMessage'>, +}; + +function CreateMissingSIWEBackupMessage(props: Props): React.Node { + const styles = useStyles(unboundStyles); + const registrationContext = React.useContext(RegistrationContext); + invariant(registrationContext, 'registrationContext should be set'); + const { cachedSelections, setCachedSelections } = registrationContext; + + const onSuccessfulWalletSignature = React.useCallback( + (result: SIWEResult) => { + const { message, signature } = result; + setCachedSelections(oldUserSelections => ({ + ...oldUserSelections, + siweBackupSecrets: { message, signature }, + })); + }, + [setCachedSelections], + ); + + React.useEffect(() => { + if (cachedSelections.siweBackupSecrets) { + props.navigation.goBack(); + } + }, [cachedSelections.siweBackupSecrets, props]); + + return ( + + + + ); +} + +const safeAreaEdges = ['top']; +const unboundStyles = { + container: { + flex: 1, + backgroundColor: 'panelBackground', + justifyContent: 'space-between', + }, +}; + +export default CreateMissingSIWEBackupMessage; diff --git a/native/navigation/root-navigator.react.js b/native/navigation/root-navigator.react.js --- a/native/navigation/root-navigator.react.js +++ b/native/navigation/root-navigator.react.js @@ -53,8 +53,10 @@ UserProfileBottomSheetNavigatorRouteName, KeyserverSelectionBottomSheetRouteName, ConnectFarcasterBottomSheetRouteName, + CreateMissingSIWEBackupMessageRouteName, } from './route-names.js'; import LoggedOutModal from '../account/logged-out-modal.react.js'; +import CreateMissingSIWEBackupMessage from '../account/registration/missing-registration-data/missing-siwe-backup-message.react.js'; import RegistrationNavigator from '../account/registration/registration-navigator.react.js'; import TermsAndPrivacyModal from '../account/terms-and-privacy-modal.react.js'; import ThreadPickerModal from '../calendar/thread-picker-modal.react.js'; @@ -291,6 +293,10 @@ component={ConnectFarcasterBottomSheet} options={modalOverlayScreenOptions} /> + ); } diff --git a/native/navigation/route-names.js b/native/navigation/route-names.js --- a/native/navigation/route-names.js +++ b/native/navigation/route-names.js @@ -123,6 +123,8 @@ export const CoolOrNerdModeSelectionRouteName = 'CoolOrNerdModeSelection'; export const ConnectEthereumRouteName = 'ConnectEthereum'; export const CreateSIWEBackupMessageRouteName = 'CreateSIWEBackupMessage'; +export const CreateMissingSIWEBackupMessageRouteName = + 'CreateMissingSIWEBackupMessage'; export const ExistingEthereumAccountRouteName = 'ExistingEthereumAccount'; export const ConnectFarcasterRouteName = 'ConnectFarcaster'; export const UsernameSelectionRouteName = 'UsernameSelection'; @@ -177,6 +179,7 @@ +TunnelbrokerMenu: void, +KeyserverSelectionBottomSheet: KeyserverSelectionBottomSheetParams, +ConnectFarcasterBottomSheet: void, + +CreateMissingSIWEBackupMessage: void, }; export type MessageTooltipRouteNames = diff --git a/native/root.react.js b/native/root.react.js --- a/native/root.react.js +++ b/native/root.react.js @@ -40,6 +40,7 @@ import { TunnelbrokerProvider } from 'lib/tunnelbroker/tunnelbroker-context.js'; import { actionLogger } from 'lib/utils/action-logger.js'; +import { MissingRegistrationDataHandler } from './account/registration/missing-registration-data/missing-registration-data-handler.react.js'; import { RegistrationContextProvider } from './account/registration/registration-context-provider.react.js'; import NativeEditThreadAvatarProvider from './avatars/native-edit-thread-avatar-provider.react.js'; import BackupHandler from './backup/backup-handler.js'; @@ -298,6 +299,7 @@ + );