Changeset View
Changeset View
Standalone View
Standalone View
native/account/registration/connect-ethereum.react.js
// @flow | // @flow | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { Text, View } from 'react-native'; | import { Text, View } from 'react-native'; | ||||
import { | import { | ||||
exactSearchUser, | exactSearchUser, | ||||
exactSearchUserActionTypes, | exactSearchUserActionTypes, | ||||
} from 'lib/actions/user-actions.js'; | } from 'lib/actions/user-actions.js'; | ||||
import { ENSCacheContext } from 'lib/components/ens-cache-provider.react.js'; | |||||
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; | import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; | ||||
import type { SIWEResult } from 'lib/types/siwe-types.js'; | import type { SIWEResult } from 'lib/types/siwe-types.js'; | ||||
import { | import { | ||||
useServerCall, | useServerCall, | ||||
useDispatchActionPromise, | useDispatchActionPromise, | ||||
} from 'lib/utils/action-utils.js'; | } from 'lib/utils/action-utils.js'; | ||||
import RegistrationButtonContainer from './registration-button-container.react.js'; | import RegistrationButtonContainer from './registration-button-container.react.js'; | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | navigate<'UsernameSelection'>({ | ||||
name: UsernameSelectionRouteName, | name: UsernameSelectionRouteName, | ||||
params, | params, | ||||
}); | }); | ||||
}, [navigate, params]); | }, [navigate, params]); | ||||
const exactSearchUserCall = useServerCall(exactSearchUser); | const exactSearchUserCall = useServerCall(exactSearchUser); | ||||
const dispatchActionPromise = useDispatchActionPromise(); | const dispatchActionPromise = useDispatchActionPromise(); | ||||
const cacheContext = React.useContext(ENSCacheContext); | |||||
const { ensCache } = cacheContext; | |||||
const onSuccessfulWalletSignature = React.useCallback( | const onSuccessfulWalletSignature = React.useCallback( | ||||
async (result: SIWEResult) => { | async (result: SIWEResult) => { | ||||
const searchPromise = exactSearchUserCall(result.address); | const searchPromise = exactSearchUserCall(result.address); | ||||
dispatchActionPromise(exactSearchUserActionTypes, searchPromise); | dispatchActionPromise(exactSearchUserActionTypes, searchPromise); | ||||
// We want to figure out if the user has an ENS avatar now | |||||
// so that we can default to the ENS avatar in AvatarSelection | |||||
const avatarURIPromise = (async () => { | |||||
if (!ensCache) { | |||||
return null; | |||||
} | |||||
return await ensCache.getAvatarURIForAddress(result.address); | |||||
})(); | |||||
const { userInfo } = await searchPromise; | const { userInfo } = await searchPromise; | ||||
if (userInfo) { | if (userInfo) { | ||||
navigate<'ExistingEthereumAccount'>({ | navigate<'ExistingEthereumAccount'>({ | ||||
name: ExistingEthereumAccountRouteName, | name: ExistingEthereumAccountRouteName, | ||||
params: result, | params: result, | ||||
}); | }); | ||||
return; | return; | ||||
} | } | ||||
const avatarURI = await avatarURIPromise; | |||||
const newUserSelections = { | const newUserSelections = { | ||||
...userSelections, | ...userSelections, | ||||
accountSelections: { | accountSelections: { | ||||
accountType: 'ethereum', | accountType: 'ethereum', | ||||
...result, | ...result, | ||||
avatarURI, | |||||
}, | }, | ||||
}; | }; | ||||
navigate<'AvatarSelection'>({ | navigate<'AvatarSelection'>({ | ||||
name: AvatarSelectionRouteName, | name: AvatarSelectionRouteName, | ||||
params: { userSelections: newUserSelections }, | params: { userSelections: newUserSelections }, | ||||
}); | }); | ||||
}, | }, | ||||
[userSelections, exactSearchUserCall, dispatchActionPromise, navigate], | [ | ||||
userSelections, | |||||
exactSearchUserCall, | |||||
dispatchActionPromise, | |||||
navigate, | |||||
ensCache, | |||||
], | |||||
); | ); | ||||
let siwePanel; | let siwePanel; | ||||
if (panelState !== 'closed') { | if (panelState !== 'closed') { | ||||
siwePanel = ( | siwePanel = ( | ||||
<SIWEPanel | <SIWEPanel | ||||
onClosing={onPanelClosing} | onClosing={onPanelClosing} | ||||
onClosed={onPanelClosed} | onClosed={onPanelClosed} | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |