0xtrails 0.6.6 → 0.7.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/dist/aave.d.ts +10 -2
- package/dist/aave.d.ts.map +1 -1
- package/dist/analytics.d.ts +26 -0
- package/dist/analytics.d.ts.map +1 -1
- package/dist/{ccip-CbJrlK-L.js → ccip-fConRNoG.js} +21 -21
- package/dist/chains.d.ts +23 -8
- package/dist/chains.d.ts.map +1 -1
- package/dist/constants.d.ts +5 -5
- package/dist/constants.d.ts.map +1 -1
- package/dist/customTokens.d.ts +12 -0
- package/dist/customTokens.d.ts.map +1 -0
- package/dist/decoders.d.ts +2 -2
- package/dist/decoders.d.ts.map +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/fees.d.ts +37 -2
- package/dist/fees.d.ts.map +1 -1
- package/dist/gasless.d.ts +15 -36
- package/dist/gasless.d.ts.map +1 -1
- package/dist/{index-w7_dK4c5.js → index-BbajxCG_.js} +59269 -77146
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +828 -359
- package/dist/indexerClient.d.ts.map +1 -1
- package/dist/intentReceiptMonitor.d.ts +1 -1
- package/dist/intentReceiptMonitor.d.ts.map +1 -1
- package/dist/intentReceiptPoller.d.ts +1 -1
- package/dist/intentReceiptPoller.d.ts.map +1 -1
- package/dist/intents.d.ts +3 -2
- package/dist/intents.d.ts.map +1 -1
- package/dist/mode.d.ts +1 -1
- package/dist/mode.d.ts.map +1 -1
- package/dist/mutations.d.ts +2 -2
- package/dist/mutations.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +2 -2
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prices.d.ts +1 -1
- package/dist/prices.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +2 -2
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/time.d.ts +6 -0
- package/dist/time.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts +40 -25
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/tokens.d.ts +54 -14
- package/dist/tokens.d.ts.map +1 -1
- package/dist/trailsClient.d.ts +1 -1
- package/dist/trailsClient.d.ts.map +1 -1
- package/dist/trailsRouter.d.ts +2 -1
- package/dist/trailsRouter.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +3 -2
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +2 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/execution/transactionState.d.ts +1 -1
- package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +5 -3
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +5 -3
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/quote/feeExtractors.d.ts +1 -6
- package/dist/transactionIntent/quote/feeExtractors.d.ts.map +1 -1
- package/dist/transactionIntent/quote/normalizeQuote.d.ts +4 -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 +28 -5
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactionIntent/utils/testnetHelpers.d.ts +0 -1
- package/dist/transactionIntent/utils/testnetHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/validators.d.ts +0 -2
- package/dist/transactionIntent/validators.d.ts.map +1 -1
- package/dist/transactions.d.ts +2 -2
- package/dist/transactions.d.ts.map +1 -1
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/wallets.d.ts +1 -0
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/AddressWalletIcon.d.ts +6 -0
- package/dist/widget/components/AddressWalletIcon.d.ts.map +1 -0
- package/dist/widget/components/ChainFilterDropdown.d.ts +2 -6
- package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
- package/dist/widget/components/ChainImage.d.ts.map +1 -1
- package/dist/widget/components/ChainList.d.ts +0 -5
- package/dist/widget/components/ChainList.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts +6 -6
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
- package/dist/widget/components/DebugMenu.d.ts +1 -1
- package/dist/widget/components/DebugMenu.d.ts.map +1 -1
- package/dist/widget/components/DebugScreensList.d.ts.map +1 -1
- package/dist/widget/components/DepositTracker.d.ts.map +1 -1
- package/dist/widget/components/Earn.d.ts +5 -5
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/FeeOption.d.ts +1 -1
- package/dist/widget/components/FeeOption.d.ts.map +1 -1
- package/dist/widget/components/FeeOptions.d.ts +2 -2
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/Footer.d.ts +1 -1
- package/dist/widget/components/Footer.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts +5 -5
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts +0 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/FundSwap.d.ts +6 -6
- package/dist/widget/components/FundSwap.d.ts.map +1 -1
- package/dist/widget/components/HookModalContent.d.ts +8 -0
- package/dist/widget/components/HookModalContent.d.ts.map +1 -0
- package/dist/widget/components/OriginSelectionAmount.d.ts +11 -0
- package/dist/widget/components/OriginSelectionAmount.d.ts.map +1 -0
- package/dist/widget/components/Pay.d.ts +5 -5
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts +5 -5
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/PoolWithdraw.d.ts +3 -3
- package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts +2 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/RecentTokens.d.ts +4 -4
- package/dist/widget/components/RecentTokens.d.ts.map +1 -1
- package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/ShadowPortal.d.ts +6 -0
- package/dist/widget/components/ShadowPortal.d.ts.map +1 -0
- package/dist/widget/components/Swap.d.ts +6 -6
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/ThemeProvider.d.ts +1 -1
- package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
- package/dist/widget/components/TokenList.d.ts +3 -4
- package/dist/widget/components/TokenList.d.ts.map +1 -1
- package/dist/widget/components/TokenSelector.d.ts +3 -4
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/Tooltip.d.ts +6 -1
- package/dist/widget/components/Tooltip.d.ts.map +1 -1
- package/dist/widget/components/TrailsHookModal.d.ts +10 -0
- package/dist/widget/components/TrailsHookModal.d.ts.map +1 -0
- package/dist/widget/components/WaasFeeOptions.d.ts +3 -0
- package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
- package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/components/WidgetProviders.d.ts +14 -0
- package/dist/widget/components/WidgetProviders.d.ts.map +1 -0
- package/dist/widget/css/compiled.css +1 -1
- package/dist/widget/hooks/useAddressWalletIcon.d.ts +10 -0
- package/dist/widget/hooks/useAddressWalletIcon.d.ts.map +1 -0
- package/dist/widget/hooks/useBalanceVisible.d.ts +1 -1
- package/dist/widget/hooks/useBalanceVisible.d.ts.map +1 -1
- package/dist/widget/hooks/useChainFilter.d.ts +1 -1
- package/dist/widget/hooks/useChainFilter.d.ts.map +1 -1
- package/dist/widget/hooks/useCheckout.d.ts +13 -1
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useConnector.d.ts +4 -0
- package/dist/widget/hooks/useConnector.d.ts.map +1 -0
- package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
- package/dist/widget/hooks/useCustomTokenFetch.d.ts +19 -0
- package/dist/widget/hooks/useCustomTokenFetch.d.ts.map +1 -0
- package/dist/widget/hooks/useCustomTokenSearch.d.ts +20 -0
- package/dist/widget/hooks/useCustomTokenSearch.d.ts.map +1 -0
- package/dist/widget/hooks/useDebounce.d.ts +10 -0
- package/dist/widget/hooks/useDebounce.d.ts.map +1 -0
- package/dist/widget/hooks/useDebugScreens.d.ts +7 -2
- package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts +3 -19
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
- package/dist/widget/hooks/useDestinationSelectedToken.d.ts +1 -14
- package/dist/widget/hooks/useDestinationSelectedToken.d.ts.map +1 -1
- package/dist/widget/hooks/useEarnPool.d.ts +1 -1
- package/dist/widget/hooks/useEarnPool.d.ts.map +1 -1
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useIsMobile.d.ts +5 -0
- package/dist/widget/hooks/useIsMobile.d.ts.map +1 -0
- package/dist/widget/hooks/useMode.d.ts +2 -2
- package/dist/widget/hooks/useMode.d.ts.map +1 -1
- package/dist/widget/hooks/useOriginSelectedToken.d.ts +2 -15
- package/dist/widget/hooks/useOriginSelectedToken.d.ts.map +1 -1
- package/dist/widget/hooks/usePayMessage.d.ts.map +1 -1
- package/dist/widget/hooks/usePriceImpactWarning.d.ts +1 -1
- package/dist/widget/hooks/usePriceImpactWarning.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +173 -4
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useRecentTokens.d.ts +3 -3
- package/dist/widget/hooks/useRecentTokens.d.ts.map +1 -1
- package/dist/widget/hooks/useRecipients.d.ts +1 -1
- package/dist/widget/hooks/useRecipients.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFeeOption.d.ts +2 -2
- package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFundMethod.d.ts +1 -1
- package/dist/widget/hooks/useSelectedFundMethod.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedRecipient.d.ts +1 -1
- package/dist/widget/hooks/useSelectedRecipient.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +9 -31
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useSwapAmount.d.ts +1 -1
- package/dist/widget/hooks/useSwapAmount.d.ts.map +1 -1
- package/dist/widget/hooks/useTheme.d.ts +1 -1
- package/dist/widget/hooks/useTheme.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts +7 -31
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/hooks/useTrailsSendTransaction.d.ts +83 -0
- package/dist/widget/hooks/useTrailsSendTransaction.d.ts.map +1 -0
- package/dist/widget/hooks/useWalletConnectUri.d.ts +11 -0
- package/dist/widget/hooks/useWalletConnectUri.d.ts.map +1 -0
- package/dist/widget/hooks/useWidgetProps.d.ts +5 -0
- package/dist/widget/hooks/useWidgetProps.d.ts.map +1 -1
- package/dist/widget/index.d.ts +2 -0
- package/dist/widget/index.d.ts.map +1 -1
- package/dist/widget/index.js +8 -5
- package/dist/widget/providers/TrailsModalProvider.d.ts +65 -0
- package/dist/widget/providers/TrailsModalProvider.d.ts.map +1 -0
- package/dist/widget/providers/TrailsProvider.d.ts +1 -1
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -1
- package/dist/widget/types.d.ts +11 -18
- package/dist/widget/types.d.ts.map +1 -1
- package/dist/widget/widget.d.ts +20 -11
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +45 -49
- package/src/aave.ts +387 -138
- package/src/analytics.ts +208 -2
- package/src/chains.ts +65 -64
- package/src/constants.ts +18 -14
- package/src/customTokens.ts +151 -0
- package/src/decoders.ts +4 -7
- package/src/error.ts +7 -3
- package/src/fees.ts +239 -125
- package/src/gasless.ts +54 -108
- package/src/index.ts +29 -9
- package/src/indexerClient.ts +2 -0
- package/src/intentReceiptMonitor.ts +1 -4
- package/src/intentReceiptPoller.ts +2 -2
- package/src/intents.ts +16 -5
- package/src/mode.ts +1 -1
- package/src/mutations.ts +7 -3
- package/src/prepareSend.ts +19 -14
- package/src/prices.ts +1 -1
- package/src/sequenceWallet.ts +2 -2
- package/src/time.ts +28 -0
- package/src/tokenBalances.ts +348 -153
- package/src/tokens.ts +393 -142
- package/src/trailsClient.ts +1 -1
- package/src/trailsRouter.ts +4 -5
- package/src/transactionIntent/deposits/depositOrchestrator.ts +6 -2
- package/src/transactionIntent/deposits/gaslessDeposit.ts +13 -7
- package/src/transactionIntent/deposits/standardDeposit.ts +1 -1
- package/src/transactionIntent/execution/transactionState.ts +1 -1
- package/src/transactionIntent/handlers/crossChain.ts +75 -37
- package/src/transactionIntent/handlers/sameChainSameToken.ts +66 -20
- package/src/transactionIntent/quote/feeExtractors.ts +1 -29
- package/src/transactionIntent/quote/normalizeQuote.ts +99 -7
- package/src/transactionIntent/quote/quoteHelpers.ts +1 -1
- package/src/transactionIntent/types.ts +31 -6
- package/src/transactionIntent/utils/testnetHelpers.ts +0 -5
- package/src/transactionIntent/validators.ts +0 -30
- package/src/transactions.ts +3 -3
- package/src/utils.ts +18 -0
- package/src/wallets.ts +32 -10
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistory.tsx +2 -1
- package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +2 -2
- package/src/widget/components/AddressWalletIcon.tsx +29 -0
- package/src/widget/components/ChainFilterDropdown.tsx +2 -8
- package/src/widget/components/ChainImage.tsx +8 -5
- package/src/widget/components/ChainList.tsx +6 -8
- package/src/widget/components/ClassicSwap.tsx +93 -85
- package/src/widget/components/ConnectWallet.tsx +1 -2
- package/src/widget/components/ConnectedWallets.tsx +17 -4
- package/src/widget/components/DebugMenu.tsx +2 -2
- package/src/widget/components/DebugScreensList.tsx +0 -1
- package/src/widget/components/DepositTracker.tsx +20 -34
- package/src/widget/components/Earn.tsx +7 -6
- package/src/widget/components/FeeOption.tsx +4 -4
- package/src/widget/components/FeeOptions.tsx +19 -39
- package/src/widget/components/Footer.tsx +1 -1
- package/src/widget/components/Fund.tsx +23 -119
- package/src/widget/components/FundMethods.tsx +9 -6
- package/src/widget/components/FundSwap.tsx +6 -5
- package/src/widget/components/FundingMethodSelectorButton.tsx +2 -2
- package/src/widget/components/HookModalContent.tsx +306 -0
- package/src/widget/components/Modal.tsx +1 -1
- package/src/widget/components/OriginSelectionAmount.tsx +135 -0
- package/src/widget/components/Pay.tsx +66 -124
- package/src/widget/components/PoolDeposit.tsx +11 -55
- package/src/widget/components/PoolWithdraw.tsx +3 -3
- package/src/widget/components/QuoteDetails.tsx +473 -728
- package/src/widget/components/Receipt.tsx +74 -7
- package/src/widget/components/RecentTokens.tsx +8 -8
- package/src/widget/components/RecipientSelectorButton.tsx +4 -2
- package/src/widget/components/ScreenHeader.tsx +2 -2
- package/src/widget/components/SearchInputField.tsx +1 -1
- package/src/widget/components/ShadowPortal.tsx +58 -0
- package/src/widget/components/Swap.tsx +6 -5
- package/src/widget/components/ThemeProvider.tsx +1 -1
- package/src/widget/components/TokenList.tsx +3 -4
- package/src/widget/components/TokenSelector.tsx +211 -80
- package/src/widget/components/Tooltip.tsx +18 -7
- package/src/widget/components/TrailsHookModal.tsx +118 -0
- package/src/widget/components/WaasFeeOptions.tsx +333 -138
- package/src/widget/components/WalletConfirmation.tsx +7 -2
- package/src/widget/components/WalletConnect.tsx +197 -235
- package/src/widget/components/WidgetProviders.tsx +75 -0
- package/src/widget/hooks/useAddressWalletIcon.ts +53 -0
- package/src/widget/hooks/useBalanceVisible.tsx +1 -1
- package/src/widget/hooks/useChainFilter.tsx +1 -1
- package/src/widget/hooks/useCheckout.ts +13 -1
- package/src/widget/hooks/useConnector.tsx +18 -0
- package/src/widget/hooks/useCurrentScreen.tsx +3 -3
- package/src/widget/hooks/useCustomTokenFetch.tsx +72 -0
- package/src/widget/hooks/useCustomTokenSearch.tsx +402 -0
- package/src/widget/hooks/useDebounce.ts +25 -0
- package/src/widget/hooks/useDebugScreens.ts +26 -10
- package/src/widget/hooks/useDefaultTokenSelection.tsx +99 -143
- package/src/widget/hooks/useDestinationSelectedToken.tsx +1 -14
- package/src/widget/hooks/useEarnPool.tsx +1 -1
- package/src/widget/hooks/useIntentTransactionHistory.ts +20 -11
- package/src/widget/hooks/useIsMobile.tsx +50 -0
- package/src/widget/hooks/useMode.ts +2 -3
- package/src/widget/hooks/useOriginSelectedToken.tsx +2 -15
- package/src/widget/hooks/usePayMessage.tsx +31 -11
- package/src/widget/hooks/usePriceImpactWarning.ts +1 -1
- package/src/widget/hooks/useQuote.ts +189 -6
- package/src/widget/hooks/useRecentTokens.ts +6 -6
- package/src/widget/hooks/useRecipients.ts +1 -1
- package/src/widget/hooks/useSelectedFeeOption.tsx +2 -2
- package/src/widget/hooks/useSelectedFundMethod.tsx +1 -1
- package/src/widget/hooks/useSelectedRecipient.tsx +1 -1
- package/src/widget/hooks/useSendForm.ts +328 -152
- package/src/widget/hooks/useSwapAmount.tsx +1 -1
- package/src/widget/hooks/useTheme.tsx +1 -1
- package/src/widget/hooks/useTokenList.ts +672 -400
- package/src/widget/hooks/useTrailsSendTransaction.ts +949 -0
- package/src/widget/hooks/useWalletConnectUri.tsx +228 -0
- package/src/widget/hooks/useWidgetProps.tsx +3 -1
- package/src/widget/index.tsx +12 -0
- package/src/widget/providers/TrailsModalProvider.tsx +195 -0
- package/src/widget/providers/TrailsProvider.tsx +9 -3
- package/src/widget/types.ts +12 -20
- package/src/widget/widget.tsx +598 -385
- package/dist/cctp.d.ts +0 -3
- package/dist/cctp.d.ts.map +0 -1
- package/dist/lifi.d.ts +0 -4
- package/dist/lifi.d.ts.map +0 -1
- package/dist/meshconnect.d.ts +0 -171
- package/dist/meshconnect.d.ts.map +0 -1
- package/dist/relaySdk.d.ts +0 -87
- package/dist/relaySdk.d.ts.map +0 -1
- package/dist/widget/components/MeshConnectExchanges.d.ts +0 -7
- package/dist/widget/components/MeshConnectExchanges.d.ts.map +0 -1
- package/dist/widget/components/MeshConnectFlow.d.ts +0 -13
- package/dist/widget/components/MeshConnectFlow.d.ts.map +0 -1
- package/dist/widget/components/MeshConnectIframe.d.ts +0 -15
- package/dist/widget/components/MeshConnectIframe.d.ts.map +0 -1
- package/dist/widget/components/Receive.d.ts +0 -12
- package/dist/widget/components/Receive.d.ts.map +0 -1
- package/dist/widget/hooks/useSelectedMeshExchange.d.ts +0 -14
- package/dist/widget/hooks/useSelectedMeshExchange.d.ts.map +0 -1
- package/src/cctp.ts +0 -54
- package/src/lifi.ts +0 -108
- package/src/meshconnect.ts +0 -531
- package/src/relaySdk.ts +0 -703
- package/src/widget/components/MeshConnectExchanges.tsx +0 -290
- package/src/widget/components/MeshConnectFlow.tsx +0 -90
- package/src/widget/components/MeshConnectIframe.tsx +0 -500
- package/src/widget/components/Receive.tsx +0 -175
- package/src/widget/hooks/useSelectedMeshExchange.tsx +0 -46
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TokenPrice, FeeOption } from "@
|
|
2
|
-
import { JsonEncode } from "@
|
|
1
|
+
import type { TokenPrice, FeeOption } from "@0xtrails/api"
|
|
2
|
+
import { JsonEncode } from "@0xtrails/api"
|
|
3
3
|
import type React from "react"
|
|
4
4
|
import { useCallback, useEffect, useMemo, useState, useRef } from "react"
|
|
5
5
|
import {
|
|
@@ -32,11 +32,13 @@ import {
|
|
|
32
32
|
formatAmount,
|
|
33
33
|
formatAmountDisplay,
|
|
34
34
|
} from "../../tokenBalances.js"
|
|
35
|
-
import
|
|
35
|
+
import { useQuery } from "@tanstack/react-query"
|
|
36
|
+
import type { Token } from "../../tokens.js"
|
|
36
37
|
import {
|
|
37
38
|
useSupportedTokens,
|
|
38
39
|
useTokenAddress,
|
|
39
40
|
useTokenInfo,
|
|
41
|
+
getSupportedTokens,
|
|
40
42
|
} from "../../tokens.js"
|
|
41
43
|
import type { CheckoutOnHandlers } from "./useCheckout.js"
|
|
42
44
|
import { useResolveEnsAddress } from "../../ens.js"
|
|
@@ -51,30 +53,7 @@ import {
|
|
|
51
53
|
type ProcessedFeeOption,
|
|
52
54
|
} from "./useSelectedFeeOption.js"
|
|
53
55
|
import { useWidgetProps } from "./useWidgetProps.js"
|
|
54
|
-
|
|
55
|
-
export interface Token {
|
|
56
|
-
id: number
|
|
57
|
-
name: string
|
|
58
|
-
symbol: string
|
|
59
|
-
balance: string
|
|
60
|
-
imageUrl: string
|
|
61
|
-
chainId: number
|
|
62
|
-
contractAddress: string
|
|
63
|
-
tokenPriceUsd?: number
|
|
64
|
-
balanceUsdFormatted?: string
|
|
65
|
-
contractInfo?: {
|
|
66
|
-
decimals: number
|
|
67
|
-
symbol: string
|
|
68
|
-
name: string
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export type TokenInfo = {
|
|
73
|
-
symbol: string
|
|
74
|
-
name: string
|
|
75
|
-
imageUrl: string
|
|
76
|
-
decimals: number
|
|
77
|
-
}
|
|
56
|
+
import { useCustomTokens } from "../../customTokens.js"
|
|
78
57
|
|
|
79
58
|
type ChainInfo = {
|
|
80
59
|
id: number
|
|
@@ -112,8 +91,8 @@ export type UseSendProps = {
|
|
|
112
91
|
tradeType?: TradeType
|
|
113
92
|
quoteProvider?: string
|
|
114
93
|
fundMethod?: string
|
|
115
|
-
mode?: "pay" | "fund" | "earn" | "swap"
|
|
116
|
-
|
|
94
|
+
mode?: "pay" | "fund" | "earn" | "swap"
|
|
95
|
+
onNavigateToOnramp?: (
|
|
117
96
|
props: {
|
|
118
97
|
toTokenSymbol: string
|
|
119
98
|
toTokenAmount: string
|
|
@@ -121,6 +100,7 @@ export type UseSendProps = {
|
|
|
121
100
|
toRecipientAddress: string
|
|
122
101
|
},
|
|
123
102
|
quote?: PrepareSendQuote | null,
|
|
103
|
+
continueSend?: () => Promise<void>,
|
|
124
104
|
) => void
|
|
125
105
|
checkoutOnHandlers?: CheckoutOnHandlers
|
|
126
106
|
refetchTrigger?: number
|
|
@@ -144,15 +124,15 @@ export type UseSendReturn = {
|
|
|
144
124
|
recipient: string
|
|
145
125
|
recipientInput: string
|
|
146
126
|
selectedDestinationChain: ChainInfo | null
|
|
147
|
-
selectedDestToken:
|
|
127
|
+
selectedDestToken: Token | null
|
|
148
128
|
setAmount: (amount: string) => void
|
|
149
129
|
setRecipient: (recipient: string) => void
|
|
150
130
|
setRecipientInput: (recipientInput: string) => void
|
|
151
131
|
setSelectedDestinationChain: (chain: ChainInfo) => void
|
|
152
|
-
setSelectedDestToken: (token:
|
|
132
|
+
setSelectedDestToken: (token: Token | null) => void
|
|
153
133
|
setSelectedFeeOption: (token: FeeOption | null) => void
|
|
154
134
|
processedFeeOptions: ProcessedFeeOption[]
|
|
155
|
-
supportedTokens:
|
|
135
|
+
supportedTokens: Token[]
|
|
156
136
|
supportedChains: ChainInfo[]
|
|
157
137
|
ensAddress: string | null
|
|
158
138
|
isWaitingForWalletConfirm: boolean
|
|
@@ -198,7 +178,7 @@ export function useSendForm({
|
|
|
198
178
|
quoteProvider,
|
|
199
179
|
fundMethod,
|
|
200
180
|
mode,
|
|
201
|
-
|
|
181
|
+
onNavigateToOnramp,
|
|
202
182
|
checkoutOnHandlers,
|
|
203
183
|
refetchTrigger = 0,
|
|
204
184
|
}: UseSendProps): UseSendReturn {
|
|
@@ -269,6 +249,24 @@ export function useSendForm({
|
|
|
269
249
|
const { supportedTokens } = useSupportedTokens({
|
|
270
250
|
chainId: selectedDestinationChain?.id,
|
|
271
251
|
})
|
|
252
|
+
// Get official supported tokens (before merging with custom tokens) to check if token is truly custom
|
|
253
|
+
const trailsConfig = useTrails()
|
|
254
|
+
const { data: officialSupportedTokens = [] } = useQuery({
|
|
255
|
+
queryKey: [
|
|
256
|
+
"supportedTokens",
|
|
257
|
+
trailsConfig.trailsApiUrl,
|
|
258
|
+
trailsConfig.trailsApiKey,
|
|
259
|
+
],
|
|
260
|
+
queryFn: () =>
|
|
261
|
+
getSupportedTokens({
|
|
262
|
+
trailsApiKey: trailsConfig.trailsApiKey,
|
|
263
|
+
trailsApiUrl: trailsConfig.trailsApiUrl,
|
|
264
|
+
}),
|
|
265
|
+
staleTime: 60 * 60 * 1000, // 1 hour
|
|
266
|
+
gcTime: 24 * 60 * 60 * 1000, // 24 hours
|
|
267
|
+
refetchOnWindowFocus: false,
|
|
268
|
+
refetchOnReconnect: false,
|
|
269
|
+
})
|
|
272
270
|
|
|
273
271
|
// Get RPC clients for known chainIds using hooks (reads from TrailsProvider context)
|
|
274
272
|
const destinationChainPublicClient = useChainRpcClient(
|
|
@@ -382,6 +380,8 @@ export function useSendForm({
|
|
|
382
380
|
|
|
383
381
|
const isCustomToken = useMemo(() => toToken?.startsWith("0x"), [toToken])
|
|
384
382
|
|
|
383
|
+
const { addCustomToken } = useCustomTokens()
|
|
384
|
+
|
|
385
385
|
const {
|
|
386
386
|
tokenInfo: customTokenInfo,
|
|
387
387
|
isLoading: isLoadingCustomToken,
|
|
@@ -404,9 +404,70 @@ export function useSendForm({
|
|
|
404
404
|
)
|
|
405
405
|
}, [isCustomToken, errorCustomToken, isLoadingCustomToken, customTokenInfo])
|
|
406
406
|
|
|
407
|
+
// Save custom token to storage when successfully fetched via toToken prop
|
|
408
|
+
// Only save if it doesn't exist in the base supported tokens list
|
|
409
|
+
useEffect(() => {
|
|
410
|
+
if (
|
|
411
|
+
customTokenInfo &&
|
|
412
|
+
!errorCustomToken &&
|
|
413
|
+
isCustomToken &&
|
|
414
|
+
toChainId &&
|
|
415
|
+
toToken &&
|
|
416
|
+
customTokenInfo.symbol &&
|
|
417
|
+
customTokenInfo.name &&
|
|
418
|
+
customTokenInfo.decimals !== undefined
|
|
419
|
+
) {
|
|
420
|
+
// Check if token already exists in official supported tokens (before merging)
|
|
421
|
+
const existsInOfficialSupportedTokens = officialSupportedTokens.some(
|
|
422
|
+
(token: Token) =>
|
|
423
|
+
token.chainId === toChainId &&
|
|
424
|
+
token.contractAddress.toLowerCase() === toToken.toLowerCase(),
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
// Only add to custom tokens if it's not an official supported token
|
|
428
|
+
if (!existsInOfficialSupportedTokens) {
|
|
429
|
+
const chainInfo = getChainInfo(toChainId)
|
|
430
|
+
const chainName = chainInfo?.name || `Chain ${toChainId}`
|
|
431
|
+
|
|
432
|
+
// Convert tokenInfo to Token format, then to SupportedToken for storage
|
|
433
|
+
// isCustomToken will be set to true by addCustomToken
|
|
434
|
+
const customToken: Token = {
|
|
435
|
+
tokenId: `${toChainId}-${toToken.toLowerCase()}`,
|
|
436
|
+
chainId: toChainId,
|
|
437
|
+
contractAddress: toToken,
|
|
438
|
+
symbol: customTokenInfo.symbol,
|
|
439
|
+
name: customTokenInfo.name,
|
|
440
|
+
decimals: customTokenInfo.decimals,
|
|
441
|
+
chainName,
|
|
442
|
+
imageUrl: customTokenInfo.imageUrl || "",
|
|
443
|
+
isCustomToken: true,
|
|
444
|
+
}
|
|
445
|
+
addCustomToken(customToken)
|
|
446
|
+
logger.console.log(
|
|
447
|
+
"[trails-sdk] Added custom token from toToken prop to storage:",
|
|
448
|
+
customToken,
|
|
449
|
+
)
|
|
450
|
+
} else {
|
|
451
|
+
logger.console.log(
|
|
452
|
+
"[trails-sdk] Token from toToken prop already exists in supported tokens, skipping custom token addition:",
|
|
453
|
+
{ toToken, toChainId },
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}, [
|
|
458
|
+
customTokenInfo,
|
|
459
|
+
errorCustomToken,
|
|
460
|
+
isCustomToken,
|
|
461
|
+
toChainId,
|
|
462
|
+
toToken,
|
|
463
|
+
addCustomToken,
|
|
464
|
+
officialSupportedTokens,
|
|
465
|
+
])
|
|
466
|
+
|
|
407
467
|
useEffect(() => {
|
|
408
468
|
if (isCustomToken && customTokenInfo && !isLoadingCustomToken) {
|
|
409
|
-
|
|
469
|
+
// customTokenInfo is already Token from getTokenInfo
|
|
470
|
+
setSelectedDestToken(customTokenInfo as Token)
|
|
410
471
|
}
|
|
411
472
|
}, [customTokenInfo, isCustomToken, isLoadingCustomToken])
|
|
412
473
|
|
|
@@ -425,36 +486,41 @@ export function useSendForm({
|
|
|
425
486
|
}
|
|
426
487
|
|
|
427
488
|
if (selectedDestinationChain) {
|
|
428
|
-
return
|
|
429
|
-
(
|
|
489
|
+
return (
|
|
490
|
+
supportedTokens.find(
|
|
491
|
+
(token) => token.chainId === selectedDestinationChain.id,
|
|
492
|
+
) || null
|
|
430
493
|
)
|
|
431
494
|
}
|
|
432
|
-
return supportedTokens?.[0]
|
|
495
|
+
return supportedTokens?.[0] || null
|
|
433
496
|
}, [supportedTokens, selectedDestinationChain, mode])
|
|
434
497
|
|
|
435
498
|
const [isChainDropdownOpen, setIsChainDropdownOpen] = useState(false)
|
|
436
499
|
const [isTokenDropdownOpen, setIsTokenDropdownOpen] = useState(false)
|
|
437
|
-
const [selectedDestToken, setSelectedDestToken] = useState<
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
(
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
500
|
+
const [selectedDestToken, setSelectedDestToken] = useState<Token | null>(
|
|
501
|
+
() => {
|
|
502
|
+
let token = defaultDestToken
|
|
503
|
+
if (toToken && !isCustomToken) {
|
|
504
|
+
const isToTokenAddress = isAddress(toToken)
|
|
505
|
+
token =
|
|
506
|
+
supportedTokens.find(
|
|
507
|
+
(token) =>
|
|
508
|
+
(isToTokenAddress // Match by specified destination token address or symbol
|
|
509
|
+
? token.contractAddress.toLowerCase() === toToken.toLowerCase()
|
|
510
|
+
: token.symbol === toToken) &&
|
|
511
|
+
(toChainId // Match by specified destination chain id
|
|
512
|
+
? token.chainId === toChainId
|
|
513
|
+
: selectedDestinationChain?.id), // Select by selected destination chain id
|
|
514
|
+
) || null
|
|
515
|
+
}
|
|
451
516
|
|
|
452
|
-
|
|
453
|
-
|
|
517
|
+
return token
|
|
518
|
+
},
|
|
519
|
+
)
|
|
454
520
|
|
|
455
521
|
useEffect(() => {
|
|
456
522
|
if (!selectedDestToken && defaultDestToken) {
|
|
457
|
-
setSelectedDestToken(defaultDestToken
|
|
523
|
+
setSelectedDestToken(defaultDestToken)
|
|
458
524
|
}
|
|
459
525
|
}, [selectedDestToken, defaultDestToken])
|
|
460
526
|
|
|
@@ -506,7 +572,7 @@ export function useSendForm({
|
|
|
506
572
|
{
|
|
507
573
|
tokenSymbol: selectedToken.symbol,
|
|
508
574
|
tokenAddress: selectedToken.contractAddress,
|
|
509
|
-
chainId: selectedToken.chainId,
|
|
575
|
+
chainId: selectedToken.chainId || 0,
|
|
510
576
|
},
|
|
511
577
|
]
|
|
512
578
|
: [],
|
|
@@ -537,7 +603,7 @@ export function useSendForm({
|
|
|
537
603
|
: token.chainId === selectedDestinationChain.id),
|
|
538
604
|
)
|
|
539
605
|
if (newToken) {
|
|
540
|
-
setSelectedDestToken(newToken
|
|
606
|
+
setSelectedDestToken(newToken)
|
|
541
607
|
}
|
|
542
608
|
}
|
|
543
609
|
}, [
|
|
@@ -593,10 +659,10 @@ export function useSendForm({
|
|
|
593
659
|
)
|
|
594
660
|
|
|
595
661
|
const balanceFormatted =
|
|
596
|
-
selectedToken?.balance && selectedToken?.
|
|
662
|
+
selectedToken?.balance && selectedToken?.decimals
|
|
597
663
|
? formatRawAmount(
|
|
598
|
-
selectedToken.balance,
|
|
599
|
-
selectedToken.
|
|
664
|
+
selectedToken.balance || "0",
|
|
665
|
+
selectedToken.decimals || 18,
|
|
600
666
|
)
|
|
601
667
|
: "0"
|
|
602
668
|
const balanceUsdDisplay = selectedToken?.balanceUsdFormatted ?? ""
|
|
@@ -635,11 +701,42 @@ export function useSendForm({
|
|
|
635
701
|
})
|
|
636
702
|
|
|
637
703
|
const destinationTokenAddress = useMemo(() => {
|
|
704
|
+
// If toToken prop is set and is a custom token address, use it
|
|
638
705
|
if (isCustomToken) {
|
|
706
|
+
logger.console.log(
|
|
707
|
+
"[trails-sdk] [CUSTOM-TOKEN] Using toToken prop as destinationTokenAddress:",
|
|
708
|
+
toToken,
|
|
709
|
+
)
|
|
639
710
|
return toToken ?? null
|
|
640
711
|
}
|
|
641
|
-
|
|
642
|
-
|
|
712
|
+
// If selectedDestToken has a contractAddress, use it directly (handles custom tokens selected from UI)
|
|
713
|
+
if (selectedDestToken?.contractAddress) {
|
|
714
|
+
logger.console.log(
|
|
715
|
+
"[trails-sdk] [CUSTOM-TOKEN] Using contractAddress from selectedDestToken:",
|
|
716
|
+
{
|
|
717
|
+
contractAddress: selectedDestToken.contractAddress,
|
|
718
|
+
symbol: selectedDestToken.symbol,
|
|
719
|
+
},
|
|
720
|
+
)
|
|
721
|
+
return selectedDestToken.contractAddress
|
|
722
|
+
}
|
|
723
|
+
// Otherwise, try to look it up by symbol
|
|
724
|
+
const addressFromSymbol = destinationTokenAddressFromTokenSymbol ?? null
|
|
725
|
+
logger.console.log(
|
|
726
|
+
"[trails-sdk] [CUSTOM-TOKEN] Using address from symbol lookup:",
|
|
727
|
+
{
|
|
728
|
+
addressFromSymbol,
|
|
729
|
+
symbol: selectedDestToken?.symbol,
|
|
730
|
+
},
|
|
731
|
+
)
|
|
732
|
+
return addressFromSymbol
|
|
733
|
+
}, [
|
|
734
|
+
isCustomToken,
|
|
735
|
+
toToken,
|
|
736
|
+
selectedDestToken?.contractAddress,
|
|
737
|
+
selectedDestToken?.symbol,
|
|
738
|
+
destinationTokenAddressFromTokenSymbol,
|
|
739
|
+
])
|
|
643
740
|
|
|
644
741
|
// Calculate raw amount (in wei/smallest unit)
|
|
645
742
|
const amountRaw = useMemo(() => {
|
|
@@ -648,10 +745,7 @@ export function useSendForm({
|
|
|
648
745
|
return "0"
|
|
649
746
|
}
|
|
650
747
|
|
|
651
|
-
if (
|
|
652
|
-
!amount &&
|
|
653
|
-
!(selectedToken?.contractInfo?.decimals || selectedDestToken?.decimals)
|
|
654
|
-
) {
|
|
748
|
+
if (!amount && !(selectedToken?.decimals || selectedDestToken?.decimals)) {
|
|
655
749
|
logger.console.warn("[trails-sdk] Missing token decimals for quote", {
|
|
656
750
|
amount,
|
|
657
751
|
selectedToken,
|
|
@@ -661,10 +755,7 @@ export function useSendForm({
|
|
|
661
755
|
return "0"
|
|
662
756
|
}
|
|
663
757
|
|
|
664
|
-
if (
|
|
665
|
-
tradeType === TradeType.EXACT_INPUT &&
|
|
666
|
-
!selectedToken?.contractInfo?.decimals
|
|
667
|
-
) {
|
|
758
|
+
if (tradeType === TradeType.EXACT_INPUT && !selectedToken?.decimals) {
|
|
668
759
|
logger.console.warn(
|
|
669
760
|
"[trails-sdk] Missing source token decimals for quote",
|
|
670
761
|
{
|
|
@@ -688,7 +779,7 @@ export function useSendForm({
|
|
|
688
779
|
// For EXACT_OUTPUT: use destination token decimals (user enters destination amount)
|
|
689
780
|
const decimals =
|
|
690
781
|
tradeType === TradeType.EXACT_INPUT
|
|
691
|
-
? selectedToken?.
|
|
782
|
+
? selectedToken?.decimals
|
|
692
783
|
: selectedDestToken?.decimals
|
|
693
784
|
|
|
694
785
|
if (!decimals) {
|
|
@@ -711,7 +802,7 @@ export function useSendForm({
|
|
|
711
802
|
selectedDestToken,
|
|
712
803
|
selectedToken,
|
|
713
804
|
selectedDestToken?.decimals,
|
|
714
|
-
selectedToken?.
|
|
805
|
+
selectedToken?.decimals,
|
|
715
806
|
tradeType,
|
|
716
807
|
])
|
|
717
808
|
|
|
@@ -770,12 +861,9 @@ export function useSendForm({
|
|
|
770
861
|
? {
|
|
771
862
|
symbol: selectedToken.symbol,
|
|
772
863
|
contractAddress: selectedToken.contractAddress,
|
|
773
|
-
chainId: selectedToken.chainId,
|
|
774
|
-
contractInfo: selectedToken.contractInfo,
|
|
864
|
+
chainId: selectedToken.chainId || 0,
|
|
775
865
|
}
|
|
776
866
|
: null,
|
|
777
|
-
isCustomToken,
|
|
778
|
-
toToken,
|
|
779
867
|
recipient,
|
|
780
868
|
conditions: {
|
|
781
869
|
hasAccount: !!account,
|
|
@@ -861,8 +949,8 @@ export function useSendForm({
|
|
|
861
949
|
setError(null)
|
|
862
950
|
setQuoteError(null)
|
|
863
951
|
|
|
864
|
-
const sourceTokenDecimals = selectedToken.
|
|
865
|
-
const destinationTokenDecimals = selectedDestToken.decimals
|
|
952
|
+
const sourceTokenDecimals = selectedToken.decimals || 18
|
|
953
|
+
const destinationTokenDecimals = selectedDestToken.decimals || 18
|
|
866
954
|
|
|
867
955
|
if (!sourceTokenDecimals || !destinationTokenDecimals) {
|
|
868
956
|
logger.console.warn("[trails-sdk] Missing token decimals for quote", {
|
|
@@ -879,7 +967,7 @@ export function useSendForm({
|
|
|
879
967
|
return
|
|
880
968
|
}
|
|
881
969
|
|
|
882
|
-
let sourceTokenPriceUsd = selectedToken.
|
|
970
|
+
let sourceTokenPriceUsd = selectedToken.priceUsd ?? null
|
|
883
971
|
let destinationTokenPriceUsd = destTokenPrices?.[0]?.priceUsd ?? null
|
|
884
972
|
|
|
885
973
|
if (!sourceTokenPriceUsd) {
|
|
@@ -887,7 +975,7 @@ export function useSendForm({
|
|
|
887
975
|
const price = await getTokenPrice(trailsClient, {
|
|
888
976
|
tokenAddress: selectedToken.contractAddress,
|
|
889
977
|
tokenSymbol: selectedToken.symbol,
|
|
890
|
-
chainId: selectedToken.chainId,
|
|
978
|
+
chainId: selectedToken.chainId || 0,
|
|
891
979
|
})
|
|
892
980
|
sourceTokenPriceUsd = price?.priceUsd ?? null
|
|
893
981
|
} catch (error) {
|
|
@@ -941,12 +1029,12 @@ export function useSendForm({
|
|
|
941
1029
|
) {
|
|
942
1030
|
nativeTokenPriceUsd = sourceTokenPriceUsd
|
|
943
1031
|
} else {
|
|
944
|
-
const originChain = getChainInfo(selectedToken.chainId)
|
|
1032
|
+
const originChain = getChainInfo(selectedToken.chainId || 0)
|
|
945
1033
|
const nativeTokenSymbol = originChain?.nativeCurrency?.symbol ?? ""
|
|
946
1034
|
const nativePrice = await getTokenPrice(trailsClient, {
|
|
947
1035
|
tokenSymbol: nativeTokenSymbol,
|
|
948
1036
|
tokenAddress: zeroAddress,
|
|
949
|
-
chainId: selectedToken.chainId,
|
|
1037
|
+
chainId: selectedToken.chainId || 0,
|
|
950
1038
|
})
|
|
951
1039
|
nativeTokenPriceUsd = nativePrice?.priceUsd ?? 0
|
|
952
1040
|
}
|
|
@@ -954,14 +1042,11 @@ export function useSendForm({
|
|
|
954
1042
|
const options = {
|
|
955
1043
|
account,
|
|
956
1044
|
originTokenAddress: selectedToken.contractAddress,
|
|
957
|
-
originChainId: selectedToken.chainId,
|
|
1045
|
+
originChainId: selectedToken.chainId || 0,
|
|
958
1046
|
originTokenBalance:
|
|
959
1047
|
fundMethod === "qr-code" || fundMethod === "exchange"
|
|
960
|
-
? parseUnits(
|
|
961
|
-
|
|
962
|
-
selectedToken.contractInfo?.decimals ?? 18,
|
|
963
|
-
).toString() // needs to be an amount that is greater than the minimum amount for the swap
|
|
964
|
-
: selectedToken.balance,
|
|
1048
|
+
? parseUnits("100", selectedToken.decimals ?? 18).toString() // needs to be an amount that is greater than the minimum amount for the swap
|
|
1049
|
+
: selectedToken.balance || "0",
|
|
965
1050
|
destinationChainId: selectedDestinationChain.id,
|
|
966
1051
|
recipient,
|
|
967
1052
|
destinationTokenAddress,
|
|
@@ -982,7 +1067,8 @@ export function useSendForm({
|
|
|
982
1067
|
destinationTokenDecimals,
|
|
983
1068
|
paymasterUrl:
|
|
984
1069
|
paymasterUrls?.find(
|
|
985
|
-
(p) =>
|
|
1070
|
+
(p) =>
|
|
1071
|
+
p.chainId.toString() === (selectedToken.chainId || 0).toString(),
|
|
986
1072
|
)?.url ?? undefined,
|
|
987
1073
|
originNativeTokenPriceUsd: nativeTokenPriceUsd,
|
|
988
1074
|
quoteProvider: effectiveQuoteProvider,
|
|
@@ -996,6 +1082,8 @@ export function useSendForm({
|
|
|
996
1082
|
originPublicClient: originChainPublicClient ?? undefined,
|
|
997
1083
|
destinationPublicClient: destinationChainPublicClient ?? undefined,
|
|
998
1084
|
isSmartWallet,
|
|
1085
|
+
trailsApiKey,
|
|
1086
|
+
trailsApiUrl: trailsConfig.trailsApiUrl,
|
|
999
1087
|
}
|
|
1000
1088
|
|
|
1001
1089
|
logger.console.log(
|
|
@@ -1061,15 +1149,13 @@ export function useSendForm({
|
|
|
1061
1149
|
recipient,
|
|
1062
1150
|
destinationTokenAddress,
|
|
1063
1151
|
destinationTokenAddressFromTokenSymbol,
|
|
1064
|
-
isCustomToken,
|
|
1065
|
-
toToken,
|
|
1066
1152
|
sequenceIndexerUrl,
|
|
1067
1153
|
selectedDestToken?.symbol,
|
|
1068
1154
|
selectedDestinationChain?.id,
|
|
1069
1155
|
selectedToken?.contractAddress,
|
|
1070
1156
|
selectedToken?.chainId,
|
|
1071
1157
|
selectedToken?.balance,
|
|
1072
|
-
selectedToken?.
|
|
1158
|
+
selectedToken?.priceUsd,
|
|
1073
1159
|
toCalldata,
|
|
1074
1160
|
refundAddress,
|
|
1075
1161
|
paymasterUrls,
|
|
@@ -1091,6 +1177,7 @@ export function useSendForm({
|
|
|
1091
1177
|
originChainPublicClient,
|
|
1092
1178
|
destinationChainPublicClient,
|
|
1093
1179
|
isSmartWallet,
|
|
1180
|
+
trailsConfig.trailsApiUrl,
|
|
1094
1181
|
])
|
|
1095
1182
|
|
|
1096
1183
|
// Auto-fetch quotes when inputs change (debounced)
|
|
@@ -1107,6 +1194,36 @@ export function useSendForm({
|
|
|
1107
1194
|
const isSenderSameAsRecipient =
|
|
1108
1195
|
account?.address?.toLowerCase() === recipient?.toLowerCase()
|
|
1109
1196
|
|
|
1197
|
+
const conditions = {
|
|
1198
|
+
hasAmount: !!amount,
|
|
1199
|
+
amountNotZero: amount !== "0",
|
|
1200
|
+
hasDestinationTokenAddress: !!destinationTokenAddress,
|
|
1201
|
+
isValidRecipient,
|
|
1202
|
+
hasSelectedDestTokenSymbol: !!selectedDestToken?.symbol,
|
|
1203
|
+
hasSelectedDestinationChain: !!selectedDestinationChain?.id,
|
|
1204
|
+
hasSelectedToken: !!selectedToken,
|
|
1205
|
+
isSameToken,
|
|
1206
|
+
isSenderSameAsRecipient,
|
|
1207
|
+
mode,
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
logger.console.log(
|
|
1211
|
+
"[trails-sdk] [CUSTOM-TOKEN] Quote trigger conditions check:",
|
|
1212
|
+
{
|
|
1213
|
+
...conditions,
|
|
1214
|
+
selectedDestToken: selectedDestToken
|
|
1215
|
+
? {
|
|
1216
|
+
symbol: selectedDestToken.symbol,
|
|
1217
|
+
decimals: selectedDestToken.decimals,
|
|
1218
|
+
contractAddress: selectedDestToken.contractAddress,
|
|
1219
|
+
}
|
|
1220
|
+
: null,
|
|
1221
|
+
destinationTokenAddress,
|
|
1222
|
+
amount,
|
|
1223
|
+
recipient,
|
|
1224
|
+
},
|
|
1225
|
+
)
|
|
1226
|
+
|
|
1110
1227
|
if (
|
|
1111
1228
|
!amount ||
|
|
1112
1229
|
amount === "0" ||
|
|
@@ -1119,6 +1236,24 @@ export function useSendForm({
|
|
|
1119
1236
|
isSenderSameAsRecipient &&
|
|
1120
1237
|
(mode === "swap" || mode === "fund"))
|
|
1121
1238
|
) {
|
|
1239
|
+
logger.console.log(
|
|
1240
|
+
"[trails-sdk] [CUSTOM-TOKEN] Quote blocked - missing conditions:",
|
|
1241
|
+
{
|
|
1242
|
+
blockedReasons: {
|
|
1243
|
+
noAmount: !amount || amount === "0",
|
|
1244
|
+
noDestinationTokenAddress: !destinationTokenAddress,
|
|
1245
|
+
invalidRecipient: !isValidRecipient,
|
|
1246
|
+
noSelectedDestTokenSymbol: !selectedDestToken?.symbol,
|
|
1247
|
+
noSelectedDestinationChain: !selectedDestinationChain?.id,
|
|
1248
|
+
noSelectedToken: !selectedToken,
|
|
1249
|
+
sameTokenAndRecipient:
|
|
1250
|
+
isSameToken &&
|
|
1251
|
+
isSenderSameAsRecipient &&
|
|
1252
|
+
(mode === "swap" || mode === "fund"),
|
|
1253
|
+
},
|
|
1254
|
+
conditions,
|
|
1255
|
+
},
|
|
1256
|
+
)
|
|
1122
1257
|
setPrepareSendResult(null)
|
|
1123
1258
|
latestResolvedIntentIdRef.current = null
|
|
1124
1259
|
quoteInputsFingerprintRef.current = null
|
|
@@ -1129,9 +1264,19 @@ export function useSendForm({
|
|
|
1129
1264
|
|
|
1130
1265
|
const nextQuoteInputsFingerprint = buildQuoteInputsFingerprint()
|
|
1131
1266
|
|
|
1267
|
+
logger.console.log("[trails-sdk] [CUSTOM-TOKEN] Quote fingerprint check:", {
|
|
1268
|
+
currentFingerprint: quoteInputsFingerprintRef.current,
|
|
1269
|
+
nextFingerprint: nextQuoteInputsFingerprint,
|
|
1270
|
+
willTrigger:
|
|
1271
|
+
quoteInputsFingerprintRef.current !== nextQuoteInputsFingerprint,
|
|
1272
|
+
})
|
|
1273
|
+
|
|
1132
1274
|
// Fingerprint all quote-driving inputs so we can invalidate debounced quotes immediately when
|
|
1133
1275
|
// the user switches tokens; this fixes the stale quote so that it stays loading until the new quote is ready.
|
|
1134
1276
|
if (quoteInputsFingerprintRef.current !== nextQuoteInputsFingerprint) {
|
|
1277
|
+
logger.console.log(
|
|
1278
|
+
"[trails-sdk] [CUSTOM-TOKEN] Quote fingerprint changed, triggering quote fetch",
|
|
1279
|
+
)
|
|
1135
1280
|
quoteInputsFingerprintRef.current = nextQuoteInputsFingerprint
|
|
1136
1281
|
latestResolvedIntentIdRef.current = null
|
|
1137
1282
|
setPrepareSendResult(null)
|
|
@@ -1140,6 +1285,9 @@ export function useSendForm({
|
|
|
1140
1285
|
}
|
|
1141
1286
|
|
|
1142
1287
|
const timeoutId = setTimeout(() => {
|
|
1288
|
+
logger.console.log(
|
|
1289
|
+
"[trails-sdk] [CUSTOM-TOKEN] Debounce timeout completed, calling getQuote",
|
|
1290
|
+
)
|
|
1143
1291
|
getQuote()
|
|
1144
1292
|
}, 500) // Debounce by 500ms
|
|
1145
1293
|
|
|
@@ -1157,7 +1305,7 @@ export function useSendForm({
|
|
|
1157
1305
|
selectedToken?.contractAddress,
|
|
1158
1306
|
selectedToken?.chainId,
|
|
1159
1307
|
selectedToken?.balance,
|
|
1160
|
-
selectedToken?.
|
|
1308
|
+
selectedToken?.priceUsd,
|
|
1161
1309
|
recipient, // Add recipient to trigger quote re-fetch when it changes
|
|
1162
1310
|
// selectedFeeOption is passed to send() at execution time, not needed here
|
|
1163
1311
|
buildQuoteInputsFingerprint,
|
|
@@ -1190,14 +1338,25 @@ export function useSendForm({
|
|
|
1190
1338
|
},
|
|
1191
1339
|
)
|
|
1192
1340
|
|
|
1193
|
-
setFeeOptions
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1341
|
+
// Convert Token[] to TokenWithBalance[] for setFeeOptions
|
|
1342
|
+
const tokensWithBalance = filteredTokensFormattedRef.current.map(
|
|
1343
|
+
(token) => ({
|
|
1344
|
+
chainId: token.chainId || 0,
|
|
1345
|
+
contractAddress: token.contractAddress,
|
|
1346
|
+
balance: token.balance,
|
|
1347
|
+
imageUrl: token.imageUrl,
|
|
1348
|
+
}),
|
|
1197
1349
|
)
|
|
1350
|
+
|
|
1351
|
+
setFeeOptions(apiFeeOptions, selectedToken?.chainId, tokensWithBalance)
|
|
1198
1352
|
}, [prepareSendResult, selectedToken?.chainId, setFeeOptions])
|
|
1199
1353
|
|
|
1200
1354
|
const processSend = useCallback(async () => {
|
|
1355
|
+
logger.console.log("[trails-sdk] processSend called", {
|
|
1356
|
+
fundMethod,
|
|
1357
|
+
hasOnNavigateToOnramp: !!onNavigateToOnramp,
|
|
1358
|
+
hasPrepareSendResult: !!prepareSendResult,
|
|
1359
|
+
})
|
|
1201
1360
|
try {
|
|
1202
1361
|
if (!prepareSendResult) {
|
|
1203
1362
|
setError("No quote available. Please wait for quote to load.")
|
|
@@ -1249,59 +1408,6 @@ export function useSendForm({
|
|
|
1249
1408
|
quote,
|
|
1250
1409
|
)
|
|
1251
1410
|
|
|
1252
|
-
// Handle exchange fund method - navigate to mesh-connect
|
|
1253
|
-
if (fundMethod === "exchange" && onNavigateToMeshConnect) {
|
|
1254
|
-
const originChainId = quote?.originChain?.id
|
|
1255
|
-
const destinationChainId = quote?.destinationChain?.id
|
|
1256
|
-
|
|
1257
|
-
const toTokenSymbol = quote?.originToken?.symbol // MeshConnect will deposit origin token
|
|
1258
|
-
const toTokenAmount = normalizeNumber(
|
|
1259
|
-
quote.originAmountFormatted,
|
|
1260
|
-
).toString() // MeshConnect will deposit origin token amount
|
|
1261
|
-
const toChainId = quote?.originChain?.id // MeshConnect will deposit to origin chain
|
|
1262
|
-
const toRecipientAddress = quote.originDepositAddress // MeshConnect will deposit to origin address
|
|
1263
|
-
|
|
1264
|
-
logger.console.log(
|
|
1265
|
-
"[trails-sdk] Navigating to mesh-connect with props:",
|
|
1266
|
-
{
|
|
1267
|
-
toTokenSymbol,
|
|
1268
|
-
toTokenAmount,
|
|
1269
|
-
toChainId,
|
|
1270
|
-
toRecipientAddress,
|
|
1271
|
-
},
|
|
1272
|
-
)
|
|
1273
|
-
|
|
1274
|
-
if (originChainId === destinationChainId) {
|
|
1275
|
-
throw new Error(
|
|
1276
|
-
"[trails-sdk] Must be different chain than the origin chain to use mesh-connect",
|
|
1277
|
-
)
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
if (
|
|
1281
|
-
!toTokenSymbol ||
|
|
1282
|
-
!toTokenAmount ||
|
|
1283
|
-
!toChainId ||
|
|
1284
|
-
!toRecipientAddress
|
|
1285
|
-
) {
|
|
1286
|
-
throw new Error(
|
|
1287
|
-
"[trails-sdk] Missing required props for mesh-connect",
|
|
1288
|
-
)
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
onNavigateToMeshConnect(
|
|
1292
|
-
{
|
|
1293
|
-
toTokenSymbol,
|
|
1294
|
-
toTokenAmount,
|
|
1295
|
-
toChainId,
|
|
1296
|
-
toRecipientAddress,
|
|
1297
|
-
},
|
|
1298
|
-
prepareSendResult.quote,
|
|
1299
|
-
)
|
|
1300
|
-
|
|
1301
|
-
await handleSend()
|
|
1302
|
-
return
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
1411
|
function onOriginSend() {
|
|
1306
1412
|
logger.console.log("[trails-sdk] onOriginSend called")
|
|
1307
1413
|
onConfirm()
|
|
@@ -1347,6 +1453,78 @@ export function useSendForm({
|
|
|
1347
1453
|
})
|
|
1348
1454
|
}
|
|
1349
1455
|
|
|
1456
|
+
// Handle exchange fund method - navigate to onramp
|
|
1457
|
+
if (fundMethod === "exchange" && onNavigateToOnramp) {
|
|
1458
|
+
logger.console.log(
|
|
1459
|
+
"[trails-sdk] Exchange fund method detected, navigating to onramp",
|
|
1460
|
+
{
|
|
1461
|
+
fundMethod,
|
|
1462
|
+
hasOnNavigateToOnramp: !!onNavigateToOnramp,
|
|
1463
|
+
quote: !!quote,
|
|
1464
|
+
},
|
|
1465
|
+
)
|
|
1466
|
+
|
|
1467
|
+
const originChainId = quote?.originChain?.id
|
|
1468
|
+
const destinationChainId = quote?.destinationChain?.id
|
|
1469
|
+
|
|
1470
|
+
const toTokenSymbol = quote?.originToken?.symbol // Onramp will deposit origin token
|
|
1471
|
+
const toTokenAmount = normalizeNumber(
|
|
1472
|
+
quote.originAmountFormatted,
|
|
1473
|
+
).toString() // Onramp will deposit origin token amount
|
|
1474
|
+
const toChainId = quote?.originChain?.id // Onramp will deposit to origin chain
|
|
1475
|
+
const toRecipientAddress = quote.originDepositAddress // Onramp will deposit to origin address
|
|
1476
|
+
|
|
1477
|
+
logger.console.log("[trails-sdk] Navigating to onramp with props:", {
|
|
1478
|
+
toTokenSymbol,
|
|
1479
|
+
toTokenAmount,
|
|
1480
|
+
toChainId,
|
|
1481
|
+
toRecipientAddress,
|
|
1482
|
+
originChainId,
|
|
1483
|
+
destinationChainId,
|
|
1484
|
+
})
|
|
1485
|
+
|
|
1486
|
+
// Onramp can be used for both same-chain and cross-chain transfers
|
|
1487
|
+
// It deposits funds to the origin deposit address, which works for both scenarios
|
|
1488
|
+
// No need to restrict to cross-chain only
|
|
1489
|
+
|
|
1490
|
+
if (
|
|
1491
|
+
!toTokenSymbol ||
|
|
1492
|
+
!toTokenAmount ||
|
|
1493
|
+
!toChainId ||
|
|
1494
|
+
!toRecipientAddress
|
|
1495
|
+
) {
|
|
1496
|
+
throw new Error("[trails-sdk] Missing required props for onramp")
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
// Store handleSend to be called after onramp completes
|
|
1500
|
+
onNavigateToOnramp(
|
|
1501
|
+
{
|
|
1502
|
+
toTokenSymbol,
|
|
1503
|
+
toTokenAmount,
|
|
1504
|
+
toChainId,
|
|
1505
|
+
toRecipientAddress,
|
|
1506
|
+
},
|
|
1507
|
+
prepareSendResult.quote,
|
|
1508
|
+
handleSend, // Pass handleSend callback to be called after onramp completes
|
|
1509
|
+
)
|
|
1510
|
+
|
|
1511
|
+
// Don't call handleSend here - it will be called after onramp completes
|
|
1512
|
+
setIsSubmitting(false)
|
|
1513
|
+
setIsWaitingForWalletConfirm(false)
|
|
1514
|
+
return
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
// Log if exchange method was expected but not handled
|
|
1518
|
+
if (fundMethod === "exchange") {
|
|
1519
|
+
logger.console.error(
|
|
1520
|
+
"[trails-sdk] Exchange fund method detected but onNavigateToOnramp is not available",
|
|
1521
|
+
{
|
|
1522
|
+
fundMethod,
|
|
1523
|
+
hasOnNavigateToOnramp: !!onNavigateToOnramp,
|
|
1524
|
+
},
|
|
1525
|
+
)
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1350
1528
|
async function walletConfirmRetryHandler() {
|
|
1351
1529
|
logger.console.log("[trails-sdk] walletConfirmRetryHandler called")
|
|
1352
1530
|
try {
|
|
@@ -1393,7 +1571,7 @@ export function useSendForm({
|
|
|
1393
1571
|
recipient,
|
|
1394
1572
|
onError,
|
|
1395
1573
|
fundMethod,
|
|
1396
|
-
|
|
1574
|
+
onNavigateToOnramp,
|
|
1397
1575
|
selectedFeeOption, // Include so handleSend captures latest value
|
|
1398
1576
|
buildQuoteInputsFingerprint,
|
|
1399
1577
|
])
|
|
@@ -1465,8 +1643,6 @@ export function useSendForm({
|
|
|
1465
1643
|
return `Swap`
|
|
1466
1644
|
} else if (mode === "earn") {
|
|
1467
1645
|
return `Deposit`
|
|
1468
|
-
} else if (mode === "receive") {
|
|
1469
|
-
return `Pay`
|
|
1470
1646
|
} else {
|
|
1471
1647
|
return `Continue on wallet`
|
|
1472
1648
|
}
|