Skip to content

feat: Display Unlimited for really large spending caps on Permit #29102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 19, 2024

Conversation

pedronfigueiredo
Copy link
Contributor

@pedronfigueiredo pedronfigueiredo commented Dec 11, 2024

Description

Uses UNLIMITED_THRESHOLD to determine wether or not to show a permit amount as "Unlimited". Updates unit tests.

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3763

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.

@pedronfigueiredo pedronfigueiredo added the team-confirmations Push issues to confirmations team label Dec 11, 2024
@pedronfigueiredo pedronfigueiredo self-assigned this Dec 11, 2024
@pedronfigueiredo pedronfigueiredo requested a review from a team as a code owner December 11, 2024 16:01
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.

@pedronfigueiredo pedronfigueiredo changed the title Display Unlimited for really large spending caps on Permit feat: Display Unlimited for really large spending caps on Permit Dec 11, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [1448df0]
Page Load Metrics (1792 ± 119 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint35523151627478230
domContentLoaded147422881764249120
load149523151792248119
domInteractive2089412110
backgroundConnect784282211
firstReactRender1577412411
getState56313147
initialActions01000
loadScripts105418931351244117
setupStore646994
uiStartup164425131967257124
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 580 Bytes (0.01%)
  • common: 0 Bytes (0.00%)

truncatedStartChars: 15,
truncatedEndChars: 0,
skipCharacterInEnd: true,
})}
Copy link
Contributor

Choose a reason for hiding this comment

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

@pedronfigueiredo : not all decoded simulation are Spending Cap some are even amount that user will receive. Can you plz confirm with if this change is ok for all state change types in decoded simulations.

@pedronfigueiredo pedronfigueiredo force-pushed the pnf/3763 branch 2 times, most recently from 161d49a to e68c588 Compare December 13, 2024 11:22
@metamaskbot
Copy link
Collaborator

Builds ready [e68c588]
Page Load Metrics (1723 ± 81 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30521141587458220
domContentLoaded14732066170216378
load14772113172316981
domInteractive256738136
backgroundConnect95925189
firstReactRender1697392713
getState56114168
initialActions01000
loadScripts10561608126014469
setupStore672192210
uiStartup16742370204620398
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 1.09 KiB (0.01%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [41c27cc]
Page Load Metrics (1815 ± 82 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15062242181518287
domContentLoaded14882159178317082
load15122164181517082
domInteractive268645189
backgroundConnect985322311
firstReactRender17101422713
getState56017178
initialActions01000
loadScripts10651650132315273
setupStore784282813
uiStartup167829512128305147
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 746 Bytes (0.01%)
  • common: 0 Bytes (0.00%)

@pedronfigueiredo pedronfigueiredo force-pushed the pnf/3763 branch 2 times, most recently from c88c37d to 359cb29 Compare December 13, 2024 16:32
@metamaskbot
Copy link
Collaborator

Builds ready [359cb29]
Page Load Metrics (1584 ± 33 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1404169715906632
domContentLoaded1380168015617134
load1408169315846933
domInteractive2498432110
backgroundConnect86224189
firstReactRender1690372613
getState45011136
initialActions00000
loadScripts1000127511676029
setupStore66217199
uiStartup15932178182813866
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 746 Bytes (0.01%)
  • common: 0 Bytes (0.00%)

@@ -10,7 +10,7 @@ import { formatAmount } from '../../../../simulation-details/formatAmount';
import { useDecodedTransactionData } from '../../hooks/useDecodedTransactionData';
import { useIsNFT } from './use-is-nft';

const UNLIMITED_THRESHOLD = 10 ** 15;
export const UNLIMITED_THRESHOLD = 10 ** 15;
Copy link
Contributor

Choose a reason for hiding this comment

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

It will be better to move the constant to a constants file.

return {
tokenValue: formatAmount('en-US', tokenAmount),
tokenValueMaxPrecision: formatAmountMaxPrecision('en-US', tokenAmount),
shouldShowUnlimitedValue: Number(value) > UNLIMITED_THRESHOLD,
Copy link
Contributor

@jpuri jpuri Dec 17, 2024

Choose a reason for hiding this comment

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

shouldShowUnlimitedValue will be Number(value) > UNLIMITED_THRESHOLD && canDisplayValueAsUnlimited .

We do not gain a lot by memoising it, but if we choose to do so it will be better to memoise whole of Number(value) > UNLIMITED_THRESHOLD && canDisplayValueAsUnlimited here I think.

@metamaskbot
Copy link
Collaborator

Builds ready [fe64529]
Page Load Metrics (1916 ± 93 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16012216191518489
domContentLoaded15462206188519694
load15512218191619593
domInteractive24112522311
backgroundConnect875312210
firstReactRender17109483517
getState685302713
initialActions01000
loadScripts11701705144716680
setupStore66014157
uiStartup177930522323391188
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 1.11 KiB (0.01%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [31bd740]
Page Load Metrics (1703 ± 116 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint148323751710244117
domContentLoaded147123271682239115
load147923381703242116
domInteractive24106493014
backgroundConnect76122178
firstReactRender1671402311
getState45014147
initialActions00000
loadScripts103218561253227109
setupStore65612126
uiStartup167425931939256123
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 1.11 KiB (0.01%)
  • common: 0 Bytes (0.00%)

jpuri
jpuri previously approved these changes Dec 17, 2024
matthewwalsh0
matthewwalsh0 previously approved these changes Dec 18, 2024
Copy link
Member

Choose a reason for hiding this comment

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

Could we extend ui/pages/confirmations/components/confirm/info/shared/constants.ts which also has a single constant in? 😄

@@ -0,0 +1 @@
export const UNLIMITED_THRESHOLD = 10 ** 15;
Copy link
Member

Choose a reason for hiding this comment

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

Minor, maybe TOKEN_VALUE_UNLIMITED_THRESHOLD for clarity?

tokenValue: formatAmount('en-US', tokenAmount),
tokenValueMaxPrecision: formatAmountMaxPrecision('en-US', tokenAmount),
shouldShowUnlimitedValue:
canDisplayValueAsUnlimited && Number(value) > UNLIMITED_THRESHOLD,
Copy link
Member

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 cast, what other type could it be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

value can be both a number or a string

digiwand
digiwand previously approved these changes Dec 18, 2024
@@ -56,6 +56,9 @@ type PermitSimulationValueDisplayParams = {

/** True if value is being debited to wallet */
debit?: boolean;

/** Wether a large amount can be substituted by "Unlimited" */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** Wether a large amount can be substituted by "Unlimited" */
/** Whether a large amount can be substituted by "Unlimited" */

@metamaskbot
Copy link
Collaborator

Builds ready [da8f3d1]
Page Load Metrics (1412 ± 27 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30615131365248119
domContentLoaded1318147713975225
load1330151314125727
domInteractive2294422110
backgroundConnect84318126
firstReactRender1498382914
getState45712147
initialActions01000
loadScripts929112510286029
setupStore576162311
uiStartup14982033170817082
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 875 Bytes (0.01%)
  • common: 0 Bytes (0.00%)

@pedronfigueiredo pedronfigueiredo added this pull request to the merge queue Dec 19, 2024
Merged via the queue into main with commit 13a1fcf Dec 19, 2024
77 checks passed
@pedronfigueiredo pedronfigueiredo deleted the pnf/3763 branch December 19, 2024 15:42
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2024
@metamaskbot metamaskbot added the release-12.11.0 Issue or pull request that will be included in release 12.11.0 label Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.11.0 Issue or pull request that will be included in release 12.11.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants