1
- import { BigNumber } from 'bignumber.js' ;
2
1
import { Hex } from '@metamask/utils' ;
2
+ import { BigNumber } from 'bignumber.js' ;
3
3
import React , { useMemo } from 'react' ;
4
4
import { useSelector } from 'react-redux' ;
5
-
6
5
import { TokenStandard } from '../../../../../../../../../shared/constants/transaction' ;
7
6
import { calcTokenAmount } from '../../../../../../../../../shared/lib/transactions-controller-utils' ;
8
7
import {
9
8
Box ,
10
9
Text ,
11
10
} from '../../../../../../../../components/component-library' ;
11
+ import Tooltip from '../../../../../../../../components/ui/tooltip' ;
12
12
import {
13
13
BlockSize ,
14
14
BorderRadius ,
15
15
Display ,
16
16
JustifyContent ,
17
17
TextAlign ,
18
18
} from '../../../../../../../../helpers/constants/design-system' ;
19
- import Tooltip from '../../../../../../../../components/ui/tooltip' ;
20
19
import { shortenString } from '../../../../../../../../helpers/utils/util' ;
20
+ import { useI18nContext } from '../../../../../../../../hooks/useI18nContext' ;
21
21
import { selectConversionRateByChainId } from '../../../../../../../../selectors' ;
22
22
import { AssetPill } from '../../../../../simulation-details/asset-pill' ;
23
+ import { IndividualFiatDisplay } from '../../../../../simulation-details/fiat-display' ;
23
24
import {
24
25
formatAmount ,
25
26
formatAmountMaxPrecision ,
26
27
} from '../../../../../simulation-details/formatAmount' ;
27
- import { IndividualFiatDisplay } from '../../../../../simulation-details/fiat-display ' ;
28
+ import { UNLIMITED_THRESHOLD } from '../../../approve/hooks/use-approve-token-simulation ' ;
28
29
import { getAmountColors } from '../../../utils' ;
29
30
30
31
const NATIVE_DECIMALS = 18 ;
@@ -49,13 +50,24 @@ const NativeValueDisplay: React.FC<PermitSimulationValueDisplayParams> = ({
49
50
credit,
50
51
debit,
51
52
} ) => {
53
+ const t = useI18nContext ( ) ;
54
+
52
55
const conversionRate = useSelector ( ( state ) =>
53
56
selectConversionRateByChainId ( state , chainId ) ,
54
57
) ;
55
58
56
- const { fiatValue, tokenValue, tokenValueMaxPrecision } = useMemo ( ( ) => {
59
+ const {
60
+ fiatValue,
61
+ tokenValue,
62
+ tokenValueMaxPrecision,
63
+ shouldShowUnlimitedValue,
64
+ } = useMemo ( ( ) => {
57
65
if ( ! value ) {
58
- return { tokenValue : null , tokenValueMaxPrecision : null } ;
66
+ return {
67
+ tokenValue : null ,
68
+ tokenValueMaxPrecision : null ,
69
+ shouldShowUnlimitedValue : false ,
70
+ } ;
59
71
}
60
72
61
73
const tokenAmount = calcTokenAmount ( value , NATIVE_DECIMALS ) ;
@@ -66,6 +78,7 @@ const NativeValueDisplay: React.FC<PermitSimulationValueDisplayParams> = ({
66
78
: undefined ,
67
79
tokenValue : formatAmount ( 'en-US' , tokenAmount ) ,
68
80
tokenValueMaxPrecision : formatAmountMaxPrecision ( 'en-US' , tokenAmount ) ,
81
+ shouldShowUnlimitedValue : Number ( value ) > UNLIMITED_THRESHOLD ,
69
82
} ;
70
83
} , [ conversionRate , value ] ) ;
71
84
@@ -96,13 +109,15 @@ const NativeValueDisplay: React.FC<PermitSimulationValueDisplayParams> = ({
96
109
>
97
110
{ credit && '+ ' }
98
111
{ debit && '- ' }
99
- { tokenValue !== null &&
100
- shortenString ( tokenValue || '' , {
101
- truncatedCharLimit : 15 ,
102
- truncatedStartChars : 15 ,
103
- truncatedEndChars : 0 ,
104
- skipCharacterInEnd : true ,
105
- } ) }
112
+ { shouldShowUnlimitedValue
113
+ ? t ( 'unlimited' )
114
+ : tokenValue !== null &&
115
+ shortenString ( tokenValue || '' , {
116
+ truncatedCharLimit : 15 ,
117
+ truncatedStartChars : 15 ,
118
+ truncatedEndChars : 0 ,
119
+ skipCharacterInEnd : true ,
120
+ } ) }
106
121
</ Text >
107
122
</ Tooltip >
108
123
</ Box >
0 commit comments