fix: handle evm unsupported chains gracefully in send flow for custom network cp-13.17.0#39806
Merged
fix: handle evm unsupported chains gracefully in send flow for custom network cp-13.17.0#39806
Conversation
Contributor
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Contributor
✨ Files requiring CODEOWNER review ✨🔄 @MetaMask/swaps-engineers (1 files, +19 -0)
|
Contributor
Builds ready [207acc0]
UI Startup Metrics (1376 ± 82 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚀 Bundle size reduced!]
|
Contributor
Builds ready [3fbca98]
UI Startup Metrics (1396 ± 85 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚀 Bundle size reduced!]
|
mikesposito
reviewed
Feb 5, 2026
Comment on lines
+239
to
+243
| // Before converting decimal strings to hex, check if it's a non-EVM chainId | ||
| // This prevents misidentifying non-EVM chains (e.g., Solana, Bitcoin, Tron) as EVM | ||
| if (isNonEvmChainId(chainId)) { | ||
| return false; | ||
| } |
Member
There was a problem hiding this comment.
Thoughts on moving this to the top of the function? We'd return early from the function, and we wouldn't have an if statement inside another else statement
mikesposito
reviewed
Feb 5, 2026
Comment on lines
+476
to
+499
| it('should return true for EVM chain ids passed as decimal strings', () => { | ||
| // Test Injective testnet (1439) - the original bug case | ||
| expect(isEvmChainId('1439' as Hex)).toBe(true); | ||
| // Test other EVM chains as decimal strings | ||
| expect(isEvmChainId('1' as Hex)).toBe(true); // Ethereum mainnet | ||
| expect(isEvmChainId('137' as Hex)).toBe(true); // Polygon | ||
| expect(isEvmChainId('1776' as Hex)).toBe(true); // Injective mainnet | ||
| }); | ||
|
|
||
| it('should return false for non-EVM chain ids passed as decimal strings', () => { | ||
| // Test Solana (1151111081099710) | ||
| expect(isEvmChainId('1151111081099710' as Hex)).toBe(false); | ||
| // Test Bitcoin (20000000000001) | ||
| expect(isEvmChainId('20000000000001' as Hex)).toBe(false); | ||
| // Test Tron (728126428) | ||
| expect(isEvmChainId('728126428' as Hex)).toBe(false); | ||
| }); | ||
|
|
||
| it('should handle Injective testnet chainId in different formats', () => { | ||
| // All these should return true for Injective testnet (1439) | ||
| expect(isEvmChainId('1439' as Hex)).toBe(true); // Decimal string | ||
| expect(isEvmChainId('0x59f' as Hex)).toBe(true); // Hex format | ||
| expect(isEvmChainId('eip155:1439' as CaipChainId)).toBe(true); // CAIP format | ||
| }); |
Member
There was a problem hiding this comment.
nit:
Suggested change
| it('should return true for EVM chain ids passed as decimal strings', () => { | |
| // Test Injective testnet (1439) - the original bug case | |
| expect(isEvmChainId('1439' as Hex)).toBe(true); | |
| // Test other EVM chains as decimal strings | |
| expect(isEvmChainId('1' as Hex)).toBe(true); // Ethereum mainnet | |
| expect(isEvmChainId('137' as Hex)).toBe(true); // Polygon | |
| expect(isEvmChainId('1776' as Hex)).toBe(true); // Injective mainnet | |
| }); | |
| it('should return false for non-EVM chain ids passed as decimal strings', () => { | |
| // Test Solana (1151111081099710) | |
| expect(isEvmChainId('1151111081099710' as Hex)).toBe(false); | |
| // Test Bitcoin (20000000000001) | |
| expect(isEvmChainId('20000000000001' as Hex)).toBe(false); | |
| // Test Tron (728126428) | |
| expect(isEvmChainId('728126428' as Hex)).toBe(false); | |
| }); | |
| it('should handle Injective testnet chainId in different formats', () => { | |
| // All these should return true for Injective testnet (1439) | |
| expect(isEvmChainId('1439' as Hex)).toBe(true); // Decimal string | |
| expect(isEvmChainId('0x59f' as Hex)).toBe(true); // Hex format | |
| expect(isEvmChainId('eip155:1439' as CaipChainId)).toBe(true); // CAIP format | |
| }); | |
| it.each(['1439' as Hex, '1' as Hex, '137' as Hex, '1776' as Hex])( | |
| 'should return true for EVM chain ids passed as decimal strings', | |
| (chainId) => { | |
| expect(isEvmChainId(chainId)).toBe(true); | |
| }, | |
| ); | |
| it.each([ | |
| '1151111081099710' as Hex, | |
| '20000000000001' as Hex, | |
| '728126428' as Hex, | |
| ])( | |
| 'should return false for non-EVM chain ids passed as decimal strings', | |
| (chainId) => { | |
| expect(isEvmChainId(chainId)).toBe(false); | |
| }, | |
| ); | |
| it.each(['1439' as Hex, '0x59f', 'eip155:1439'])( | |
| 'should handle Injective testnet chainId in different formats', | |
| (chainId) => { | |
| expect(isEvmChainId(chainId)).toBe(true); | |
| }, | |
| ); |
micaelae
approved these changes
Feb 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes error when sending native tokens on EVM networks with decimal string chainIds (e.g., Injective testnet). The fix normalizes decimal string chainIds to hex format in
isEvmChainIdbefore conversion, preventing conversion errors. Defensive error handling is also added as a fallback for unsupported chains.Changelog
CHANGELOG entry: Fixed error when sending native tokens on EVM networks when chainId is provided as decimal string.
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
Screen.Recording.2026-02-04.at.23.25.00.mov
After
Screen.Recording.2026-02-04.at.23.21.43.mov
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Touches chain-id normalization and native asset lookups that can affect pricing/send flows across many networks; changes are small but impact broad utility functions and error handling paths.
Overview
Fixes failures when EVM
chainIds are provided as decimal strings (e.g. Injective testnet) by updatingisEvmChainIdto normalize non-CAIP/non-hex inputs (after guarding withisNonEvmChainId) before converting to CAIP.Makes native-asset resolution more defensive on unsupported/custom networks:
toAssetIdnow catchesgetNativeAssetForChainIderrors and returnsundefined, the UI addsgetNativeAssetForChainIdSafe, anduseCurrentPriceuses it to avoid throwing and to return no price when a nativeassetIdcan’t be derived. Tests were updated/added to cover decimal-string chain IDs and unsupported-chain native asset handling.Written by Cursor Bugbot for commit 3fbca98. This will update automatically on new commits. Configure here.