@lifi/widget 3.13.2 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/esm/AppDrawer.style.d.ts +1 -1
- package/dist/esm/components/ActiveTransactions/ActiveTransactions.style.d.ts +1 -1
- package/dist/esm/components/AlertMessage/AlertMessage.d.ts +2 -2
- package/dist/esm/components/AlertMessage/AlertMessage.js +1 -1
- package/dist/esm/components/AlertMessage/AlertMessage.js.map +1 -1
- package/dist/esm/components/AmountInput/AmountInputAdornment.style.d.ts +1 -1
- package/dist/esm/components/AmountInput/PriceFormHelperText.js +7 -4
- package/dist/esm/components/AmountInput/PriceFormHelperText.js.map +1 -1
- package/dist/esm/components/BaseTransactionButton/BaseTransactionButton.js +2 -2
- package/dist/esm/components/BaseTransactionButton/BaseTransactionButton.js.map +1 -1
- package/dist/esm/components/ButtonTertiary.d.ts +1 -1
- package/dist/esm/components/ButtonTertiary.js +4 -5
- package/dist/esm/components/ButtonTertiary.js.map +1 -1
- package/dist/esm/components/Card/CardHeader.d.ts +1 -1
- package/dist/esm/components/Card/CardIconButton.d.ts +1 -1
- package/dist/esm/components/Card/CardLabel.js +0 -1
- package/dist/esm/components/Card/CardLabel.js.map +1 -1
- package/dist/esm/components/FeeBreakdownTooltip.js +3 -4
- package/dist/esm/components/FeeBreakdownTooltip.js.map +1 -1
- package/dist/esm/components/GasMessage/FundsSufficiencyMessage.js +1 -1
- package/dist/esm/components/GasMessage/FundsSufficiencyMessage.js.map +1 -1
- package/dist/esm/components/Header/Header.style.d.ts +1 -1
- package/dist/esm/components/Header/SettingsButton.style.d.ts +1 -1
- package/dist/esm/components/RouteCard/RouteCard.js +8 -3
- package/dist/esm/components/RouteCard/RouteCard.js.map +1 -1
- package/dist/esm/components/RouteCard/getMatchingLabels.d.ts +3 -0
- package/dist/esm/components/RouteCard/getMatchingLabels.js +34 -0
- package/dist/esm/components/RouteCard/getMatchingLabels.js.map +1 -0
- package/dist/esm/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
- package/dist/esm/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/dist/esm/components/Skeleton/WidgetSkeleton.style.d.ts +2 -2
- package/dist/esm/components/Step/Step.js +17 -8
- package/dist/esm/components/Step/Step.js.map +1 -1
- package/dist/esm/components/StepActions/StepActions.js +8 -8
- package/dist/esm/components/StepActions/StepActions.js.map +1 -1
- package/dist/esm/components/ToAddressRequiredMessage.js +1 -1
- package/dist/esm/components/ToAddressRequiredMessage.js.map +1 -1
- package/dist/esm/components/Token/Token.js +3 -3
- package/dist/esm/components/Token/Token.js.map +1 -1
- package/dist/esm/components/TokenList/TokenList.style.d.ts +1 -1
- package/dist/esm/components/TokenList/TokenListItem.js +4 -6
- package/dist/esm/components/TokenList/TokenListItem.js.map +1 -1
- package/dist/esm/components/TokenRate/TokenRate.js +5 -7
- package/dist/esm/components/TokenRate/TokenRate.js.map +1 -1
- package/dist/esm/components/TransactionDetails.js +3 -7
- package/dist/esm/components/TransactionDetails.js.map +1 -1
- package/dist/esm/config/version.d.ts +1 -1
- package/dist/esm/config/version.js +1 -1
- package/dist/esm/i18n/en.json +4 -2
- package/dist/esm/pages/SendToWallet/BookmarkAddressSheet.js +1 -2
- package/dist/esm/pages/SendToWallet/BookmarkAddressSheet.js.map +1 -1
- package/dist/esm/pages/SendToWallet/ConfirmAddressSheet.d.ts +1 -0
- package/dist/esm/pages/SendToWallet/ConfirmAddressSheet.js +6 -4
- package/dist/esm/pages/SendToWallet/ConfirmAddressSheet.js.map +1 -1
- package/dist/esm/pages/SendToWallet/SendToWalletPage.js +5 -3
- package/dist/esm/pages/SendToWallet/SendToWalletPage.js.map +1 -1
- package/dist/esm/pages/SendToWallet/SendToWalletPage.style.d.ts +2 -2
- package/dist/esm/pages/TransactionPage/ExchangeRateBottomSheet.js +2 -2
- package/dist/esm/pages/TransactionPage/ExchangeRateBottomSheet.js.map +1 -1
- package/dist/esm/providers/I18nProvider/I18nProvider.js +3 -1
- package/dist/esm/providers/I18nProvider/I18nProvider.js.map +1 -1
- package/dist/esm/stores/routes/useExecutingRoutesIds.js +2 -2
- package/dist/esm/stores/routes/useExecutingRoutesIds.js.map +1 -1
- package/dist/esm/themes/createTheme.js +4 -5
- package/dist/esm/themes/createTheme.js.map +1 -1
- package/dist/esm/types/widget.d.ts +18 -1
- package/dist/esm/types/widget.js.map +1 -1
- package/dist/esm/utils/compactNumberFormatter.d.ts +10 -0
- package/dist/esm/utils/compactNumberFormatter.js +81 -0
- package/dist/esm/utils/compactNumberFormatter.js.map +1 -0
- package/dist/esm/utils/compactNumberFormatter.test.d.ts +1 -0
- package/dist/esm/utils/compactNumberFormatter.test.js +64 -0
- package/dist/esm/utils/compactNumberFormatter.test.js.map +1 -0
- package/dist/esm/utils/converters.js +2 -2
- package/dist/esm/utils/converters.js.map +1 -1
- package/dist/esm/utils/fees.js +2 -3
- package/dist/esm/utils/fees.js.map +1 -1
- package/dist/esm/utils/format.d.ts +1 -10
- package/dist/esm/utils/format.js +8 -47
- package/dist/esm/utils/format.js.map +1 -1
- package/dist/esm/utils/getPriceImpact.js +7 -6
- package/dist/esm/utils/getPriceImpact.js.map +1 -1
- package/dist/esm/utils/percentFormatter.js.map +1 -0
- package/package.json +13 -14
- package/src/components/AlertMessage/AlertMessage.tsx +3 -3
- package/src/components/AmountInput/PriceFormHelperText.tsx +8 -4
- package/src/components/BaseTransactionButton/BaseTransactionButton.tsx +3 -3
- package/src/components/ButtonTertiary.tsx +4 -5
- package/src/components/Card/CardLabel.tsx +0 -1
- package/src/components/FeeBreakdownTooltip.tsx +3 -4
- package/src/components/GasMessage/FundsSufficiencyMessage.tsx +1 -1
- package/src/components/RouteCard/RouteCard.tsx +12 -2
- package/src/components/RouteCard/getMatchingLabels.ts +53 -0
- package/src/components/Step/Step.tsx +23 -12
- package/src/components/StepActions/StepActions.tsx +16 -13
- package/src/components/ToAddressRequiredMessage.tsx +1 -1
- package/src/components/Token/Token.tsx +7 -2
- package/src/components/TokenList/TokenListItem.tsx +9 -9
- package/src/components/TokenRate/TokenRate.tsx +5 -11
- package/src/components/TransactionDetails.tsx +4 -8
- package/src/config/version.ts +1 -1
- package/src/i18n/en.json +4 -2
- package/src/pages/SendToWallet/BookmarkAddressSheet.tsx +2 -3
- package/src/pages/SendToWallet/ConfirmAddressSheet.tsx +28 -6
- package/src/pages/SendToWallet/SendToWalletPage.tsx +8 -2
- package/src/pages/TransactionPage/ExchangeRateBottomSheet.tsx +2 -2
- package/src/providers/I18nProvider/I18nProvider.tsx +3 -1
- package/src/stores/routes/useExecutingRoutesIds.ts +2 -2
- package/src/themes/createTheme.ts +6 -8
- package/src/themes/types.ts +0 -1
- package/src/types/widget.ts +22 -0
- package/src/utils/compactNumberFormatter.test.ts +67 -0
- package/src/utils/compactNumberFormatter.ts +91 -0
- package/src/utils/converters.ts +6 -4
- package/src/utils/fees.ts +6 -4
- package/src/utils/format.ts +14 -60
- package/src/utils/getPriceImpact.ts +15 -6
- package/dist/esm/providers/I18nProvider/percentFormatter.js.map +0 -1
- /package/dist/esm/{providers/I18nProvider → utils}/percentFormatter.d.ts +0 -0
- /package/dist/esm/{providers/I18nProvider → utils}/percentFormatter.js +0 -0
- /package/src/{providers/I18nProvider → utils}/percentFormatter.ts +0 -0
package/src/utils/format.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import { formatUnits } from 'viem'
|
|
2
2
|
|
|
3
|
-
const subscriptMap = ['₀', '₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', '₉']
|
|
4
|
-
|
|
5
|
-
export const precisionFormatter = new Intl.NumberFormat('en', {
|
|
6
|
-
notation: 'standard',
|
|
7
|
-
roundingPriority: 'morePrecision',
|
|
8
|
-
maximumSignificantDigits: 6,
|
|
9
|
-
maximumFractionDigits: 6,
|
|
10
|
-
useGrouping: false,
|
|
11
|
-
})
|
|
12
|
-
|
|
13
3
|
/**
|
|
14
4
|
* Format token amount to at least 6 decimals.
|
|
15
5
|
* @param amount amount to format.
|
|
@@ -21,11 +11,11 @@ export function formatTokenAmount(
|
|
|
21
11
|
) {
|
|
22
12
|
const formattedAmount = amount ? formatUnits(amount, decimals) : '0'
|
|
23
13
|
const parsedAmount = Number.parseFloat(formattedAmount)
|
|
24
|
-
if (parsedAmount
|
|
14
|
+
if (!parsedAmount || Number.isNaN(Number(formattedAmount))) {
|
|
25
15
|
return '0'
|
|
26
16
|
}
|
|
27
17
|
|
|
28
|
-
return
|
|
18
|
+
return formattedAmount
|
|
29
19
|
}
|
|
30
20
|
|
|
31
21
|
export function formatSlippage(
|
|
@@ -86,58 +76,22 @@ export function formatInputAmount(
|
|
|
86
76
|
return `${integer || (fraction ? '0' : '')}${fraction ? `.${fraction}` : ''}`
|
|
87
77
|
}
|
|
88
78
|
|
|
89
|
-
export function formatTokenPrice(
|
|
79
|
+
export function formatTokenPrice(
|
|
80
|
+
amount?: string | bigint,
|
|
81
|
+
price?: string,
|
|
82
|
+
decimals?: number
|
|
83
|
+
) {
|
|
90
84
|
if (!amount || !price) {
|
|
91
85
|
return 0
|
|
92
86
|
}
|
|
93
|
-
if (Number.isNaN(Number(amount)) || Number.isNaN(Number(price))) {
|
|
94
|
-
return 0
|
|
95
|
-
}
|
|
96
|
-
return Number.parseFloat(amount) * Number.parseFloat(price)
|
|
97
|
-
}
|
|
98
87
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
* @param {Intl.NumberFormatOptions} options An object that contains one or more properties that specify comparison options.
|
|
104
|
-
* @returns {string} - The number formatted as a string, with subscripts for leading zeros if applicable.
|
|
105
|
-
*/
|
|
106
|
-
export function convertToSubscriptFormat(
|
|
107
|
-
value: number,
|
|
108
|
-
options?: Intl.NumberFormatOptions
|
|
109
|
-
): string {
|
|
110
|
-
let formattedValue: string
|
|
111
|
-
if (options) {
|
|
112
|
-
formattedValue = value.toLocaleString('en', options)
|
|
113
|
-
} else {
|
|
114
|
-
formattedValue = precisionFormatter.format(value)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Calculate the number of zeros after the decimal point
|
|
118
|
-
const d = Math.ceil(Math.log10(Math.abs(value)))
|
|
88
|
+
const formattedAmount =
|
|
89
|
+
typeof amount === 'bigint' && decimals !== undefined
|
|
90
|
+
? formatUnits(amount, decimals)
|
|
91
|
+
: amount.toString()
|
|
119
92
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return formattedValue
|
|
93
|
+
if (Number.isNaN(Number(formattedAmount)) || Number.isNaN(Number(price))) {
|
|
94
|
+
return 0
|
|
123
95
|
}
|
|
124
|
-
|
|
125
|
-
// Calculate the number of leading zeros in the fractional part
|
|
126
|
-
const leadingZeros = Math.abs(d)
|
|
127
|
-
|
|
128
|
-
const fractionalPartExtractor = value > 0 ? 2 : 3
|
|
129
|
-
|
|
130
|
-
// Extract the fractional part of the formatted value, excluding the leading zeros and "0." or "-0."
|
|
131
|
-
const fractionalPart = formattedValue.slice(
|
|
132
|
-
leadingZeros + fractionalPartExtractor
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
// Convert the number of leading zeros to their corresponding Unicode subscript characters
|
|
136
|
-
const subscript = leadingZeros
|
|
137
|
-
.toString()
|
|
138
|
-
.split('')
|
|
139
|
-
.map((digit) => subscriptMap[digit as any])
|
|
140
|
-
.join('')
|
|
141
|
-
|
|
142
|
-
return `${value > 0 ? '' : '-'}0.0${subscript}${fractionalPart}`
|
|
96
|
+
return Number.parseFloat(formattedAmount) * Number.parseFloat(price)
|
|
143
97
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Token } from '@lifi/sdk'
|
|
2
|
-
import {
|
|
2
|
+
import { formatTokenPrice } from './format.js'
|
|
3
3
|
|
|
4
4
|
interface GetPriceImpractProps {
|
|
5
5
|
fromToken: Token
|
|
@@ -14,13 +14,22 @@ export const getPriceImpact = ({
|
|
|
14
14
|
fromAmount,
|
|
15
15
|
toAmount,
|
|
16
16
|
}: GetPriceImpractProps) => {
|
|
17
|
-
const
|
|
18
|
-
|
|
17
|
+
const fromTokenPrice = formatTokenPrice(
|
|
18
|
+
fromAmount,
|
|
19
|
+
fromToken.priceUSD,
|
|
20
|
+
fromToken.decimals
|
|
21
|
+
)
|
|
22
|
+
const toTokenPrice = formatTokenPrice(
|
|
23
|
+
toAmount,
|
|
24
|
+
toToken.priceUSD,
|
|
25
|
+
toToken.decimals
|
|
26
|
+
)
|
|
19
27
|
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
if (!fromTokenPrice) {
|
|
29
|
+
return 0
|
|
30
|
+
}
|
|
22
31
|
|
|
23
32
|
const priceImpact = toTokenPrice / fromTokenPrice - 1
|
|
24
33
|
|
|
25
|
-
return
|
|
34
|
+
return priceImpact
|
|
26
35
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"percentFormatter.js","sourceRoot":"","sources":["../../../../src/providers/I18nProvider/percentFormatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAuB,EAAE,OAAY,EAAE,EAAE;IACxE,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE;QAC3C,GAAG,OAAO;QACV,KAAK,EAAE,SAAS;KACjB,CAAC,CAAA;IACF,OAAO,CAAC,KAAU,EAAE,EAAE;QACpB,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACpE,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAA;QACvC,CAAC;QACD,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAChC,CAAC,CAAA;AACH,CAAC,CAAA"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|