Skip to content

Commit

Permalink
fix: dont show address book suggestions after a valid adddress has be…
Browse files Browse the repository at this point in the history
…en entered (#3268)
  • Loading branch information
jmealy authored Feb 19, 2024
1 parent e4d819d commit 1be52b5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/common/AddressBookInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1be52b5

Please sign in to comment.