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
|
@@ -69,6 +69,7 @@ export function usePayMessage(): UsePayMessageReturn {
|
|
|
69
69
|
toChainId,
|
|
70
70
|
toAmount,
|
|
71
71
|
toToken,
|
|
72
|
+
toCalldata,
|
|
72
73
|
} = useWidgetProps()
|
|
73
74
|
|
|
74
75
|
const { targetAmountUsdFormatted } = useTargetAmount()
|
|
@@ -121,12 +122,24 @@ export function usePayMessage(): UsePayMessageReturn {
|
|
|
121
122
|
case "APP_DESCRIPTION":
|
|
122
123
|
parts.push({ type: "text", value: appDescription || "" })
|
|
123
124
|
break
|
|
124
|
-
case "TO_AMOUNT_USD":
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
case "TO_AMOUNT_USD": {
|
|
126
|
+
const usdValue = targetAmountUsdFormatted || "$0.00"
|
|
127
|
+
// If USD value is $0, use token amount + symbol instead
|
|
128
|
+
if (usdValue === "$0.00" || usdValue === "$0") {
|
|
129
|
+
const tokenAmount = toAmount || "0"
|
|
130
|
+
const tokenSymbol = tokenInfo?.symbol || ""
|
|
131
|
+
parts.push({
|
|
132
|
+
type: "amount",
|
|
133
|
+
value: `${tokenAmount} ${tokenSymbol}`.trim(),
|
|
134
|
+
})
|
|
135
|
+
} else {
|
|
136
|
+
parts.push({
|
|
137
|
+
type: "amount",
|
|
138
|
+
value: usdValue,
|
|
139
|
+
})
|
|
140
|
+
}
|
|
129
141
|
break
|
|
142
|
+
}
|
|
130
143
|
case "TO_ADDRESS":
|
|
131
144
|
parts.push({ type: "toAddress", value: toAddress || "" })
|
|
132
145
|
break
|
|
@@ -228,11 +241,17 @@ export function usePayMessage(): UsePayMessageReturn {
|
|
|
228
241
|
{/* Large amount in center */}
|
|
229
242
|
<div className="font-bold text-center">
|
|
230
243
|
{(() => {
|
|
231
|
-
const
|
|
244
|
+
const usdValue = targetAmountUsdFormatted || "$0.00"
|
|
245
|
+
const tokenAmount = toAmount || "0"
|
|
232
246
|
const tokenSymbol = tokenInfo?.symbol || ""
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
247
|
+
|
|
248
|
+
// If USD value is $0, show token amount + symbol instead
|
|
249
|
+
const displayText =
|
|
250
|
+
usdValue === "$0.00" || usdValue === "$0"
|
|
251
|
+
? `${tokenAmount} ${tokenSymbol}`.trim()
|
|
252
|
+
: targetAmountUsdFormatted
|
|
253
|
+
? usdValue
|
|
254
|
+
: `${tokenAmount} ${tokenSymbol}`.trim()
|
|
236
255
|
|
|
237
256
|
// Dynamic font size based on text length
|
|
238
257
|
const textLength = displayText.length
|
|
@@ -255,8 +274,8 @@ export function usePayMessage(): UsePayMessageReturn {
|
|
|
255
274
|
{/* Recipient info below */}
|
|
256
275
|
{toAddress && (
|
|
257
276
|
<div className="flex items-center space-x-2 text-center">
|
|
258
|
-
<span className="text-sm text-gray-
|
|
259
|
-
to
|
|
277
|
+
<span className="text-sm text-gray-900 dark:text-gray-100">
|
|
278
|
+
{toCalldata ? "to" : "Recipient"}
|
|
260
279
|
</span>
|
|
261
280
|
<Identicon value={toAddress} size={20} />
|
|
262
281
|
<a
|
|
@@ -434,6 +453,7 @@ export function usePayMessage(): UsePayMessageReturn {
|
|
|
434
453
|
tokenInfo,
|
|
435
454
|
toChainId,
|
|
436
455
|
toAddress,
|
|
456
|
+
toCalldata,
|
|
437
457
|
targetAmountUsdFormatted,
|
|
438
458
|
toAmount,
|
|
439
459
|
])
|
|
@@ -11,7 +11,7 @@ const PriceImpactWarningContext =
|
|
|
11
11
|
|
|
12
12
|
export const PriceImpactWarningProvider = PriceImpactWarningContext.Provider
|
|
13
13
|
|
|
14
|
-
export
|
|
14
|
+
export function usePriceImpactWarning(): PriceImpactWarningConfig {
|
|
15
15
|
const context = useContext(PriceImpactWarningContext)
|
|
16
16
|
return context || {}
|
|
17
17
|
}
|
|
@@ -14,29 +14,48 @@ import { prepareSend } from "../../prepareSend.js"
|
|
|
14
14
|
import { abortControllerRegistry } from "../../abortController.js"
|
|
15
15
|
import { TradeType } from "../../prepareSend.js"
|
|
16
16
|
import { getChainInfo, useChainRpcClient } from "../../chains.js"
|
|
17
|
-
import type { IntentTransaction } from "@
|
|
17
|
+
import type { IntentTransaction } from "@0xtrails/api"
|
|
18
18
|
import type { PrepareSendOptions } from "../../transactionIntent/types.js"
|
|
19
19
|
import type { Chain } from "../../chains.js"
|
|
20
|
-
import type {
|
|
20
|
+
import type { Token } from "../../tokens.js"
|
|
21
21
|
import type { TransactionState } from "../../transactions.js"
|
|
22
22
|
import type { PrepareSendFees } from "../../prepareSend.js"
|
|
23
23
|
import { getTokenPrice } from "../../prices.js"
|
|
24
24
|
import { useCommitIntent, useExecuteIntent } from "../../mutations.js"
|
|
25
25
|
import type { CheckoutOnHandlers } from "./useCheckout.js"
|
|
26
|
-
import type { FeeOption } from "@
|
|
27
|
-
|
|
26
|
+
import type { FeeOption } from "@0xtrails/api"
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Configuration options for the `useQuote` hook.
|
|
30
|
+
*
|
|
31
|
+
* All parameters are optional, but the hook will not fetch a quote until all required
|
|
32
|
+
* parameters are provided (walletClient, fromTokenAddress, fromChainId, toTokenAddress,
|
|
33
|
+
* toChainId, swapAmount, toRecipient).
|
|
34
|
+
*/
|
|
28
35
|
export type UseQuoteProps = {
|
|
36
|
+
/** The wallet client from wagmi (e.g., from `useWalletClient()`). Required for quote fetching. */
|
|
29
37
|
walletClient?: any // TODO: fix this, has to do with viem/wagmi versions
|
|
38
|
+
/** The contract address of the origin token. */
|
|
30
39
|
fromTokenAddress?: string | null
|
|
40
|
+
/** The chain ID of the origin chain */
|
|
31
41
|
fromChainId?: number | null
|
|
42
|
+
/** The contract address of the destination token. */
|
|
32
43
|
toTokenAddress?: string | null
|
|
44
|
+
/** The chain ID of the destination chain. */
|
|
33
45
|
toChainId?: number | null
|
|
46
|
+
/** Optional custom calldata for the destination chain. Used for executing arbitrary contract calls. */
|
|
34
47
|
toCalldata?: string | null
|
|
48
|
+
/** The amount to swap, as a string or bigint in the token's smallest unit (wei/smallest unit). For example, 1 USDC (6 decimals) = '1000000'. */
|
|
35
49
|
swapAmount?: string | bigint
|
|
50
|
+
/** The recipient address for the destination token. */
|
|
36
51
|
toRecipient?: string | null
|
|
52
|
+
/** The trade type: `TradeType.EXACT_INPUT` (you specify input amount) or `TradeType.EXACT_OUTPUT` (you specify output amount). Defaults to `EXACT_OUTPUT`. */
|
|
37
53
|
tradeType?: TradeType | null
|
|
54
|
+
/** Slippage tolerance as a decimal string or number (e.g., '0.005' for 0.5%, '0.01' for 1%). Defaults to a reasonable value if not provided. */
|
|
38
55
|
slippageTolerance?: string | number | null
|
|
56
|
+
/** Optional callback function that receives transaction state updates during swap execution. */
|
|
39
57
|
onStatusUpdate?: ((transactionStates: TransactionState[]) => void) | null
|
|
58
|
+
/** Optional quote provider ID to use. If not specified, the best available provider will be selected. */
|
|
40
59
|
quoteProvider?: string | null
|
|
41
60
|
/**
|
|
42
61
|
* Optional checkout event handlers for tracking the states of a Trails transaction.
|
|
@@ -67,14 +86,26 @@ export type UseQuoteProps = {
|
|
|
67
86
|
* - `triggerCheckoutStatusUpdate`
|
|
68
87
|
*/
|
|
69
88
|
checkoutOnHandlers?: Partial<CheckoutOnHandlers>
|
|
89
|
+
/** Optional paymaster URL for gasless ERC-4337 transactions. */
|
|
70
90
|
paymasterUrl?: string
|
|
91
|
+
/** Optional fee option selection (e.g., user selects USDC as the fee token instead of ETH) */
|
|
71
92
|
selectedFeeOption?: FeeOption | null
|
|
93
|
+
/** Optional AbortSignal to cancel the quote request. */
|
|
72
94
|
abortSignal?: AbortSignal
|
|
95
|
+
/** Optional API key override for Trails API access. */
|
|
73
96
|
apiKey?: string | null
|
|
97
|
+
/** Optional environment override for node gateway ('prod' | 'dev' | 'local' | 'cors-anywhere'). */
|
|
74
98
|
nodeGatewayEnv?: "prod" | "dev" | "local" | "cors-anywhere"
|
|
99
|
+
/** Optional flag to indicate if the wallet is a smart wallet. */
|
|
75
100
|
isSmartWallet?: boolean | null
|
|
76
101
|
}
|
|
77
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Return type for the `swap` function returned by {@link useQuote}.
|
|
105
|
+
*
|
|
106
|
+
* Contains information about both the origin and destination transactions,
|
|
107
|
+
* including transaction hashes, explorer URLs, and receipts.
|
|
108
|
+
*/
|
|
78
109
|
export type SwapReturn = {
|
|
79
110
|
originTransaction: {
|
|
80
111
|
transactionHash?: string | null
|
|
@@ -89,24 +120,35 @@ export type SwapReturn = {
|
|
|
89
120
|
totalCompletionSeconds?: number
|
|
90
121
|
}
|
|
91
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Information about a quote provider (LiFi, CCTP, Relay, etc.) used for routing the swap.
|
|
125
|
+
*/
|
|
92
126
|
export type QuoteProviderInfo = {
|
|
93
127
|
id: string
|
|
94
128
|
name: string
|
|
95
129
|
url: string
|
|
96
130
|
}
|
|
97
131
|
|
|
132
|
+
/**
|
|
133
|
+
* A quote object containing all the details about a Trails intent transaction.
|
|
134
|
+
*
|
|
135
|
+
* Includes token amounts, fees, price impact, estimated completion time,
|
|
136
|
+
* and other relevant information for displaying to the user.
|
|
137
|
+
*/
|
|
98
138
|
export type Quote = {
|
|
99
139
|
fromAmount: string
|
|
100
140
|
fromAmountMin: string
|
|
101
141
|
toAmount: string
|
|
102
142
|
toAmountMin: string
|
|
103
|
-
originToken:
|
|
104
|
-
destinationToken:
|
|
143
|
+
originToken: Token
|
|
144
|
+
destinationToken: Token
|
|
105
145
|
originChain: Chain
|
|
106
146
|
destinationChain: Chain
|
|
107
147
|
fees: PrepareSendFees
|
|
108
148
|
slippageTolerance: string
|
|
109
149
|
priceImpact: string
|
|
150
|
+
priceImpactUsd?: string
|
|
151
|
+
priceImpactUsdDisplay?: string
|
|
110
152
|
completionEstimateSeconds: number
|
|
111
153
|
transactionStates?: TransactionState[]
|
|
112
154
|
originTokenRate?: string
|
|
@@ -118,19 +160,147 @@ export type Quote = {
|
|
|
118
160
|
gasCostUsdDisplay?: string
|
|
119
161
|
gasCost?: string
|
|
120
162
|
gasCostFormatted?: string
|
|
163
|
+
totalFeesUsd?: number
|
|
164
|
+
totalFeesUsdDisplay?: string
|
|
165
|
+
totalGasUsd?: number
|
|
166
|
+
totalGasUsdDisplay?: string
|
|
167
|
+
allProviderFeesUsd?: number
|
|
168
|
+
allProviderFeesUsdDisplay?: string
|
|
121
169
|
}
|
|
122
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Return type for the {@link useQuote} hook.
|
|
173
|
+
*
|
|
174
|
+
* Provides the quote data, swap function, loading state, error information,
|
|
175
|
+
* and utility functions for managing the quote lifecycle.
|
|
176
|
+
*/
|
|
123
177
|
export type UseQuoteReturn = {
|
|
178
|
+
/** The quote object with swap details, or `null` if not available. */
|
|
124
179
|
quote: Quote | null
|
|
180
|
+
/** A function to execute the swap, or `null` if not available. Returns a Promise that resolves to swap result with transaction receipts. */
|
|
125
181
|
swap: (() => Promise<SwapReturn | null>) | null
|
|
182
|
+
/** Boolean indicating if a quote is currently being fetched. */
|
|
126
183
|
isLoadingQuote: boolean
|
|
184
|
+
/** Any error that occurred while fetching the quote, or `null`. */
|
|
127
185
|
quoteError: unknown
|
|
186
|
+
/** A user-friendly error message string. */
|
|
128
187
|
quoteErrorPrettified: string
|
|
188
|
+
/** Function to manually refetch the quote (useful for refreshing stale quotes). */
|
|
129
189
|
refetchQuote: () => void
|
|
190
|
+
/** Function to abort any in-flight quote requests. */
|
|
130
191
|
abort: () => void
|
|
131
192
|
}
|
|
132
193
|
|
|
133
194
|
// TODO: consolidate useSendForm, prepareSend, and useQuote hooks into a single hook
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* React hook for fetching quotes and executing cross-chain or same-chain intent transactions.
|
|
198
|
+
*
|
|
199
|
+
* This hook provides a simple interface to get quotes for intent transactions and execute them.
|
|
200
|
+
* It handles both cross-chain and same-chain intent transactions, automatically fetching token balances,
|
|
201
|
+
* calculating fees, and providing transaction state updates.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* Cross-chain swap example:
|
|
205
|
+
* ```tsx
|
|
206
|
+
* import { useQuote, TradeType } from '0xtrails'
|
|
207
|
+
* import { useEffect } from 'react'
|
|
208
|
+
* import { useWalletClient, useAccount } from 'wagmi'
|
|
209
|
+
*
|
|
210
|
+
* export const Swap = () => {
|
|
211
|
+
* const { data: walletClient } = useWalletClient()
|
|
212
|
+
* const { address } = useAccount()
|
|
213
|
+
*
|
|
214
|
+
* const { quote, swap, isLoadingQuote, quoteError, refetchQuote } = useQuote({
|
|
215
|
+
* walletClient,
|
|
216
|
+
* fromTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC
|
|
217
|
+
* fromChainId: 1, // Ethereum
|
|
218
|
+
* toTokenAddress: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC
|
|
219
|
+
* toChainId: 8453, // Base
|
|
220
|
+
* swapAmount: '1000000', // 1 USDC (6 decimals)
|
|
221
|
+
* tradeType: TradeType.EXACT_INPUT,
|
|
222
|
+
* toRecipient: address,
|
|
223
|
+
* slippageTolerance: '0.005', // 0.5%
|
|
224
|
+
* onStatusUpdate: (states) => {
|
|
225
|
+
* console.log('Transaction states:', states)
|
|
226
|
+
* }
|
|
227
|
+
* })
|
|
228
|
+
*
|
|
229
|
+
* // Quotes can become stale; refetch every ~30 seconds
|
|
230
|
+
* useEffect(() => {
|
|
231
|
+
* const id = setInterval(() => {
|
|
232
|
+
* refetchQuote?.()
|
|
233
|
+
* }, 30000)
|
|
234
|
+
* return () => clearInterval(id)
|
|
235
|
+
* }, [refetchQuote])
|
|
236
|
+
*
|
|
237
|
+
* const handleSwap = async () => {
|
|
238
|
+
* if (!swap) return
|
|
239
|
+
*
|
|
240
|
+
* try {
|
|
241
|
+
* const result = await swap()
|
|
242
|
+
* console.log('Swap completed:', result)
|
|
243
|
+
* } catch (error) {
|
|
244
|
+
* console.error('Swap failed:', error)
|
|
245
|
+
* }
|
|
246
|
+
* }
|
|
247
|
+
*
|
|
248
|
+
* if (isLoadingQuote) return <div>Getting quote...</div>
|
|
249
|
+
* if (quoteError) return <div>Error: {String(quoteError)}</div>
|
|
250
|
+
* if (!quote) return <div>No quote available</div>
|
|
251
|
+
*
|
|
252
|
+
* return (
|
|
253
|
+
* <div>
|
|
254
|
+
* <div>From: {quote.fromAmount} {quote.originToken.symbol}</div>
|
|
255
|
+
* <div>To: {quote.toAmount} {quote.destinationToken.symbol}</div>
|
|
256
|
+
* <button onClick={handleSwap}>Execute Swap</button>
|
|
257
|
+
* </div>
|
|
258
|
+
* )
|
|
259
|
+
* }
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @param props - Configuration options for the quote
|
|
263
|
+
* @param props.walletClient - The wallet client from wagmi (e.g., from `useWalletClient()`)
|
|
264
|
+
* @param props.fromTokenAddress - The contract address of the token to swap from.
|
|
265
|
+
* @param props.fromChainId - The chain ID of the origin chain
|
|
266
|
+
* @param props.toTokenAddress - The contract address of the token to swap to. Use `zeroAddress` for native tokens
|
|
267
|
+
* @param props.toChainId - The chain ID of the destination chain
|
|
268
|
+
* @param props.swapAmount - The amount to swap, as a string or bigint in the token's smallest unit (wei/smallest unit). For example, 1 USDC (6 decimals) = '1000000'
|
|
269
|
+
* @param props.tradeType - The trade type: `TradeType.EXACT_INPUT` (you specify input amount) or `TradeType.EXACT_OUTPUT` (you specify output amount). Defaults to `EXACT_OUTPUT`
|
|
270
|
+
* @param props.toRecipient - The recipient address for the destination token.
|
|
271
|
+
* @param props.slippageTolerance - Slippage tolerance as a decimal string or number (e.g., '0.005' for 0.5%, '0.01' for 1%). Defaults to a reasonable value if not provided
|
|
272
|
+
* @param props.toCalldata - Optional custom calldata for the destination chain. Used for executing arbitrary contract calls (e.g., swap and mint an NFT on destination chain)
|
|
273
|
+
* @param props.onStatusUpdate - Optional callback function that receives transaction state updates during swap execution
|
|
274
|
+
* @param props.quoteProvider - Optional quote provider ID to use (auto, lifi, relay, cctp, direct). If not specified, the best available provider will be selected
|
|
275
|
+
* @param props.checkoutOnHandlers - Optional event handlers for tracking checkout/transaction lifecycle events
|
|
276
|
+
* @param props.paymasterUrl - Optional paymaster URL for gasless ERC-4337 transactions
|
|
277
|
+
* @param props.selectedFeeOption - Optional fee option selection (e.g., user selects USDC as the fee token instead of ETH)
|
|
278
|
+
* @param props.abortSignal - Optional AbortSignal to cancel the quote request
|
|
279
|
+
* @param props.apiKey - Optional API key override for Trails API access
|
|
280
|
+
* @param props.nodeGatewayEnv - Optional environment override ('prod' | 'dev' | 'local' | 'cors-anywhere')
|
|
281
|
+
* @param props.isSmartWallet - Optional flag to indicate if the wallet is a smart wallet
|
|
282
|
+
*
|
|
283
|
+
* @returns An object containing:
|
|
284
|
+
* - `quote` - The quote object with swap details, or `null` if not available
|
|
285
|
+
* - `swap` - A function to execute the swap, or `null` if not available. Returns a Promise that resolves to swap result with transaction receipts
|
|
286
|
+
* - `isLoadingQuote` - Boolean indicating if a quote is currently being fetched
|
|
287
|
+
* - `quoteError` - Any error that occurred while fetching the quote, or `null`
|
|
288
|
+
* - `quoteErrorPrettified` - A user-friendly error message string
|
|
289
|
+
* - `refetchQuote` - Function to manually refetch the quote (useful for refreshing stale quotes)
|
|
290
|
+
* - `abort` - Function to abort any in-flight quote requests
|
|
291
|
+
*
|
|
292
|
+
* @remarks
|
|
293
|
+
* - The hook uses React Query internally, so quotes are cached and automatically refetched based on query key changes
|
|
294
|
+
* - Quotes are considered stale after 30 seconds. You may want to periodically call `refetchQuote()` to keep quotes fresh
|
|
295
|
+
* - The hook will not fetch a quote until all required parameters are provided (walletClient, token addresses, chain IDs, swap amount, recipient)
|
|
296
|
+
* - For native tokens (ETH, MATIC, etc.), use the zero address (`0x0000000000000000000000000000000000000000`)
|
|
297
|
+
*
|
|
298
|
+
* @see {@link TradeType} for available trade types
|
|
299
|
+
* @see {@link Quote} for the quote object structure
|
|
300
|
+
* @see {@link SwapReturn} for the swap result structure
|
|
301
|
+
*
|
|
302
|
+
* For more information go to {@link https://docs.trails.build/sdk/hooks#usequote-hook}
|
|
303
|
+
*/
|
|
134
304
|
export function useQuote({
|
|
135
305
|
walletClient,
|
|
136
306
|
fromTokenAddress,
|
|
@@ -471,6 +641,8 @@ export function useQuote({
|
|
|
471
641
|
originPublicClient: originPublicClient ?? undefined,
|
|
472
642
|
destinationPublicClient: destinationPublicClient ?? undefined,
|
|
473
643
|
isSmartWallet: isSmartWallet ?? undefined,
|
|
644
|
+
trailsApiKey,
|
|
645
|
+
trailsApiUrl,
|
|
474
646
|
}
|
|
475
647
|
|
|
476
648
|
logger.console.log("[trails-sdk] options", options)
|
|
@@ -488,6 +660,9 @@ export function useQuote({
|
|
|
488
660
|
destinationChain: prepareSendQuote.destinationChain,
|
|
489
661
|
fees: prepareSendQuote.fees,
|
|
490
662
|
priceImpact: prepareSendQuote.priceImpact,
|
|
663
|
+
priceImpactUsd: prepareSendQuote.priceImpactUsd ?? undefined,
|
|
664
|
+
priceImpactUsdDisplay:
|
|
665
|
+
prepareSendQuote.priceImpactUsdDisplay ?? undefined,
|
|
491
666
|
completionEstimateSeconds: prepareSendQuote.completionEstimateSeconds,
|
|
492
667
|
slippageTolerance: prepareSendQuote.slippageTolerance,
|
|
493
668
|
transactionStates: prepareSendQuote.transactionStates,
|
|
@@ -502,6 +677,14 @@ export function useQuote({
|
|
|
502
677
|
gasCostUsdDisplay: prepareSendQuote.gasCostUsdDisplay ?? undefined,
|
|
503
678
|
gasCost: prepareSendQuote.gasCost ?? undefined,
|
|
504
679
|
gasCostFormatted: prepareSendQuote.gasCostFormatted ?? undefined,
|
|
680
|
+
totalFeesUsd: prepareSendQuote.grandTotalUsd ?? undefined,
|
|
681
|
+
totalFeesUsdDisplay:
|
|
682
|
+
prepareSendQuote.grandTotalUsdDisplay ?? undefined,
|
|
683
|
+
totalGasUsd: prepareSendQuote.totalGasUsd ?? undefined,
|
|
684
|
+
totalGasUsdDisplay: prepareSendQuote.totalGasUsdDisplay ?? undefined,
|
|
685
|
+
allProviderFeesUsd: prepareSendQuote.allProviderFeesUsd ?? undefined,
|
|
686
|
+
allProviderFeesUsdDisplay:
|
|
687
|
+
prepareSendQuote.allProviderFeesUsdDisplay ?? undefined,
|
|
505
688
|
}
|
|
506
689
|
|
|
507
690
|
const swap = async (): Promise<SwapReturn> => {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { JsonEncode } from "@
|
|
1
|
+
import { JsonEncode } from "@0xtrails/api"
|
|
2
2
|
import { useState, useEffect, useCallback } from "react"
|
|
3
|
-
import type {
|
|
3
|
+
import type { Token } from "../../tokens.js"
|
|
4
4
|
import { logger } from "../../logger.js"
|
|
5
5
|
|
|
6
6
|
interface RecentTokensStorage {
|
|
7
|
-
[accountAddress: string]:
|
|
7
|
+
[accountAddress: string]: Token[]
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const RECENT_TOKENS_KEY = "trails_recent_tokens"
|
|
11
11
|
const MAX_RECENT_TOKENS = 10
|
|
12
12
|
|
|
13
13
|
export function useRecentTokens(accountAddress?: string) {
|
|
14
|
-
const [recentTokens, setRecentTokens] = useState<
|
|
14
|
+
const [recentTokens, setRecentTokens] = useState<Token[]>([])
|
|
15
15
|
|
|
16
16
|
// Load recent tokens from localStorage for the current account
|
|
17
17
|
useEffect(() => {
|
|
@@ -38,7 +38,7 @@ export function useRecentTokens(accountAddress?: string) {
|
|
|
38
38
|
|
|
39
39
|
// Add or update a recent token
|
|
40
40
|
const addRecentToken = useCallback(
|
|
41
|
-
(token:
|
|
41
|
+
(token: Token) => {
|
|
42
42
|
if (!accountAddress) return
|
|
43
43
|
|
|
44
44
|
try {
|
|
@@ -55,7 +55,7 @@ export function useRecentTokens(accountAddress?: string) {
|
|
|
55
55
|
(t) =>
|
|
56
56
|
!(
|
|
57
57
|
t.contractAddress === token.contractAddress &&
|
|
58
|
-
t.chainId === token.chainId
|
|
58
|
+
(t.chainId || 0) === (token.chainId || 0)
|
|
59
59
|
),
|
|
60
60
|
)
|
|
61
61
|
|
|
@@ -12,7 +12,7 @@ export interface RecentRecipient {
|
|
|
12
12
|
const STORAGE_KEY = "trails-recent-recipients"
|
|
13
13
|
const MAX_RECENT_RECIPIENTS = 10
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export function useRecipients() {
|
|
16
16
|
const [recentRecipients, setRecentRecipients] = useState<RecentRecipient[]>(
|
|
17
17
|
[],
|
|
18
18
|
)
|
|
@@ -7,7 +7,7 @@ import React, {
|
|
|
7
7
|
useMemo,
|
|
8
8
|
type ReactNode,
|
|
9
9
|
} from "react"
|
|
10
|
-
import type { FeeOption } from "@
|
|
10
|
+
import type { FeeOption } from "@0xtrails/api"
|
|
11
11
|
import { formatRawAmount, formatUsdAmountDisplay } from "../../tokenBalances.js"
|
|
12
12
|
import { logger } from "../../index.js"
|
|
13
13
|
import { isNativeToken, normalizeAddress } from "../../utils.js"
|
|
@@ -301,7 +301,7 @@ export const SelectedFeeOptionProvider: React.FC<
|
|
|
301
301
|
)
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
export
|
|
304
|
+
export function useSelectedFeeOption(): SelectedFeeOptionContextType {
|
|
305
305
|
const context = useContext(SelectedFeeOptionContext)
|
|
306
306
|
|
|
307
307
|
if (context === undefined) {
|
|
@@ -30,7 +30,7 @@ export const SelectedFundMethodProvider = ({
|
|
|
30
30
|
)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export
|
|
33
|
+
export function useSelectedFundMethod(): SelectedFundMethodContextType {
|
|
34
34
|
const context = useContext(SelectedFundMethodContext)
|
|
35
35
|
if (context === undefined) {
|
|
36
36
|
throw new Error(
|
|
@@ -47,7 +47,7 @@ export const SelectedRecipientProvider: React.FC<
|
|
|
47
47
|
)
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export
|
|
50
|
+
export function useSelectedRecipient() {
|
|
51
51
|
const context = useContext(SelectedRecipientContext)
|
|
52
52
|
if (context === undefined) {
|
|
53
53
|
throw new Error(
|