0xtrails 0.12.0 → 0.12.2
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/dist/analytics.d.ts +65 -50
- package/dist/analytics.d.ts.map +1 -1
- package/dist/{ccip-DtfgR432.js → ccip-62W6LwH2.js} +28 -28
- package/dist/chains.d.ts.map +1 -1
- package/dist/error.d.ts +2 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/estimate.d.ts.map +1 -1
- package/dist/fees.d.ts.map +1 -1
- package/dist/{index-CHiCSmCD.js → index-C0QTNYIA.js} +43750 -41806
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +199 -171
- package/dist/localeUtils.d.ts.map +1 -1
- package/dist/meld/components/MeldCountriesList.d.ts +0 -2
- package/dist/meld/components/MeldCountriesList.d.ts.map +1 -1
- package/dist/meld/components/MeldFundMethods.d.ts.map +1 -1
- package/dist/meld/components/MeldTokensList.d.ts.map +1 -1
- package/dist/meld/utils/meld.d.ts +2 -52
- package/dist/meld/utils/meld.d.ts.map +1 -1
- package/dist/poolUtils.d.ts.map +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prices.d.ts +1 -2
- package/dist/prices.d.ts.map +1 -1
- package/dist/query/balance.fetchers.d.ts +2 -2
- package/dist/query/balance.fetchers.d.ts.map +1 -1
- package/dist/query/fiat.fetchers.d.ts +11 -0
- package/dist/query/fiat.fetchers.d.ts.map +1 -0
- package/dist/query/fiat.hooks.d.ts +18 -0
- package/dist/query/fiat.hooks.d.ts.map +1 -0
- package/dist/query/fiat.queries.d.ts +24 -0
- package/dist/query/fiat.queries.d.ts.map +1 -0
- package/dist/query/meld.fetchers.d.ts +19 -0
- package/dist/query/meld.fetchers.d.ts.map +1 -0
- package/dist/query/meld.hooks.d.ts +4 -0
- package/dist/query/meld.hooks.d.ts.map +1 -0
- package/dist/query/meld.queries.d.ts +61 -0
- package/dist/query/meld.queries.d.ts.map +1 -0
- package/dist/recover.d.ts.map +1 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts +7 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/intentHandler.d.ts +2 -0
- package/dist/transactionIntent/handlers/intentHandler.d.ts.map +1 -1
- package/dist/transactionIntent/quote/normalizeQuote.d.ts +2 -2
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +2 -0
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactionIntent/utils/balanceChecker.d.ts +3 -1
- package/dist/transactionIntent/utils/balanceChecker.d.ts.map +1 -1
- package/dist/transactions.d.ts +2 -9
- package/dist/transactions.d.ts.map +1 -1
- package/dist/umd/trails.min.js +206 -152
- package/dist/utils/fiat.d.ts +8 -0
- package/dist/utils/fiat.d.ts.map +1 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/passthrough.d.ts +5 -2
- package/dist/utils/passthrough.d.ts.map +1 -1
- package/dist/utils/validation.d.ts +33 -0
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/walletUtils.d.ts +1 -1
- package/dist/walletUtils.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/DepositTracker.d.ts.map +1 -1
- package/dist/widget/components/Earn.d.ts +2 -0
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/FeeOption.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/HookModalContent.d.ts.map +1 -1
- package/dist/widget/components/MeldForm.d.ts.map +1 -1
- package/dist/widget/components/MeldHistory.d.ts.map +1 -1
- package/dist/widget/components/MeldStepsFlow.d.ts.map +1 -1
- package/dist/widget/components/OFTProgressBar.d.ts +2 -0
- package/dist/widget/components/OFTProgressBar.d.ts.map +1 -1
- package/dist/widget/components/OnRampProviderSelector.d.ts.map +1 -1
- package/dist/widget/components/OnrampHistoryRow.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PercentageMaxButtons.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts +2 -0
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
- package/dist/widget/components/Swap.d.ts +2 -0
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
- package/dist/widget/components/Withdraw.d.ts.map +1 -1
- package/dist/widget/hooks/useAmountUsd.d.ts.map +1 -1
- package/dist/widget/hooks/useCustomTokenSearch.d.ts.map +1 -1
- package/dist/widget/hooks/useDisplayCurrencyPreference.d.ts.map +1 -1
- package/dist/widget/hooks/useFiatOnRampCurrencies.d.ts +3 -21
- package/dist/widget/hooks/useFiatOnRampCurrencies.d.ts.map +1 -1
- package/dist/widget/hooks/useMeldTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useOnRampCountryDefaults.d.ts +0 -18
- package/dist/widget/hooks/useOnRampCountryDefaults.d.ts.map +1 -1
- package/dist/widget/hooks/useOnRampPaymentMethods.d.ts +2 -18
- package/dist/widget/hooks/useOnRampPaymentMethods.d.ts.map +1 -1
- package/dist/widget/hooks/useOnRampQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +5 -1
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +3 -1
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenWithFreshBalance.d.ts +3 -2
- package/dist/widget/hooks/useTokenWithFreshBalance.d.ts.map +1 -1
- package/dist/widget/index.js +1 -1
- package/dist/widget/types/commonProps.d.ts +2 -0
- package/dist/widget/types/commonProps.d.ts.map +1 -1
- package/dist/widget/utils/transactionFailure.d.ts +20 -0
- package/dist/widget/utils/transactionFailure.d.ts.map +1 -0
- package/dist/widget/widget.d.ts +44 -3
- package/dist/widget/widget.d.ts.map +1 -1
- package/dist/widget/workers/intentExecutionWorker.d.ts.map +1 -1
- package/package.json +22 -22
- package/src/analytics.ts +115 -79
- package/src/chains.ts +0 -1
- package/src/error.ts +11 -0
- package/src/estimate.ts +12 -7
- package/src/fees.ts +0 -1
- package/src/index.ts +11 -0
- package/src/localeUtils.ts +3 -1
- package/src/meld/components/MeldCountriesList.tsx +30 -15
- package/src/meld/components/MeldFundMethods.tsx +8 -4
- package/src/meld/components/MeldTokensList.tsx +90 -2
- package/src/meld/utils/meld.ts +3 -400
- package/src/poolUtils.ts +5 -19
- package/src/prepareSend.ts +32 -5
- package/src/prices.ts +7 -33
- package/src/query/balance.fetchers.ts +128 -168
- package/src/query/fiat.fetchers.ts +33 -0
- package/src/query/fiat.hooks.ts +71 -0
- package/src/query/fiat.queries.ts +67 -0
- package/src/query/meld.fetchers.ts +97 -0
- package/src/query/meld.hooks.ts +18 -0
- package/src/query/meld.queries.ts +184 -0
- package/src/recover.ts +6 -1
- package/src/tokens.ts +31 -6
- package/src/transactionIntent/deposits/depositOrchestrator.ts +2 -0
- package/src/transactionIntent/deposits/gaslessDeposit.ts +9 -2
- package/src/transactionIntent/deposits/standardDeposit.ts +35 -14
- package/src/transactionIntent/handlers/intentHandler.ts +134 -138
- package/src/transactionIntent/quote/normalizeQuote.ts +31 -22
- package/src/transactionIntent/quote/quoteHelpers.ts +24 -7
- package/src/transactionIntent/types.ts +2 -0
- package/src/transactionIntent/utils/balanceChecker.ts +10 -4
- package/src/transactions.ts +22 -13
- package/src/umd.tsx +1 -1
- package/src/utils/fiat.ts +32 -0
- package/src/utils/format.ts +1 -3
- package/src/utils/passthrough.ts +19 -3
- package/src/utils/validation.ts +88 -0
- package/src/utils.ts +2 -1
- package/src/walletUtils.ts +2 -2
- package/src/widget/components/AccountIntentTransactionHistory.tsx +2 -2
- package/src/widget/components/ClassicSwap.tsx +10 -4
- package/src/widget/components/DepositTracker.tsx +2 -5
- package/src/widget/components/Earn.tsx +6 -0
- package/src/widget/components/FeeOption.tsx +15 -8
- package/src/widget/components/Fund.tsx +16 -11
- package/src/widget/components/FundMethods.tsx +255 -192
- package/src/widget/components/HookModalContent.tsx +4 -0
- package/src/widget/components/MeldForm.tsx +44 -42
- package/src/widget/components/MeldHistory.tsx +4 -3
- package/src/widget/components/MeldStepsFlow.tsx +33 -71
- package/src/widget/components/OFTProgressBar.tsx +32 -12
- package/src/widget/components/OnRampProviderSelector.tsx +2 -1
- package/src/widget/components/OnrampHistoryRow.tsx +2 -1
- package/src/widget/components/Pay.tsx +8 -2
- package/src/widget/components/PercentageMaxButtons.tsx +5 -3
- package/src/widget/components/PoolDeposit.tsx +6 -0
- package/src/widget/components/PoolWithdraw.tsx +1 -1
- package/src/widget/components/QuoteDetails.tsx +5 -4
- package/src/widget/components/Receipt.tsx +4 -3
- package/src/widget/components/SlippageToleranceSettings.tsx +3 -2
- package/src/widget/components/Swap.tsx +2 -0
- package/src/widget/components/TransferPendingVertical.tsx +21 -28
- package/src/widget/components/UserPreferences.tsx +1 -1
- package/src/widget/components/Withdraw.tsx +20 -14
- package/src/widget/hooks/useAmountUsd.ts +3 -15
- package/src/widget/hooks/useCustomTokenSearch.tsx +2 -6
- package/src/widget/hooks/useDisplayCurrencyPreference.tsx +1 -2
- package/src/widget/hooks/useFiatOnRampCurrencies.ts +11 -76
- package/src/widget/hooks/useMeldTransactionHistory.ts +24 -89
- package/src/widget/hooks/useOnRampCountryDefaults.ts +3 -49
- package/src/widget/hooks/useOnRampPaymentMethods.ts +21 -100
- package/src/widget/hooks/useOnRampQuote.ts +2 -5
- package/src/widget/hooks/useQuote.ts +10 -12
- package/src/widget/hooks/useSendForm.ts +6 -0
- package/src/widget/hooks/useTokenList.ts +3 -6
- package/src/widget/hooks/useTokenWithFreshBalance.ts +141 -11
- package/src/widget/types/commonProps.ts +2 -0
- package/src/widget/utils/transactionFailure.ts +52 -0
- package/src/widget/widget.tsx +137 -59
- package/src/widget/workers/intentExecutionWorker.ts +3 -1
- package/dist/widget/hooks/useExchangeRate.d.ts +0 -31
- package/dist/widget/hooks/useExchangeRate.d.ts.map +0 -1
- package/dist/widget/hooks/useFiatCurrencyList.d.ts +0 -3
- package/dist/widget/hooks/useFiatCurrencyList.d.ts.map +0 -1
- package/src/widget/hooks/useExchangeRate.ts +0 -257
- package/src/widget/hooks/useFiatCurrencyList.ts +0 -66
|
@@ -5,26 +5,91 @@ import {
|
|
|
5
5
|
WIDGET_REFRESH_INTERVAL,
|
|
6
6
|
} from "../../query/balance.hooks.js"
|
|
7
7
|
import type { Address } from "viem"
|
|
8
|
+
import { erc20Abi } from "viem"
|
|
9
|
+
import { useBalance, useReadContract } from "wagmi"
|
|
8
10
|
import { logger } from "../../index.js"
|
|
11
|
+
import { isNativeToken, addressEqual } from "../../utils/address.js"
|
|
12
|
+
import { formatBalanceFields } from "../../utils/format.js"
|
|
9
13
|
|
|
10
|
-
import { addressEqual } from "../../utils/address.js"
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
13
|
-
* This
|
|
15
|
+
* Reads the on-chain balance for a single token (native or ERC20).
|
|
16
|
+
* This is the source of truth — it bypasses the indexer entirely.
|
|
17
|
+
*/
|
|
18
|
+
function useOnChainBalance(
|
|
19
|
+
token: Token | null | undefined,
|
|
20
|
+
accountAddress?: string,
|
|
21
|
+
): { balance: string | undefined; isLoading: boolean } {
|
|
22
|
+
const isNative = isNativeToken(token?.contractAddress)
|
|
23
|
+
const enabled = !!token && !!accountAddress && !!token.chainId
|
|
24
|
+
|
|
25
|
+
// Native token balance (ETH, MATIC, etc.)
|
|
26
|
+
const { data: nativeData, isLoading: nativeLoading } = useBalance({
|
|
27
|
+
address: accountAddress as Address | undefined,
|
|
28
|
+
chainId: token?.chainId,
|
|
29
|
+
query: {
|
|
30
|
+
enabled: enabled && isNative,
|
|
31
|
+
refetchInterval: WIDGET_REFRESH_INTERVAL,
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// ERC20 token balance
|
|
36
|
+
const { data: erc20Data, isLoading: erc20Loading } = useReadContract({
|
|
37
|
+
address: token?.contractAddress as Address | undefined,
|
|
38
|
+
abi: erc20Abi,
|
|
39
|
+
functionName: "balanceOf",
|
|
40
|
+
args: accountAddress ? [accountAddress as Address] : undefined,
|
|
41
|
+
chainId: token?.chainId,
|
|
42
|
+
query: {
|
|
43
|
+
enabled: enabled && !isNative,
|
|
44
|
+
refetchInterval: WIDGET_REFRESH_INTERVAL,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return useMemo(() => {
|
|
49
|
+
if (!enabled) return { balance: undefined, isLoading: false }
|
|
50
|
+
|
|
51
|
+
if (isNative) {
|
|
52
|
+
return {
|
|
53
|
+
balance: nativeData?.value?.toString(),
|
|
54
|
+
isLoading: nativeLoading,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
balance: erc20Data?.toString(),
|
|
60
|
+
isLoading: erc20Loading,
|
|
61
|
+
}
|
|
62
|
+
}, [
|
|
63
|
+
enabled,
|
|
64
|
+
isNative,
|
|
65
|
+
nativeData?.value,
|
|
66
|
+
nativeLoading,
|
|
67
|
+
erc20Data,
|
|
68
|
+
erc20Loading,
|
|
69
|
+
])
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Enriches a token with fresh balance data from the cache/API,
|
|
74
|
+
* with an on-chain balance read as source of truth fallback.
|
|
75
|
+
* This prevents displaying stale balance data from localStorage or props.
|
|
14
76
|
*/
|
|
15
77
|
export function useTokenWithFreshBalance(
|
|
16
78
|
token: Token | null | undefined,
|
|
17
79
|
accountAddress?: string,
|
|
18
80
|
disabled?: boolean,
|
|
19
81
|
): { token: Token | null | undefined; isLoadingBalance: boolean } {
|
|
20
|
-
// Fetch fresh balance data for the account
|
|
21
|
-
// We are already filtering the token here, we don't need to pass it to the API, it will collide with useTokenBalances because they share the same query key.
|
|
82
|
+
// Fetch fresh balance data for the account (indexer-backed, includes USD prices)
|
|
22
83
|
const { sortedTokens, isLoadingBalances } = useTokenBalances(
|
|
23
84
|
accountAddress as Address | null,
|
|
24
85
|
undefined,
|
|
25
86
|
{ disabled: disabled, refetchInterval: WIDGET_REFRESH_INTERVAL },
|
|
26
87
|
)
|
|
27
88
|
|
|
89
|
+
// On-chain balance as source of truth for the selected token
|
|
90
|
+
const { balance: onChainBalance, isLoading: isLoadingOnChain } =
|
|
91
|
+
useOnChainBalance(disabled ? null : token, accountAddress)
|
|
92
|
+
|
|
28
93
|
logger.console.log(
|
|
29
94
|
"[trails-sdk] sortedTokens FROM useTokenWithFreshBalance",
|
|
30
95
|
sortedTokens,
|
|
@@ -35,7 +100,7 @@ export function useTokenWithFreshBalance(
|
|
|
35
100
|
if (!token) return token
|
|
36
101
|
if (!sortedTokens) return token // Return original if no fresh data available
|
|
37
102
|
|
|
38
|
-
// Find matching token in balance data
|
|
103
|
+
// Find matching token in indexer balance data
|
|
39
104
|
const freshToken = sortedTokens.find(
|
|
40
105
|
(t: Token) =>
|
|
41
106
|
addressEqual(t.contractAddress, token.contractAddress) &&
|
|
@@ -43,6 +108,28 @@ export function useTokenWithFreshBalance(
|
|
|
43
108
|
)
|
|
44
109
|
|
|
45
110
|
if (freshToken) {
|
|
111
|
+
// If on-chain balance is lower than indexer balance, the indexer is stale —
|
|
112
|
+
// use the on-chain value as source of truth for the balance fields.
|
|
113
|
+
if (onChainBalance !== undefined && freshToken.balance) {
|
|
114
|
+
try {
|
|
115
|
+
const onChain = BigInt(onChainBalance)
|
|
116
|
+
const indexed = BigInt(freshToken.balance)
|
|
117
|
+
if (onChain < indexed) {
|
|
118
|
+
const fields = formatBalanceFields(onChainBalance, token.decimals)
|
|
119
|
+
return {
|
|
120
|
+
...token,
|
|
121
|
+
...fields,
|
|
122
|
+
balanceUsd: freshToken.balanceUsd,
|
|
123
|
+
balanceUsdFormatted: freshToken.balanceUsdFormatted,
|
|
124
|
+
isSufficientBalance: freshToken.isSufficientBalance,
|
|
125
|
+
priceUsd: freshToken.priceUsd,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
} catch {
|
|
129
|
+
// Fall through to indexer balance
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
46
133
|
// Merge token metadata with fresh balance data
|
|
47
134
|
return {
|
|
48
135
|
...token,
|
|
@@ -57,11 +144,41 @@ export function useTokenWithFreshBalance(
|
|
|
57
144
|
}
|
|
58
145
|
}
|
|
59
146
|
|
|
60
|
-
//
|
|
147
|
+
// Token not found in indexer data — use on-chain balance as source of truth
|
|
148
|
+
if (onChainBalance !== undefined) {
|
|
149
|
+
const fields = formatBalanceFields(onChainBalance, token.decimals)
|
|
150
|
+
return {
|
|
151
|
+
...token,
|
|
152
|
+
...fields,
|
|
153
|
+
balanceUsd: 0,
|
|
154
|
+
balanceUsdFormatted: "$0.00",
|
|
155
|
+
isSufficientBalance: false,
|
|
156
|
+
priceUsd: token.priceUsd,
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Token not found and no on-chain data yet — zero out if indexer has loaded
|
|
161
|
+
if (sortedTokens.length > 0 || !isLoadingBalances) {
|
|
162
|
+
return {
|
|
163
|
+
...token,
|
|
164
|
+
balance: "0",
|
|
165
|
+
balanceDisplay: "0",
|
|
166
|
+
balanceLocaleDisplay: "0",
|
|
167
|
+
balanceFormatted: "0",
|
|
168
|
+
balanceUsd: 0,
|
|
169
|
+
balanceUsdFormatted: "$0.00",
|
|
170
|
+
isSufficientBalance: false,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Return original token while still loading
|
|
61
175
|
return token
|
|
62
|
-
}, [token, sortedTokens])
|
|
176
|
+
}, [token, sortedTokens, isLoadingBalances, onChainBalance])
|
|
63
177
|
|
|
64
|
-
return {
|
|
178
|
+
return {
|
|
179
|
+
token: tokenWithFreshBalance,
|
|
180
|
+
isLoadingBalance: isLoadingBalances || isLoadingOnChain,
|
|
181
|
+
}
|
|
65
182
|
}
|
|
66
183
|
|
|
67
184
|
/**
|
|
@@ -107,10 +224,23 @@ export function useTokensWithFreshBalance(
|
|
|
107
224
|
}
|
|
108
225
|
}
|
|
109
226
|
|
|
110
|
-
//
|
|
227
|
+
// Token not found — balance is likely zero (filtered out by useTokenBalances)
|
|
228
|
+
if (sortedTokens.length > 0 || !isLoadingBalances) {
|
|
229
|
+
return {
|
|
230
|
+
...token,
|
|
231
|
+
balance: "0",
|
|
232
|
+
balanceDisplay: "0",
|
|
233
|
+
balanceLocaleDisplay: "0",
|
|
234
|
+
balanceFormatted: "0",
|
|
235
|
+
balanceUsd: 0,
|
|
236
|
+
balanceUsdFormatted: "$0.00",
|
|
237
|
+
isSufficientBalance: false,
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
111
241
|
return token
|
|
112
242
|
})
|
|
113
|
-
}, [tokens, sortedTokens])
|
|
243
|
+
}, [tokens, sortedTokens, isLoadingBalances])
|
|
114
244
|
|
|
115
245
|
return { tokens: tokensWithFreshBalance, isLoadingBalance: isLoadingBalances }
|
|
116
246
|
}
|
|
@@ -45,6 +45,8 @@ export interface BaseProps {
|
|
|
45
45
|
toCalldata?: string
|
|
46
46
|
swapProvider?: string
|
|
47
47
|
bridgeProvider?: string
|
|
48
|
+
swapProviderFallback?: boolean
|
|
49
|
+
bridgeProviderFallback?: boolean
|
|
48
50
|
fundMethod?: FundMethod
|
|
49
51
|
checkoutOnHandlers?: CheckoutOnHandlers
|
|
50
52
|
selectedToken: Token | null
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { TransactionState } from "../../transactions.js"
|
|
2
|
+
|
|
3
|
+
export const hasFailedTransaction = (tx: TransactionState): boolean => {
|
|
4
|
+
const hasFailedState = tx.state === "failed"
|
|
5
|
+
const hasFailureEvent = tx.decodedGuestModuleEvents?.some(
|
|
6
|
+
(event) => event.type === "CallFailed",
|
|
7
|
+
)
|
|
8
|
+
return hasFailedState || Boolean(hasFailureEvent)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const hasAbortedTransaction = (tx: TransactionState): boolean => {
|
|
12
|
+
const hasAbortedState = tx.state === "aborted"
|
|
13
|
+
const hasAbortedEvent = tx.decodedGuestModuleEvents?.some(
|
|
14
|
+
(event) => event.type === "CallAborted",
|
|
15
|
+
)
|
|
16
|
+
return hasAbortedState || Boolean(hasAbortedEvent)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns true when a transaction should be treated as failed in widget UI.
|
|
21
|
+
*
|
|
22
|
+
* A transaction is considered failed if:
|
|
23
|
+
* - its lifecycle state is `failed` or `aborted`, or
|
|
24
|
+
* - decoded guest module events include `CallFailed` or `CallAborted`.
|
|
25
|
+
*/
|
|
26
|
+
export function hasFailedOrAbortedTransaction(
|
|
27
|
+
tx?: TransactionState | null,
|
|
28
|
+
): boolean {
|
|
29
|
+
if (!tx) return false
|
|
30
|
+
|
|
31
|
+
const hasFailedState = tx.state === "failed" || tx.state === "aborted"
|
|
32
|
+
const hasFailureEvent = tx.decodedGuestModuleEvents?.some(
|
|
33
|
+
(event) => event.type === "CallFailed" || event.type === "CallAborted",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
return hasFailedState || Boolean(hasFailureEvent)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Returns true when any transaction in the list is failed or aborted.
|
|
41
|
+
*
|
|
42
|
+
* This is used for screen-level decisions (for example, showing failure CTAs
|
|
43
|
+
* or rendering the receipt in failure state) so pending/receipt logic stays
|
|
44
|
+
* consistent across components.
|
|
45
|
+
*/
|
|
46
|
+
export function hasAnyFailedOrAbortedTransactions(
|
|
47
|
+
transactionStates?: TransactionState[] | null,
|
|
48
|
+
): boolean {
|
|
49
|
+
return Boolean(
|
|
50
|
+
transactionStates?.some((tx) => hasFailedOrAbortedTransaction(tx)),
|
|
51
|
+
)
|
|
52
|
+
}
|