-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update Redesign Signature Permit to show ellipsis at max 15 dig…
…its (#26227) <!-- 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? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26227?quickstart=1) ## **Related issues** Fixes: #26226 Fixes: MetaMask/MetaMask-planning#2730 (older, original issue) ## **Manual testing steps** 1. Go to cowswap 2. Swap a token with gas-free approve for another token 3. Notice the permit signature screen or 1. run `yarn storybook` 2. go to http://localhost:6006/?path=/story/pages-confirmations-confirm-signatures-signedtypeddatav3orv4--permit-story&args=msgParams.data:3.0001231231212312e+22 3. copy and paste the following into data ``` "{\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"version\",\"type\":\"string\"},{\"name\":\"chainId\",\"type\":\"uint256\"},{\"name\":\"verifyingContract\",\"type\":\"address\"}],\"Permit\":[{\"name\":\"owner\",\"type\":\"address\"},{\"name\":\"spender\",\"type\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\"},{\"name\":\"nonce\",\"type\":\"uint256\"},{\"name\":\"deadline\",\"type\":\"uint256\"}]},\"primaryType\":\"Permit\",\"domain\":{\"name\":\"MyToken\",\"version\":\"1\",\"verifyingContract\":\"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC\",\"chainId\":1},\"message\":{\"owner\":\"0x935e73edb9ff52e23bac7f7e043a1ecd06d05477\",\"spender\":\"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4\",\"value\":30001231231212312138768,\"nonce\":0,\"deadline\":50000000000}}" ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <img width="520" src="https://github.com/user-attachments/assets/1b6e45cb-f54b-45e5-968c-141359de7466"> <img width="320" src="https://github.com/user-attachments/assets/804d4e8a-1c47-470e-88a4-c6195c5cf96e"> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.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
9 changed files
with
144 additions
and
69 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
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
103 changes: 61 additions & 42 deletions
103
ui/pages/confirmations/components/simulation-details/formatAmount.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 |
---|---|---|
@@ -1,51 +1,70 @@ | ||
import { BigNumber } from 'bignumber.js'; | ||
import { formatAmount } from './formatAmount'; | ||
import { ellipsisAmountText, formatAmount } from './formatAmount'; | ||
|
||
describe('formatAmount', () => { | ||
const locale = 'en-US'; | ||
describe('#ellipsisAmountText', () => { | ||
const MOCK_MAX_LEFT_DIGITS = 15; | ||
|
||
it('returns "0" for zero amount', () => { | ||
expect(formatAmount(locale, new BigNumber(0))).toBe('0'); | ||
// @ts-expect-error This is missing from the Mocha type definitions | ||
it.each([ | ||
['1.003', '1.003'], | ||
['1,034', '1,034'], | ||
['1,213,098,292,340,945', '1,213,098,292,340,94...'], | ||
['30,001,231,231,212,312,138,768', '30,001,231,231,212,3...'], | ||
])( | ||
'formats amount greater than or equal to 1 with appropriate decimal precision (%s => %s)', | ||
(amount: string, expected: string) => { | ||
expect(ellipsisAmountText(amount, MOCK_MAX_LEFT_DIGITS)).toBe(expected); | ||
}, | ||
); | ||
}); | ||
|
||
it('returns "<0.000001" for 0 < amount < MIN_AMOUNT', () => { | ||
expect(formatAmount(locale, new BigNumber(0.0000009))).toBe('<0.000001'); | ||
}); | ||
describe('#formatAmount', () => { | ||
const locale = 'en-US'; | ||
|
||
it('returns "0" for zero amount', () => { | ||
expect(formatAmount(locale, new BigNumber(0))).toBe('0'); | ||
}); | ||
|
||
// @ts-expect-error This is missing from the Mocha type definitions | ||
it.each([ | ||
[0.0000456, '0.000046'], | ||
[0.0004567, '0.000457'], | ||
[0.003456, '0.00346'], | ||
[0.023456, '0.0235'], | ||
[0.125456, '0.125'], | ||
])( | ||
'formats amount less than 1 with maximum significant digits (%s => %s)', | ||
(amount: number, expected: string) => { | ||
expect(formatAmount(locale, new BigNumber(amount))).toBe(expected); | ||
}, | ||
); | ||
it('returns "<0.000001" for 0 < amount < MIN_AMOUNT', () => { | ||
expect(formatAmount(locale, new BigNumber(0.0000009))).toBe('<0.000001'); | ||
}); | ||
|
||
// @ts-expect-error This is missing from the Mocha type definitions | ||
it.each([ | ||
[1.0034, '1.003'], | ||
[1.034, '1.034'], | ||
[1.3034, '1.303'], | ||
[12.0345, '12.03'], | ||
[121.456, '121.5'], | ||
[1034.123, '1,034'], | ||
[47361034.006, '47,361,034'], | ||
['12130982923409.5', '12,130,982,923,410'], | ||
['1213098292340944.5', '1,213,098,292,340,945'], | ||
['30001231231212312138768', '30,001,231,231,212,312,138,768'], | ||
[ | ||
'1157920892373161954235709850086879078532699846656405640394575.84007913129639935', | ||
'1,157,920,892,373,161,954,235,709,850,086,879,078,532,699,846,656,405,640,394,576', | ||
], | ||
])( | ||
'formats amount greater than or equal to 1 with appropriate decimal precision (%s => %s)', | ||
(amount: number, expected: string) => { | ||
expect(formatAmount(locale, new BigNumber(amount))).toBe(expected); | ||
}, | ||
); | ||
// @ts-expect-error This is missing from the Mocha type definitions | ||
it.each([ | ||
[0.0000456, '0.000046'], | ||
[0.0004567, '0.000457'], | ||
[0.003456, '0.00346'], | ||
[0.023456, '0.0235'], | ||
[0.125456, '0.125'], | ||
])( | ||
'formats amount less than 1 with maximum significant digits (%s => %s)', | ||
(amount: number, expected: string) => { | ||
expect(formatAmount(locale, new BigNumber(amount))).toBe(expected); | ||
}, | ||
); | ||
|
||
// @ts-expect-error This is missing from the Mocha type definitions | ||
it.each([ | ||
[1.0034, '1.003'], | ||
[1.034, '1.034'], | ||
[1.3034, '1.303'], | ||
[12.0345, '12.03'], | ||
[121.456, '121.5'], | ||
[1034.123, '1,034'], | ||
[47361034.006, '47,361,034'], | ||
['12130982923409.5', '12,130,982,923,410'], | ||
['1213098292340944.5', '1,213,098,292,340,945'], | ||
['30001231231212312138768', '30,001,231,231,212,312,138,768'], | ||
[ | ||
'1157920892373161954235709850086879078532699846656405640394575.84007913129639935', | ||
'1,157,920,892,373,161,954,235,709,850,086,879,078,532,699,846,656,405,640,394,576', | ||
], | ||
])( | ||
'formats amount greater than or equal to 1 with appropriate decimal precision (%s => %s)', | ||
(amount: number, expected: string) => { | ||
expect(formatAmount(locale, new BigNumber(amount))).toBe(expected); | ||
}, | ||
); | ||
}); | ||
}); |
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