@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.
Files changed (122) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/esm/AppDrawer.style.d.ts +1 -1
  3. package/dist/esm/components/ActiveTransactions/ActiveTransactions.style.d.ts +1 -1
  4. package/dist/esm/components/AlertMessage/AlertMessage.d.ts +2 -2
  5. package/dist/esm/components/AlertMessage/AlertMessage.js +1 -1
  6. package/dist/esm/components/AlertMessage/AlertMessage.js.map +1 -1
  7. package/dist/esm/components/AmountInput/AmountInputAdornment.style.d.ts +1 -1
  8. package/dist/esm/components/AmountInput/PriceFormHelperText.js +7 -4
  9. package/dist/esm/components/AmountInput/PriceFormHelperText.js.map +1 -1
  10. package/dist/esm/components/BaseTransactionButton/BaseTransactionButton.js +2 -2
  11. package/dist/esm/components/BaseTransactionButton/BaseTransactionButton.js.map +1 -1
  12. package/dist/esm/components/ButtonTertiary.d.ts +1 -1
  13. package/dist/esm/components/ButtonTertiary.js +4 -5
  14. package/dist/esm/components/ButtonTertiary.js.map +1 -1
  15. package/dist/esm/components/Card/CardHeader.d.ts +1 -1
  16. package/dist/esm/components/Card/CardIconButton.d.ts +1 -1
  17. package/dist/esm/components/Card/CardLabel.js +0 -1
  18. package/dist/esm/components/Card/CardLabel.js.map +1 -1
  19. package/dist/esm/components/FeeBreakdownTooltip.js +3 -4
  20. package/dist/esm/components/FeeBreakdownTooltip.js.map +1 -1
  21. package/dist/esm/components/GasMessage/FundsSufficiencyMessage.js +1 -1
  22. package/dist/esm/components/GasMessage/FundsSufficiencyMessage.js.map +1 -1
  23. package/dist/esm/components/Header/Header.style.d.ts +1 -1
  24. package/dist/esm/components/Header/SettingsButton.style.d.ts +1 -1
  25. package/dist/esm/components/RouteCard/RouteCard.js +8 -3
  26. package/dist/esm/components/RouteCard/RouteCard.js.map +1 -1
  27. package/dist/esm/components/RouteCard/getMatchingLabels.d.ts +3 -0
  28. package/dist/esm/components/RouteCard/getMatchingLabels.js +34 -0
  29. package/dist/esm/components/RouteCard/getMatchingLabels.js.map +1 -0
  30. package/dist/esm/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
  31. package/dist/esm/components/SendToWallet/SendToWallet.style.d.ts +1 -1
  32. package/dist/esm/components/Skeleton/WidgetSkeleton.style.d.ts +2 -2
  33. package/dist/esm/components/Step/Step.js +17 -8
  34. package/dist/esm/components/Step/Step.js.map +1 -1
  35. package/dist/esm/components/StepActions/StepActions.js +8 -8
  36. package/dist/esm/components/StepActions/StepActions.js.map +1 -1
  37. package/dist/esm/components/ToAddressRequiredMessage.js +1 -1
  38. package/dist/esm/components/ToAddressRequiredMessage.js.map +1 -1
  39. package/dist/esm/components/Token/Token.js +3 -3
  40. package/dist/esm/components/Token/Token.js.map +1 -1
  41. package/dist/esm/components/TokenList/TokenList.style.d.ts +1 -1
  42. package/dist/esm/components/TokenList/TokenListItem.js +4 -6
  43. package/dist/esm/components/TokenList/TokenListItem.js.map +1 -1
  44. package/dist/esm/components/TokenRate/TokenRate.js +5 -7
  45. package/dist/esm/components/TokenRate/TokenRate.js.map +1 -1
  46. package/dist/esm/components/TransactionDetails.js +3 -7
  47. package/dist/esm/components/TransactionDetails.js.map +1 -1
  48. package/dist/esm/config/version.d.ts +1 -1
  49. package/dist/esm/config/version.js +1 -1
  50. package/dist/esm/i18n/en.json +4 -2
  51. package/dist/esm/pages/SendToWallet/BookmarkAddressSheet.js +1 -2
  52. package/dist/esm/pages/SendToWallet/BookmarkAddressSheet.js.map +1 -1
  53. package/dist/esm/pages/SendToWallet/ConfirmAddressSheet.d.ts +1 -0
  54. package/dist/esm/pages/SendToWallet/ConfirmAddressSheet.js +6 -4
  55. package/dist/esm/pages/SendToWallet/ConfirmAddressSheet.js.map +1 -1
  56. package/dist/esm/pages/SendToWallet/SendToWalletPage.js +5 -3
  57. package/dist/esm/pages/SendToWallet/SendToWalletPage.js.map +1 -1
  58. package/dist/esm/pages/SendToWallet/SendToWalletPage.style.d.ts +2 -2
  59. package/dist/esm/pages/TransactionPage/ExchangeRateBottomSheet.js +2 -2
  60. package/dist/esm/pages/TransactionPage/ExchangeRateBottomSheet.js.map +1 -1
  61. package/dist/esm/providers/I18nProvider/I18nProvider.js +3 -1
  62. package/dist/esm/providers/I18nProvider/I18nProvider.js.map +1 -1
  63. package/dist/esm/stores/routes/useExecutingRoutesIds.js +2 -2
  64. package/dist/esm/stores/routes/useExecutingRoutesIds.js.map +1 -1
  65. package/dist/esm/themes/createTheme.js +4 -5
  66. package/dist/esm/themes/createTheme.js.map +1 -1
  67. package/dist/esm/types/widget.d.ts +18 -1
  68. package/dist/esm/types/widget.js.map +1 -1
  69. package/dist/esm/utils/compactNumberFormatter.d.ts +10 -0
  70. package/dist/esm/utils/compactNumberFormatter.js +81 -0
  71. package/dist/esm/utils/compactNumberFormatter.js.map +1 -0
  72. package/dist/esm/utils/compactNumberFormatter.test.d.ts +1 -0
  73. package/dist/esm/utils/compactNumberFormatter.test.js +64 -0
  74. package/dist/esm/utils/compactNumberFormatter.test.js.map +1 -0
  75. package/dist/esm/utils/converters.js +2 -2
  76. package/dist/esm/utils/converters.js.map +1 -1
  77. package/dist/esm/utils/fees.js +2 -3
  78. package/dist/esm/utils/fees.js.map +1 -1
  79. package/dist/esm/utils/format.d.ts +1 -10
  80. package/dist/esm/utils/format.js +8 -47
  81. package/dist/esm/utils/format.js.map +1 -1
  82. package/dist/esm/utils/getPriceImpact.js +7 -6
  83. package/dist/esm/utils/getPriceImpact.js.map +1 -1
  84. package/dist/esm/utils/percentFormatter.js.map +1 -0
  85. package/package.json +13 -14
  86. package/src/components/AlertMessage/AlertMessage.tsx +3 -3
  87. package/src/components/AmountInput/PriceFormHelperText.tsx +8 -4
  88. package/src/components/BaseTransactionButton/BaseTransactionButton.tsx +3 -3
  89. package/src/components/ButtonTertiary.tsx +4 -5
  90. package/src/components/Card/CardLabel.tsx +0 -1
  91. package/src/components/FeeBreakdownTooltip.tsx +3 -4
  92. package/src/components/GasMessage/FundsSufficiencyMessage.tsx +1 -1
  93. package/src/components/RouteCard/RouteCard.tsx +12 -2
  94. package/src/components/RouteCard/getMatchingLabels.ts +53 -0
  95. package/src/components/Step/Step.tsx +23 -12
  96. package/src/components/StepActions/StepActions.tsx +16 -13
  97. package/src/components/ToAddressRequiredMessage.tsx +1 -1
  98. package/src/components/Token/Token.tsx +7 -2
  99. package/src/components/TokenList/TokenListItem.tsx +9 -9
  100. package/src/components/TokenRate/TokenRate.tsx +5 -11
  101. package/src/components/TransactionDetails.tsx +4 -8
  102. package/src/config/version.ts +1 -1
  103. package/src/i18n/en.json +4 -2
  104. package/src/pages/SendToWallet/BookmarkAddressSheet.tsx +2 -3
  105. package/src/pages/SendToWallet/ConfirmAddressSheet.tsx +28 -6
  106. package/src/pages/SendToWallet/SendToWalletPage.tsx +8 -2
  107. package/src/pages/TransactionPage/ExchangeRateBottomSheet.tsx +2 -2
  108. package/src/providers/I18nProvider/I18nProvider.tsx +3 -1
  109. package/src/stores/routes/useExecutingRoutesIds.ts +2 -2
  110. package/src/themes/createTheme.ts +6 -8
  111. package/src/themes/types.ts +0 -1
  112. package/src/types/widget.ts +22 -0
  113. package/src/utils/compactNumberFormatter.test.ts +67 -0
  114. package/src/utils/compactNumberFormatter.ts +91 -0
  115. package/src/utils/converters.ts +6 -4
  116. package/src/utils/fees.ts +6 -4
  117. package/src/utils/format.ts +14 -60
  118. package/src/utils/getPriceImpact.ts +15 -6
  119. package/dist/esm/providers/I18nProvider/percentFormatter.js.map +0 -1
  120. /package/dist/esm/{providers/I18nProvider → utils}/percentFormatter.d.ts +0 -0
  121. /package/dist/esm/{providers/I18nProvider → utils}/percentFormatter.js +0 -0
  122. /package/src/{providers/I18nProvider → utils}/percentFormatter.ts +0 -0
@@ -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 === 0 || Number.isNaN(Number(formattedAmount))) {
14
+ if (!parsedAmount || Number.isNaN(Number(formattedAmount))) {
25
15
  return '0'
26
16
  }
27
17
 
28
- return precisionFormatter.format(parsedAmount)
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(amount?: string, price?: string) {
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
- * Converts a number to a subscript format if it contains leading zeros in the fractional part.
101
- *
102
- * @param {number} value - The number to be converted.
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
- // If the value does not have significant leading zeros in the fractional part, return the formatted value as is
121
- if (d > -3 || !value) {
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 { formatTokenAmount, formatTokenPrice } from './format.js'
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 fromTokenAmount = formatTokenAmount(fromAmount, fromToken.decimals)
18
- const fromTokenPrice = formatTokenPrice(fromTokenAmount, fromToken.priceUSD)
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
- const toTokenAmount = formatTokenAmount(toAmount, toToken.decimals)
21
- const toTokenPrice = formatTokenPrice(toTokenAmount, toToken.priceUSD) || 0.01
28
+ if (!fromTokenPrice) {
29
+ return 0
30
+ }
22
31
 
23
32
  const priceImpact = toTokenPrice / fromTokenPrice - 1
24
33
 
25
- return Number(priceImpact)
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"}