@lifi/widget 3.14.0-beta.0 → 3.14.1
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 +22 -0
- package/dist/esm/components/ActiveTransactions/ActiveTransactionItem.js +0 -1
- package/dist/esm/components/ActiveTransactions/ActiveTransactionItem.js.map +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/PriceFormHelperText.js +7 -4
- package/dist/esm/components/AmountInput/PriceFormHelperText.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/RouteCard/RouteCard.js +4 -8
- package/dist/esm/components/RouteCard/RouteCard.js.map +1 -1
- package/dist/esm/components/Step/CircularProgress.js +1 -2
- package/dist/esm/components/Step/CircularProgress.js.map +1 -1
- package/dist/esm/components/Step/CircularProgress.style.js +2 -13
- package/dist/esm/components/Step/CircularProgress.style.js.map +1 -1
- package/dist/esm/components/Step/StepProcess.js +1 -2
- package/dist/esm/components/Step/StepProcess.js.map +1 -1
- package/dist/esm/components/Step/StepTimer.js +1 -2
- package/dist/esm/components/Step/StepTimer.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/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/config/version.js.map +1 -1
- package/dist/esm/hooks/useProcessMessage.js +6 -18
- package/dist/esm/hooks/useProcessMessage.js.map +1 -1
- package/dist/esm/hooks/useRoutes.d.ts +2 -2
- package/dist/esm/hooks/useRoutes.js +58 -99
- package/dist/esm/hooks/useRoutes.js.map +1 -1
- package/dist/esm/hooks/useSetContentHeight.d.ts +1 -1
- package/dist/esm/hooks/useSetContentHeight.js +3 -2
- package/dist/esm/hooks/useSetContentHeight.js.map +1 -1
- package/dist/esm/i18n/en.json +14 -16
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pages/SendToWallet/ConfirmAddressSheet.d.ts +1 -0
- package/dist/esm/pages/SendToWallet/ConfirmAddressSheet.js +22 -14
- 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/TransactionPage/ExchangeRateBottomSheet.js +2 -2
- package/dist/esm/pages/TransactionPage/ExchangeRateBottomSheet.js.map +1 -1
- package/dist/esm/providers/I18nProvider/I18nProvider.js +4 -2
- package/dist/esm/providers/I18nProvider/I18nProvider.js.map +1 -1
- package/dist/esm/providers/WalletProvider/SDKProviders.js +15 -2
- package/dist/esm/providers/WalletProvider/SDKProviders.js.map +1 -1
- package/dist/esm/providers/WalletProvider/getSafeMultisigConfig.d.ts +8 -0
- package/dist/esm/providers/WalletProvider/getSafeMultisigConfig.js +95 -0
- package/dist/esm/providers/WalletProvider/getSafeMultisigConfig.js.map +1 -0
- package/dist/esm/types/widget.d.ts +0 -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/currencyExtendedFormatter.js.map +1 -0
- 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 +8 -8
- package/src/components/ActiveTransactions/ActiveTransactionItem.tsx +0 -1
- package/src/components/AlertMessage/AlertMessage.tsx +3 -3
- package/src/components/AmountInput/PriceFormHelperText.tsx +8 -4
- package/src/components/FeeBreakdownTooltip.tsx +3 -4
- package/src/components/GasMessage/FundsSufficiencyMessage.tsx +1 -1
- package/src/components/RouteCard/RouteCard.tsx +6 -9
- package/src/components/Step/CircularProgress.style.tsx +2 -13
- package/src/components/Step/CircularProgress.tsx +1 -2
- package/src/components/Step/StepProcess.tsx +1 -2
- package/src/components/Step/StepTimer.tsx +1 -3
- 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/hooks/useProcessMessage.ts +5 -24
- package/src/hooks/useRoutes.ts +66 -127
- package/src/hooks/useSetContentHeight.ts +4 -2
- package/src/i18n/en.json +14 -16
- package/src/index.ts +3 -0
- package/src/pages/SendToWallet/ConfirmAddressSheet.tsx +81 -40
- package/src/pages/SendToWallet/SendToWalletPage.tsx +8 -2
- package/src/pages/TransactionPage/ExchangeRateBottomSheet.tsx +2 -2
- package/src/providers/I18nProvider/I18nProvider.tsx +4 -2
- package/src/providers/WalletProvider/SDKProviders.tsx +16 -2
- package/src/providers/WalletProvider/getSafeMultisigConfig.ts +144 -0
- package/src/types/widget.ts +0 -1
- 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/currencyExtendedFormatter.js.map +0 -1
- package/dist/esm/providers/I18nProvider/percentFormatter.js.map +0 -1
- /package/dist/esm/{providers/I18nProvider → utils}/currencyExtendedFormatter.d.ts +0 -0
- /package/dist/esm/{providers/I18nProvider → utils}/currencyExtendedFormatter.js +0 -0
- /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}/currencyExtendedFormatter.ts +0 -0
- /package/src/{providers/I18nProvider → utils}/percentFormatter.ts +0 -0
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
import type { MouseEventHandler } from 'react'
|
|
14
14
|
import { useRef, useState } from 'react'
|
|
15
15
|
import { useTranslation } from 'react-i18next'
|
|
16
|
-
import { formatUnits } from 'viem'
|
|
17
16
|
import { useExplorer } from '../../hooks/useExplorer.js'
|
|
18
17
|
import { formatTokenAmount, formatTokenPrice } from '../../utils/format.js'
|
|
19
18
|
import { shortenAddress } from '../../utils/wallet.js'
|
|
@@ -66,12 +65,6 @@ export const TokenListItemButton: React.FC<TokenListItemButtonProps> = ({
|
|
|
66
65
|
const { t } = useTranslation()
|
|
67
66
|
const { getAddressLink } = useExplorer()
|
|
68
67
|
|
|
69
|
-
const tokenPrice = token.amount
|
|
70
|
-
? formatTokenPrice(
|
|
71
|
-
formatUnits(token.amount, token.decimals),
|
|
72
|
-
token.priceUSD
|
|
73
|
-
)
|
|
74
|
-
: undefined
|
|
75
68
|
const container = useRef(null)
|
|
76
69
|
const timeoutId = useRef<ReturnType<typeof setTimeout>>(undefined)
|
|
77
70
|
const [showAddress, setShowAddress] = useState(false)
|
|
@@ -93,6 +86,12 @@ export const TokenListItemButton: React.FC<TokenListItemButtonProps> = ({
|
|
|
93
86
|
setShowAddress(false)
|
|
94
87
|
}
|
|
95
88
|
}
|
|
89
|
+
const tokenAmount = formatTokenAmount(token.amount, token.decimals)
|
|
90
|
+
const tokenPrice = formatTokenPrice(
|
|
91
|
+
token.amount,
|
|
92
|
+
token.priceUSD,
|
|
93
|
+
token.decimals
|
|
94
|
+
)
|
|
96
95
|
|
|
97
96
|
return (
|
|
98
97
|
<ListItemButton
|
|
@@ -186,9 +185,10 @@ export const TokenListItemButton: React.FC<TokenListItemButtonProps> = ({
|
|
|
186
185
|
sx={{
|
|
187
186
|
fontWeight: 600,
|
|
188
187
|
}}
|
|
188
|
+
title={tokenAmount}
|
|
189
189
|
>
|
|
190
|
-
{t('format.
|
|
191
|
-
value:
|
|
190
|
+
{t('format.tokenAmount', {
|
|
191
|
+
value: tokenAmount,
|
|
192
192
|
})}
|
|
193
193
|
</Typography>
|
|
194
194
|
) : null}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { RouteExtended } from '@lifi/sdk'
|
|
2
2
|
import type { TypographyProps } from '@mui/material'
|
|
3
3
|
import type { MouseEventHandler } from 'react'
|
|
4
|
+
import { useTranslation } from 'react-i18next'
|
|
4
5
|
import { formatUnits } from 'viem'
|
|
5
6
|
import { create } from 'zustand'
|
|
6
|
-
import {
|
|
7
|
-
convertToSubscriptFormat,
|
|
8
|
-
precisionFormatter,
|
|
9
|
-
} from '../../utils/format.js'
|
|
10
7
|
import { TokenRateTypography } from './TokenRate.style.js'
|
|
11
8
|
|
|
12
9
|
interface TokenRateProps extends TypographyProps {
|
|
@@ -24,6 +21,7 @@ const useTokenRate = create<TokenRateState>((set) => ({
|
|
|
24
21
|
}))
|
|
25
22
|
|
|
26
23
|
export const TokenRate: React.FC<TokenRateProps> = ({ route }) => {
|
|
24
|
+
const { t } = useTranslation()
|
|
27
25
|
const { isForward, toggleIsForward } = useTokenRate()
|
|
28
26
|
|
|
29
27
|
const toggleRate: MouseEventHandler<HTMLSpanElement> = (e) => {
|
|
@@ -54,16 +52,12 @@ export const TokenRate: React.FC<TokenRateProps> = ({ route }) => {
|
|
|
54
52
|
Number.parseFloat(formatUnits(toToken.amount!, toToken.decimals))
|
|
55
53
|
|
|
56
54
|
const rateText = isForward
|
|
57
|
-
? `1 ${fromToken.symbol} ≈ ${
|
|
58
|
-
: `1 ${toToken.symbol} ≈ ${
|
|
59
|
-
|
|
60
|
-
const rateTitle = isForward
|
|
61
|
-
? `1 ${fromToken.symbol} ≈ ${precisionFormatter.format(fromToRate)} ${toToken.symbol}`
|
|
62
|
-
: `1 ${toToken.symbol} ≈ ${precisionFormatter.format(toFromRate)} ${fromToken.symbol}`
|
|
55
|
+
? `1 ${fromToken.symbol} ≈ ${t('format.tokenAmount', { value: fromToRate })} ${toToken.symbol}`
|
|
56
|
+
: `1 ${toToken.symbol} ≈ ${t('format.tokenAmount', { value: toFromRate })} ${fromToken.symbol}`
|
|
63
57
|
|
|
64
58
|
return (
|
|
65
59
|
// biome-ignore lint/a11y/useSemanticElements:
|
|
66
|
-
<TokenRateTypography onClick={toggleRate} role="button"
|
|
60
|
+
<TokenRateTypography onClick={toggleRate} role="button">
|
|
67
61
|
{rateText}
|
|
68
62
|
</TokenRateTypography>
|
|
69
63
|
)
|
|
@@ -8,11 +8,10 @@ import type { CardProps } from '@mui/material'
|
|
|
8
8
|
import { Box, Collapse, Tooltip, Typography } from '@mui/material'
|
|
9
9
|
import { useState } from 'react'
|
|
10
10
|
import { useTranslation } from 'react-i18next'
|
|
11
|
-
import { formatUnits } from 'viem'
|
|
12
11
|
import { useWidgetConfig } from '../providers/WidgetProvider/WidgetProvider.js'
|
|
13
12
|
import { isRouteDone } from '../stores/routes/utils.js'
|
|
14
13
|
import { getAccumulatedFeeCostsBreakdown } from '../utils/fees.js'
|
|
15
|
-
import { formatTokenAmount } from '../utils/format.js'
|
|
14
|
+
import { formatTokenAmount, formatTokenPrice } from '../utils/format.js'
|
|
16
15
|
import { getPriceImpact } from '../utils/getPriceImpact.js'
|
|
17
16
|
import { Card } from './Card/Card.js'
|
|
18
17
|
import { CardIconButton } from './Card/CardIconButton.js'
|
|
@@ -56,14 +55,11 @@ export const TransactionDetails: React.FC<TransactionDetailsProps> = ({
|
|
|
56
55
|
BigInt(feeCollectionStep.estimate.fromAmount) -
|
|
57
56
|
BigInt(feeCollectionStep.estimate.toAmount)
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
feeAmountUSD = formatTokenPrice(
|
|
60
59
|
estimatedFromAmount,
|
|
60
|
+
feeCollectionStep.action.fromToken.priceUSD,
|
|
61
61
|
feeCollectionStep.action.fromToken.decimals
|
|
62
62
|
)
|
|
63
|
-
|
|
64
|
-
feeAmountUSD =
|
|
65
|
-
Number.parseFloat(feeAmount) *
|
|
66
|
-
Number.parseFloat(feeCollectionStep.action.fromToken.priceUSD)
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
const showIntegratorFeeCollectionDetails =
|
|
@@ -245,7 +241,7 @@ export const TransactionDetails: React.FC<TransactionDetailsProps> = ({
|
|
|
245
241
|
sx={{ cursor: 'help' }}
|
|
246
242
|
>
|
|
247
243
|
<Typography variant="body2">
|
|
248
|
-
{t('format.
|
|
244
|
+
{t('format.tokenAmount', {
|
|
249
245
|
value: formatTokenAmount(
|
|
250
246
|
BigInt(route.toAmountMin),
|
|
251
247
|
route.toToken.decimals
|
package/src/config/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget'
|
|
2
|
-
export const version = '3.14.
|
|
2
|
+
export const version = '3.14.1'
|
|
@@ -39,7 +39,6 @@ const processStatusMessages: Record<
|
|
|
39
39
|
ProcessStatus,
|
|
40
40
|
(
|
|
41
41
|
t: TFunction,
|
|
42
|
-
step: LiFiStep,
|
|
43
42
|
subvariant?: WidgetSubvariant,
|
|
44
43
|
subvariantOptions?: SubvariantOptions
|
|
45
44
|
) => string
|
|
@@ -48,18 +47,9 @@ const processStatusMessages: Record<
|
|
|
48
47
|
> = {
|
|
49
48
|
TOKEN_ALLOWANCE: {
|
|
50
49
|
STARTED: (t) => t('main.process.tokenAllowance.started'),
|
|
51
|
-
ACTION_REQUIRED: (t
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}),
|
|
55
|
-
PENDING: (t, step) =>
|
|
56
|
-
t('main.process.tokenAllowance.pending', {
|
|
57
|
-
tokenSymbol: step.action.fromToken.symbol,
|
|
58
|
-
}),
|
|
59
|
-
DONE: (t, step) =>
|
|
60
|
-
t('main.process.tokenAllowance.done', {
|
|
61
|
-
tokenSymbol: step.action.fromToken.symbol,
|
|
62
|
-
}),
|
|
50
|
+
ACTION_REQUIRED: (t) => t('main.process.tokenAllowance.pending'),
|
|
51
|
+
PENDING: (t) => t('main.process.tokenAllowance.pending'),
|
|
52
|
+
DONE: (t) => t('main.process.tokenAllowance.done'),
|
|
63
53
|
},
|
|
64
54
|
SWITCH_CHAIN: {
|
|
65
55
|
ACTION_REQUIRED: (t) => t('main.process.switchChain.actionRequired'),
|
|
@@ -67,30 +57,22 @@ const processStatusMessages: Record<
|
|
|
67
57
|
},
|
|
68
58
|
SWAP: {
|
|
69
59
|
STARTED: (t) => t('main.process.swap.started'),
|
|
70
|
-
PERMIT_REQUIRED: (t, step) =>
|
|
71
|
-
t('main.process.swap.permitRequired', {
|
|
72
|
-
tokenSymbol: step.action.fromToken.symbol,
|
|
73
|
-
}),
|
|
74
60
|
ACTION_REQUIRED: (t) => t('main.process.swap.actionRequired'),
|
|
75
61
|
PENDING: (t) => t('main.process.swap.pending'),
|
|
76
|
-
DONE: (t,
|
|
62
|
+
DONE: (t, subvariant, subvariantOptions) =>
|
|
77
63
|
subvariant === 'custom'
|
|
78
64
|
? t(`main.process.${subvariantOptions?.custom ?? 'checkout'}.done`)
|
|
79
65
|
: t('main.process.swap.done'),
|
|
80
66
|
},
|
|
81
67
|
CROSS_CHAIN: {
|
|
82
68
|
STARTED: (t) => t('main.process.bridge.started'),
|
|
83
|
-
PERMIT_REQUIRED: (t, step) =>
|
|
84
|
-
t('main.process.bridge.permitRequired', {
|
|
85
|
-
tokenSymbol: step.action.fromToken.symbol,
|
|
86
|
-
}),
|
|
87
69
|
ACTION_REQUIRED: (t) => t('main.process.bridge.actionRequired'),
|
|
88
70
|
PENDING: (t) => t('main.process.bridge.pending'),
|
|
89
71
|
DONE: (t) => t('main.process.bridge.done'),
|
|
90
72
|
},
|
|
91
73
|
RECEIVING_CHAIN: {
|
|
92
74
|
PENDING: (t) => t('main.process.receivingChain.pending'),
|
|
93
|
-
DONE: (t,
|
|
75
|
+
DONE: (t, subvariant, subvariantOptions) =>
|
|
94
76
|
subvariant === 'custom'
|
|
95
77
|
? t(`main.process.${subvariantOptions?.custom ?? 'checkout'}.done`)
|
|
96
78
|
: t('main.process.receivingChain.done'),
|
|
@@ -247,7 +229,6 @@ export function getProcessMessage(
|
|
|
247
229
|
]?.(t) ??
|
|
248
230
|
processStatusMessages[process.type]?.[process.status]?.(
|
|
249
231
|
t,
|
|
250
|
-
step,
|
|
251
232
|
subvariant,
|
|
252
233
|
subvariantOptions
|
|
253
234
|
)
|
package/src/hooks/useRoutes.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import type { Route, Token } from '@lifi/sdk'
|
|
2
|
-
import {
|
|
3
|
-
LiFiErrorCode,
|
|
4
|
-
convertQuoteToRoute,
|
|
5
|
-
getContractCallsQuote,
|
|
6
|
-
getRelayerQuote,
|
|
7
|
-
getRoutes,
|
|
8
|
-
isEVMPermitStep,
|
|
9
|
-
} from '@lifi/sdk'
|
|
1
|
+
import type { Route, RoutesResponse, Token } from '@lifi/sdk'
|
|
2
|
+
import { LiFiErrorCode, getContractCallsQuote, getRoutes } from '@lifi/sdk'
|
|
10
3
|
import { useAccount } from '@lifi/wallet-management'
|
|
11
4
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
12
5
|
import { parseUnits } from 'viem'
|
|
@@ -39,7 +32,6 @@ export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
|
|
|
39
32
|
exchanges,
|
|
40
33
|
fee,
|
|
41
34
|
feeConfig,
|
|
42
|
-
useRelayerRoutes,
|
|
43
35
|
} = useWidgetConfig()
|
|
44
36
|
const setExecutableRoute = useSetExecutableRoute()
|
|
45
37
|
const queryClient = useQueryClient()
|
|
@@ -266,9 +258,27 @@ export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
|
|
|
266
258
|
contractCallQuote.toolDetails = toolDetails
|
|
267
259
|
}
|
|
268
260
|
|
|
269
|
-
const route: Route =
|
|
261
|
+
const route: Route = {
|
|
262
|
+
id: crypto.randomUUID(),
|
|
263
|
+
fromChainId: contractCallQuote.action.fromChainId,
|
|
264
|
+
fromAmountUSD: contractCallQuote.estimate.fromAmountUSD || '',
|
|
265
|
+
fromAmount: contractCallQuote.action.fromAmount,
|
|
266
|
+
fromToken: contractCallQuote.action.fromToken,
|
|
267
|
+
fromAddress: contractCallQuote.action.fromAddress,
|
|
268
|
+
toChainId: contractCallQuote.action.toChainId,
|
|
269
|
+
toAmountUSD: contractCallQuote.estimate.toAmountUSD || '',
|
|
270
|
+
toAmount: contractCallQuote.estimate.toAmount,
|
|
271
|
+
toAmountMin: contractCallQuote.estimate.toAmountMin,
|
|
272
|
+
toToken: toToken!,
|
|
273
|
+
toAddress:
|
|
274
|
+
contractCallQuote.action.toAddress ||
|
|
275
|
+
contractCallQuote.action.fromAddress,
|
|
276
|
+
gasCostUSD: contractCallQuote.estimate.gasCosts?.[0].amountUSD,
|
|
277
|
+
steps: [contractCallQuote],
|
|
278
|
+
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
279
|
+
}
|
|
270
280
|
|
|
271
|
-
return [route]
|
|
281
|
+
return { routes: [route] } as RoutesResponse
|
|
272
282
|
}
|
|
273
283
|
|
|
274
284
|
// Prevent sending a request for the same chain token combinations.
|
|
@@ -276,110 +286,50 @@ export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
|
|
|
276
286
|
return
|
|
277
287
|
}
|
|
278
288
|
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
enabledRefuel && gasRecommendationFromAmount
|
|
302
|
-
? gasRecommendationFromAmount
|
|
303
|
-
: undefined,
|
|
304
|
-
options: {
|
|
305
|
-
allowSwitchChain:
|
|
306
|
-
subvariant === 'refuel' ? false : allowSwitchChain,
|
|
307
|
-
bridges:
|
|
308
|
-
allowBridges?.length || disabledBridges.length
|
|
309
|
-
? {
|
|
310
|
-
allow: allowBridges,
|
|
311
|
-
deny: disabledBridges.length
|
|
312
|
-
? disabledBridges
|
|
313
|
-
: undefined,
|
|
314
|
-
}
|
|
289
|
+
const data = await getRoutes(
|
|
290
|
+
{
|
|
291
|
+
fromAddress,
|
|
292
|
+
fromAmount: fromAmount.toString(),
|
|
293
|
+
fromChainId,
|
|
294
|
+
fromTokenAddress,
|
|
295
|
+
toAddress,
|
|
296
|
+
toChainId,
|
|
297
|
+
toTokenAddress,
|
|
298
|
+
fromAmountForGas:
|
|
299
|
+
enabledRefuel && gasRecommendationFromAmount
|
|
300
|
+
? gasRecommendationFromAmount
|
|
301
|
+
: undefined,
|
|
302
|
+
options: {
|
|
303
|
+
allowSwitchChain:
|
|
304
|
+
subvariant === 'refuel' ? false : allowSwitchChain,
|
|
305
|
+
bridges:
|
|
306
|
+
allowBridges?.length || disabledBridges.length
|
|
307
|
+
? {
|
|
308
|
+
allow: allowBridges,
|
|
309
|
+
deny: disabledBridges.length
|
|
310
|
+
? disabledBridges
|
|
315
311
|
: undefined,
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
312
|
+
}
|
|
313
|
+
: undefined,
|
|
314
|
+
exchanges:
|
|
315
|
+
allowExchanges?.length || disabledExchanges.length
|
|
316
|
+
? {
|
|
317
|
+
allow: allowExchanges,
|
|
318
|
+
deny: disabledExchanges.length
|
|
319
|
+
? disabledExchanges
|
|
324
320
|
: undefined,
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
{
|
|
336
|
-
fromAddress,
|
|
337
|
-
fromAmount: fromAmount.toString(),
|
|
338
|
-
fromChain: fromChainId,
|
|
339
|
-
fromToken: fromTokenAddress,
|
|
340
|
-
toAddress,
|
|
341
|
-
toChain: toChainId,
|
|
342
|
-
toToken: toTokenAddress,
|
|
343
|
-
fromAmountForGas:
|
|
344
|
-
enabledRefuel && gasRecommendationFromAmount
|
|
345
|
-
? gasRecommendationFromAmount
|
|
346
|
-
: undefined,
|
|
347
|
-
order: routePriority,
|
|
348
|
-
slippage: formattedSlippage,
|
|
349
|
-
fee: calculatedFee || fee,
|
|
350
|
-
...(allowBridges?.length || disabledBridges.length
|
|
351
|
-
? {
|
|
352
|
-
allowBridges: allowBridges,
|
|
353
|
-
denyBridges: disabledBridges.length
|
|
354
|
-
? disabledBridges
|
|
355
|
-
: undefined,
|
|
356
|
-
}
|
|
357
|
-
: undefined),
|
|
358
|
-
...(allowExchanges?.length || disabledExchanges.length
|
|
359
|
-
? {
|
|
360
|
-
allowExchanges: allowExchanges,
|
|
361
|
-
denyExchanges: disabledExchanges.length
|
|
362
|
-
? disabledExchanges
|
|
363
|
-
: undefined,
|
|
364
|
-
}
|
|
365
|
-
: undefined),
|
|
366
|
-
},
|
|
367
|
-
{ signal }
|
|
368
|
-
)
|
|
369
|
-
.then((response) => {
|
|
370
|
-
const quote = {
|
|
371
|
-
...response.data.quote.step,
|
|
372
|
-
...response.data.quote,
|
|
373
|
-
}
|
|
374
|
-
return convertQuoteToRoute(quote)
|
|
375
|
-
})
|
|
376
|
-
.catch(() => null)
|
|
377
|
-
: Promise.resolve(null),
|
|
378
|
-
])
|
|
379
|
-
|
|
380
|
-
if (routesResult?.routes[0] && fromAddress) {
|
|
321
|
+
}
|
|
322
|
+
: undefined,
|
|
323
|
+
order: routePriority,
|
|
324
|
+
slippage: formattedSlippage,
|
|
325
|
+
fee: calculatedFee || fee,
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
{ signal }
|
|
329
|
+
)
|
|
330
|
+
if (data.routes[0] && fromAddress) {
|
|
381
331
|
// Update local tokens cache to keep priceUSD in sync
|
|
382
|
-
const { fromToken, toToken } =
|
|
332
|
+
const { fromToken, toToken } = data.routes[0]
|
|
383
333
|
;[fromToken, toToken].forEach((token) => {
|
|
384
334
|
queryClient.setQueriesData<Token[]>(
|
|
385
335
|
{ queryKey: ['token-balances', fromAddress, token.chainId] },
|
|
@@ -399,16 +349,8 @@ export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
|
|
|
399
349
|
)
|
|
400
350
|
})
|
|
401
351
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
// Add relayer route if available
|
|
406
|
-
if (relayerRouteResult) {
|
|
407
|
-
routes.splice(1, 0, relayerRouteResult)
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
emitter.emit(WidgetEvent.AvailableRoutes, routes)
|
|
411
|
-
return routes
|
|
352
|
+
emitter.emit(WidgetEvent.AvailableRoutes, data.routes)
|
|
353
|
+
return data
|
|
412
354
|
},
|
|
413
355
|
enabled: isEnabled,
|
|
414
356
|
staleTime: refetchTime,
|
|
@@ -419,9 +361,6 @@ export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
|
|
|
419
361
|
)
|
|
420
362
|
},
|
|
421
363
|
retry(failureCount, error: any) {
|
|
422
|
-
if (process.env.NODE_ENV === 'development') {
|
|
423
|
-
console.warn('Route query failed:', { failureCount, error })
|
|
424
|
-
}
|
|
425
364
|
if (failureCount >= 5) {
|
|
426
365
|
return false
|
|
427
366
|
}
|
|
@@ -443,7 +382,7 @@ export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
|
|
|
443
382
|
}
|
|
444
383
|
|
|
445
384
|
return {
|
|
446
|
-
routes: data,
|
|
385
|
+
routes: data?.routes,
|
|
447
386
|
isLoading: isEnabled && isLoading,
|
|
448
387
|
isFetching,
|
|
449
388
|
isFetched,
|
|
@@ -8,9 +8,11 @@ import { useDefaultElementId } from './useDefaultElementId.js'
|
|
|
8
8
|
// CSS changes in those components can have implications for the functionality in this hook
|
|
9
9
|
|
|
10
10
|
export const useSetContentHeight = (
|
|
11
|
-
ref: MutableRefObject<HTMLElement | null
|
|
11
|
+
ref: MutableRefObject<HTMLElement | null>,
|
|
12
|
+
dependency?: unknown
|
|
12
13
|
) => {
|
|
13
14
|
const elementId = useDefaultElementId()
|
|
15
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: we use dependency to refresh height
|
|
14
16
|
useLayoutEffect(() => {
|
|
15
17
|
const relativeContainer = getRelativeContainer(elementId)
|
|
16
18
|
if (
|
|
@@ -24,5 +26,5 @@ export const useSetContentHeight = (
|
|
|
24
26
|
return () => {
|
|
25
27
|
relativeContainer.style.removeProperty('min-height')
|
|
26
28
|
}
|
|
27
|
-
}, [elementId, ref])
|
|
29
|
+
}, [elementId, ref, dependency])
|
|
28
30
|
}
|
package/src/i18n/en.json
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
"format": {
|
|
7
7
|
"currency": "{{value, currencyExt(currency: USD)}}",
|
|
8
8
|
"number": "{{value, number(maximumFractionDigits: 9)}}",
|
|
9
|
-
"percent": "{{value, percent(maximumFractionDigits: 2)}}"
|
|
9
|
+
"percent": "{{value, percent(maximumFractionDigits: 2)}}",
|
|
10
|
+
"tokenAmount": "{{value, numberExt}}"
|
|
10
11
|
},
|
|
11
12
|
"button": {
|
|
12
13
|
"auto": "Auto",
|
|
@@ -88,7 +89,8 @@
|
|
|
88
89
|
"emptyBridgesList": "We couldn't find any bridges that match your search",
|
|
89
90
|
"emptyExchangesList": "We couldn't find any exchanges that match your search",
|
|
90
91
|
"emptyTransactionHistory": "Transaction history is only stored locally and will be deleted if you clear your browser data.",
|
|
91
|
-
"
|
|
92
|
+
"smartContractAccount": "Always ensure your smart contract account is set up on the destination chain to avoid potential fund loss.",
|
|
93
|
+
"fundsToExchange": "Funds sent directly to exchanges might not be recoverable.",
|
|
92
94
|
"toAddressIsRequired": "Please provide the destination wallet address to which the funds will be transferred.",
|
|
93
95
|
"routeNotFound": "Reasons for that could be: low liquidity, amount selected is too low, gas costs are too high or there are no routes for the selected combination."
|
|
94
96
|
},
|
|
@@ -220,10 +222,9 @@
|
|
|
220
222
|
"priceImpact": "Price impact",
|
|
221
223
|
"process": {
|
|
222
224
|
"bridge": {
|
|
223
|
-
"
|
|
224
|
-
"actionRequired": "Sign bridge transaction",
|
|
225
|
+
"actionRequired": "Please sign the transaction",
|
|
225
226
|
"done": "Bridge transaction confirmed",
|
|
226
|
-
"pending": "
|
|
227
|
+
"pending": "Waiting for bridge transaction",
|
|
227
228
|
"started": "Preparing bridge transaction"
|
|
228
229
|
},
|
|
229
230
|
"checkout": {
|
|
@@ -239,21 +240,19 @@
|
|
|
239
240
|
"refunded": "Bridge transaction refunded"
|
|
240
241
|
},
|
|
241
242
|
"swap": {
|
|
242
|
-
"
|
|
243
|
-
"actionRequired": "Sign swap transaction",
|
|
243
|
+
"actionRequired": "Please sign the transaction",
|
|
244
244
|
"done": "Swap completed",
|
|
245
|
-
"pending": "
|
|
245
|
+
"pending": "Waiting for swap transaction",
|
|
246
246
|
"started": "Preparing swap transaction"
|
|
247
247
|
},
|
|
248
248
|
"switchChain": {
|
|
249
|
-
"actionRequired": "
|
|
250
|
-
"done": "Chain switched"
|
|
249
|
+
"actionRequired": "Chain switch required",
|
|
250
|
+
"done": "Chain switched successfully"
|
|
251
251
|
},
|
|
252
252
|
"tokenAllowance": {
|
|
253
|
-
"
|
|
254
|
-
"
|
|
255
|
-
"
|
|
256
|
-
"started": "Preparing approval transaction"
|
|
253
|
+
"done": "Token allowance approved",
|
|
254
|
+
"pending": "Waiting for token allowance",
|
|
255
|
+
"started": "Setting token allowance"
|
|
257
256
|
}
|
|
258
257
|
},
|
|
259
258
|
"quotedAmount": "Quoted amount",
|
|
@@ -281,8 +280,7 @@
|
|
|
281
280
|
"transferId": "Transfer ID",
|
|
282
281
|
"tags": {
|
|
283
282
|
"cheapest": "Best Return",
|
|
284
|
-
"fastest": "Fastest"
|
|
285
|
-
"gasless": "Gasless"
|
|
283
|
+
"fastest": "Fastest"
|
|
286
284
|
},
|
|
287
285
|
"to": "To",
|
|
288
286
|
"tokenOnChain": "{{tokenSymbol}} on {{chainName}}",
|
package/src/index.ts
CHANGED
|
@@ -24,4 +24,7 @@ export * from './types/events.js'
|
|
|
24
24
|
export type { TokenAmount } from './types/token.js'
|
|
25
25
|
export * from './types/widget.js'
|
|
26
26
|
export { getPriceImpact } from './utils/getPriceImpact.js'
|
|
27
|
+
export { percentFormatter } from './utils/percentFormatter.js'
|
|
28
|
+
export { compactNumberFormatter } from './utils/compactNumberFormatter.js'
|
|
29
|
+
export { currencyExtendedFormatter } from './utils/currencyExtendedFormatter.js'
|
|
27
30
|
export { navigationRoutes } from './utils/navigationRoutes.js'
|