-
Notifications
You must be signed in to change notification settings - Fork 22
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
when removing address, remove it only for that chain id #1202
when removing address, remove it only for that chain id #1202
Conversation
await updateUserAddressBookEntries((previousContacts) => previousContacts.filter((contact) => | ||
!(contact.address === removeAddressBookEntry.data.address | ||
&& (contact.chainId === removeAddressBookEntry.data.chainId || (contact.chainId === undefined && removeAddressBookEntry.data.chainId === 1n)))) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while code works perfectly fine, it may be more readable with the conditions broken down a bit
await updateUserAddressBookEntries((previousContacts) => previousContacts.filter((contact) => | |
!(contact.address === removeAddressBookEntry.data.address | |
&& (contact.chainId === removeAddressBookEntry.data.chainId || (contact.chainId === undefined && removeAddressBookEntry.data.chainId === 1n)))) | |
) | |
await updateUserAddressBookEntries((previousContacts) => { | |
const shouldKeepContact = (contact: typeof previousContacts[number]) => { | |
const isNotTheAddressToRemove = contact.address !== removeAddressBookEntry.data.address | |
const isNotWithinTheSameChain = contact.chainId !== removeAddressBookEntry.data.chainId | |
const isChainIdNotUniversal = !(contact.chainId === undefined && removeAddressBookEntry.data.chainId === 1n) | |
if (isNotTheAddressToRemove) return true | |
return isNotWithinTheSameChain && isChainIdNotUniversal | |
} | |
return previousContacts.filter(shouldKeepContact) | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I don't think this makes it cleaner as those variable names just say directly what the statement is
No description provided.