-
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: improvement for how we display big and small numbers #25438
Changes from all commits
9e57e6e
5ee78f2
343b38a
a15aaa1
4e3dc68
244eb3d
b6ddf18
5960490
b0b36b8
17b55f0
448e558
a0b91ef
ac15aa4
8c99c92
435bd22
a4568ae
5c745db
4d49efb
b750515
7ca13a1
5ef63d3
673f415
09682d1
e277ff8
0e04701
e266251
5252c02
3af6950
6cff17f
8ae0cc1
b90c647
f915032
0e6ba95
677ddeb
71f6f54
cb7eb4c
c5539fb
5afd7fa
fabd406
3c396ac
767c6b5
8b43b18
ee06044
eea6d30
ea38343
e6d6fe1
8eb1284
7507aab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { NameType } from '@metamask/name-controller'; | ||
import { BigNumber } from 'bignumber.js'; | ||
|
||
import { parseTypedDataMessage } from '../../../../../../../../shared/modules/transaction.utils'; | ||
import { Numeric } from '../../../../../../../../shared/modules/Numeric'; | ||
|
@@ -12,6 +13,7 @@ import { | |
import { useI18nContext } from '../../../../../../../hooks/useI18nContext'; | ||
import { currentConfirmationSelector } from '../../../../../../../selectors'; | ||
import { Box, Text } from '../../../../../../../components/component-library'; | ||
import Tooltip from '../../../../../../../components/ui/tooltip'; | ||
import { | ||
BackgroundColor, | ||
BorderRadius, | ||
|
@@ -21,7 +23,10 @@ import { | |
import { SignatureRequestType } from '../../../../../types/confirm'; | ||
import useTokenExchangeRate from '../../../../../../../components/app/currency-input/hooks/useTokenExchangeRate'; | ||
import { IndividualFiatDisplay } from '../../../../simulation-details/fiat-display'; | ||
import { formatNumber } from '../../../utils'; | ||
import { | ||
formatAmount, | ||
formatAmountMaxPrecision, | ||
} from '../../../../simulation-details/formatAmount'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could move this to a higher level util but I think this makes sense in this context since we're also a simulation component 👍 |
||
import { ConfirmInfoSection } from '../../../../../../../components/app/confirm/info/row/section'; | ||
|
||
const PermitSimulation: React.FC<{ | ||
|
@@ -46,6 +51,14 @@ const PermitSimulation: React.FC<{ | |
return undefined; | ||
}, [exchangeRate, value]); | ||
|
||
const { tokenValue, tokenValueMaxPrecision } = useMemo(() => { | ||
const valueBN = new BigNumber(value / Math.pow(10, tokenDecimals)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same logic we do in the decimals PR, perhaps an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new util for just division does may not be very useful. |
||
return { | ||
tokenValue: formatAmount('en-US', valueBN), | ||
tokenValueMaxPrecision: formatAmountMaxPrecision('en-US', valueBN), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar to the existing simulation UI, I think we should support varying locales rather than only en-US There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note there were some issues with this code. We are addressing the issues here: |
||
}; | ||
}, [tokenDecimals, value]); | ||
|
||
return ( | ||
<ConfirmInfoSection> | ||
<ConfirmInfoRow | ||
|
@@ -58,17 +71,21 @@ const PermitSimulation: React.FC<{ | |
<Box style={{ marginLeft: 'auto' }}> | ||
<Box display={Display.Flex}> | ||
<Box display={Display.Inline} marginInlineEnd={1}> | ||
<Text | ||
backgroundColor={BackgroundColor.backgroundAlternative} | ||
borderRadius={BorderRadius.XL} | ||
paddingInline={2} | ||
textAlign={TextAlign.Center} | ||
<Tooltip | ||
position="bottom" | ||
title={tokenValueMaxPrecision} | ||
wrapperStyle={{ minWidth: 0 }} | ||
interactive | ||
> | ||
{formatNumber( | ||
value / Math.pow(10, tokenDecimals), | ||
tokenDecimals, | ||
)} | ||
</Text> | ||
<Text | ||
backgroundColor={BackgroundColor.backgroundAlternative} | ||
borderRadius={BorderRadius.XL} | ||
paddingInline={2} | ||
textAlign={TextAlign.Center} | ||
> | ||
{tokenValue} | ||
</Text> | ||
</Tooltip> | ||
</Box> | ||
<Name value={verifyingContract} type={NameType.ETHEREUM_ADDRESS} /> | ||
</Box> | ||
|
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.
Minor, but is it worth a constant for this such as
TEXT_MOCK
?