Skip to content

Conversation

@Nodonisko
Copy link
Contributor

@Nodonisko Nodonisko commented Nov 18, 2025

Explanation

While working on MetaMask/metamask-mobile#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

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • 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 68f77e1. This will update automatically on new commits. Configure here.

@Nodonisko Nodonisko requested a review from a team as a code owner November 18, 2025 17:50
@Nodonisko Nodonisko force-pushed the chore/faster-bridge-utils branch from c84da43 to 68f77e1 Compare November 18, 2025 17:52
) => {
if (isCaipChainId(chainId)) {
return chainId === SolScope.Mainnet.toString();
return chainId === SOLANA_MAINNET_CHAIN_ID_STRING;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to convert these chain IDs to strings at all? Shouldn't they already be strings? (If the reason is because we're getting a lint error due to enums, we should be able to bypass that.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants