Skip to content

Commit 025d78d

Browse files
temp+chore: cp-7.51.0 faster address checksum (#16926) (#17174)
## **Description** This [PR](#16926) is originally from @Nodonisko from Margelo This PR uses new faster memoized functions for working with address checksum. There is already significant boost in AccountList performance and it should be even better when MetaMask/core#6054 is released and also when we fix Blockies Avatars. ## **Related issues** Fixes: #15560 ## **Manual testing steps** 1. Open Account List 2. It should feel faster than before ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** You can set that before then was lot of interrupted work before Account List modal is even displayed. It takes around ~7s from click to modal to be actually visible. <img width="1324" alt="Screenshot 2025-07-03 at 21 36 06" src="https://github.com/user-attachments/assets/7c624f31-db84-4ade-9df6-a116bff9a68f" /> ### **After** Here it takes only around ~3s to mount. (still slow but much better than before) <img width="1325" alt="Screenshot 2025-07-03 at 21 38 16" src="https://github.com/user-attachments/assets/96a5a4f1-59b7-4cfa-b58c-ac84eb238654" /> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. Co-authored-by: Daniel Suchý <suchydan@gmail.com>
2 parents 3e4fa52 + 55bc8a6 commit 025d78d

File tree

19 files changed

+72
-38
lines changed

19 files changed

+72
-38
lines changed

app/component-library/components-temp/Price/AggregatedPercentage/AggregatedPercentageCrossChains.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ jest.mock('../../../../selectors/currencyRateController', () => ({
2323
}));
2424

2525
jest.mock('ethereumjs-util', () => ({
26-
toChecksumAddress: jest.fn((address) => address),
2726
zeroAddress: jest.fn(() => '0x0000000000000000000000000000000000000000'),
2827
}));
2928

29+
jest.mock('../../../../util/address', () => ({
30+
toChecksumAddress: jest.fn((address) => address),
31+
}));
32+
3033
describe('AggregatedPercentageCrossChains', () => {
3134
const mockStore = configureStore([]);
3235
let store: Store;

app/component-library/components-temp/Price/AggregatedPercentage/AggregatedPercentageCrossChains.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import {
1010
FORMATTED_VALUE_PRICE_TEST_ID,
1111
FORMATTED_PERCENTAGE_TEST_ID,
1212
} from './AggregatedPercentage.constants';
13-
import { toChecksumAddress, zeroAddress } from 'ethereumjs-util';
13+
import { zeroAddress } from 'ethereumjs-util';
1414
import { selectTokenMarketData } from '../../../../selectors/tokenRatesController';
1515
import {
1616
MarketDataMapping,
1717
TokensWithBalances,
1818
} from '../../../../components/hooks/useGetFormattedTokensPerChain';
1919
import { getFormattedAmountChange, getPercentageTextColor } from './utils';
2020
import { AggregatedPercentageCrossChainsProps } from './AggregatedPercentageCrossChains.types';
21+
import { toChecksumAddress } from '../../../../util/address';
2122

2223
export const getCalculatedTokenAmount1dAgo = (
2324
tokenFiatBalance: number,

app/components/UI/AccountFromToInfoCard/AddressFrom.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { toChecksumAddress } from 'ethereumjs-util';
21
import React, { useEffect, useState } from 'react';
32
import { View } from 'react-native';
43
import { useSelector } from 'react-redux';
@@ -16,6 +15,7 @@ import {
1615
import {
1716
getLabelTextByAddress,
1817
renderAccountName,
18+
toChecksumAddress,
1919
} from '../../../util/address';
2020
import useAddressBalance from '../../hooks/useAddressBalance/useAddressBalance';
2121
import stylesheet from './AddressFrom.styles';

app/components/UI/Bridge/hooks/useTokensWithBalance/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo } from 'react';
22
import { useSelector } from 'react-redux';
3-
import { CaipChainId, getChecksumAddress, Hex } from '@metamask/utils';
3+
import { CaipChainId, Hex } from '@metamask/utils';
44
import { TokenI } from '../../../Tokens/types';
55
import { selectTokensBalances } from '../../../../../selectors/tokenBalancesController';
66
import {
@@ -30,6 +30,7 @@ import { renderNumber, renderFiat } from '../../../../../util/number';
3030
import { formatUnits } from 'ethers/lib/utils';
3131
import { BigNumber } from 'ethers';
3232
import { selectAccountsByChainId } from '../../../../../selectors/accountTrackerController';
33+
import { toChecksumAddress } from '../../../../../util/address';
3334

3435
interface CalculateFiatBalancesParams {
3536
assets: TokenI[];
@@ -90,7 +91,7 @@ export const calculateEvmBalances = ({
9091
// Native EVM token
9192
if (token.isETH || token.isNative) {
9293
const nativeTokenBalanceAtomicHex =
93-
evmAccountsByChainId?.[chainId]?.[getChecksumAddress(selectedAddress)]
94+
evmAccountsByChainId?.[chainId]?.[toChecksumAddress(selectedAddress)]
9495
?.balance || '0x0';
9596
const nativeTokenBalance = formatUnits(
9697
BigNumber.from(nativeTokenBalanceAtomicHex),
@@ -116,7 +117,7 @@ export const calculateEvmBalances = ({
116117
);
117118
const erc20BalanceAtomicHex =
118119
multiChainTokenBalances?.[token.address as Hex] ||
119-
multiChainTokenBalances?.[getChecksumAddress(token.address as Hex)] ||
120+
multiChainTokenBalances?.[toChecksumAddress(token.address as Hex)] ||
120121
'0x0';
121122

122123
const erc20Balance = formatUnits(

app/components/UI/PaymentRequest/AssetList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { fontStyles } from '../../../../styles/common';
66
import Identicon from '../../Identicon';
77
import NetworkMainAssetLogo from '../../NetworkMainAssetLogo';
88
import { useSelector } from 'react-redux';
9-
import { toChecksumAddress } from 'ethereumjs-util';
109
import { useTheme } from '../../../../util/theme';
1110
import { selectTokenList } from '../../../../selectors/tokenListController';
1211
import { ImportTokenViewSelectorsIDs } from '../../../../../e2e/selectors/wallet/ImportTokenView.selectors';
12+
import { toChecksumAddress } from '../../../../util/address';
1313

1414
// TODO: Replace "any" with type
1515
// eslint-disable-next-line @typescript-eslint/no-explicit-any

app/components/UI/TransactionElement/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import {
1616
renderFullAddress,
1717
areAddressesEqual,
1818
toFormattedAddress,
19+
toChecksumAddress,
1920
} from '../../../util/address';
2021
import {
2122
decodeTransferData,
2223
isCollectibleAddress,
2324
getActionKey,
2425
TRANSACTION_TYPES,
2526
} from '../../../util/transactions';
26-
import { toChecksumAddress } from 'ethereumjs-util';
2727
import { swapsUtils } from '@metamask/swaps-controller';
2828
import { isSwapsNativeAsset } from '../Swaps/utils';
2929
import Engine from '../../../core/Engine';

app/components/Views/Settings/Contacts/ContactForm/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import PropTypes from 'prop-types';
1313
import { getEditableOptions } from '../../../../UI/Navbar';
1414
import StyledButton from '../../../../UI/StyledButton';
1515
import Engine from '../../../../../core/Engine';
16-
import { toChecksumAddress } from 'ethereumjs-util';
1716
import { connect } from 'react-redux';
1817
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
1918
import { strings } from '../../../../../../locales/i18n';
2019
import {
2120
renderShortAddress,
2221
areAddressesEqual,
2322
validateAddressOrENS,
23+
toChecksumAddress,
2424
} from '../../../../../util/address';
2525
import ErrorMessage from '../../../confirmations/legacy/SendFlow/ErrorMessage';
2626
import AntIcon from 'react-native-vector-icons/AntDesign';

app/components/Views/confirmations/hooks/useAccountInfo.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import { toChecksumAddress } from 'ethereumjs-util';
21
import { useMemo } from 'react';
32
import { useSelector } from 'react-redux';
43
import { Hex } from '@metamask/utils';
54

65
import Engine from '../../../../core/Engine';
76
import useAddressBalance from '../../../../components/hooks/useAddressBalance/useAddressBalance';
87
import { selectInternalAccounts } from '../../../../selectors/accountsController';
9-
import { renderAccountName } from '../../../../util/address';
8+
import { renderAccountName, toChecksumAddress } from '../../../../util/address';
109
import { selectCurrentCurrency } from '../../../../selectors/currencyRateController';
1110
import { formatWithThreshold } from '../../../../util/assets';
1211
import I18n from '../../../../../locales/i18n';
1312

1413
const useAccountInfo = (address: string, chainId: Hex) => {
1514
const internalAccounts = useSelector(selectInternalAccounts);
16-
const activeAddress = toChecksumAddress(address);
15+
const activeAddress = toChecksumAddress(address as Hex);
1716
const { addressBalance: accountBalance } = useAddressBalance(
1817
undefined,
1918
address,

app/components/Views/confirmations/legacy/Send/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
fromWei,
1818
fromTokenMinimalUnit,
1919
} from '../../../../../util/number';
20-
import { toChecksumAddress } from 'ethereumjs-util';
2120
import { strings } from '../../../../../../locales/i18n';
2221
import { getTransactionOptionsTitle } from '../../../../UI/Navbar';
2322
import { connect } from 'react-redux';
@@ -36,7 +35,11 @@ import {
3635
generateTransferData,
3736
} from '../../../../../util/transactions';
3837
import Logger from '../../../../../util/Logger';
39-
import { getAddress, areAddressesEqual } from '../../../../../util/address';
38+
import {
39+
getAddress,
40+
areAddressesEqual,
41+
toChecksumAddress,
42+
} from '../../../../../util/address';
4043
import { MAINNET } from '../../../../../constants/network';
4144
import BigNumber from 'bignumber.js';
4245
import { WalletDevice } from '@metamask/transaction-controller';

app/components/Views/confirmations/legacy/SendFlow/SendTo/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { Fragment, PureComponent } from 'react';
22
import { View, ScrollView, Alert, Platform, BackHandler } from 'react-native';
33
import PropTypes from 'prop-types';
44
import { connect } from 'react-redux';
5-
import { toChecksumAddress } from 'ethereumjs-util';
65
import { SafeAreaView } from 'react-native-safe-area-context';
76
import Icon from 'react-native-vector-icons/FontAwesome';
87
import AddressList from '../AddressList';
@@ -21,6 +20,7 @@ import {
2120
isValidHexAddress,
2221
validateAddressOrENS,
2322
areAddressesEqual,
23+
toChecksumAddress,
2424
} from '../../../../../../util/address';
2525
import { getEther, getTicker } from '../../../../../../util/transactions';
2626
import {

0 commit comments

Comments
 (0)