-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
|
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
|
There was a problem hiding this 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
metamask-mobile/app/components/Views/confirmations/utils/validations/approve.ts
Lines 3 to 32 in 03662bd
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)) { |
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
Lines 102 to 108 in 03662bd
isDisabled={!!error} | |
onPress={async () => { | |
setIsDataUpdating(true); | |
await onSpendingCapUpdate?.(newSpendingCap); | |
onClose(); | |
setIsDataUpdating(false); | |
}} |
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
Lines 82 to 83 in 03662bd
decimals: decimals ?? 1, | |
spendingCap: amount ?? '', |
Was this report helpful? Give feedback by reacting with 👍 or 👎
|
There was a problem hiding this 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.
As I've already ran e2e tests 5 times and having the same failures on |
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
Screenshots/Recordings
Before
After
spending.cap.modal.mp4
Pre-merge author checklist
Pre-merge reviewer checklist