You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Implement onAmountInput in send flow amount for non-EVM validation (#37345)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
This PR aims to implement `onAmountInput` RPC call into amount
validations of send flow.
[](https://codespaces.new/MetaMask/metamask-extension/pull/37345?quickstart=1)
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: null
## **Related issues**
Fixes: #37188
## **Manual testing steps**
Case 1:
1. Go to send flow
2. Try send Sol
3. Don't type anything in amount input and click "Continue"
4. You should be able to see confirmation (not infinite spinner)
Case 2:
1. Go to send flow
2. Try send BTC
3. Don't type anything in amount input and click "Continue"
4. You shouldn't be able to proceed confirmation because "0" is not a
valid amount for BTC transaction
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [X] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [X] I've completed the PR template to the best of my ability
- [X] I’ve included tests if applicable
- [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [X] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds non-EVM amount validation using snaps, integrates it into the
send flow, refactors amount error handling, and updates tests.
>
> - **Send Flow UI**:
> - `AmountRecipient`: integrates `useAmountValidation` and
`useSendType`; on Continue, runs `validateNonEvmAmountAsync` for non-EVM
before submit; removes local amount error state; passes `amountError` to
`Amount`; updates button label/disabled logic to use `amountError`.
> - `Amount`: switches prop from `setAmountValueError` to `amountError`;
removes internal validation state/effects; displays error based on prop
only.
> - **Hooks/Validation**:
> - New `useSnapAmountOnInput` hook to call `validateAmountMultichain`
for non-EVM amount checks.
> - Overhauls `useAmountValidation` to async pipeline (positive number,
ERC1155 balance, token balance, non-EVM snap); exposes
`validateNonEvmAmountAsync`; adds snap error mapping.
> - Enhances validators: `validateERC1155Balance` (guards, standards),
`validateTokenBalance` (decimals param), and new
`validatePositiveNumericString`.
> - `useSendActions`: for non-EVM, sends `amount` with
`addLeadingZeroIfNeeded(value || '0')`.
> - **Tests**:
> - Adds tests for non-EVM validation flow in
`amount-recipient.test.tsx` and new hook tests
`useSnapAmountOnInput.test.ts`.
> - Expands `useAmountValidation.test.ts` with edge cases and new
validators.
> - Updates `amount.test.tsx` to reflect new `Amount` API and behavior.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
c6eac31. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
0 commit comments