Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't show address suggestions after a valid address has been entered #3268

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading