diff --git a/src/hooks/useIsWrapped.ts b/src/hooks/useIsWrapped.ts new file mode 100644 index 000000000..734425ac7 --- /dev/null +++ b/src/hooks/useIsWrapped.ts @@ -0,0 +1,16 @@ +import { useOwner } from './ensjs/public/useOwner' + +type UseIsWrappedParameters = { + name: string + enabled?: boolean +} + +export const useIsWrapped = ({ name, enabled = true }: UseIsWrappedParameters) => { + const { data: ownerData, isLoading, isCachedData } = useOwner({ name, enabled }) + + return { + data: ownerData ? ownerData.ownershipLevel === 'nameWrapper' : undefined, + isLoading, + isCachedData, + } +} diff --git a/src/test-utils.tsx b/src/test-utils.tsx index 55b6db8c2..a1cfa7c1b 100644 --- a/src/test-utils.tsx +++ b/src/test-utils.tsx @@ -48,6 +48,7 @@ jest.mock('wagmi', () => { useSignTypedData: jest.fn(), useBlockNumber: jest.fn(), useSendTransaction: jest.fn(), + useEnsAvatar: jest.fn(), configureChains: jest.fn(() => ({})), } }) diff --git a/src/transaction-flow/input/ExtendNames/ExtendNames-flow.test.tsx b/src/transaction-flow/input/ExtendNames/ExtendNames-flow.test.tsx index cb95decd4..85c92e549 100644 --- a/src/transaction-flow/input/ExtendNames/ExtendNames-flow.test.tsx +++ b/src/transaction-flow/input/ExtendNames/ExtendNames-flow.test.tsx @@ -1,14 +1,14 @@ import { mockFunction, render, screen } from '@app/test-utils' -import { useEstimateGasLimitForTransactions } from '@app/hooks/gasEstimation/useEstimateGasLimitForTransactions' +import { usePrice } from '@app/hooks/ensjs/public/usePrice' +import { useEstimateGasLimitForTransaction } from '@app/hooks/gasEstimation/useEstimateGasLimitForTransactions' -import { usePrice } from '../../../hooks/usePrice' import ExtendNames from './ExtendNames-flow' -jest.mock('@app/hooks/useEstimateGasLimitForTransactions') -jest.mock('../../../hooks/usePrice') +jest.mock('@app/hooks/gasEstimation/useEstimateGasLimitForTransactions') +jest.mock('@app/hooks/ensjs/public/usePrice') -const mockUseEstimateGasLimitForTransactions = mockFunction(useEstimateGasLimitForTransactions) +const mockUseEstimateGasLimitForTransaction = mockFunction(useEstimateGasLimitForTransaction) const mockUsePrice = mockFunction(usePrice) jest.mock('@ensdomains/thorin', () => { @@ -39,16 +39,18 @@ jest.mock( ) describe('Extendnames', () => { - mockUseEstimateGasLimitForTransactions.mockReturnValue({ - gasLimit: '0x5208', + mockUseEstimateGasLimitForTransaction.mockReturnValue({ + gasLimit: 21000n, + gasPrice: 100n, error: null, isLoading: true, }) mockUsePrice.mockReturnValue({ - total: { - mul: () => 0.1, + data: { + base: 100n, + premium: 0n, }, - loading: false, + isLoading: false, }) it('should render', async () => { render( diff --git a/src/transaction-flow/input/ProfileEditor/ProfileEditor-flow.tsx b/src/transaction-flow/input/ProfileEditor/ProfileEditor-flow.tsx index f72247903..0071a108f 100644 --- a/src/transaction-flow/input/ProfileEditor/ProfileEditor-flow.tsx +++ b/src/transaction-flow/input/ProfileEditor/ProfileEditor-flow.tsx @@ -21,7 +21,8 @@ import { ProfileRecord } from '@app/constants/profileRecordOptions' import { useChainId } from '@app/hooks/chain/useChainId' import { useContractAddress } from '@app/hooks/chain/useContractAddress' import { useResolverStatus } from '@app/hooks/resolver/useResolverStatus' -import { useNameDetails } from '@app/hooks/useNameDetails' +import { useIsWrapped } from '@app/hooks/useIsWrapped' +import { useProfile } from '@app/hooks/useProfile' import { ProfileEditorForm, useProfileEditorForm } from '@app/hooks/useProfileEditorForm' import TransactionLoader from '@app/transaction-flow/TransactionLoader' import { TransactionItem, makeTransactionItem } from '@app/transaction-flow/transaction' @@ -158,7 +159,11 @@ const ProfileEditor = ({ data = {}, transactions = [], dispatch, onDismiss }: Pr const { name = '', resumable = false } = data - const { profile, isWrapped, isLoading: profileLoading } = useNameDetails({ name }) + const { data: profile, isLoading: isProfileLoading } = useProfile({ name }) + const { data: isWrapped = false, isLoading: isWrappedLoading } = useIsWrapped({ name }) + + const isLoading = isProfileLoading || isWrappedLoading + const existingRecords = profileToProfileRecords(profile) const { @@ -206,12 +211,12 @@ const ProfileEditor = ({ data = {}, transactions = [], dispatch, onDismiss }: Pr } }) } - if (!profileLoading) { + if (!isLoading) { updateProfileRecordsWithTransactionData() setIsRecordsUpdated(true) } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [profileLoading, transactions, setIsRecordsUpdated, isRecordsUpdated]) + }, [isLoading, transactions, setIsRecordsUpdated, isRecordsUpdated]) const resolverAddress = useContractAddress({ contract: 'ensPublicResolver' }) @@ -256,10 +261,10 @@ const ProfileEditor = ({ data = {}, transactions = [], dispatch, onDismiss }: Pr }, [resolverStatus.isLoading, resolverStatus.data?.hasLatestResolver, transactions.length]) useEffect(() => { - if (!profileLoading && !profile?.isMigrated) { + if (!isProfileLoading && !profile?.isMigrated) { setView('warning') } - }, [profileLoading, profile?.isMigrated]) + }, [isProfileLoading, profile?.isMigrated]) const handleDeleteRecord = (record: ProfileRecord, index: number) => { removeRecordAtIndex(index) @@ -275,7 +280,8 @@ const ProfileEditor = ({ data = {}, transactions = [], dispatch, onDismiss }: Pr ? getResolverWrapperAwareness({ chainId, resolverAddress: profile?.resolverAddress }) : false - if (profileLoading || resolverStatus.isLoading || !isRecordsUpdated) return + if (isLoading || resolverStatus.isLoading || !isRecordsUpdated) return + return ( ({ ProfileBlurb: () =>
Profile Blurb
, })) -jest.mock('@app/hooks/useAvatar') const mockUseBreakpoint = mockFunction(useBreakpoint) -const mockUseNameDetails = mockFunction(useNameDetails) const mockUseContractAddress = mockFunction(useContractAddress) const mockUseResolverStatus = mockFunction(useResolverStatus) -const mockUseNetwork = mockFunction(useNetwork) -const mockUseBasicName = mockFunction(useBasicName) const mockUseProfile = mockFunction(useProfile) +const mockUseIsWrapped = mockFunction(useIsWrapped) const mockUseQueryKeys = mockFunction(useQueryKeys) -const mockUseAvatar = mockFunction(useAvatar) +const mockUseEnsAvatar = mockFunction(useEnsAvatar) const mockDispatch = jest.fn() @@ -189,13 +172,14 @@ const makeResolverStatus = (keys?: string[], isLoading = false) => ({ isLoading, }) +beforeEach(() => { + setupIntersectionObserverMock() +}) + describe('ProfileEditor', () => { beforeEach(() => { - mockUseNameDetails.mockReturnValue( - mockProfileData as unknown as { profile: Profile; loading: boolean }, - ) - - mockUseNetwork.mockReturnValue({ chain: { id: 1 } }) + mockUseProfile.mockReturnValue(mockProfileData) + mockUseIsWrapped.mockReturnValue({ data: false, isLoading: false }) mockUseBreakpoint.mockReturnValue({ xs: true, @@ -205,7 +189,6 @@ describe('ProfileEditor', () => { xl: false, }) - setupIntersectionObserverMock() window.scroll = jest.fn() mockUseContractAddress.mockReturnValue('0x0') @@ -213,14 +196,9 @@ describe('ProfileEditor', () => { mockUseResolverStatus.mockReturnValue( makeResolverStatus(['hasResolver', 'hasLatestResolver', 'hasValidResolver']), ) - mockUseBasicName.mockReturnValue({ isWrapped: false }) - - mockUseQueryKeys.mockReturnValue({ - profile: () => ['profile', 'test.eth'], - }) - mockUseAvatar.mockReturnValue({ - avatar: 'avatar', + mockUseEnsAvatar.mockReturnValue({ + data: 'avatar', isLoading: false, }) }) @@ -254,7 +232,7 @@ describe('ResolverWarningOverlay', () => { data: { contract, name: 'test.eth', - resolver: '0x123', + resolverAddress: '0x123', }, name: 'updateResolver', }, @@ -290,7 +268,7 @@ describe('ResolverWarningOverlay', () => { data: { contract, name: 'test.eth', - resolver: '0x123', + resolverAddress: '0x123', }, name: 'updateResolver', }, @@ -320,7 +298,7 @@ describe('ResolverWarningOverlay', () => { { data: { name: 'test.eth', - resolver: '0x123', + resolverAddress: '0x123', }, name: 'resetProfile', }, @@ -328,7 +306,7 @@ describe('ResolverWarningOverlay', () => { data: { contract: 'registry', name: 'test.eth', - resolver: '0x123', + resolverAddress: '0x123', }, name: 'updateResolver', }, @@ -358,7 +336,7 @@ describe('ResolverWarningOverlay', () => { { data: { name: 'test.eth', - resolver: '0x123', + resolverAddress: '0x123', }, name: 'migrateProfileWithReset', }, @@ -366,7 +344,7 @@ describe('ResolverWarningOverlay', () => { data: { contract: 'registry', name: 'test.eth', - resolver: '0x123', + resolverAddress: '0x123', }, name: 'updateResolver', }, @@ -375,21 +353,11 @@ describe('ResolverWarningOverlay', () => { } beforeEach(() => { - mockUseNameDetails.mockReturnValue( - mockProfileData as unknown as { profile: Profile; loading: boolean }, - ) + mockUseProfile.mockReturnValue(mockProfileData) mockUseContractAddress.mockReturnValue('0x123') - mockUseNetwork.mockReturnValue({ chain: { id: 1 } }) - mockUseBasicName.mockReturnValue({ isWrapped: false }) - mockUseProfile.mockReturnValue({ - profile: mockProfileData.profile as any, - loading: false, - }) - mockUseQueryKeys.mockReturnValue({ - profile: () => ['profile', 'test.eth'], - }) - mockUseAvatar.mockReturnValue({ - avatar: 'avatar', + mockUseIsWrapped.mockReturnValue({ data: false, isLoading: false }) + mockUseEnsAvatar.mockReturnValue({ + data: 'avatar', isLoading: false, }) mockDispatch.mockClear() @@ -418,10 +386,7 @@ describe('ResolverWarningOverlay', () => { describe('Resolver not name wrapper aware', () => { beforeEach(() => { - mockUseNameDetails.mockReturnValue({ ...mockProfileData, isWrapped: true } as unknown as { - profile: Profile - loading: boolean - }) + mockUseIsWrapped.mockReturnValue({ data: true, isLoading: false }) mockUseResolverStatus.mockReturnValue(makeResolverStatus(['hasResolver', 'hasValidResolver'])) }) diff --git a/src/transaction-flow/input/RevokePermissions/RevokePermissions.test.tsx b/src/transaction-flow/input/RevokePermissions/RevokePermissions.test.tsx index a66867ada..2f6c02794 100644 --- a/src/transaction-flow/input/RevokePermissions/RevokePermissions.test.tsx +++ b/src/transaction-flow/input/RevokePermissions/RevokePermissions.test.tsx @@ -1,12 +1,17 @@ -import { render, screen, userEvent, waitFor } from '@app/test-utils' +import { mockFunction, render, screen, userEvent, waitFor } from '@app/test-utils' +import { usePrimaryName } from '@app/hooks/ensjs/public/usePrimaryName' import { makeTransactionItem } from '@app/transaction-flow/transaction' import { DeepPartial } from '@app/types' import RevokePermissions, { Props } from './RevokePermissions-flow' +jest.mock('@app/hooks/ensjs/public/usePrimaryName') + jest.spyOn(Date, 'now').mockImplementation(() => new Date('2023-01-01').getTime()) +const mockUsePrimaryName = mockFunction(usePrimaryName) + const mockDispatch = jest.fn() const mockOnDismiss = jest.fn() @@ -46,6 +51,10 @@ const makeData = (overrides: DeepPartial = {}) => { } as Data } +beforeEach(() => { + mockUsePrimaryName.mockReturnValue({ data: null, isLoading: false }) +}) + afterEach(() => { jest.clearAllMocks() }) @@ -138,11 +147,11 @@ describe('RevokePermissions', () => { parent: ['PARENT_CANNOT_CONTROL', 'CAN_EXTEND_EXPIRY'], child: [ 'CANNOT_UNWRAP', - 'CANNOT_CREATE_SUBDOMAIN', + 'CANNOT_BURN_FUSES', 'CANNOT_TRANSFER', 'CANNOT_SET_RESOLVER', 'CANNOT_SET_TTL', - 'CANNOT_BURN_FUSES', + 'CANNOT_CREATE_SUBDOMAIN', ], }, expiry: 1675238574, @@ -453,10 +462,10 @@ describe('RevokePermissions', () => { contract: 'setFuses', fuses: [ 'CANNOT_UNWRAP', - 'CANNOT_CREATE_SUBDOMAIN', 'CANNOT_TRANSFER', 'CANNOT_SET_RESOLVER', 'CANNOT_SET_TTL', + 'CANNOT_CREATE_SUBDOMAIN', ], }), ], @@ -517,10 +526,10 @@ describe('RevokePermissions', () => { name: 'sub.test.eth', contract: 'setFuses', fuses: [ - 'CANNOT_CREATE_SUBDOMAIN', 'CANNOT_TRANSFER', 'CANNOT_SET_RESOLVER', 'CANNOT_SET_TTL', + 'CANNOT_CREATE_SUBDOMAIN', ], }), ], diff --git a/src/transaction-flow/input/SelectPrimaryName/SelectPrimaryName-flow.tsx b/src/transaction-flow/input/SelectPrimaryName/SelectPrimaryName-flow.tsx index 79155e1a6..19eb6d4d9 100644 --- a/src/transaction-flow/input/SelectPrimaryName/SelectPrimaryName-flow.tsx +++ b/src/transaction-flow/input/SelectPrimaryName/SelectPrimaryName-flow.tsx @@ -20,8 +20,8 @@ import { useChainId } from '@app/hooks/chain/useChainId' import { useNamesForAddress } from '@app/hooks/ensjs/subgraph/useNamesForAddress' import { useGetPrimaryNameTransactionFlowItem } from '@app/hooks/primary/useGetPrimaryNameTransactionFlowItem' import { useResolverStatus } from '@app/hooks/resolver/useResolverStatus' -import { useBasicName } from '@app/hooks/useBasicName' import useDebouncedCallback from '@app/hooks/useDebouncedCallback' +import { useIsWrapped } from '@app/hooks/useIsWrapped' import { useProfile } from '@app/hooks/useProfile' import { usePublicClient } from '@app/hooks/usePublicClient' import { @@ -199,8 +199,8 @@ const SelectPrimaryName = ({ data: { address }, dispatch, onDismiss }: Props) => name: 'name', }) - const { isWrapped, isLoading: isBasicNameLoading } = useBasicName({ - name: selectedName?.name, + const { data: isWrapped, isLoading: isWrappedLoading } = useIsWrapped({ + name: selectedName?.name!, enabled: !!selectedName?.name, }) const { data: selectedNameProfile } = useProfile({ @@ -211,7 +211,7 @@ const SelectPrimaryName = ({ data: { address }, dispatch, onDismiss }: Props) => const resolverStatus = useResolverStatus({ name: selectedName?.name!, - enabled: !!selectedName && !isBasicNameLoading, + enabled: !!selectedName && !isWrappedLoading, migratedRecordsMatch: { type: 'address', match: { id: 60, value: address } }, }) @@ -295,7 +295,7 @@ const SelectPrimaryName = ({ data: { address }, dispatch, onDismiss }: Props) => const isLoading = isLoadingNames || isMutationLoading const isLoadingName = - resolverStatus.isLoading || isBasicNameLoading || getPrimarynameTransactionFlowItem.isLoading + resolverStatus.isLoading || isWrappedLoading || getPrimarynameTransactionFlowItem.isLoading // Show header if more than one page has been loaded, if only one page has been loaded but there is another page, or if there is an active search query const showHeader = diff --git a/src/transaction-flow/input/SelectPrimaryName/SelectPrimaryName.test.tsx b/src/transaction-flow/input/SelectPrimaryName/SelectPrimaryName.test.tsx index d4fac2ce4..5d61267d2 100644 --- a/src/transaction-flow/input/SelectPrimaryName/SelectPrimaryName.test.tsx +++ b/src/transaction-flow/input/SelectPrimaryName/SelectPrimaryName.test.tsx @@ -1,7 +1,15 @@ -import { render, screen, userEvent, waitFor } from '@app/test-utils' +import { mockFunction, render, screen, userEvent, waitFor } from '@app/test-utils' -import { decodeLabelhash, labelhash } from '@ensdomains/ensjs/utils/labels' +import { labelhash } from 'viem' +import { getDecodedName } from '@ensdomains/ensjs/subgraph' +import { decodeLabelhash } from '@ensdomains/ensjs/utils' + +import { useNamesForAddress } from '@app/hooks/ensjs/subgraph/useNamesForAddress' +import { useGetPrimaryNameTransactionFlowItem } from '@app/hooks/primary/useGetPrimaryNameTransactionFlowItem' +import { useResolverStatus } from '@app/hooks/resolver/useResolverStatus' +import { useIsWrapped } from '@app/hooks/useIsWrapped' +import { useProfile } from '@app/hooks/useProfile' import { makeTransactionItem } from '@app/transaction-flow/transaction' import SelectPrimaryName, { @@ -24,21 +32,24 @@ jest.mock('@app/components/@atoms/NameDetailItem/TaggedNameItem', () => ({ TaggedNameItem: ({ name, ...props }: any) =>
{name}
, })) -const mockGetDecryptedName = jest.fn().mockImplementation((name: string) => Promise.resolve(name)) -const mockUseEns = jest.fn().mockReturnValue({ - ready: true, - getDecryptedName: () => mockGetDecryptedName(), -}) -jest.mock('@app/utils/EnsProvider', () => ({ - useEns: () => mockUseEns(), -})) +jest.mock('@ensdomains/ensjs/subgraph') + +jest.mock('@app/hooks/ensjs/subgraph/useNamesForAddress') +jest.mock('@app/hooks/resolver/useResolverStatus') +jest.mock('@app/hooks/useIsWrapped') +jest.mock('@app/hooks/useProfile') +jest.mock('@app/hooks/primary/useGetPrimaryNameTransactionFlowItem') + +const mockGetDecodedName = mockFunction(getDecodedName) +mockGetDecodedName.mockImplementation((_: any, { name }) => Promise.resolve(name)) const makeName = (index: number, overwrites?: any) => ({ name: `test${index}.eth`, id: `0x${index}`, ...overwrites, }) -const mockUseAvailablePrimaryNamesForAddress = jest.fn().mockReturnValue({ +const mockUseNamesForAddress = mockFunction(useNamesForAddress) +mockUseNamesForAddress.mockReturnValue({ data: { pages: [ new Array(5) @@ -49,55 +60,38 @@ const mockUseAvailablePrimaryNamesForAddress = jest.fn().mockReturnValue({ }, isLoading: false, }) -jest.mock( - '@app/hooks/names/useAvailablePrimaryNamesForAddress/useAvailablePrimaryNamesForAddress', - () => ({ - useAvailablePrimaryNamesForAddress: () => mockUseAvailablePrimaryNamesForAddress(), - }), -) - -jest.mock('@app/hooks/useContractAddress', () => ({ - useContractAddress: () => '0xPublicResolver', -})) -const mockUseResolverStatus = jest.fn().mockReturnValue({ +const mockUseResolverStatus = mockFunction(useResolverStatus) +mockUseResolverStatus.mockReturnValue({ data: { isAuthorized: true, }, isLoading: false, }) -jest.mock('@app/hooks/resolver/useResolverStatus', () => ({ - useResolverStatus: () => mockUseResolverStatus(), -})) -const mockUseBasicName = jest.fn().mockReturnValue({ - isWrapped: true, +const mockUseIsWrapped = mockFunction(useIsWrapped) +mockUseIsWrapped.mockReturnValue({ + data: false, isLoading: false, }) -jest.mock('@app/hooks/useBasicName', () => ({ - useBasicName: () => mockUseBasicName(), -})) -const mockUseProfile = jest.fn().mockReturnValue({ - profile: { - records: {}, +const mockUseProfile = mockFunction(useProfile) +mockUseProfile.mockReturnValue({ + data: { + coins: [], + texts: [], resolverAddress: '0xresolver', }, isLoading: false, }) -jest.mock('@app/hooks/useProfile', () => ({ - useProfile: () => mockUseProfile(), -})) -const mockUseGetPrimaryNameTransactionItem = jest.fn().mockReturnValue({ +const mockUseGetPrimaryNameTransactionItem = mockFunction(useGetPrimaryNameTransactionFlowItem) +mockUseGetPrimaryNameTransactionItem.mockReturnValue({ callBack: () => ({ transactions: [makeTransactionItem('setPrimaryName', { name: 'test.eth', address: '0x123' })], }), isLoading: false, }) -jest.mock('@app/hooks/primary/useGetPrimaryNameTransactionFlowItem', () => ({ - useGetPrimaryNameTransactionFlowItem: () => mockUseGetPrimaryNameTransactionItem(), -})) const mockDispatch = jest.fn() @@ -173,7 +167,7 @@ describe('getNameFromUnknownLabels', () => { describe('SelectPrimaryName', () => { it('should show loading if data hook is loading', async () => { - mockUseAvailablePrimaryNamesForAddress.mockReturnValueOnce({ + mockUseNamesForAddress.mockReturnValueOnce({ data: undefined, isLoading: true, }) @@ -187,19 +181,8 @@ describe('SelectPrimaryName', () => { await waitFor(() => expect(screen.getByText('loading')).toBeInTheDocument()) }) - it('should show loading message if ens hook is loading', async () => { - mockUseEns.mockReturnValueOnce({ - ready: false, - getResolver: jest.fn(), - }) - render( - {}} onDismiss={() => {}} />, - ) - await waitFor(() => expect(screen.getByText('loading')).toBeInTheDocument()) - }) - it('should show no name message if data returns an empty array', async () => { - mockUseAvailablePrimaryNamesForAddress.mockReturnValueOnce({ + mockUseNamesForAddress.mockReturnValueOnce({ data: { pages: [[]], }, @@ -249,7 +232,7 @@ describe('SelectPrimaryName', () => { }) it('should call dispatch if encrpyted name can be decrypted', async () => { - mockUseAvailablePrimaryNamesForAddress.mockReturnValueOnce({ + mockUseNamesForAddress.mockReturnValueOnce({ data: { pages: [ [ @@ -263,7 +246,7 @@ describe('SelectPrimaryName', () => { }, isLoading: false, }) - mockGetDecryptedName.mockReturnValueOnce('test.eth') + mockGetDecodedName.mockReturnValueOnce(Promise.resolve('test.eth')) render( { }) it('should be able to decrpyt name and dispatch', async () => { - mockUseAvailablePrimaryNamesForAddress.mockReturnValue({ + mockUseNamesForAddress.mockReturnValue({ data: { pages: [ [ @@ -291,7 +274,7 @@ describe('SelectPrimaryName', () => { }, isLoading: false, }) - mockGetDecryptedName.mockReturnValueOnce(`${encodeLabel('test')}.eth`) + mockGetDecodedName.mockReturnValueOnce(Promise.resolve(`${encodeLabel('test')}.eth`)) render( { data: { name: 'test.eth' }, }, ` - Object { - "data": Object { + { + "data": { "address": "0x123", "name": "test.eth", }, diff --git a/src/transaction-flow/input/SelectPrimaryName/components/TaggedNameItemWithFuseCheck.test.tsx b/src/transaction-flow/input/SelectPrimaryName/components/TaggedNameItemWithFuseCheck.test.tsx index 55b0c698d..e6eeda69d 100644 --- a/src/transaction-flow/input/SelectPrimaryName/components/TaggedNameItemWithFuseCheck.test.tsx +++ b/src/transaction-flow/input/SelectPrimaryName/components/TaggedNameItemWithFuseCheck.test.tsx @@ -1,26 +1,29 @@ -import { render, screen } from '@app/test-utils' +import { mockFunction, render, screen } from '@app/test-utils' + +import { useResolverStatus } from '@app/hooks/resolver/useResolverStatus' import { TaggedNameItemWithFuseCheck } from './TaggedNameItemWithFuseCheck' +jest.mock('@app/hooks/resolver/useResolverStatus') + jest.mock('@app/components/@atoms/NameDetailItem/TaggedNameItem', () => ({ TaggedNameItem: ({ name }: any) =>
{name}
, })) -const mockUseResolverStatus = jest.fn().mockReturnValue({ +const mockUseResolverStatus = mockFunction(useResolverStatus) +mockUseResolverStatus.mockReturnValue({ data: { isAuthorized: true, }, isLoading: false, }) -jest.mock('@app/hooks/resolver/useResolverStatus', () => ({ - useResolverStatus: () => mockUseResolverStatus(), -})) - const baseProps: any = { name: 'test.eth', - isResolvedAddress: true, - isWrappedOwner: false, + relation: { + resolvedAddress: true, + wrappedOwner: false, + }, fuses: {}, } @@ -41,8 +44,10 @@ describe('TaggedNameItemWithFuseCheck', () => { , @@ -61,8 +66,10 @@ describe('TaggedNameItemWithFuseCheck', () => { , @@ -81,8 +88,10 @@ describe('TaggedNameItemWithFuseCheck', () => { , @@ -101,8 +110,10 @@ describe('TaggedNameItemWithFuseCheck', () => { , @@ -121,8 +132,10 @@ describe('TaggedNameItemWithFuseCheck', () => { , diff --git a/src/transaction-flow/input/SelectPrimaryName/components/TaggedNameItemWithFuseCheck.tsx b/src/transaction-flow/input/SelectPrimaryName/components/TaggedNameItemWithFuseCheck.tsx index a27c42c41..95c6c3049 100644 --- a/src/transaction-flow/input/SelectPrimaryName/components/TaggedNameItemWithFuseCheck.tsx +++ b/src/transaction-flow/input/SelectPrimaryName/components/TaggedNameItemWithFuseCheck.tsx @@ -3,10 +3,12 @@ import { ComponentProps, useMemo } from 'react' import { TaggedNameItem } from '@app/components/@atoms/NameDetailItem/TaggedNameItem' import { useResolverStatus } from '@app/hooks/resolver/useResolverStatus' -type Props = { isResolvedAddress?: boolean } & ComponentProps -export const TaggedNameItemWithFuseCheck = ({ isResolvedAddress, ...props }: Props) => { +type Props = ComponentProps +export const TaggedNameItemWithFuseCheck = (props: Props) => { const skip = - isResolvedAddress || !props.relation?.wrappedOwner || !props.fuses?.child.CANNOT_SET_RESOLVER + props.relation?.resolvedAddress || + !props.relation?.wrappedOwner || + !props.fuses?.child.CANNOT_SET_RESOLVER const resolverStatus = useResolverStatus({ name: props.name!, enabled: !skip }) diff --git a/src/transaction-flow/input/UnknownLabels/UnknownLabels.test.tsx b/src/transaction-flow/input/UnknownLabels/UnknownLabels.test.tsx index 79d6e4780..e960f72ca 100644 --- a/src/transaction-flow/input/UnknownLabels/UnknownLabels.test.tsx +++ b/src/transaction-flow/input/UnknownLabels/UnknownLabels.test.tsx @@ -2,7 +2,7 @@ import { render, screen, userEvent } from '@app/test-utils' import { ComponentProps } from 'react' -import { encodeLabel } from '@ensdomains/ensjs/utils/labels' +import { encodeLabelhash } from '@ensdomains/ensjs/utils' import UnknownLabels from './UnknownLabels-flow' @@ -14,6 +14,14 @@ const labels = { sub: '0xfa1ea47215815692a5f1391cff19abbaf694c82fb2151a4c351b6c0eeaaf317b', } +const encodeLabel = (str: string) => { + try { + return encodeLabelhash(str) + } catch { + return str + } +} + const renderHelper = (data: Omit['data'], 'key'>) => { const newData = { ...data,