From e0af666d3aaff1c0375f6f0c80d9093fe37462ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Galley?= Date: Mon, 26 Aug 2024 17:00:00 -0400 Subject: [PATCH] rename --- .../UsernameProfileSettingsName/index.tsx | 2 +- apps/web/src/hooks/useSetPrimaryBasename.ts | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/apps/web/src/components/Basenames/UsernameProfileSettingsName/index.tsx b/apps/web/src/components/Basenames/UsernameProfileSettingsName/index.tsx index f24b61408b..49960dfaae 100644 --- a/apps/web/src/components/Basenames/UsernameProfileSettingsName/index.tsx +++ b/apps/web/src/components/Basenames/UsernameProfileSettingsName/index.tsx @@ -21,7 +21,7 @@ export default function UsernameProfileSettingsName() { isLoading: setPrimaryNameIsLoading, canSetUsernameAsPrimary, } = useSetPrimaryBasename({ - basename: profileUsername, + secondaryUsername: profileUsername, }); // Error & Analytics diff --git a/apps/web/src/hooks/useSetPrimaryBasename.ts b/apps/web/src/hooks/useSetPrimaryBasename.ts index 9cf1fbfd99..416b7e3ab4 100644 --- a/apps/web/src/hooks/useSetPrimaryBasename.ts +++ b/apps/web/src/hooks/useSetPrimaryBasename.ts @@ -22,15 +22,15 @@ import { useUsernameProfile } from 'apps/web/src/components/Basenames/UsernamePr */ type UseSetPrimaryBasenameProps = { - basename: BaseName; + secondaryUsername: BaseName; }; -export default function useSetPrimaryBasename({ basename }: UseSetPrimaryBasenameProps) { +export default function useSetPrimaryBasename({ secondaryUsername }: UseSetPrimaryBasenameProps) { const { address } = useAccount(); const { logError } = useErrors(); const { currentWalletIsProfileOwner } = useUsernameProfile(); - const { basenameChain: secondaryBaseChain } = useBasenameChain(basename); + const { basenameChain: secondaryUsernameChain } = useBasenameChain(secondaryUsername); // Get current primary username // Note: This is sometimes undefined @@ -43,12 +43,12 @@ export default function useSetPrimaryBasename({ basename }: UseSetPrimaryBasenam address: address, }); - const usernamesDiffer = basename !== primaryUsername; + const usernamesDiffer = secondaryUsername !== primaryUsername; const canSetUsernameAsPrimary = usernamesDiffer && currentWalletIsProfileOwner; const { initiateTransaction, transactionIsLoading, transactionIsSuccess } = useWriteContractWithReceipt({ - chain: secondaryBaseChain, + chain: secondaryUsernameChain, eventName: 'update_primary_name', }); @@ -62,7 +62,7 @@ export default function useSetPrimaryBasename({ basename }: UseSetPrimaryBasenam const setPrimaryName = useCallback(async () => { // Already primary - if (basename === primaryUsername) return; + if (secondaryUsername === primaryUsername) return; // No user is connected if (!address) return; @@ -70,8 +70,13 @@ export default function useSetPrimaryBasename({ basename }: UseSetPrimaryBasenam try { await initiateTransaction({ abi: ReverseRegistrarAbi, - address: USERNAME_REVERSE_REGISTRAR_ADDRESSES[secondaryBaseChain.id], - args: [address, address, USERNAME_L2_RESOLVER_ADDRESSES[secondaryBaseChain.id], basename], + address: USERNAME_REVERSE_REGISTRAR_ADDRESSES[secondaryUsernameChain.id], + args: [ + address, + address, + USERNAME_L2_RESOLVER_ADDRESSES[secondaryUsernameChain.id], + secondaryUsername, + ], functionName: 'setNameForAddr', }); } catch (error) { @@ -79,7 +84,14 @@ export default function useSetPrimaryBasename({ basename }: UseSetPrimaryBasenam } return true; - }, [basename, primaryUsername, address, initiateTransaction, secondaryBaseChain.id, logError]); + }, [ + secondaryUsername, + primaryUsername, + address, + initiateTransaction, + secondaryUsernameChain.id, + logError, + ]); const isLoading = transactionIsLoading || primaryUsernameIsLoading || primaryUsernameIsFetching;