Skip to content

Commit

Permalink
Merge branch 'main' into fix/premium-chart-target-price
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jun 20, 2023
2 parents 1d6f18a + 3ea2bce commit 68a8711
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/hooks/useAdvancedEditor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react'
import { useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { Pattern, match } from 'ts-pattern'

import { RecordOptions } from '@ensdomains/ensjs/utils/recordHelpers'

Expand Down Expand Up @@ -242,12 +243,10 @@ const useAdvancedEditor = ({ profile, loading, overwrites, callback }: Props) =>

const contentHash = dirtyFields.other?.contentHash

const abi = dirtyFields.other?.abi?.data
? {
data: dirtyFields.other.abi.data,
contentType: 1,
}
: undefined
const abi = match(dirtyFields.other?.abi?.data)
.with('', () => ({ data: '' }))
.with(Pattern.string, (data) => ({ data, contentType: 1 }))
.otherwise(() => undefined)

const records = {
texts,
Expand Down
42 changes: 42 additions & 0 deletions src/transaction-flow/input/AdvancedEditor/AdvancedEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ const mockProfileData = {
addr: 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH',
},
],
abi: {
data: JSON.stringify([
{
inputs: [
{
internalType: 'string',
type: 'string',
name: 'name',
},
],
stateMutability: 'nonpayable',
outputs: [],
name: 'setName',
type: 'function',
},
]),
contentType: 1,
},
},
resolverAddress: '0x0',
isMigrated: true,
Expand Down Expand Up @@ -405,4 +423,28 @@ describe('AdvancedEditor', () => {
}
}
})

it('should allow removing abi', async () => {
render(
<AdvancedEditor dispatch={mockDispatch} onDismiss={() => {}} data={{ name: 'test.eth' }} />,
)
const tab = await screen.findByTestId('other-tab')
fireEvent.click(tab)

const abiInput = await screen.findByLabelText('advancedEditor.tabs.other.abi.label')
await userEvent.clear(abiInput)

const submitBtn = screen.getByText('action.save')
await waitFor(() => {
expect(submitBtn).not.toHaveAttribute('disabled')
})
await userEvent.click(submitBtn)

await waitFor(() => {
expect(mockDispatch).toHaveBeenCalled()
})
expect(mockDispatch.mock.calls[0][0].payload[0].data.records.abi).toEqual({
data: '',
})
})
})

0 comments on commit 68a8711

Please sign in to comment.