-
Notifications
You must be signed in to change notification settings - Fork 5k
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
feat: Update Redesign Signature Permit to show ellipsis at max 15 digits #26227
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a65d821
feat: display ellipsis if > 15 digits permit amounts
digiwand e2a9718
fix: rm no longer needed css ellipsis
digiwand 706d6d9
refactor: remove unused isEllipsis from ConfirmInfoRowText
digiwand 25b4f0a
test:fix: snapshots related to permit ellipsis
digiwand 566166e
chore: rm stale comments
digiwand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we re-use Goktug's
shortenString
function here?From
ui/helpers/utils/util.js
.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.
I think it’s better to keep it as is since this requires more logic to count the digits and preserve the “,”
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.
Sorry, I lost the design and issue ticket for this and ended up created a new ticket. Now that I've seen the relevant issue, we needed to do max 15 characters and not digits
https://github.com/MetaMask/MetaMask-planning/issues/2845
Updated to use
shortenString
here: #26458