Skip to content

Commit

Permalink
fix: async validation loader in AddressInput (#1464)
Browse files Browse the repository at this point in the history
* fix: async validation loader in AddressInput

* fix: condition and add testcase
  • Loading branch information
schmanu authored Jan 9, 2023
1 parent fe45b06 commit e1e196f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/components/common/AddressInput/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,31 @@ describe('AddressInput tests', () => {
await waitFor(() => expect(utils.getByLabelText(`${TEST_ADDRESS_B} is wrong`, { exact: false })).toBeDefined())
})

it('should show a spinner when validation is in progress', async () => {
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))

const { input, utils } = setup('', async (val) => {
await sleep(2000)
return `${val} is wrong`
})

act(() => {
fireEvent.change(input, { target: { value: `gor:${TEST_ADDRESS_A}` } })
jest.advanceTimersByTime(1000)
})

await waitFor(() => {
expect(utils.getByRole('progressbar')).toBeDefined()
expect(utils.queryByLabelText(`${TEST_ADDRESS_A} is wrong`, { exact: false })).toBeNull()
})

act(() => {
jest.advanceTimersByTime(1000)
})

await waitFor(() => expect(utils.getByLabelText(`${TEST_ADDRESS_A} is wrong`, { exact: false })).toBeDefined())
})

it('should resolve ENS names', async () => {
const { input } = setup('')

Expand Down
4 changes: 2 additions & 2 deletions src/components/common/AddressInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const AddressInput = ({ name, validate, required = true, deps, ...props }: Addre
register,
setValue,
control,
formState: { errors },
formState: { errors, isValidating },
trigger,
} = useFormContext()
const currentChain = useCurrentChain()
Expand Down Expand Up @@ -72,7 +72,7 @@ const AddressInput = ({ name, validate, required = true, deps, ...props }: Addre
<InputAdornment position="end">{currentShortName}:</InputAdornment>
),

endAdornment: resolving && (
endAdornment: (resolving || isValidating) && (
<InputAdornment position="end">
<CircularProgress size={20} />
</InputAdornment>
Expand Down

0 comments on commit e1e196f

Please sign in to comment.