diff --git a/native/account/registration/connect-farcaster.react.js b/native/account/registration/connect-farcaster.react.js index 5bc768a35..121654a2b 100644 --- a/native/account/registration/connect-farcaster.react.js +++ b/native/account/registration/connect-farcaster.react.js @@ -1,131 +1,144 @@ // @flow +import invariant from 'invariant'; import * as React from 'react'; import RegistrationButtonContainer from './registration-button-container.react.js'; 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, EthereumAccountSelection, } from './registration-types.js'; import FarcasterPrompt from '../../components/farcaster-prompt.react.js'; import FarcasterWebView from '../../components/farcaster-web-view.react.js'; import type { FarcasterWebViewState } from '../../components/farcaster-web-view.react.js'; import { type NavigationRoute, UsernameSelectionRouteName, AvatarSelectionRouteName, } from '../../navigation/route-names.js'; export type ConnectFarcasterParams = { +userSelections: { +coolOrNerdMode: CoolOrNerdMode, +keyserverURL: string, +ethereumAccount?: EthereumAccountSelection, }, }; type Props = { +navigation: RegistrationNavigationProp<'ConnectFarcaster'>, +route: NavigationRoute<'ConnectFarcaster'>, }; function ConnectFarcaster(prop: Props): React.Node { const { navigation, route } = prop; const { navigate } = navigation; const { params } = route; + const registrationContext = React.useContext(RegistrationContext); + invariant(registrationContext, 'registrationContext should be set'); + const { setCachedSelections } = registrationContext; + const [webViewState, setWebViewState] = React.useState('closed'); const goToNextStep = React.useCallback( (fid?: ?string) => { setWebViewState('closed'); const { ethereumAccount, ...restUserSelections } = params.userSelections; if (ethereumAccount) { navigate<'AvatarSelection'>({ name: AvatarSelectionRouteName, params: { ...params, userSelections: { ...restUserSelections, accountSelection: ethereumAccount, farcasterID: fid, }, }, }); } else { navigate<'UsernameSelection'>({ name: UsernameSelectionRouteName, params: { ...params, userSelections: { ...restUserSelections, farcasterID: fid, }, }, }); } }, [navigate, params], ); const onSkip = React.useCallback(() => goToNextStep(), [goToNextStep]); - const onSuccess = React.useCallback(() => { - // TODO: implement onSuccess - }, []); + const onSuccess = React.useCallback( + (fid: string) => { + goToNextStep(fid); + setCachedSelections(oldUserSelections => ({ + ...oldUserSelections, + farcasterID: fid, + })); + }, + [goToNextStep, setCachedSelections], + ); const onPressConnectFarcaster = React.useCallback(() => { setWebViewState('opening'); }, []); const connectButtonVariant = webViewState === 'opening' ? 'loading' : 'enabled'; const connectFarcaster = React.useMemo( () => ( ), [ connectButtonVariant, onPressConnectFarcaster, onSkip, onSuccess, webViewState, ], ); return connectFarcaster; } const styles = { scrollViewContentContainer: { flexGrow: 1, }, }; export default ConnectFarcaster; diff --git a/native/account/registration/registration-types.js b/native/account/registration/registration-types.js index 1a36fa70f..6e2dc6ad5 100644 --- a/native/account/registration/registration-types.js +++ b/native/account/registration/registration-types.js @@ -1,63 +1,64 @@ // @flow import type { UpdateUserAvatarRequest, 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'; export type CoolOrNerdMode = 'cool' | 'nerd'; export type EthereumAccountSelection = { +accountType: 'ethereum', ...SIWEResult, +avatarURI: ?string, }; export type UsernameAccountSelection = { +accountType: 'username', +username: string, +password: string, }; export type AccountSelection = | EthereumAccountSelection | UsernameAccountSelection; export type AvatarData = | { +needsUpload: true, +mediaSelection: NativeMediaSelection, +clientAvatar: ClientAvatar, } | { +needsUpload: false, +updateUserAvatarRequest: UpdateUserAvatarRequest, +clientAvatar: ClientAvatar, }; export type RegistrationServerCallInput = { +coolOrNerdMode: CoolOrNerdMode, +keyserverURL: string, +farcasterID: ?string, +accountSelection: AccountSelection, +avatarData: ?AvatarData, }; export type CachedUserSelections = { +coolOrNerdMode?: CoolOrNerdMode, +keyserverURL?: string, +username?: string, +password?: string, +avatarData?: ?AvatarData, +ethereumAccount?: EthereumAccountSelection, + +farcasterID?: string, }; export const ensAvatarSelection: AvatarData = { needsUpload: false, updateUserAvatarRequest: { type: 'ens' }, clientAvatar: { type: 'ens' }, }; export const enableNewRegistrationMode = __DEV__;