core
core copied to clipboard
chore(bridge-controller): faster utils
Explanation
While working on https://github.com/MetaMask/metamask-mobile/pull/22744 I noticed that if do this small change of pre-converting values I can save up to 25% of time when looping though big array of tokens where this functions were used multiple times per one loop.
References
- Related to https://github.com/MetaMask/metamask-mobile/pull/22744
Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
- [x] I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
- [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
[!NOTE] Precomputes chain ID string constants and uses them in
isSolanaChainId,isBitcoinChainId, andisTronChainIdwithinutils/bridge.ts.
- utils/bridge.ts:
- Add constants:
SOLANA_MAINNET_CHAIN_ID_STRING,SOLANA_CHAIN_ID_STRING,BITCOIN_MAINNET_CHAIN_ID_STRING,BITCOIN_CHAIN_ID_STRING,TRON_MAINNET_CHAIN_ID_STRING,TRON_CHAIN_ID_STRING.- Update
isSolanaChainId,isBitcoinChainId,isTronChainIdto compare against precomputed strings instead of inlinetoString()calls.Written by Cursor Bugbot for commit 68f77e1f1848bae3e01d2fc3179fcaa782789a66. This will update automatically on new commits. Configure here.