diff --git a/native/account/registration/avatar-selection.react.js b/native/account/registration/avatar-selection.react.js
--- a/native/account/registration/avatar-selection.react.js
+++ b/native/account/registration/avatar-selection.react.js
@@ -28,6 +28,7 @@
type EthereumAccountSelections = {
+accountType: 'ethereum',
...SIWEResult,
+ +avatarURI: ?string,
};
type UsernameAccountSelections = {
@@ -56,6 +57,12 @@
+clientAvatar: ClientAvatar,
};
+const ensDefaultSelection = {
+ needsUpload: false,
+ updateUserAvatarRequest: { type: 'ens' },
+ clientAvatar: { type: 'ens' },
+};
+
type Props = {
+navigation: RegistrationNavigationProp<'AvatarSelection'>,
+route: NavigationRoute<'AvatarSelection'>,
@@ -72,7 +79,15 @@
invariant(editUserAvatarContext, 'editUserAvatarContext should be set');
const { setRegistrationMode } = editUserAvatarContext;
- const [avatarData, setAvatarData] = React.useState();
+ const prefetchedAvatarURI =
+ accountSelections.accountType === 'ethereum'
+ ? accountSelections.avatarURI
+ : undefined;
+
+ const [avatarData, setAvatarData] = React.useState(
+ prefetchedAvatarURI ? ensDefaultSelection : undefined,
+ );
+
const setClientAvatarFromSelection = React.useCallback(
(selection: UserAvatarSelection) => {
if (selection.needsUpload) {
@@ -128,7 +143,11 @@
Pick an avatar
-
+
diff --git a/native/account/registration/connect-ethereum.react.js b/native/account/registration/connect-ethereum.react.js
--- a/native/account/registration/connect-ethereum.react.js
+++ b/native/account/registration/connect-ethereum.react.js
@@ -7,6 +7,7 @@
exactSearchUser,
exactSearchUserActionTypes,
} 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 type { SIWEResult } from 'lib/types/siwe-types.js';
import {
@@ -127,10 +128,23 @@
const exactSearchUserCall = useServerCall(exactSearchUser);
const dispatchActionPromise = useDispatchActionPromise();
+ const cacheContext = React.useContext(ENSCacheContext);
+ const { ensCache } = cacheContext;
+
const onSuccessfulWalletSignature = React.useCallback(
async (result: SIWEResult) => {
const searchPromise = exactSearchUserCall(result.address);
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;
if (userInfo) {
@@ -141,11 +155,14 @@
return;
}
+ const avatarURI = await avatarURIPromise;
+
const newUserSelections = {
...userSelections,
accountSelections: {
accountType: 'ethereum',
...result,
+ avatarURI,
},
};
navigate<'AvatarSelection'>({
@@ -153,7 +170,13 @@
params: { userSelections: newUserSelections },
});
},
- [userSelections, exactSearchUserCall, dispatchActionPromise, navigate],
+ [
+ userSelections,
+ exactSearchUserCall,
+ dispatchActionPromise,
+ navigate,
+ ensCache,
+ ],
);
let siwePanel;
diff --git a/native/avatars/edit-user-avatar.react.js b/native/avatars/edit-user-avatar.react.js
--- a/native/avatars/edit-user-avatar.react.js
+++ b/native/avatars/edit-user-avatar.react.js
@@ -24,7 +24,11 @@
type Props =
| { +userID: ?string, +disabled?: boolean }
- | { +userInfo: ?GenericUserInfoWithAvatar, +disabled?: boolean };
+ | {
+ +userInfo: ?GenericUserInfoWithAvatar,
+ +disabled?: boolean,
+ +prefetchedAvatarURI: ?string,
+ };
function EditUserAvatar(props: Props): React.Node {
const editUserAvatarContext = React.useContext(EditUserAvatarContext);
invariant(editUserAvatarContext, 'editUserAvatarContext should be set');
@@ -43,7 +47,8 @@
() => getETHAddressForUserInfo(userInfo),
[userInfo],
);
- const ensAvatarURI = useENSAvatar(ethAddress);
+ const fetchedENSAvatarURI = useENSAvatar(ethAddress);
+ const ensAvatarURI = fetchedENSAvatarURI ?? props.prefetchedAvatarURI;
const { navigate } = useNavigation();