From ca22bfd60f028b9aa508b4d37ec4b0ffb54a9080 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri <1247834+brunobar79@users.noreply.github.com> Date: Fri, 7 Jun 2024 14:26:57 -0400 Subject: [PATCH] reorg ens related calls (#5828) --- src/components/cards/ENSCreateProfileCard.tsx | 22 +++++++++---------- src/hooks/useOnAvatarPress.ts | 14 +++++------- src/redux/wallets.ts | 2 -- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/components/cards/ENSCreateProfileCard.tsx b/src/components/cards/ENSCreateProfileCard.tsx index c04936b76ec..e905091f6de 100644 --- a/src/components/cards/ENSCreateProfileCard.tsx +++ b/src/components/cards/ENSCreateProfileCard.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useCallback, useEffect } from 'react'; import ENSAvatarGrid from '../../assets/ensAvatarGrid.png'; import ENSIcon from '../../assets/ensIcon.png'; import { useNavigation } from '../../navigation/Navigation'; @@ -33,8 +33,15 @@ export const ENSCreateProfileCard = () => { // 40 represents the horizontal padding outside the card const imageWidth = deviceWidth - 40; - const handlePress = () => { + const { uniqueDomain } = useAccountENSDomains(); + + const handlePress = useCallback(() => { if (!isReadOnlyWallet || enableActionsOnReadOnlyWallet) { + if (uniqueDomain?.name) { + prefetchENSAvatar(uniqueDomain.name); + prefetchENSRecords(uniqueDomain.name); + } + analyticsV2.track(analyticsV2.event.cardPressed, { cardName: 'ENSCreateProfileCard', routeName, @@ -46,16 +53,7 @@ export const ENSCreateProfileCard = () => { } else { watchingAlert(); } - }; - - const { uniqueDomain } = useAccountENSDomains(); - - useEffect(() => { - if (uniqueDomain?.name) { - prefetchENSAvatar(uniqueDomain.name); - prefetchENSRecords(uniqueDomain.name); - } - }, [uniqueDomain]); + }, [isReadOnlyWallet, navigate, routeName, uniqueDomain?.name]); return ( diff --git a/src/hooks/useOnAvatarPress.ts b/src/hooks/useOnAvatarPress.ts index cf47929b0ea..4c7323bcf24 100644 --- a/src/hooks/useOnAvatarPress.ts +++ b/src/hooks/useOnAvatarPress.ts @@ -54,14 +54,6 @@ export default ({ screenType = 'transaction' }: UseOnAvatarPressProps = {}) => { const { startRegistration } = useENSRegistration(); const { setNextEmoji } = useUpdateEmoji(); - useEffect(() => { - if (accountENS) { - prefetchENSAvatar(accountENS); - prefetchENSCover(accountENS); - prefetchENSRecords(accountENS); - } - }, [accountENS]); - const onAvatarRemovePhoto = useCallback(async () => { const newWallets: typeof wallets = { ...wallets, @@ -256,6 +248,12 @@ export default ({ screenType = 'transaction' }: UseOnAvatarPressProps = {}) => { }, [accountENS, navigate]); const onAvatarPress = useCallback(() => { + if (accountENS) { + prefetchENSAvatar(accountENS); + prefetchENSCover(accountENS); + prefetchENSRecords(accountENS); + } + if (hasENSAvatar && accountENS) { onAvatarPressProfile(); } else { diff --git a/src/redux/wallets.ts b/src/redux/wallets.ts index ea733c8706f..519223b54c3 100644 --- a/src/redux/wallets.ts +++ b/src/redux/wallets.ts @@ -207,8 +207,6 @@ export const walletsLoadState = type: WALLETS_LOAD, }); - dispatch(fetchWalletNames()); - profilesEnabled && dispatch(fetchWalletENSAvatars()); return wallets; } catch (error) { logger.error(new RainbowError('Exception during walletsLoadState'), {