Skip to content

Conversation

@ghgoodreau
Copy link
Contributor

@ghgoodreau ghgoodreau commented Nov 19, 2025

Description

Adds tracking for insufficientBalance correctly for nonEVM chains.

Open in GitHub Codespaces

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

Note

Computes insufficient balance for non-EVM chains using on-chain balance and sanitized input, and centralizes amount sanitization with safer amount calculations.

  • Bridge logic (prepare page):
    • Add insufficientBalOverride for non-EVM chains using fromTokenBalance and BigNumber, passed to updateBridgeQuoteRequestParams.
    • Use safeAmountForCalc(fromAmount) when deriving srcTokenAmount to avoid invalid/partial inputs.
  • Utilities:
    • Introduce sanitizeAmountInput and safeAmountForCalc in ui/pages/bridge/utils/quote.ts.
  • UI input:
    • bridge-input-group.tsx now imports and uses shared sanitizeAmountInput; removes local sanitizer.

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

@github-actions
Copy link
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.

@metamaskbot metamaskbot added the team-swaps-and-bridge Swaps and Bridge team label Nov 19, 2025
@metamaskbot
Copy link
Collaborator

metamaskbot commented Nov 19, 2025

✨ Files requiring CODEOWNER review ✨

🔄 @MetaMask/swaps-engineers (3 files, +51 -15)
  • 📁 ui/
    • 📁 pages/
      • 📁 bridge/
        • 📁 prepare/
          • 📄 bridge-input-group.tsx +5 -12
          • 📄 prepare-bridge-page.tsx +20 -3
        • 📁 utils/
          • 📄 quote.ts +26 -0

@metamaskbot
Copy link
Collaborator

Builds ready [500d78e]
UI Startup Metrics (1225 ± 96 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard HomeuiStartup1225106117009612851368
load105089514668911031183
domContentLoaded104488714608810941176
domInteractive2314122192075
firstPaint561102146441910291179
backgroundConnect21519725310220232
firstReactRender28185293246
getState3216101123755
initialActions103112
loadScripts835663124089890956
setupStore1172331217
numNetworkReqs1367419670
BrowserifyPower User HomeuiStartup18851588263524920452452
load1007883155715010081427
domContentLoaded99287415481509911417
domInteractive36171753629147
firstPaint5928315684109431386
backgroundConnect22920449930232252
firstReactRender80441531588107
getState18414037649191321
initialActions102112
loadScripts78067513401487801201
setupStore201151102837
numNetworkReqs986619331108181
WebpackStandard HomeuiStartup831702118177849979
load59154484863604760
domContentLoaded58454083160598738
domInteractive181177141457
firstPaint22158836215181746
backgroundConnect2511132182468
firstReactRender31194783742
getState19113652327
initialActions102111
loadScripts58153882358596727
setupStore1162331316
numNetworkReqs1467720874
WebpackPower User HomeuiStartup13181153193219613921777
load6495641147126659994
domContentLoaded6305511119115632934
domInteractive32132754325142
firstPaint333601124275581901
backgroundConnect48112144354180
firstReactRender7642110138196
getState1479621317155178
initialActions102011
loadScripts6275491111113630925
setupStore18663133136
numNetworkReqs1316926251179233
FirefoxBrowserifyStandard HomeuiStartup12481075168711413141454
load105492113348811121219
domContentLoaded105392113348811121219
domInteractive63311953787134
firstPaint------
backgroundConnect3622226243767
firstReactRender22184452236
getState106748921
initialActions102012
loadScripts103190612618010871181
setupStore13522023929
numNetworkReqs1266115757
BrowserifyPower User HomeuiStartup28132082391037330673596
load12681013182019812891689
domContentLoaded12671013182019912891688
domInteractive16134777152189553
firstPaint------
backgroundConnect283301107294448989
firstReactRender904014221100135
getState25761906256193859
initialActions3133628
loadScripts1214995179218612271622
setupStore1255842199112777
numNetworkReqs98642314396214
WebpackStandard HomeuiStartup14791293188812515341764
load1262105115059813441424
domContentLoaded1261105115059813441424
domInteractive77282345298216
firstPaint------
backgroundConnect4120114194585
firstReactRender29217593040
getState136146171049
initialActions103112
loadScripts1234103614279313101393
setupStore12553101240
numNetworkReqs1367017762
WebpackPower User HomeuiStartup29362260407434431313581
load14141109188819015681791
domContentLoaded14131109188819015681790
domInteractive15232654143168505
firstPaint------
backgroundConnect187321024196226613
firstReactRender924122928100144
getState321781559321481895
initialActions2029323
loadScripts13801084178618515011754
setupStore1467797222112763
numNetworkReqs1005923645100216
📊 Page Load Benchmark Results

Current Commit: 500d78e | Date: 11/19/2025

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.05s (±44ms) 🟡 | historical mean value: 1.05s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 734ms (±40ms) 🟢 | historical mean value: 730ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 79ms (±11ms) 🟢 | historical mean value: 77ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.05s 44ms 1.03s 1.35s 1.07s 1.35s
domContentLoaded 734ms 40ms 712ms 1.01s 753ms 1.01s
firstPaint 79ms 11ms 60ms 172ms 84ms 172ms
firstContentfulPaint 79ms 11ms 60ms 172ms 84ms 172ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 53 Bytes (0%)
  • ui: 1.69 KiB (0.02%)
  • common: 20 Bytes (0%)

@ghgoodreau ghgoodreau marked this pull request as ready for review November 19, 2025 20:44
@ghgoodreau ghgoodreau requested a review from a team as a code owner November 19, 2025 20:44
@metamaskbot
Copy link
Collaborator

Builds ready [c4a5908]
UI Startup Metrics (1537 ± 143 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard HomeuiStartup15371284192614316391775
load13101097168612914031525
domContentLoaded12961048168113313921511
domInteractive3117194252793
firstPaint764110156354613251496
backgroundConnect25222947730255278
firstReactRender362269114264
getState4318114175174
initialActions107115
loadScripts1058813140813111541273
setupStore1585471827
numNetworkReqs1367518665
BrowserifyPower User HomeuiStartup19151598335729320582495
load1022895205117910211480
domContentLoaded100788720351799971471
domInteractive37161793932160
firstPaint58610915434039481392
backgroundConnect22720427912234253
firstReactRender82491311390102
getState18614138147200286
initialActions103112
loadScripts79568517721757891253
setupStore211095122641
numNetworkReqs986720032106187
WebpackStandard HomeuiStartup8397031131868461037
load59554287467601768
domContentLoaded58853885765594750
domInteractive181169131552
firstPaint17657813177156583
backgroundConnect251295192687
firstReactRender3420246243764
getState19122842126
initialActions104112
loadScripts58553684863591741
setupStore1162431317
numNetworkReqs1467620872
WebpackPower User HomeuiStartup13701178234219714141778
load67459112501296691028
domContentLoaded6535781149116645964
domInteractive33142564521152
firstPaint359641006270603945
backgroundConnect50122474163134
firstReactRender81471121386102
getState15611022219164197
initialActions101011
loadScripts6505761140114643955
setupStore19776153351
numNetworkReqs1186925245130231
FirefoxBrowserifyStandard HomeuiStartup13901163195613414561655
load115999214429112211331
domContentLoaded115899214429112181331
domInteractive77322574488156
firstPaint------
backgroundConnect4423136214886
firstReactRender25195052538
getState137141171224
initialActions103122
loadScripts113197713768711911308
setupStore15682141343
numNetworkReqs1266715760
BrowserifyPower User HomeuiStartup27011961379034828733458
load1200949166918012411610
domContentLoaded1199948166918012411609
domInteractive15233707140170539
firstPaint------
backgroundConnect22425966248252844
firstReactRender88401582197124
getState23663913241193840
initialActions3134528
loadScripts1156929161917112021573
setupStore1267796198111738
numNetworkReqs98652204299204
WebpackStandard HomeuiStartup14571247197113215131718
load12321092161910512951426
domContentLoaded12311091161910512951426
domInteractive65272324483142
firstPaint------
backgroundConnect4121190274192
firstReactRender312193123070
getState136146161146
initialActions103122
loadScripts1205107415789712701366
setupStore13684131038
numNetworkReqs1366616762
WebpackPower User HomeuiStartup28702003396836730693585
load14101145193819115521816
domContentLoaded14101145193719115521815
domInteractive14133594127154463
firstPaint------
backgroundConnect206251267225225747
firstReactRender904513919102127
getState26868894261199860
initialActions218227
loadScripts13681107190318514871754
setupStore1116839182101751
numNetworkReqs98662224297208
📊 Page Load Benchmark Results

Current Commit: c4a5908 | Date: 11/19/2025

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.03s (±40ms) 🟡 | historical mean value: 1.05s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 719ms (±38ms) 🟢 | historical mean value: 730ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 75ms (±14ms) 🟢 | historical mean value: 77ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.03s 40ms 1.00s 1.34s 1.06s 1.34s
domContentLoaded 719ms 38ms 694ms 1.02s 749ms 1.02s
firstPaint 75ms 14ms 56ms 188ms 88ms 188ms
firstContentfulPaint 75ms 14ms 56ms 188ms 88ms 188ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 53 Bytes (0%)
  • ui: 328 Bytes (0%)
  • common: 20 Bytes (0%)

@metamaskbot
Copy link
Collaborator

Builds ready [1b120d9]
UI Startup Metrics (1223 ± 106 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard HomeuiStartup12231047160710613081379
load105589513849411341214
domContentLoaded104889213769411261205
domInteractive2414102182171
firstPaint53484124040610211149
backgroundConnect21119424910215231
firstReactRender26185682845
getState29165683347
initialActions102112
loadScripts844700115492921992
setupStore1072531115
numNetworkReqs1367319669
BrowserifyPower User HomeuiStartup18411554313827519502438
load97685819311699811383
domContentLoaded96185019201679561368
domInteractive33151833428128
firstPaint5399915333919031366
backgroundConnect21719825011224239
firstReactRender78471291584112
getState18013436849187306
initialActions102011
loadScripts76165116801627591164
setupStore211076122745
numNetworkReqs976820632106187
WebpackStandard HomeuiStartup826730101874853990
load61656281663620787
domContentLoaded61255780862615780
domInteractive231499172169
firstPaint22087803147205601
backgroundConnect1163371429
firstReactRender3220241223440
getState29135593648
initialActions103112
loadScripts60955679860613772
setupStore1152341419
numNetworkReqs1367619671
WebpackPower User HomeuiStartup14511212244924015961959
load67758712641326731027
domContentLoaded66658012571316591017
domInteractive36161703629146
firstPaint270881038184265653
backgroundConnect1483361826
firstReactRender82521111289104
getState15713327534160248
initialActions102112
loadScripts66357712481296571008
setupStore241072153552
numNetworkReqs1377228052173260
FirefoxBrowserifyStandard HomeuiStartup12131044161812012601513
load101890212597910651177
domContentLoaded101789812597910651176
domInteractive59332173584119
firstPaint------
backgroundConnect3620181223769
firstReactRender22184252336
getState1167310922
initialActions103122
loadScripts99888712317510461152
setupStore134170181032
numNetworkReqs1367018866
BrowserifyPower User HomeuiStartup26111977369035428163338
load1147944173017412051499
domContentLoaded1146944173017412051499
domInteractive14233530130157500
firstPaint------
backgroundConnect19022942211235710
firstReactRender87391462095128
getState25283919251200846
initialActions3132528
loadScripts1107927170816811451446
setupStore1216802191101753
numNetworkReqs96642184290198
WebpackStandard HomeuiStartup14551266195611814871712
load1251107215629213041442
domContentLoaded1250107215619213041442
domInteractive68272304184146
firstPaint------
backgroundConnect4620283334697
firstReactRender27187272837
getState1064961116
initialActions102112
loadScripts1222105714397912811362
setupStore125194201034
numNetworkReqs1366816762
WebpackPower User HomeuiStartup28752074389335530583516
load14091133212621115431847
domContentLoaded14091132212621115431846
domInteractive13830619137157488
firstPaint------
backgroundConnect18528934201215700
firstReactRender904022624100121
getState30481905277426887
initialActions3133527
loadScripts13641115201020714821781
setupStore103679616794638
numNetworkReqs97632254497214
📊 Page Load Benchmark Results

Current Commit: 1b120d9 | Date: 11/19/2025

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±37ms) 🟡 | historical mean value: 1.05s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 726ms (±34ms) 🟢 | historical mean value: 730ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 77ms (±12ms) 🟢 | historical mean value: 77ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 37ms 1.02s 1.32s 1.06s 1.32s
domContentLoaded 726ms 34ms 708ms 982ms 748ms 982ms
firstPaint 77ms 12ms 56ms 180ms 84ms 180ms
firstContentfulPaint 77ms 12ms 56ms 180ms 84ms 180ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 74 Bytes (0%)
  • ui: 492 Bytes (0.01%)
  • common: 217 Bytes (0%)

@ghgoodreau ghgoodreau enabled auto-merge November 19, 2025 23:18
insufficientBal: providerConfig?.rpcUrl?.includes('localhost')
? true
: undefined,
: insufficientBalOverride,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
: insufficientBalOverride,
: isInsufficientBalance,

Can you reuse the isInsufficientBalance value returned by the getValidationErrors selector instead? It's the same condition used for showing balance validation errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think isInsufficientBalance is from the previous quote request, so it's always going to be behind a little, whereas these changes do it 'live' so the flag is always up to date

providerConfig?.rpcUrl,
gasIncluded,
gasIncluded7702,
insufficientBalOverride,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
insufficientBalOverride,
isInsufficientBalance,

@ghgoodreau ghgoodreau added this pull request to the merge queue Nov 20, 2025
Merged via the queue into main with commit a09309d Nov 20, 2025
188 checks passed
@ghgoodreau ghgoodreau deleted the SWAPS-3470-insufficient-bal-tracking-for-nonevm branch November 20, 2025 17:36
@github-actions github-actions bot locked and limited conversation to collaborators Nov 20, 2025
@metamaskbot metamaskbot added the release-13.11.0 Issue or pull request that will be included in release 13.11.0 label Nov 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-13.11.0 Issue or pull request that will be included in release 13.11.0 size-S team-swaps-and-bridge Swaps and Bridge team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants