Skip to content

Commit

Permalink
e2e: add optional chaining and nullish coaelescing fallbacks for `add…
Browse files Browse the repository at this point in the history
…ressBook[chainId]`
  • Loading branch information
MajorLift committed Sep 12, 2024
1 parent 982b09d commit 393ff53
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ContactForm extends PureComponent {
}, 100);
if (mode === EDIT) {
const { addressBook, chainId, internalAccounts } = this.props;
const networkAddressBook = addressBook[chainId] || {};
const networkAddressBook = addressBook?.[chainId] ?? {};
const address = this.props.route.params?.address ?? '';
const contact =
networkAddressBook[address] ||
Expand Down
4 changes: 2 additions & 2 deletions app/components/Views/Settings/Contacts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class Contacts extends PureComponent {
if (
prevProps.addressBook &&
this.props.addressBook &&
JSON.stringify(prevProps.addressBook[chainId]) !==
JSON.stringify(this.props.addressBook[chainId])
JSON.stringify(prevProps.addressBook?.[chainId] ?? {}) !==
JSON.stringify(this.props.addressBook?.[chainId] ?? {})
)
this.updateAddressList();
};
Expand Down
3 changes: 1 addition & 2 deletions app/components/Views/confirmations/Send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,7 @@ class Send extends PureComponent {
Logger.log('Error decoding transfer data', transactionMeta.data);
}
}
const existingContact =
addressBook[chainId] && addressBook[chainId][checksummedAddress];
const existingContact = addressBook?.[chainId]?.[checksummedAddress];
if (!existingContact) {
AddressBookController.set(checksummedAddress, '', chainId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const AddressList: React.FC<AddressListProps> = ({
);

const networkAddressBook: { [address: string]: AddressBookEntry } = useMemo(
() => addressBook[chainId] || {},
() => addressBook?.[chainId] ?? {},
[addressBook, chainId],
);
const parseAddressBook = useCallback(
Expand Down
9 changes: 4 additions & 5 deletions app/components/Views/confirmations/SendFlow/SendTo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class SendFlow extends PureComponent {
this.updateNavBar();
// For analytics
navigation.setParams({ providerType, isPaymentRequest });
const networkAddressBook = addressBook[chainId] || {};
const networkAddressBook = addressBook?.[chainId] ?? {};
if (!Object.keys(networkAddressBook).length) {
setTimeout(() => {
this.addressToInputRef &&
Expand Down Expand Up @@ -223,7 +223,7 @@ class SendFlow extends PureComponent {
isAddressSaved = () => {
const { toAccount } = this.state;
const { addressBook, chainId, internalAccounts } = this.props;
const networkAddressBook = addressBook[chainId] || {};
const networkAddressBook = addressBook?.[chainId] ?? {};
const checksummedAddress = toChecksumAddress(toAccount);
return !!(
networkAddressBook[checksummedAddress] ||
Expand Down Expand Up @@ -366,7 +366,7 @@ class SendFlow extends PureComponent {
const { addressBook, internalAccounts, chainId } = this.props;
if (!toAccount) return;

const networkAddressBook = addressBook[chainId] || {};
const networkAddressBook = addressBook?.[chainId] ?? {};

const checksummedAddress = toChecksumAddress(toAccount);
const matchingAccount = internalAccounts.find((account) =>
Expand Down Expand Up @@ -488,8 +488,7 @@ class SendFlow extends PureComponent {
);
const existingContact =
checksummedAddress &&
addressBook[chainId] &&
addressBook[chainId][checksummedAddress];
addressBook?.[chainId]?.[checksummedAddress];
const displayConfusableWarning =
!existingContact && confusableCollection && !!confusableCollection.length;
const displayAsWarning =
Expand Down
2 changes: 1 addition & 1 deletion app/components/hooks/useExistingAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const useExistingAddress = (address?: string): AccountInfo | undefined => {

if (!address) return;

const networkAddressBook = addressBook[chainId] || {};
const networkAddressBook = addressBook?.[chainId] ?? {};
const checksummedAddress = toChecksumAddress(address);

const matchingAddressBookEntry: AddressBookEntry | undefined =
Expand Down
2 changes: 1 addition & 1 deletion app/util/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ function checkIfAddressAlreadySaved(
internalAccounts: InternalAccount[],
) {
if (address) {
const networkAddressBook = addressBook[chainId] || {};
const networkAddressBook = addressBook?.[chainId] ?? {};

const checksummedResolvedAddress = toChecksumAddress(address);
if (
Expand Down
2 changes: 1 addition & 1 deletion app/util/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ export function getTransactionToName({
return ensRecipient;
}

const networkAddressBook = addressBook[chainId];
const networkAddressBook = addressBook?.[chainId] ?? {};
const checksummedToAddress = toChecksumAddress(toAddress);

// Convert internalAccounts array to a map for quick lookup
Expand Down

0 comments on commit 393ff53

Please sign in to comment.