Skip to content

Commit

Permalink
fix: grace period ownership warning
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jun 27, 2024
1 parent 521b5cd commit d8da818
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
4 changes: 0 additions & 4 deletions e2e/specs/stateless/extendNames.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 1 addition & 2 deletions src/components/ProfileSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -195,7 +194,7 @@ export const ProfileSnippet = ({
onClick={() => {
showExtendNamesInput(`extend-names-${name}`, {
names: [name],
isSelf: shouldShowExtendWarning(abilities.data),
isSelf: abilities.data?.canSelfExtend,
})
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
Expand All @@ -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 [
Expand All @@ -48,7 +59,7 @@ export const useExpiryActions = ({
onClick: () => {
showExtendNamesInput(`extend-names-${name}`, {
names: [name],
isSelf,
isSelf: isSelfExtendable({ ownerData, wrapperData, address }),
})
},
},
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/abilities/useAbilities.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -16,6 +17,7 @@ import { getSendAbilities } from './utils/getSendAbilities'

type ExtendAbilities = {
canExtend: boolean
canSelfExtend: boolean
}

export type DeleteAbilities = {
Expand Down Expand Up @@ -68,6 +70,7 @@ export type Abilities = ExtendAbilities &

export const DEFAULT_ABILITIES: Abilities = {
canExtend: false,
canSelfExtend: false,
canDelete: false,
canEdit: false,
canEditRecords: false,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useBasicName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions test/mock/makeMockUseAbilitiesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -487,6 +497,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => {
),
() => ({
canExtend: false,
canSelfExtend: false,
canSend: false,
canSendOwner: false,
canSendManager: false,
Expand All @@ -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,
Expand Down Expand Up @@ -530,6 +542,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => {
),
() => ({
canExtend: false,
canSelfExtend: false,
canSend: true,
canSendOwner: false,
canSendManager: true,
Expand Down Expand Up @@ -557,6 +570,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => {
),
() => ({
canExtend: false,
canSelfExtend: false,
canSend: true,
canSendOwner: false,
canSendManager: true,
Expand All @@ -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,
Expand All @@ -599,6 +614,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => {
),
() => ({
canExtend: false,
canSelfExtend: false,
canSend: false,
canSendOwner: false,
canSendManager: false,
Expand Down Expand Up @@ -629,6 +645,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => {
),
() => ({
canExtend: false,
canSelfExtend: false,
canSend: true,
canSendOwner: false,
canSendManager: true,
Expand Down Expand Up @@ -657,6 +674,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => {
),
() => ({
canExtend: false,
canSelfExtend: false,
canSend: false,
canSendOwner: false,
canSendManager: false,
Expand All @@ -682,6 +700,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => {
),
() => ({
canExtend: false,
canSelfExtend: false,
canSend: true,
canSendOwner: false,
canSendManager: true,
Expand Down Expand Up @@ -710,6 +729,7 @@ export const makeMockUseAbilitiesData = (type: MockUseAbilitiesType) => {
),
() => ({
canExtend: false,
canSelfExtend: false,
canSend: true,
canSendOwner: true,
canSendManager: false,
Expand All @@ -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,
Expand Down

0 comments on commit d8da818

Please sign in to comment.