Skip to content

feat: Implement edit spending cap modal for approve confirmations #16856

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 2 commits into from
Jul 2, 2025

Conversation

OGPoyraz
Copy link
Member

@OGPoyraz OGPoyraz commented Jul 2, 2025

Description

This PR aims to implement edit spending cap modal for ERC20 tokens in approve confirmations.

As this is the last functional PR for approve confirmations - it also adds feature flag instead of env variable hard disables it.

This spending cap modal also includes validations which is demonstrated in the screenshots section.

Related issues

Fixes: #16833

Manual testing steps

  1. Go to test dapp
  2. Deploy ERC20 token
  3. Use "approve tokens" or "increase token allowance" button

Screenshots/Recordings

Before

After

spending.cap.modal.mp4

Screenshot 2025-07-02 at 09 07 03

Screenshot 2025-07-02 at 09 07 09

Screenshot 2025-07-02 at 09 07 21

Screenshot 2025-07-02 at 09 07 31

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.

@OGPoyraz OGPoyraz requested a review from a team as a code owner July 2, 2025 07:12
@OGPoyraz OGPoyraz added No QA Needed Apply this label when your PR does not need any QA effort. Run Smoke E2E Requires smoke E2E testing no-changelog Indicates no external facing user changes, therefore no changelog documentation needed labels Jul 2, 2025
@metamaskbot metamaskbot added the team-confirmations Push issues to confirmations team label Jul 2, 2025
Copy link
Contributor

github-actions bot commented Jul 2, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 5d1bab3
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/c0fe4bfa-1e38-4235-883e-f111e8814626

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

cursor[bot]

This comment was marked as outdated.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 90.51724% with 11 lines in your changes missing coverage. Please review.

Project coverage is 72.46%. Comparing base (33b8046) to head (5d1bab3).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
...s/Views/confirmations/utils/validations/approve.ts 87.87% 2 Missing and 2 partials ⚠️
...ations/approve-and-permit2/approve-and-permit2.tsx 50.00% 0 Missing and 3 partials ⚠️
...decrease-allowance/increase-decrease-allowance.tsx 40.00% 0 Missing and 3 partials ⚠️
...onfirmations/hooks/useApproveTransactionActions.ts 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16856      +/-   ##
==========================================
+ Coverage   72.40%   72.46%   +0.06%     
==========================================
  Files        2709     2726      +17     
  Lines       58754    59084     +330     
  Branches     9254     9342      +88     
==========================================
+ Hits        42540    42818     +278     
- Misses      13517    13527      +10     
- Partials     2697     2739      +42     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@OGPoyraz OGPoyraz added Run Smoke E2E Requires smoke E2E testing and removed Run Smoke E2E Requires smoke E2E testing labels Jul 2, 2025
Copy link
Contributor

github-actions bot commented Jul 2, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 03662bd
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/ed8b73ad-9e2e-49fa-bd8c-b93514d6a1c5

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Spending Cap Validation Fails for Comma Separators

The spending cap validation logic in app/components/Views/confirmations/utils/validations/approve.ts contains multiple issues:

  • The validateValueIsPositive function fails to normalize comma decimal separators (e.g., "123,45") before parsing, leading to incorrect positive value checks. It also incorrectly allows negative values.
  • The validateAmountIsValidNumber function's regex /^\d*\.?\d+$/ incorrectly rejects valid integer inputs (e.g., "123").

app/components/Views/confirmations/utils/validations/approve.ts#L3-L32

const validateValueIsPositive = (
newSpendingCap: string,
approveMethod: ApproveMethod,
) => {
if (parseFloat(newSpendingCap) > 0) {
return false;
}
if (parseFloat(newSpendingCap) === 0) {
if (
approveMethod === ApproveMethod.INCREASE_ALLOWANCE ||
approveMethod === ApproveMethod.DECREASE_ALLOWANCE
) {
return strings(
approveMethod === ApproveMethod.INCREASE_ALLOWANCE
? 'confirm.edit_spending_cap_modal.no_zero_error_increase_allowance'
: 'confirm.edit_spending_cap_modal.no_zero_error_decrease_allowance',
);
}
return strings('confirm.edit_spending_cap_modal.no_zero_error');
}
return false;
};
const validateAmountIsValidNumber = (newSpendingCap: string) => {
const normalizedValue = newSpendingCap.replace(',', '.');
if (!/^\d*\.?\d+$/.test(normalizedValue)) {

Fix in Cursor


Bug: Modal Stuck Loading Due to Error Handling

The Save button's onPress handler has improper error handling. If onSpendingCapUpdate throws an error, setIsDataUpdating(false) is not called, leaving the modal permanently in a loading state. The async operation should be wrapped in a try-finally block to ensure setIsDataUpdating(false) is always executed.

app/components/Views/confirmations/components/modals/edit-spending-cap-modal/edit-spending-cap-modal.tsx#L102-L108

isDisabled={!!error}
onPress={async () => {
setIsDataUpdating(true);
await onSpendingCapUpdate?.(newSpendingCap);
onClose();
setIsDataUpdating(false);
}}

Fix in Cursor


Bug: Decimal Mismatch Causes Validation Issues

The ApproveAndPermit2 component uses decimals ?? 1 as the default for the EditSpendingCapButton's decimals prop, while the useApproveTransactionActions hook uses ERC20_DEFAULT_DECIMALS (typically 18) for transaction updates. This inconsistency in default decimal values can cause validation to misalign with actual transaction processing, leading to incorrect input handling.

app/components/Views/confirmations/components/approve-static-simulations/approve-and-permit2/approve-and-permit2.tsx#L82-L83

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

Copy link

sonarqubecloud bot commented Jul 2, 2025

Copy link
Contributor

@jpuri jpuri left a comment

Choose a reason for hiding this comment

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

Code changes look good to me.

Code looks very specific to use case of editing spending cap and to make it re-usable we would need to extract more generic code out of it.

@OGPoyraz
Copy link
Member Author

OGPoyraz commented Jul 2, 2025

As I've already ran e2e tests 5 times and having the same failures on run_wallet_platform_swimlane_android_smoke https://app.bitrise.io/build/80823645-35b0-4705-9d81-b170edeaa5e7 I am adding No e2e smoke needed label because this failures are not related.

@OGPoyraz OGPoyraz added No E2E Smoke Needed If the PR does not need E2E smoke test run and removed Run Smoke E2E Requires smoke E2E testing labels Jul 2, 2025
@OGPoyraz OGPoyraz enabled auto-merge July 2, 2025 14:53
@OGPoyraz OGPoyraz added this pull request to the merge queue Jul 2, 2025
Merged via the queue into main with commit bdf6f74 Jul 2, 2025
58 of 61 checks passed
@OGPoyraz OGPoyraz deleted the ogp/16833 branch July 2, 2025 15:17
@github-actions github-actions bot locked and limited conversation to collaborators Jul 2, 2025
@metamaskbot metamaskbot added the release-7.51.0 Issue or pull request that will be included in release 7.51.0 label Jul 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
No E2E Smoke Needed If the PR does not need E2E smoke test run No QA Needed Apply this label when your PR does not need any QA effort. no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.51.0 Issue or pull request that will be included in release 7.51.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement spending cap modal
4 participants