Skip to content

Conversation

@tuna1207
Copy link
Member

@tuna1207 tuna1207 commented Nov 6, 2025

Description

Previously in shield plan screen, when user change plan, the selected token approval amount didn't get updated hence user will see outdated approval amount in the confirmation screen
This PR reset the selected token when plan change to get correct latest approval amount

Open in GitHub Codespaces

Changelog

CHANGELOG entry: fix incorrect token approval amount when change shield plan

Related issues

Fixes:

Manual testing steps

  1. shield plan page
  2. select a plan and go to confirm page
  3. go back and select a different plan
  4. go to confirm page should reflect the new approval amount

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

Prevents stale approval amounts by resetting the selected token when the plan changes and refactors useAvailableTokenBalances to return {availableTokenBalances, pending, error} via useAsyncResult.

  • Hooks:
    • useAvailableTokenBalances:
      • Returns { availableTokenBalances, pending, error } instead of an array; leverages useAsyncResult (removes local useState/useEffect).
      • Adds early return when missing price or chain map; logs when token payment info missing.
      • Computes approval amounts and filters tokens with sufficient balance; keeps polling balances for payment chains.
  • Shield Plan Page (ui/pages/shield-plan/shield-plan.tsx):
    • Consumes new hook shape; uses pending to defer token selection until data ready.
    • Resets selectedToken when selectedPlan changes; only restores last-used token if it matches current plan.
    • Defaults payment method to crypto when a token is selected.

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

@metamaskbot metamaskbot added the team-onboarding Onboarding team label Nov 6, 2025
@tuna1207 tuna1207 marked this pull request as ready for review November 6, 2025 15:49
@github-actions github-actions bot added the size-M label Nov 6, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [50a1e6e]
UI Startup Metrics (1205 ± 90 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard HomeuiStartup1205104414609012721346
load104290812608311181163
domContentLoaded103690512568211081157
domInteractive2113114161752
firstPaint64685122441510651155
backgroundConnect2262152647229238
firstReactRender25184352835
getState2174992538
initialActions001001
loadScripts816685102982884935
setupStore1062331118
numNetworkReqs1367620673
BrowserifyPower User HomeuiStartup19411714255423621292554
load1024897142817412271428
domContentLoaded1017889141717312191417
domInteractive311587256587
firstPaint43115012223349021222
backgroundConnect24022529517247295
firstReactRender29254042940
getState18014823222199232
initialActions002112
loadScripts78767111321629911132
setupStore1292741127
numNetworkReqs1167324762170247
WebpackStandard HomeuiStartup8206941134928251060
load60455091982596848
domContentLoaded59754190579591832
domInteractive15115081441
firstPaint19857909190199738
backgroundConnect241176142655
firstReactRender28176293337
getState1053341216
initialActions001001
loadScripts59453989477589822
setupStore1052731217
numNetworkReqs1367619871
WebpackPower User HomeuiStartup12461134154613512711546
load644568908106711908
domContentLoaded63156387299694872
domInteractive221269163369
firstPaint33058802266586802
backgroundConnect52161945247194
firstReactRender25232922729
getState14710516518161165
initialActions001011
loadScripts62756186296683862
setupStore1062661126
numNetworkReqs1086817141165171
FirefoxBrowserifyStandard HomeuiStartup15111315192111315761720
load1285112515768813461419
domContentLoaded1285112415768813461419
domInteractive1223436160127266
firstPaint------
backgroundConnect4726133215395
firstReactRender26216462742
getState8412412818
initialActions001001
loadScripts1257109815458313181374
setupStore1263351327
numNetworkReqs1265814755
BrowserifyPower User HomeuiStartup23502078274820625462748
load12841111166218814121662
domContentLoaded12841110166218814121662
domInteractive19577616179303616
firstPaint------
backgroundConnect952839793126397
firstReactRender422967115067
getState1358619433173194
initialActions101111
loadScripts12571090163818513601638
setupStore27797294097
numNetworkReqs1336921762204217
WebpackStandard HomeuiStartup16351481202213116661944
load14061247173010414521650
domContentLoaded14061247173010414511650
domInteractive1063234350113201
firstPaint------
backgroundConnect49252302954115
firstReactRender29237692942
getState94488722
initialActions001001
loadScripts1375123017029814151564
setupStore15687131350
numNetworkReqs1367017766
WebpackPower User HomeuiStartup24962106340935226553409
load15621328201520616952015
domContentLoaded15621326201520616942015
domInteractive16672470120287470
firstPaint------
backgroundConnect953225373143253
firstReactRender33284753647
getState1156417328140173
initialActions106116
loadScripts15241305192018816491920
setupStore26967163867
numNetworkReqs1306131588206315
📊 Page Load Benchmark Results

Current Commit: 50a1e6e | Date: 11/6/2025

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±53ms) 🟡 | historical mean value: 1.04s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 727ms (±51ms) 🟢 | historical mean value: 728ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 78ms (±14ms) 🟢 | historical mean value: 77ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 53ms 1.01s 1.35s 1.06s 1.35s
domContentLoaded 727ms 51ms 701ms 1.01s 740ms 1.01s
firstPaint 78ms 14ms 60ms 204ms 84ms 204ms
firstContentfulPaint 78ms 14ms 60ms 204ms 84ms 204ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 58 Bytes (0%)
  • ui: 166 Bytes (0%)
  • common: 20 Bytes (0%)

@metamaskbot
Copy link
Collaborator

Builds ready [f31aec5]
UI Startup Metrics (1206 ± 119 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard HomeuiStartup1206962151611912781420
load1033836130610710901221
domContentLoaded1025831129510710841217
domInteractive2114113141952
firstPaint68284130541510601208
backgroundConnect20517229126219258
firstReactRender22165152332
getState1975392438
initialActions001001
loadScripts8286511061978871007
setupStore1062221114
numNetworkReqs1367620674
BrowserifyPower User HomeuiStartup18761572237023521082370
load1032888153520312971535
domContentLoaded1024881150319812881503
domInteractive291574184874
firstPaint860194154240713021542
backgroundConnect2312212579236257
firstReactRender28253842838
getState17115220816181208
initialActions001011
loadScripts800661127119610561271
setupStore14103881238
numNetworkReqs1397332288242322
WebpackStandard HomeuiStartup821704117881829966
load602557100271606730
domContentLoaded59654997468601718
domInteractive16115591443
firstPaint188571013179193576
backgroundConnect231175132453
firstReactRender29186183438
getState1161821214
initialActions001001
loadScripts59354696366599707
setupStore1163141318
numNetworkReqs1367319670
WebpackPower User HomeuiStartup11971041175319912231753
load599521870105643870
domContentLoaded57750678589604785
domInteractive211253143353
firstPaint38377788255608788
backgroundConnect721630485162304
firstReactRender26232712627
getState1247515324138153
initialActions001001
loadScripts57350477887596778
setupStore1063681036
numNetworkReqs1257122853166228
FirefoxBrowserifyStandard HomeuiStartup14531283182310015091670
load1239110214057513091356
domContentLoaded1239110214057513091355
domInteractive1203333056122218
firstPaint------
backgroundConnect4225144204789
firstReactRender25214142535
getState74384715
initialActions001001
loadScripts1215108713737112841331
setupStore1375171227
numNetworkReqs1266415755
BrowserifyPower User HomeuiStartup27312322373840129703738
load15501265203025418482030
domContentLoaded15501264202925518472029
domInteractive22796665189301665
firstPaint------
backgroundConnect11732370114149370
firstReactRender463271115471
getState1448621439191214
initialActions506816168
loadScripts15141240198624717721986
setupStore63753412550534
numNetworkReqs1347130773204307
WebpackStandard HomeuiStartup17101530229414717552079
load14491289186810014921633
domContentLoaded14491289186710014921633
domInteractive1053239948112175
firstPaint------
backgroundConnect57292934059122
firstReactRender32248293346
getState11421823740
initialActions001001
loadScripts1412125718379514611589
setupStore17874121649
numNetworkReqs1366918767
WebpackPower User HomeuiStartup25362210295023727942950
load15311266185517116561855
domContentLoaded15301266185417116561854
domInteractive17337541150301541
firstPaint------
backgroundConnect88372577284257
firstReactRender44316295262
getState1396119243181192
initialActions106116
loadScripts15021243180016616261800
setupStore3571444531144
numNetworkReqs1326731474191314
📊 Page Load Benchmark Results

Current Commit: f31aec5 | Date: 11/7/2025

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±39ms) 🟡 | historical mean value: 1.03s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 722ms (±36ms) 🟢 | historical mean value: 718ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 77ms (±14ms) 🟢 | historical mean value: 76ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 39ms 1.01s 1.32s 1.07s 1.32s
domContentLoaded 722ms 36ms 699ms 990ms 732ms 990ms
firstPaint 77ms 14ms 60ms 200ms 88ms 200ms
firstContentfulPaint 77ms 14ms 60ms 200ms 88ms 200ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 669 Bytes (0.01%)
  • ui: 3.48 KiB (0.05%)
  • common: 62 Bytes (0%)

@metamaskbot
Copy link
Collaborator

Builds ready [4ab428c]
UI Startup Metrics (1249 ± 99 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard HomeuiStartup1249109315749912981432
load107494412968611241227
domContentLoaded106894012898611191222
domInteractive221599152154
firstPaint61996131142410601217
backgroundConnect2322202637236243
firstReactRender30195783445
getState247118142845
initialActions001001
loadScripts842706105685896997
setupStore1172841319
numNetworkReqs1367619670
BrowserifyPower User HomeuiStartup17911618251425420122514
load941819132917511351329
domContentLoaded934812132217511301322
domInteractive271580205080
firstPaint59316712653768581265
backgroundConnect18917522312193223
firstReactRender26223632736
getState16013420518173205
initialActions001011
loadScripts75364211041679511104
setupStore1282661126
numNetworkReqs1217425167175251
WebpackStandard HomeuiStartup8187011134858251041
load60055391075593843
domContentLoaded59354789872588817
domInteractive16116891440
firstPaint19860901202171732
backgroundConnect231261122352
firstReactRender29177893340
getState1053231214
initialActions001001
loadScripts59154588770586806
setupStore1254661228
numNetworkReqs1367620872
WebpackPower User HomeuiStartup12851155186418013361864
load652579927110702927
domContentLoaded636566899103683899
domInteractive261372213672
firstPaint30670908280571908
backgroundConnect531116052121160
firstReactRender27243732837
getState1397918929153189
initialActions002102
loadScripts632564889100673889
setupStore1262782027
numNetworkReqs1097021845163218
FirefoxBrowserifyStandard HomeuiStartup14601290199913115211727
load1232111214889012971403
domContentLoaded1231111114889012971403
domInteractive1083637656105259
firstPaint------
backgroundConnect4627158245185
firstReactRender27216582742
getState74304715
initialActions001001
loadScripts1206109414318712611381
setupStore167230231434
numNetworkReqs1266215758
BrowserifyPower User HomeuiStartup23622093308426124643084
load13211119170017215051700
domContentLoaded13211118169917115041699
domInteractive17264392114314392
firstPaint------
backgroundConnect1102630094203300
firstReactRender39295174751
getState1173617438161174
initialActions102112
loadScripts12901100163115814411631
setupStore2961784031178
numNetworkReqs1507129871214298
WebpackStandard HomeuiStartup15871402209913116201901
load13601192173910513941587
domContentLoaded13601192173810513941587
domInteractive943041747102194
firstPaint------
backgroundConnect49191662652114
firstReactRender29227992940
getState846810635
initialActions001001
loadScripts13291174170010013591546
setupStore1265881226
numNetworkReqs1366817764
WebpackPower User HomeuiStartup26192259355139129173551
load15191291201320316772013
domContentLoaded15181290201320416762013
domInteractive15441432125297432
firstPaint------
backgroundConnect12435375111270375
firstReactRender47341021655102
getState1246928251132282
initialActions106116
loadScripts14831270193119516471931
setupStore3461514735151
numNetworkReqs1306031487223314
📊 Page Load Benchmark Results

Current Commit: 4ab428c | Date: 11/8/2025

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±38ms) 🟡 | historical mean value: 1.04s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 722ms (±36ms) 🟢 | historical mean value: 723ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 76ms (±10ms) 🟢 | historical mean value: 77ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 38ms 1.01s 1.30s 1.07s 1.30s
domContentLoaded 722ms 36ms 698ms 979ms 759ms 979ms
firstPaint 76ms 10ms 60ms 160ms 84ms 160ms
firstContentfulPaint 76ms 10ms 60ms 160ms 84ms 160ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 962 Bytes (0.02%)
  • ui: -2.58 KiB (-0.04%)
  • common: 880 Bytes (0.01%)


// reset selected token if selected plan changes
useEffect(() => {
setSelectedToken(undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this set to be default instead of undefined?
Like what we do in the above useEffects.
If I'm not mistaken, we don't need new side effects hook for this (we already have the (useEffect) hook which does the similar thing)?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah no that wouldn't work, since the above effect is only set if there is no selected token set yet to set the default token, if there is already token set, it won't trigger again, so that it won't run everytime token balance change

@tuna1207 tuna1207 requested a review from lwin-kyaw November 10, 2025 04:58
@lwin-kyaw lwin-kyaw added this pull request to the merge queue Nov 10, 2025
Merged via the queue into main with commit 5f8ff4c Nov 10, 2025
173 checks passed
@lwin-kyaw lwin-kyaw deleted the fix/shield-plan-change-crypto-approval branch November 10, 2025 06:23
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2025
@metamaskbot metamaskbot added the release-13.10.0 Issue or pull request that will be included in release 13.10.0 label Nov 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-shield release-13.10.0 Issue or pull request that will be included in release 13.10.0 size-M team-onboarding Onboarding team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants