-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement send max to send flow (#12754)
<!-- 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 implements "Use Max" feature to the send flow. In the `Amount` step we set `maxValueMode` as `true`. When user gets in to the `Confirm` step, depending on the value, transaction value is getting updated. ## **Related issues** #8516 ## **Manual testing steps** 1. Try send eth - initiate from wallet 2. "Use max" value on the `Amount` screen 3. See that amount is adjusted on every gas update ## **Screenshots/Recordings** https://github.com/user-attachments/assets/b785887e-1cb1-4937-9b3d-c15cc72057ea ### **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 Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/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-mobile/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.
- Loading branch information
Showing
10 changed files
with
226 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/components/Views/confirmations/SendFlow/Confirm/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { updateTransactionToMaxValue } from './utils'; | ||
import { BN } from 'ethereumjs-util'; | ||
import { toWei } from '../../../../../util/number'; | ||
|
||
// Mock the Engine and its context | ||
jest.mock('../../../../../util/transaction-controller', () => ({ | ||
updateEditableParams: jest.fn().mockResolvedValue({ | ||
txParams: { value: '0x0' }, | ||
}), | ||
})); | ||
|
||
describe('updateTransactionToMaxValue', () => { | ||
it('should update the transaction value correctly', async () => { | ||
const transactionId = 'testTransactionId'; | ||
const isEIP1559Transaction = true; | ||
const EIP1559GasTransaction = { gasFeeMaxNative: '0.01' }; | ||
const legacyGasTransaction = { gasFeeMaxNative: '0.02' }; | ||
const accountBalance = '0x2386f26fc10000'; // 0.1 ether in wei | ||
const setTransactionValue = jest.fn(); | ||
|
||
await updateTransactionToMaxValue({ | ||
transactionId, | ||
isEIP1559Transaction, | ||
EIP1559GasTransaction, | ||
legacyGasTransaction, | ||
accountBalance, | ||
setTransactionValue, | ||
}); | ||
|
||
// Calculate expected max transaction value | ||
const accountBalanceBN = new BN('2386f26fc10000', 16); // 0.1 ether in wei | ||
const transactionFeeMax = new BN(toWei('0.01', 'ether'), 10); | ||
const expectedMaxTransactionValueBN = | ||
accountBalanceBN.sub(transactionFeeMax); | ||
const expectedMaxTransactionValueHex = | ||
'0x' + expectedMaxTransactionValueBN.toString(16); | ||
|
||
// Check if setTransactionValue was called with the correct value | ||
expect(setTransactionValue).toHaveBeenCalledWith( | ||
expectedMaxTransactionValueHex, | ||
); | ||
}); | ||
}); |
Oops, something went wrong.