From 1be52b50d8f79eef46e2e5da621442a87f0b0234 Mon Sep 17 00:00:00 2001 From: James Mealy Date: Mon, 19 Feb 2024 16:21:37 +0100 Subject: [PATCH] fix: dont show address book suggestions after a valid adddress has been entered (#3268) --- src/components/common/AddressBookInput/index.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/common/AddressBookInput/index.tsx b/src/components/common/AddressBookInput/index.tsx index feefebe680..0988458a77 100644 --- a/src/components/common/AddressBookInput/index.tsx +++ b/src/components/common/AddressBookInput/index.tsx @@ -10,6 +10,7 @@ import InfoIcon from '@/public/images/notifications/info.svg' import EntryDialog from '@/components/address-book/EntryDialog' import css from './styles.module.css' import inputCss from '@/styles/inputs.module.css' +import { isValidAddress } from '@/utils/validation' const abFilterOptions = createFilterOptions({ stringify: (option: { label: string; name: string }) => option.name + ' ' + option.label, @@ -35,6 +36,12 @@ const AddressBookInput = ({ name, canAdd, ...props }: AddressInputProps & { canA [addressBookEntries, addressValue], ) + const customFilterOptions = (options: any, state: any) => { + // Don't show suggestions from the address book once a valid address has been entered. + if (isValidAddress(addressValue)) return [] + return abFilterOptions(options, state) + } + const handleOpenAutocomplete = () => { setOpen((value) => !value) } @@ -75,7 +82,7 @@ const AddressBookInput = ({ name, canAdd, ...props }: AddressInputProps & { canA options={addressBookEntries} onChange={(_, value) => (typeof value === 'string' ? field.onChange(value) : field.onChange(value.label))} onInputChange={(_, value) => setValue(name, value)} - filterOptions={abFilterOptions} + filterOptions={customFilterOptions} componentsProps={{ paper: { elevation: 2,