Skip to content
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

feat: Add redesigned ERC20 Approve confirmation and SpendingCap section #26606

Merged
merged 25 commits into from
Sep 2, 2024

Conversation

pedronfigueiredo
Copy link
Contributor

@pedronfigueiredo pedronfigueiredo commented Aug 22, 2024

Description

Introduces support for ERC20 token transactions with the approve type. This includes a new spending cap section and bespoke logic in the "static simulation" section. Above a certain threshold, spending caps are represented as "Unlimited".

Open in GitHub Codespaces

Related issues

Fixes: #2924

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Screenshot 2024-08-22 at 12 30 02 Screenshot 2024-08-22 at 12 30 06

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 Aug 22, 2024
@pedronfigueiredo pedronfigueiredo self-assigned this Aug 22, 2024
@pedronfigueiredo pedronfigueiredo requested review from a team as code owners August 22, 2024 11:20
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 force-pushed the pnf/2924 branch 4 times, most recently from fd15e88 to e0713a6 Compare August 22, 2024 14:05
@pedronfigueiredo pedronfigueiredo changed the title feat: Add redesigned ERC20 Approve confirmation feat: Add redesigned ERC20 Approve confirmation and SpendingCap section Aug 23, 2024
@pedronfigueiredo pedronfigueiredo force-pushed the pnf/2924 branch 2 times, most recently from d3260a4 to 8c3d68e Compare August 26, 2024 13:13
@bschorchit
Copy link

@pedronfigueiredo for the erc20 approve and increaseAllowance, can we update the subtitle copy and the copy within the estimated changes to match the one here? Ty 💛

Subtitle
Update to: This site wants permission to spend your tokens.

Estimated changes
Update to: You’re giving someone else permission to spend this amount from your account.

Key row within Estimated changes
Update to: Spending cap

Screenshot 2024-08-26 at 18 27 29

@metamaskbot
Copy link
Collaborator

Builds ready [f86909d]
Page Load Metrics (81 ± 12 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint762031113014
domContentLoaded51164772512
load58165812412
domInteractive1910133209
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 6.47 KiB (0.09%)
  • common: 261 Bytes (0.00%)

Copy link

codecov bot commented Aug 27, 2024

Codecov Report

Attention: Patch coverage is 56.81818% with 38 lines in your changes missing coverage. Please review.

Project coverage is 70.06%. Comparing base (f354888) to head (50a7441).
Report is 77 commits behind head on develop.

Files with missing lines Patch % Lines
...ations/components/confirm/info/approve/approve.tsx 17.95% 32 Missing ⚠️
...s/confirmations/components/confirm/title/title.tsx 53.85% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #26606      +/-   ##
===========================================
- Coverage    70.08%   70.06%   -0.02%     
===========================================
  Files         1414     1417       +3     
  Lines        49328    49407      +79     
  Branches     13781    13811      +30     
===========================================
+ Hits         34568    34615      +47     
- Misses       14760    14792      +32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

sonarcloud bot commented Aug 29, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [50a7441]
Page Load Metrics (1793 ± 80 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint32123031730362174
domContentLoaded15822290177516881
load15942300179316780
domInteractive23238494823
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 5.69 KiB (0.08%)
  • common: 261 Bytes (0.00%)

}
editIconClassName="edit-spending-cap"
/>
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Putting JSX in variable is INHO not great idea, any reason for not including it inline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the idea is to reduce code duplication in the following code block

      <ConfirmInfoRow
        label={t('spendingCap')}
        tooltip={t('spendingCapTooltipDesc')}
      >
        {tokenAmount === UNLIMITED_MSG ? (
          <Tooltip title={formattedTokenNum}>{SpendingCapElement}</Tooltip>
        ) : (
          SpendingCapElement
        )}
      </ConfirmInfoRow>

This was changed to address feedback on this comment #26606 (comment)

symbol: string;
};

export const useReceivedToken = () => {
Copy link
Member

Choose a reason for hiding this comment

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

Can this file now be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be removed in the next PR

switch (confirmation?.type) {
case TransactionType.contractInteraction:
return t('confirmTitleTransaction');
case TransactionType.tokenMethodApprove:
return t('confirmTitleApproveTransaction');
if (isNFT) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor, ternary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

keeping it as is for now since it's the pattern in use in this file

);
}, [transactionMeta]);

const isNFT = value?.standard !== TokenStandard.ERC20;
Copy link
Member

Choose a reason for hiding this comment

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

Minor, I appreciate we're only using this for labels currently, but one to keep an eye on as some wouldn't consider an ERC-1155 an NFT if it supported multiple of a token ID.


const decodedSpendingCap = value
? new BigNumber(value.data[0].params[1].value)
.dividedBy(new BigNumber(10).pow(Number(decimals)))
Copy link
Member

Choose a reason for hiding this comment

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

Minor, not the problem of this PR but we do this math a lot so a applyDecimals util or similar would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to be addressed in a later PR

@pedronfigueiredo pedronfigueiredo merged commit 4844619 into develop Sep 2, 2024
78 checks passed
@pedronfigueiredo pedronfigueiredo deleted the pnf/2924 branch September 2, 2024 09:46
@github-actions github-actions bot locked and limited conversation to collaborators Sep 2, 2024
@metamaskbot metamaskbot added the release-12.6.0 Issue or pull request that will be included in release 12.6.0 label Sep 2, 2024
@gauthierpetetin gauthierpetetin added release-12.5.0 Issue or pull request that will be included in release 12.5.0 and removed release-12.6.0 Issue or pull request that will be included in release 12.6.0 labels Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.5.0 Issue or pull request that will be included in release 12.5.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants