Skip to content

Commit

Permalink
fix: remove primary name flow if manager transfer is required
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Mar 28, 2024
1 parent eba13b7 commit 47c311b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
27 changes: 22 additions & 5 deletions src/utils/checkAvailablePrimaryName.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { describe, expect, it } from 'vitest'

import { GetOwnerReturnType, GetWrapperDataReturnType } from '@ensdomains/ensjs/public'

import { checkAvailablePrimaryName } from './checkAvailablePrimaryName'
import { GetOwnerReturnType, GetWrapperDataReturnType } from '@ensdomains/ensjs/public'

describe('checkAvailablePrimaryName', () => {

it('should return true for offchain names with resolved address of user', () => {
const address = '0x189fa72c8959aa18bea737d46c10826de4ef81a2'
const ownerData = undefined as GetOwnerReturnType | undefined
const profile = { address, isMigrated: undefined }
const wrappedData = undefined as GetWrapperDataReturnType | undefined

const result = checkAvailablePrimaryName('primary.eth', {
isAuthorized: true
isAuthorized: true,
} as any)({
name: 'name.eth',
relation: {
Expand All @@ -24,8 +23,26 @@ describe('checkAvailablePrimaryName', () => {
},
isMigrated: profile?.isMigrated !== false,
expiryDate: undefined,
fuses: null
fuses: null,
})
expect(result).toBe(true)
})
})
it('should return false for name where registrant is user, but nothing else', () => {
const result = checkAvailablePrimaryName(null, {
// this value would be false but is irrelevant
isAuthorized: true,
} as any)({
name: 'name.eth',
relation: {
owner: false,
registrant: true,
resolvedAddress: false,
wrappedOwner: false,
},
isMigrated: true,
expiryDate: undefined,
fuses: null,
})
expect(result).toBe(false)
})
})
5 changes: 2 additions & 3 deletions src/utils/checkAvailablePrimaryName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ const isNotTLD = (n: Pick<CheckPrimaryNameInputName, 'name'>) =>
n.name ? n.name.split('.').length > 1 : false

const isResolvedOrManagedName = ({
relation: { owner, registrant, resolvedAddress, wrappedOwner },
}: Pick<CheckPrimaryNameInputName, 'relation'>) =>
owner || registrant || wrappedOwner || resolvedAddress
relation: { owner, resolvedAddress, wrappedOwner },
}: Pick<CheckPrimaryNameInputName, 'relation'>) => owner || wrappedOwner || resolvedAddress

const isNotPrimaryName =
(primaryName?: string | null) => (n: Pick<CheckPrimaryNameInputName, 'name'>) =>
Expand Down

0 comments on commit 47c311b

Please sign in to comment.