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
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { AnimatePresence, motion } from "motion/react"
|
|
2
|
+
import { useCallback, useState, useEffect } from "react"
|
|
3
|
+
import { zeroAddress } from "viem"
|
|
4
|
+
import { useAccount } from "wagmi"
|
|
5
|
+
import { logger } from "../../logger.js"
|
|
6
|
+
import type { Token } from "../../tokens.js"
|
|
7
|
+
import {
|
|
8
|
+
useTrailsModal,
|
|
9
|
+
type HostTransactionStatus,
|
|
10
|
+
} from "../providers/TrailsModalProvider.js"
|
|
11
|
+
import Modal from "./Modal.js"
|
|
12
|
+
import TokenList from "./TokenList.js"
|
|
13
|
+
import OriginSelectionAmount from "./OriginSelectionAmount.js"
|
|
14
|
+
import WalletConfirmation from "./WalletConfirmation.js"
|
|
15
|
+
import TransferPending from "./TransferPendingVertical.js"
|
|
16
|
+
import Receipt from "./Receipt.js"
|
|
17
|
+
import { useOriginSelectedToken } from "../hooks/useOriginSelectedToken.js"
|
|
18
|
+
import { useRecentTokens } from "../hooks/useRecentTokens.js"
|
|
19
|
+
import { useWidgetProps } from "../hooks/useWidgetProps.js"
|
|
20
|
+
|
|
21
|
+
type HookModalScreen =
|
|
22
|
+
| "select-origin-token"
|
|
23
|
+
| "select-origin-amount"
|
|
24
|
+
| "wallet-confirmation"
|
|
25
|
+
| "pending"
|
|
26
|
+
| "receipt"
|
|
27
|
+
|
|
28
|
+
function getScreenFromStatus(status: HostTransactionStatus): HookModalScreen {
|
|
29
|
+
switch (status) {
|
|
30
|
+
case "awaiting-origin":
|
|
31
|
+
return "select-origin-token"
|
|
32
|
+
case "awaiting-amount":
|
|
33
|
+
return "select-origin-amount"
|
|
34
|
+
case "confirmation":
|
|
35
|
+
return "wallet-confirmation"
|
|
36
|
+
case "pending":
|
|
37
|
+
return "pending"
|
|
38
|
+
case "success":
|
|
39
|
+
case "error":
|
|
40
|
+
return "receipt"
|
|
41
|
+
default:
|
|
42
|
+
return "select-origin-token"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* HookModalContent is the core modal UI component used by useTrailsSendTransaction.
|
|
48
|
+
* It renders inside WidgetProviders, so it has access to all widget-level context providers.
|
|
49
|
+
* This component handles the modal screens: token selection, amount input, wallet confirmation,
|
|
50
|
+
* pending state, and receipt.
|
|
51
|
+
*/
|
|
52
|
+
export function HookModalContent() {
|
|
53
|
+
const { address } = useAccount()
|
|
54
|
+
const { renderInline } = useWidgetProps()
|
|
55
|
+
const {
|
|
56
|
+
isModalOpen,
|
|
57
|
+
closeModal,
|
|
58
|
+
pendingSelection,
|
|
59
|
+
setPendingSelection,
|
|
60
|
+
hostTransactionState,
|
|
61
|
+
setHostTransactionState,
|
|
62
|
+
hostTransactionQuote,
|
|
63
|
+
hostTransactionStates,
|
|
64
|
+
hostTransactionTimestamp,
|
|
65
|
+
resetHostTransactionState,
|
|
66
|
+
receiptActionButtonText,
|
|
67
|
+
onReceiptAction,
|
|
68
|
+
retryTransactionRef,
|
|
69
|
+
} = useTrailsModal()
|
|
70
|
+
|
|
71
|
+
// Debug logging
|
|
72
|
+
logger.console.log("[trails-sdk] [HookModalContent] Render state:", {
|
|
73
|
+
isModalOpen,
|
|
74
|
+
hostTransactionStatus: hostTransactionState.status,
|
|
75
|
+
hasPendingSelection: !!pendingSelection,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const { selectedToken, setSelectedToken } = useOriginSelectedToken()
|
|
79
|
+
const { recentTokens, addRecentToken } = useRecentTokens(address)
|
|
80
|
+
const [totalCompletionSeconds, setTotalCompletionSeconds] = useState<
|
|
81
|
+
number | null
|
|
82
|
+
>(null)
|
|
83
|
+
|
|
84
|
+
// Derive screen from hostTransactionState
|
|
85
|
+
const currentScreen = getScreenFromStatus(hostTransactionState.status)
|
|
86
|
+
|
|
87
|
+
// Calculate elapsed time on success
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (hostTransactionState.status === "success" && hostTransactionTimestamp) {
|
|
90
|
+
setTotalCompletionSeconds(
|
|
91
|
+
Math.max(0, Math.floor((Date.now() - hostTransactionTimestamp) / 1000)),
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
}, [hostTransactionState.status, hostTransactionTimestamp])
|
|
95
|
+
|
|
96
|
+
const handleCloseModal = useCallback(() => {
|
|
97
|
+
if (pendingSelection) {
|
|
98
|
+
logger.console.log(
|
|
99
|
+
"[trails-sdk] [HookModalContent] Closing modal, rejecting pending selection",
|
|
100
|
+
)
|
|
101
|
+
pendingSelection.reject(new Error("Modal closed by user"))
|
|
102
|
+
setPendingSelection(undefined)
|
|
103
|
+
}
|
|
104
|
+
closeModal()
|
|
105
|
+
resetHostTransactionState()
|
|
106
|
+
setSelectedToken(null)
|
|
107
|
+
}, [
|
|
108
|
+
closeModal,
|
|
109
|
+
resetHostTransactionState,
|
|
110
|
+
pendingSelection,
|
|
111
|
+
setPendingSelection,
|
|
112
|
+
setSelectedToken,
|
|
113
|
+
])
|
|
114
|
+
|
|
115
|
+
const handleTokenSelect = (token: Token) => {
|
|
116
|
+
setSelectedToken(token)
|
|
117
|
+
|
|
118
|
+
// Track the token in recent tokens
|
|
119
|
+
addRecentToken(token)
|
|
120
|
+
|
|
121
|
+
// Check if there's a pending selection request from useTrailsSendTransaction
|
|
122
|
+
if (pendingSelection) {
|
|
123
|
+
if (pendingSelection.requireAmountInput) {
|
|
124
|
+
setHostTransactionState((prev) => ({
|
|
125
|
+
...prev,
|
|
126
|
+
status: "awaiting-amount",
|
|
127
|
+
}))
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
const originAddress = token.contractAddress || zeroAddress
|
|
131
|
+
try {
|
|
132
|
+
pendingSelection.resolve({
|
|
133
|
+
fromTokenAddress: originAddress,
|
|
134
|
+
fromChainId: token.chainId ?? 0,
|
|
135
|
+
})
|
|
136
|
+
} catch (error) {
|
|
137
|
+
logger.console.error(
|
|
138
|
+
"[trails-sdk] [HookModalContent] Error resolving pending selection:",
|
|
139
|
+
error,
|
|
140
|
+
)
|
|
141
|
+
pendingSelection.reject(error as Error)
|
|
142
|
+
} finally {
|
|
143
|
+
setPendingSelection(undefined)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const handleRecentTokenSelect = (token: Token) => {
|
|
149
|
+
handleTokenSelect(token)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const handleOriginAmountSubmit = (amount: string) => {
|
|
153
|
+
if (pendingSelection && selectedToken) {
|
|
154
|
+
try {
|
|
155
|
+
pendingSelection.resolve({
|
|
156
|
+
fromTokenAddress: selectedToken.contractAddress || zeroAddress,
|
|
157
|
+
fromChainId: selectedToken.chainId ?? 0,
|
|
158
|
+
fromAmount: amount,
|
|
159
|
+
})
|
|
160
|
+
setPendingSelection(undefined)
|
|
161
|
+
} catch (error) {
|
|
162
|
+
logger.console.error(
|
|
163
|
+
"[trails-sdk] [HookModalContent] Error resolving pending selection amount:",
|
|
164
|
+
error,
|
|
165
|
+
)
|
|
166
|
+
pendingSelection.reject(error as Error)
|
|
167
|
+
setPendingSelection(undefined)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const handleHookRetry = () => {
|
|
173
|
+
if (retryTransactionRef.current) {
|
|
174
|
+
setHostTransactionState((prev) => ({
|
|
175
|
+
...prev,
|
|
176
|
+
retryEnabled: false,
|
|
177
|
+
}))
|
|
178
|
+
retryTransactionRef.current()
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const renderScreenContent = () => {
|
|
183
|
+
switch (currentScreen) {
|
|
184
|
+
case "select-origin-token":
|
|
185
|
+
return (
|
|
186
|
+
<TokenList
|
|
187
|
+
onContinue={handleTokenSelect}
|
|
188
|
+
onBack={handleCloseModal}
|
|
189
|
+
targetAmountUsd={null}
|
|
190
|
+
targetAmountUsdFormatted={null}
|
|
191
|
+
onError={(error) => {
|
|
192
|
+
logger.console.error(
|
|
193
|
+
"[trails-sdk] [HookModalContent] Token list error:",
|
|
194
|
+
error,
|
|
195
|
+
)
|
|
196
|
+
}}
|
|
197
|
+
recentTokens={recentTokens}
|
|
198
|
+
onRecentTokenSelect={handleRecentTokenSelect}
|
|
199
|
+
fundMethod={null}
|
|
200
|
+
renderInline={renderInline}
|
|
201
|
+
/>
|
|
202
|
+
)
|
|
203
|
+
case "select-origin-amount":
|
|
204
|
+
return (
|
|
205
|
+
<OriginSelectionAmount
|
|
206
|
+
token={selectedToken}
|
|
207
|
+
onBack={() =>
|
|
208
|
+
setHostTransactionState((prev) => ({
|
|
209
|
+
...prev,
|
|
210
|
+
status: "awaiting-origin",
|
|
211
|
+
}))
|
|
212
|
+
}
|
|
213
|
+
onCancel={handleCloseModal}
|
|
214
|
+
onSubmit={handleOriginAmountSubmit}
|
|
215
|
+
/>
|
|
216
|
+
)
|
|
217
|
+
case "wallet-confirmation":
|
|
218
|
+
return (
|
|
219
|
+
<WalletConfirmation
|
|
220
|
+
onBack={() =>
|
|
221
|
+
setHostTransactionState((prev) => ({
|
|
222
|
+
...prev,
|
|
223
|
+
status: "awaiting-origin",
|
|
224
|
+
}))
|
|
225
|
+
}
|
|
226
|
+
onComplete={() => {
|
|
227
|
+
// Will transition to pending via hostTransactionState update
|
|
228
|
+
}}
|
|
229
|
+
retryEnabled={hostTransactionState.retryEnabled ?? false}
|
|
230
|
+
onRetry={handleHookRetry}
|
|
231
|
+
quote={hostTransactionQuote}
|
|
232
|
+
/>
|
|
233
|
+
)
|
|
234
|
+
case "pending":
|
|
235
|
+
return (
|
|
236
|
+
<TransferPending
|
|
237
|
+
onElapsedTime={(seconds) => setTotalCompletionSeconds(seconds ?? 0)}
|
|
238
|
+
transactionStates={hostTransactionStates}
|
|
239
|
+
quote={hostTransactionQuote}
|
|
240
|
+
timestamp={hostTransactionTimestamp ?? undefined}
|
|
241
|
+
onContinue={() => {
|
|
242
|
+
// Receipt screen will be shown via hostTransactionState
|
|
243
|
+
}}
|
|
244
|
+
/>
|
|
245
|
+
)
|
|
246
|
+
case "receipt":
|
|
247
|
+
return (
|
|
248
|
+
<Receipt
|
|
249
|
+
onSendAnother={onReceiptAction ?? undefined}
|
|
250
|
+
onClose={handleCloseModal}
|
|
251
|
+
renderInline={renderInline}
|
|
252
|
+
transactionStates={hostTransactionStates}
|
|
253
|
+
totalCompletionSeconds={totalCompletionSeconds ?? undefined}
|
|
254
|
+
quote={hostTransactionQuote}
|
|
255
|
+
showCloseButton={false}
|
|
256
|
+
actionButtonText={receiptActionButtonText ?? undefined}
|
|
257
|
+
/>
|
|
258
|
+
)
|
|
259
|
+
default:
|
|
260
|
+
return null
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (!isModalOpen || hostTransactionState.status === "idle") {
|
|
265
|
+
return null
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return (
|
|
269
|
+
<Modal isOpen={isModalOpen} onClose={handleCloseModal}>
|
|
270
|
+
<motion.div
|
|
271
|
+
initial={{ opacity: 0, scale: 0.95 }}
|
|
272
|
+
animate={{ opacity: 1, scale: 1 }}
|
|
273
|
+
exit={{ opacity: 0, scale: 0.95 }}
|
|
274
|
+
transition={{
|
|
275
|
+
type: "spring",
|
|
276
|
+
stiffness: 200,
|
|
277
|
+
damping: 30,
|
|
278
|
+
mass: 1,
|
|
279
|
+
}}
|
|
280
|
+
className="flex flex-col min-h-[400px] shadow-xl p-4 sm:p-6 relative w-full max-w-[400px] min-w-0 sm:w-[400px] mx-auto custom-scrollbar trails-bg-primary trails-text-primary trails-font trails-border-radius-widget trails-widget-border"
|
|
281
|
+
layout
|
|
282
|
+
layoutId="modal-container"
|
|
283
|
+
onClick={(e) => e.stopPropagation()}
|
|
284
|
+
>
|
|
285
|
+
<AnimatePresence mode="wait">
|
|
286
|
+
<motion.div
|
|
287
|
+
key={currentScreen}
|
|
288
|
+
initial={{ opacity: 0, x: 20 }}
|
|
289
|
+
animate={{ opacity: 1, x: 0 }}
|
|
290
|
+
exit={{ opacity: 0, x: -20 }}
|
|
291
|
+
transition={{
|
|
292
|
+
type: "spring",
|
|
293
|
+
stiffness: 500,
|
|
294
|
+
damping: 30,
|
|
295
|
+
mass: 0.6,
|
|
296
|
+
}}
|
|
297
|
+
className="flex-1 flex flex-col w-full min-w-0"
|
|
298
|
+
layout
|
|
299
|
+
>
|
|
300
|
+
{renderScreenContent()}
|
|
301
|
+
</motion.div>
|
|
302
|
+
</AnimatePresence>
|
|
303
|
+
</motion.div>
|
|
304
|
+
</Modal>
|
|
305
|
+
)
|
|
306
|
+
}
|
|
@@ -51,7 +51,7 @@ const Modal: React.FC<ModalProps> = ({ isOpen, onClose, children }) => {
|
|
|
51
51
|
role="dialog"
|
|
52
52
|
aria-modal="true"
|
|
53
53
|
aria-labelledby="modal-title"
|
|
54
|
-
className="fixed inset-0 flex items-center justify-center z-50 p-4 h-full w-full text-gray-900 dark:text-white"
|
|
54
|
+
className="fixed inset-0 flex items-center justify-center z-50 p-0 sm:p-4 h-full w-full text-gray-900 dark:text-white"
|
|
55
55
|
onClick={handleClickOutside}
|
|
56
56
|
>
|
|
57
57
|
<motion.div
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { useMemo, useState } from "react"
|
|
2
|
+
import type React from "react"
|
|
3
|
+
import type { Token } from "../../tokens.js"
|
|
4
|
+
import { ScreenHeader } from "./ScreenHeader.js"
|
|
5
|
+
import { TokenImage } from "./TokenImage.js"
|
|
6
|
+
import { DynamicSizeInputField } from "./DynamicSizeInputField.js"
|
|
7
|
+
import { getChainInfo } from "../../chains.js"
|
|
8
|
+
import { formatRawAmount } from "../../tokenBalances.js"
|
|
9
|
+
|
|
10
|
+
interface OriginSelectionAmountProps {
|
|
11
|
+
token: Token | null
|
|
12
|
+
onBack: () => void
|
|
13
|
+
onCancel: () => void
|
|
14
|
+
onSubmit: (amount: string) => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const OriginSelectionAmount: React.FC<OriginSelectionAmountProps> = ({
|
|
18
|
+
token,
|
|
19
|
+
onBack,
|
|
20
|
+
onCancel,
|
|
21
|
+
onSubmit,
|
|
22
|
+
}) => {
|
|
23
|
+
const [amount, setAmount] = useState("")
|
|
24
|
+
|
|
25
|
+
const chainInfo = useMemo(
|
|
26
|
+
() => (token ? getChainInfo(token.chainId || 0) : undefined),
|
|
27
|
+
[token],
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const formattedBalance = useMemo(() => {
|
|
31
|
+
if (!token?.balance || !token.decimals) {
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return formatRawAmount(token.balance, token.decimals)
|
|
36
|
+
} catch {
|
|
37
|
+
return undefined
|
|
38
|
+
}
|
|
39
|
+
}, [token])
|
|
40
|
+
|
|
41
|
+
const handleUseMax = () => {
|
|
42
|
+
if (formattedBalance) {
|
|
43
|
+
setAmount(formattedBalance)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const handleSubmit = () => {
|
|
48
|
+
if (!amount || Number(amount) <= 0) return
|
|
49
|
+
onSubmit(amount.trim())
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div className="flex flex-col space-y-4">
|
|
54
|
+
<ScreenHeader
|
|
55
|
+
headerContent="Enter amount"
|
|
56
|
+
onBack={onBack}
|
|
57
|
+
rightSideContent={
|
|
58
|
+
<button
|
|
59
|
+
type="button"
|
|
60
|
+
onClick={onCancel}
|
|
61
|
+
className="text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
|
|
62
|
+
>
|
|
63
|
+
Cancel
|
|
64
|
+
</button>
|
|
65
|
+
}
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
<div className="flex items-center justify-between rounded-2xl border border-gray-200 dark:border-gray-700 p-4 bg-white dark:bg-gray-900/40">
|
|
69
|
+
{token ? (
|
|
70
|
+
<>
|
|
71
|
+
<div className="flex items-center gap-3">
|
|
72
|
+
<TokenImage
|
|
73
|
+
symbol={token.symbol}
|
|
74
|
+
imageUrl={token.imageUrl}
|
|
75
|
+
chainId={token.chainId}
|
|
76
|
+
contractAddress={token.contractAddress}
|
|
77
|
+
size={32}
|
|
78
|
+
/>
|
|
79
|
+
<div>
|
|
80
|
+
<div className="text-base font-semibold text-gray-900 dark:text-gray-100">
|
|
81
|
+
{token.symbol}
|
|
82
|
+
</div>
|
|
83
|
+
<div className="text-xs text-gray-500 dark:text-gray-400">
|
|
84
|
+
{chainInfo?.name ?? `Chain ${token.chainId}`}
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
{formattedBalance ? (
|
|
89
|
+
<button
|
|
90
|
+
type="button"
|
|
91
|
+
onClick={handleUseMax}
|
|
92
|
+
className="text-sm font-semibold text-blue-600 hover:text-blue-500"
|
|
93
|
+
>
|
|
94
|
+
Use max ({formattedBalance})
|
|
95
|
+
</button>
|
|
96
|
+
) : null}
|
|
97
|
+
</>
|
|
98
|
+
) : (
|
|
99
|
+
<div className="text-sm text-gray-500">Select a token first</div>
|
|
100
|
+
)}
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<div className="space-y-2">
|
|
104
|
+
<label
|
|
105
|
+
htmlFor="origin-amount-input"
|
|
106
|
+
className="text-xs font-semibold uppercase text-gray-500 dark:text-gray-400"
|
|
107
|
+
>
|
|
108
|
+
Amount to use
|
|
109
|
+
</label>
|
|
110
|
+
<div className="rounded-2xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900/40 px-4 py-3">
|
|
111
|
+
<DynamicSizeInputField
|
|
112
|
+
id="origin-amount-input"
|
|
113
|
+
value={amount}
|
|
114
|
+
onChange={(event) => setAmount(event.target.value)}
|
|
115
|
+
placeholder="0.0"
|
|
116
|
+
/>
|
|
117
|
+
</div>
|
|
118
|
+
<p className="text-xs text-gray-500 dark:text-gray-400">
|
|
119
|
+
Enter the amount you want to spend from this token.
|
|
120
|
+
</p>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<button
|
|
124
|
+
type="button"
|
|
125
|
+
onClick={handleSubmit}
|
|
126
|
+
disabled={!amount || Number(amount) <= 0}
|
|
127
|
+
className="w-full py-3 font-semibold trails-border-radius-button bg-blue-500 text-white disabled:bg-gray-200 disabled:text-gray-500 dark:disabled:bg-gray-800 dark:disabled:text-gray-500 hover:bg-blue-600 disabled:cursor-not-allowed transition-colors"
|
|
128
|
+
>
|
|
129
|
+
Continue
|
|
130
|
+
</button>
|
|
131
|
+
</div>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export default OriginSelectionAmount
|