core icon indicating copy to clipboard operation
core copied to clipboard

chore(bridge-controller): faster utils

Open Nodonisko opened this issue 3 months ago • 0 comments

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, and isTronChainId within utils/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, isTronChainId to compare against precomputed strings instead of inline toString() calls.

Written by Cursor Bugbot for commit 68f77e1f1848bae3e01d2fc3179fcaa782789a66. This will update automatically on new commits. Configure here.

Nodonisko avatar Nov 18 '25 17:11 Nodonisko