From d8da818d26a68e61ca436a68bf4a76759bc98556 Mon Sep 17 00:00:00 2001 From: tate Date: Thu, 27 Jun 2024 13:13:10 +1000 Subject: [PATCH] fix: grace period ownership warning --- e2e/specs/stateless/extendNames.spec.ts | 4 ---- src/components/ProfileSnippet.tsx | 3 +-- .../hooks/useOwnershipWarning.tsx | 1 + .../ExpirySection/hooks/useExpiryActions.tsx | 17 ++++++++++++--- src/hooks/abilities/useAbilities.ts | 7 ++++++- src/hooks/useBasicName.ts | 2 ++ test/mock/makeMockUseAbilitiesData.ts | 21 +++++++++++++++++++ 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/e2e/specs/stateless/extendNames.spec.ts b/e2e/specs/stateless/extendNames.spec.ts index 14332071e..fb682eadc 100644 --- a/e2e/specs/stateless/extendNames.spec.ts +++ b/e2e/specs/stateless/extendNames.spec.ts @@ -178,10 +178,6 @@ test('should be able to extend a single unwrapped name in grace period from prof await profilePage.getExtendButton.click() const extendNamesModal = makePageObject('ExtendNamesModal') - await test.step('should show warning message', async () => { - await expect(page.getByText('You do not own this name')).toBeVisible() - await page.getByRole('button', { name: 'I understand' }).click() - }) await test.step('should show the correct price data', async () => { await expect(extendNamesModal.getInvoiceExtensionFee).toContainText('0.0033') diff --git a/src/components/ProfileSnippet.tsx b/src/components/ProfileSnippet.tsx index 99ce0f3ef..0cdd2b515 100644 --- a/src/components/ProfileSnippet.tsx +++ b/src/components/ProfileSnippet.tsx @@ -8,7 +8,6 @@ import FastForwardSVG from '@app/assets/FastForward.svg' import { useAbilities } from '@app/hooks/abilities/useAbilities' import { useBeautifiedName } from '@app/hooks/useBeautifiedName' import { useRouterWithHistory } from '@app/hooks/useRouterWithHistory' -import { shouldShowExtendWarning } from '@app/utils/abilities/shouldShowExtendWarning' import { useTransactionFlow } from '../transaction-flow/TransactionFlowProvider' import { NameAvatar } from './AvatarWithZorb' @@ -195,7 +194,7 @@ export const ProfileSnippet = ({ onClick={() => { showExtendNamesInput(`extend-names-${name}`, { names: [name], - isSelf: shouldShowExtendWarning(abilities.data), + isSelf: abilities.data?.canSelfExtend, }) }} > diff --git a/src/components/pages/profile/[name]/tabs/OwnershipTab/hooks/useOwnershipWarning.tsx b/src/components/pages/profile/[name]/tabs/OwnershipTab/hooks/useOwnershipWarning.tsx index 104397773..c31823621 100644 --- a/src/components/pages/profile/[name]/tabs/OwnershipTab/hooks/useOwnershipWarning.tsx +++ b/src/components/pages/profile/[name]/tabs/OwnershipTab/hooks/useOwnershipWarning.tsx @@ -22,6 +22,7 @@ export const useOwnershipWarning = ({ name, nameType, details }: Input) => { const data = useMemo(() => { if (isLoading) return undefined + console.log(details.ownerData?.registrant, account.address) return match([ nameType.data, { diff --git a/src/components/pages/profile/[name]/tabs/OwnershipTab/sections/ExpirySection/hooks/useExpiryActions.tsx b/src/components/pages/profile/[name]/tabs/OwnershipTab/sections/ExpirySection/hooks/useExpiryActions.tsx index ca1ccfac0..e18995637 100644 --- a/src/components/pages/profile/[name]/tabs/OwnershipTab/sections/ExpirySection/hooks/useExpiryActions.tsx +++ b/src/components/pages/profile/[name]/tabs/OwnershipTab/sections/ExpirySection/hooks/useExpiryActions.tsx @@ -1,4 +1,5 @@ import { useTranslation } from 'react-i18next' +import type { Address } from 'viem' import { useAccount } from 'wagmi' import { GetOwnerReturnType, GetWrapperDataReturnType } from '@ensdomains/ensjs/public' @@ -9,6 +10,18 @@ import { nameLevel } from '@app/utils/name' import type { useExpiryDetails } from './useExpiryDetails' +export const isSelfExtendable = ({ + ownerData, + wrapperData, + address, +}: { + ownerData?: GetOwnerReturnType + wrapperData?: GetWrapperDataReturnType + address?: Address +}) => { + return ownerData?.registrant === address || wrapperData?.owner === address +} + export const useExpiryActions = ({ name, expiryDetails, @@ -28,8 +41,6 @@ export const useExpiryActions = ({ // TODO: remove this when we add support for extending wrapped subnames const is2ld = nameLevel(name) === '2ld' - const isSelf = ownerData?.registrant === address || wrapperData?.owner === address - const expiryDate = expiryDetails?.find(({ type }) => type === 'expiry')?.date if (!expiryDate || !is2ld) return null return [ @@ -48,7 +59,7 @@ export const useExpiryActions = ({ onClick: () => { showExtendNamesInput(`extend-names-${name}`, { names: [name], - isSelf, + isSelf: isSelfExtendable({ ownerData, wrapperData, address }), }) }, }, diff --git a/src/hooks/abilities/useAbilities.ts b/src/hooks/abilities/useAbilities.ts index a4c2b8801..4b6bf981b 100644 --- a/src/hooks/abilities/useAbilities.ts +++ b/src/hooks/abilities/useAbilities.ts @@ -1,6 +1,7 @@ import { useMemo } from 'react' import { useTranslation } from 'react-i18next' +import { isSelfExtendable } from '@app/components/pages/profile/[name]/tabs/OwnershipTab/sections/ExpirySection/hooks/useExpiryActions' import { checkETH2LDFromName } from '@app/utils/utils' import { useAccountSafely } from '../account/useAccountSafely' @@ -16,6 +17,7 @@ import { getSendAbilities } from './utils/getSendAbilities' type ExtendAbilities = { canExtend: boolean + canSelfExtend: boolean } export type DeleteAbilities = { @@ -68,6 +70,7 @@ export type Abilities = ExtendAbilities & export const DEFAULT_ABILITIES: Abilities = { canExtend: false, + canSelfExtend: false, canDelete: false, canEdit: false, canEditRecords: false, @@ -125,8 +128,10 @@ export const useAbilities = ({ name, enabled = true }: UseAbilitiesParameters) = const data: Abilities | undefined = useMemo( () => { if (!name || !address || isLoading) return DEFAULT_ABILITIES + const canExtend = !!name && checkETH2LDFromName(name) return { - canExtend: !!name && checkETH2LDFromName(name), + canExtend, + canSelfExtend: canExtend && isSelfExtendable({ ...basicNameData, address }), ...getSendAbilities({ name, address, diff --git a/src/hooks/useBasicName.ts b/src/hooks/useBasicName.ts index c9535baac..eb8dba4ac 100644 --- a/src/hooks/useBasicName.ts +++ b/src/hooks/useBasicName.ts @@ -154,10 +154,12 @@ export const useBasicName = ({ }) const ownerDataWithSubgraphRegistrant = useMemo(() => { + // console.log(ownerData) if (!ownerData) return ownerData const checkSumSubgraphRegistrant = subgraphRegistrant ? getAddress(subgraphRegistrant) : undefined + // console.log(checkSumSubgraphRegistrant) return { ...ownerData, registrant: ownerData?.registrant ?? checkSumSubgraphRegistrant, diff --git a/test/mock/makeMockUseAbilitiesData.ts b/test/mock/makeMockUseAbilitiesData.ts index f7b1fd97e..3749bef6a 100644 --- a/test/mock/makeMockUseAbilitiesData.ts +++ b/test/mock/makeMockUseAbilitiesData.ts @@ -317,6 +317,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { return match(type) .with(P.union('eth-unwrapped-2ld'), () => ({ canExtend: true, + canSelfExtend: true, canSend: true, canSendOwner: true, canSendManager: true, @@ -335,6 +336,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { })) .with(P.union('eth-unwrapped-2ld:owner'), () => ({ canExtend: true, + canSelfExtend: true, canSend: true, canSendOwner: true, canSendManager: true, @@ -353,6 +355,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { })) .with(P.union('eth-unwrapped-2ld:manager'), () => ({ canExtend: true, + canSelfExtend: false, canSend: true, canSendOwner: false, canSendManager: true, @@ -368,6 +371,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { })) .with(P.union('eth-unwrapped-2ld:unowned', 'eth-emancipated-2ld:unowned'), () => ({ canExtend: true, + canSelfExtend: false, canSend: false, canSendOwner: false, canSendManager: false, @@ -382,6 +386,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { })) .with(P.union('eth-unwrapped-2ld:grace-period'), () => ({ canExtend: true, + canSelfExtend: true, canSend: false, canSendOwner: false, canSendManager: false, @@ -397,6 +402,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { })) .with(P.union('eth-emancipated-2ld'), () => ({ canExtend: true, + canSelfExtend: true, canSend: true, canSendOwner: true, canSendManager: false, @@ -414,6 +420,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { })) .with(P.union('eth-emancipated-2ld:grace-period'), () => ({ canExtend: true, + canSelfExtend: true, canSend: false, canSendOwner: false, canSendManager: false, @@ -431,6 +438,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { })) .with(P.union('eth-burnt-2ld'), () => ({ canExtend: true, + canSelfExtend: true, canSend: false, canSendOwner: false, canSendManager: false, @@ -448,6 +456,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { })) .with(P.union('eth-burnt-2ld:unowned'), () => ({ canExtend: true, + canSelfExtend: false, canSend: false, canSendOwner: false, canSendManager: false, @@ -463,6 +472,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { })) .with(P.union('dns-unwrapped-2ld', 'dns-unwrapped-2ld:manager'), () => ({ canExtend: false, + canSelfExtend: false, canSend: true, canSendOwner: false, canSendManager: true, @@ -487,6 +497,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ), () => ({ canExtend: false, + canSelfExtend: false, canSend: false, canSendOwner: false, canSendManager: false, @@ -502,6 +513,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ) .with(P.union('dns-wrappped-2ld'), () => ({ canExtend: false, + canSelfExtend: false, canSend: true, canSendOwner: false, canSendManager: true, @@ -530,6 +542,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ), () => ({ canExtend: false, + canSelfExtend: false, canSend: true, canSendOwner: false, canSendManager: true, @@ -557,6 +570,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ), () => ({ canExtend: false, + canSelfExtend: false, canSend: true, canSendOwner: false, canSendManager: true, @@ -579,6 +593,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ) .with(P.union('eth-unwrapped-subname:unowned+unwrapped-2ld:owner'), () => ({ canExtend: false, + canSelfExtend: false, canSend: false, canSendOwner: false, canSendManager: false, @@ -599,6 +614,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ), () => ({ canExtend: false, + canSelfExtend: false, canSend: false, canSendOwner: false, canSendManager: false, @@ -629,6 +645,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ), () => ({ canExtend: false, + canSelfExtend: false, canSend: true, canSendOwner: false, canSendManager: true, @@ -657,6 +674,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ), () => ({ canExtend: false, + canSelfExtend: false, canSend: false, canSendOwner: false, canSendManager: false, @@ -682,6 +700,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ), () => ({ canExtend: false, + canSelfExtend: false, canSend: true, canSendOwner: false, canSendManager: true, @@ -710,6 +729,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ), () => ({ canExtend: false, + canSelfExtend: false, canSend: true, canSendOwner: true, canSendManager: false, @@ -732,6 +752,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => { ) .with(P.union('eth-emancipated-subname+locked-2ld:grace-period:unowned'), () => ({ canExtend: false, + canSelfExtend: false, canSend: false, canSendOwner: false, canSendManager: false,