0xtrails 0.13.2 → 0.15.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/abis/requireUtils.d.ts +134 -0
- package/dist/abis/requireUtils.d.ts.map +1 -0
- package/dist/abis/trailsHydrate.d.ts +6 -42
- package/dist/abis/trailsHydrate.d.ts.map +1 -1
- package/dist/abis/trailsRouter.d.ts +1 -1
- package/dist/abis/trailsRouter.d.ts.map +1 -1
- package/dist/actions/actionBuilder.d.ts +414 -0
- package/dist/actions/actionBuilder.d.ts.map +1 -0
- package/dist/actions/constants.d.ts +1853 -0
- package/dist/actions/constants.d.ts.map +1 -0
- package/dist/actions/custom-integrations/sushiswapV3/addresses.d.ts +4 -0
- package/dist/actions/custom-integrations/sushiswapV3/addresses.d.ts.map +1 -0
- package/dist/actions/custom-integrations/sushiswapV3/calldata.d.ts +4 -0
- package/dist/actions/custom-integrations/sushiswapV3/calldata.d.ts.map +1 -0
- package/dist/actions/custom-integrations/sushiswapV3/calls.d.ts +28 -0
- package/dist/actions/custom-integrations/sushiswapV3/calls.d.ts.map +1 -0
- package/dist/actions/custom-integrations/sushiswapV3/helpers.d.ts +15 -0
- package/dist/actions/custom-integrations/sushiswapV3/helpers.d.ts.map +1 -0
- package/dist/actions/custom-integrations/sushiswapV3/sushiswapV3.d.ts +9 -0
- package/dist/actions/custom-integrations/sushiswapV3/sushiswapV3.d.ts.map +1 -0
- package/dist/actions/custom-integrations/sushiswapV3/types.d.ts +95 -0
- package/dist/actions/custom-integrations/sushiswapV3/types.d.ts.map +1 -0
- package/dist/actions/custom-integrations/uniswapV3/addresses.d.ts +4 -0
- package/dist/actions/custom-integrations/uniswapV3/addresses.d.ts.map +1 -0
- package/dist/actions/custom-integrations/uniswapV3/calldata.d.ts +4 -0
- package/dist/actions/custom-integrations/uniswapV3/calldata.d.ts.map +1 -0
- package/dist/actions/custom-integrations/uniswapV3/calls.d.ts +50 -0
- package/dist/actions/custom-integrations/uniswapV3/calls.d.ts.map +1 -0
- package/dist/actions/custom-integrations/uniswapV3/helpers.d.ts +23 -0
- package/dist/actions/custom-integrations/uniswapV3/helpers.d.ts.map +1 -0
- package/dist/actions/custom-integrations/uniswapV3/types.d.ts +90 -0
- package/dist/actions/custom-integrations/uniswapV3/types.d.ts.map +1 -0
- package/dist/actions/custom-integrations/uniswapV3/uniswapV3.d.ts +9 -0
- package/dist/actions/custom-integrations/uniswapV3/uniswapV3.d.ts.map +1 -0
- package/dist/actions/destinationCalls.d.ts +17 -0
- package/dist/actions/destinationCalls.d.ts.map +1 -0
- package/dist/actions/dynamic.d.ts +97 -0
- package/dist/actions/dynamic.d.ts.map +1 -0
- package/dist/actions/hooks/useEarnBalances.d.ts +53 -0
- package/dist/actions/hooks/useEarnBalances.d.ts.map +1 -0
- package/dist/actions/hooks/useEarnMarkets.d.ts +29 -0
- package/dist/actions/hooks/useEarnMarkets.d.ts.map +1 -0
- package/dist/actions/hooks/useEarnProviders.d.ts +18 -0
- package/dist/actions/hooks/useEarnProviders.d.ts.map +1 -0
- package/dist/actions/hooks/useResolveActions.d.ts +28 -0
- package/dist/actions/hooks/useResolveActions.d.ts.map +1 -0
- package/dist/actions/index.d.ts +8 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +13 -0
- package/dist/actions/resolvers.d.ts +30 -0
- package/dist/actions/resolvers.d.ts.map +1 -0
- package/dist/actions/types/earn.d.ts +51 -0
- package/dist/actions/types/earn.d.ts.map +1 -0
- package/dist/actions/types.d.ts +303 -0
- package/dist/actions/types.d.ts.map +1 -0
- package/dist/actions/utils.d.ts +181 -0
- package/dist/actions/utils.d.ts.map +1 -0
- package/dist/{widget/analytics → analytics/hooks}/useWidgetAnalytics.d.ts +2 -4
- package/dist/analytics/hooks/useWidgetAnalytics.d.ts.map +1 -0
- package/dist/analytics.d.ts.map +1 -1
- package/dist/chainSwitch.d.ts.map +1 -1
- package/dist/chains-DttlfV-6.js +4 -0
- package/dist/chains-ccVR_-73.js +655 -0
- package/dist/chains.d.ts +0 -1
- package/dist/chains.d.ts.map +1 -1
- package/dist/committedIntentStore.d.ts +5 -0
- package/dist/committedIntentStore.d.ts.map +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +2 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/error.d.ts +73 -4
- package/dist/error.d.ts.map +1 -1
- package/dist/hooks/persistedToken.d.ts +22 -0
- package/dist/hooks/persistedToken.d.ts.map +1 -0
- package/dist/hooks/prepareTrailsSendTransactionDestination.d.ts +26 -0
- package/dist/hooks/prepareTrailsSendTransactionDestination.d.ts.map +1 -0
- package/dist/hooks/useAddressWalletIcon.d.ts.map +1 -0
- package/dist/hooks/useAmountUsd.d.ts.map +1 -0
- package/dist/hooks/useBalanceVisible.d.ts.map +1 -0
- package/dist/hooks/useChainFilter.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useCheckout.d.ts +15 -15
- package/dist/hooks/useCheckout.d.ts.map +1 -0
- package/dist/hooks/useClickTracking.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useCombinedHistory.d.ts +3 -2
- package/dist/hooks/useCombinedHistory.d.ts.map +1 -0
- package/dist/hooks/useConnector.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useCustomTokenSearch.d.ts +3 -2
- package/dist/hooks/useCustomTokenSearch.d.ts.map +1 -0
- package/dist/hooks/useDebounce.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useDebugScreens.d.ts +2 -2
- package/dist/hooks/useDebugScreens.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useDefaultDestinationToken.d.ts +1 -1
- package/dist/hooks/useDefaultDestinationToken.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useDefaultOriginToken.d.ts +1 -1
- package/dist/hooks/useDefaultOriginToken.d.ts.map +1 -0
- package/dist/hooks/useDepositMonitor.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useDestinationSelectedToken.d.ts +10 -2
- package/dist/hooks/useDestinationSelectedToken.d.ts.map +1 -0
- package/dist/hooks/useDisplayCurrencyPreference.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useEarnPool.d.ts +1 -1
- package/dist/hooks/useEarnPool.d.ts.map +1 -0
- package/dist/hooks/useEffectiveFundBalance.d.ts +28 -0
- package/dist/hooks/useEffectiveFundBalance.d.ts.map +1 -0
- package/dist/hooks/useExecutingIntentsCount.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useExternalFundingReceiptSync.d.ts +1 -1
- package/dist/hooks/useExternalFundingReceiptSync.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useFiatOnRampCurrencies.d.ts +1 -1
- package/dist/hooks/useFiatOnRampCurrencies.d.ts.map +1 -0
- package/dist/hooks/useFiatSelectedCurrency.d.ts.map +1 -0
- package/dist/hooks/useGetIntent.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useIntentReceiptBalances.d.ts +1 -1
- package/dist/hooks/useIntentReceiptBalances.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useIntentTransactionHistory.d.ts +2 -1
- package/dist/hooks/useIntentTransactionHistory.d.ts.map +1 -0
- package/dist/hooks/useIsMobile.d.ts.map +1 -0
- package/dist/hooks/useIsSequenceWallet.d.ts.map +1 -0
- package/dist/hooks/useLocalePreference.d.ts.map +1 -0
- package/dist/hooks/useMeldTransactionHistory.d.ts.map +1 -0
- package/dist/hooks/useMeldTransactionStatus.d.ts.map +1 -0
- package/dist/hooks/useOnRampCountryDefaults.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useOnRampPaymentMethods.d.ts +2 -2
- package/dist/hooks/useOnRampPaymentMethods.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useOnRampProviderWidget.d.ts +1 -1
- package/dist/hooks/useOnRampProviderWidget.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useOnRampQuote.d.ts +3 -3
- package/dist/hooks/useOnRampQuote.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useOnRampTransactionStatus.d.ts +1 -1
- package/dist/hooks/useOnRampTransactionStatus.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useOriginSelectedToken.d.ts +1 -1
- package/dist/hooks/useOriginSelectedToken.d.ts.map +1 -0
- package/dist/hooks/usePayMessage.d.ts.map +1 -0
- package/dist/hooks/usePriceImpactWarning.d.ts.map +1 -0
- package/dist/hooks/useQuote.d.ts +619 -0
- package/dist/hooks/useQuote.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useRecentTokens.d.ts +1 -1
- package/dist/hooks/useRecentTokens.d.ts.map +1 -0
- package/dist/hooks/useRecipients.d.ts.map +1 -0
- package/dist/hooks/useSelectedFeeOption.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useSelectedFundMethod.d.ts +11 -1
- package/dist/hooks/useSelectedFundMethod.d.ts.map +1 -0
- package/dist/hooks/useSelectedRecipient.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useSendForm.d.ts +10 -12
- package/dist/hooks/useSendForm.d.ts.map +1 -0
- package/dist/hooks/useSwapAmount.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useSwapState.d.ts +1 -1
- package/dist/hooks/useSwapState.d.ts.map +1 -0
- package/dist/hooks/useTargetAmount.d.ts.map +1 -0
- package/dist/hooks/useTheme.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useTokenList.d.ts +4 -3
- package/dist/hooks/useTokenList.d.ts.map +1 -0
- package/dist/hooks/useTrailsSendTransaction.d.ts +171 -0
- package/dist/hooks/useTrailsSendTransaction.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useViewManager.d.ts +1 -1
- package/dist/hooks/useViewManager.d.ts.map +1 -0
- package/dist/hooks/useWalletConnectUri.d.ts +19 -0
- package/dist/hooks/useWalletConnectUri.d.ts.map +1 -0
- package/dist/hooks/useWalletConnectionContext.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useWidgetProps.d.ts +1 -1
- package/dist/hooks/useWidgetProps.d.ts.map +1 -0
- package/dist/hydrate/builder.d.ts +131 -0
- package/dist/hydrate/builder.d.ts.map +1 -0
- package/dist/hydrate/constants.d.ts +13 -0
- package/dist/hydrate/constants.d.ts.map +1 -0
- package/dist/hydrate/encodeExecute.d.ts +73 -0
- package/dist/hydrate/encodeExecute.d.ts.map +1 -0
- package/dist/hydrate/index.d.ts +8 -0
- package/dist/hydrate/index.d.ts.map +1 -0
- package/dist/hydrate/index.js +14 -0
- package/dist/hydrate/multicall.d.ts +69 -0
- package/dist/hydrate/multicall.d.ts.map +1 -0
- package/dist/hydrate/payload.d.ts +38 -0
- package/dist/hydrate/payload.d.ts.map +1 -0
- package/dist/hydrate/selectors.d.ts +28 -0
- package/dist/hydrate/selectors.d.ts.map +1 -0
- package/dist/hydrate/source.d.ts +11 -0
- package/dist/hydrate/source.d.ts.map +1 -0
- package/dist/hydrate/types.d.ts +21 -0
- package/dist/hydrate/types.d.ts.map +1 -0
- package/dist/hydrate/utils.d.ts +8 -0
- package/dist/hydrate/utils.d.ts.map +1 -0
- package/dist/hydrate-BsQ8nPlI.js +882 -0
- package/dist/index.d.ts +47 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +189 -662
- package/dist/intentConfigStore.d.ts +8 -0
- package/dist/intentConfigStore.d.ts.map +1 -0
- package/dist/intentProtocolApi.d.ts +11 -0
- package/dist/intentProtocolApi.d.ts.map +1 -0
- package/dist/intentProtocolEncoding.d.ts +30 -0
- package/dist/intentProtocolEncoding.d.ts.map +1 -0
- package/dist/intentProtocolResolver.d.ts +28 -0
- package/dist/intentProtocolResolver.d.ts.map +1 -0
- package/dist/intentReceiptPoller.d.ts.map +1 -1
- package/dist/intentValidation.d.ts +5 -0
- package/dist/intentValidation.d.ts.map +1 -0
- package/dist/intents.d.ts.map +1 -1
- package/dist/keymachine/index.d.ts +20 -0
- package/dist/keymachine/index.d.ts.map +1 -1
- package/dist/mutations.d.ts.map +1 -1
- package/dist/offlineRecovery.d.ts +24 -0
- package/dist/offlineRecovery.d.ts.map +1 -0
- package/dist/onramp/MeshConnectFlow.d.ts +9 -0
- package/dist/onramp/MeshConnectFlow.d.ts.map +1 -1
- package/dist/onramp/MeshConnectIframe.d.ts +9 -0
- package/dist/onramp/MeshConnectIframe.d.ts.map +1 -1
- package/dist/onramp/TrailsOnRampProvider.d.ts.map +1 -1
- package/dist/onramp/mesh/components/MeshExchangeConfirmation.d.ts +10 -0
- package/dist/onramp/mesh/components/MeshExchangeConfirmation.d.ts.map +1 -0
- package/dist/onramp/mesh/components/MeshExchangeIcon.d.ts +13 -0
- package/dist/onramp/mesh/components/MeshExchangeIcon.d.ts.map +1 -0
- package/dist/{widget → onramp/mesh}/components/MeshExchangeSelection.d.ts +1 -0
- package/dist/onramp/mesh/components/MeshExchangeSelection.d.ts.map +1 -0
- package/dist/onramp/mesh/components/MeshSessionOptions.d.ts +15 -0
- package/dist/onramp/mesh/components/MeshSessionOptions.d.ts.map +1 -0
- package/dist/onramp/mesh/hooks/useMeshAccessTokens.d.ts +9 -0
- package/dist/onramp/mesh/hooks/useMeshAccessTokens.d.ts.map +1 -0
- package/dist/onramp/mesh/hooks/useMeshFundingSelection.d.ts +11 -0
- package/dist/onramp/mesh/hooks/useMeshFundingSelection.d.ts.map +1 -0
- package/dist/onramp/mesh/hooks/useMeshOnrampFlow.d.ts +71 -0
- package/dist/onramp/mesh/hooks/useMeshOnrampFlow.d.ts.map +1 -0
- package/dist/onramp/mesh/hooks/useMeshOnrampSessionState.d.ts +32 -0
- package/dist/onramp/mesh/hooks/useMeshOnrampSessionState.d.ts.map +1 -0
- package/dist/onramp/mesh/hooks/useMeshSelectedTokenBalance.d.ts +19 -0
- package/dist/onramp/mesh/hooks/useMeshSelectedTokenBalance.d.ts.map +1 -0
- package/dist/onramp/mesh/hooks/useMeshSessionAccountBalance.d.ts +15 -0
- package/dist/onramp/mesh/hooks/useMeshSessionAccountBalance.d.ts.map +1 -0
- package/dist/onramp/mesh/hooks/useMeshSessionStorage.d.ts +7 -0
- package/dist/onramp/mesh/hooks/useMeshSessionStorage.d.ts.map +1 -0
- package/dist/onramp/meshSessionStorage.d.ts +13 -0
- package/dist/onramp/meshSessionStorage.d.ts.map +1 -0
- package/dist/onramp/meshconnect.d.ts +6 -4
- package/dist/onramp/meshconnect.d.ts.map +1 -1
- package/dist/onramp/trailsOnramp.d.ts +8 -0
- package/dist/onramp/trailsOnramp.d.ts.map +1 -1
- package/dist/onrampClient.d.ts.map +1 -1
- package/dist/placeholder.d.ts +129 -5
- package/dist/placeholder.d.ts.map +1 -1
- package/dist/poolUtils.d.ts +0 -14
- package/dist/poolUtils.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +3 -2
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/query/balance.fetchers.d.ts +7 -1
- package/dist/query/balance.fetchers.d.ts.map +1 -1
- package/dist/query/intentProtocol.queries.d.ts +32 -0
- package/dist/query/intentProtocol.queries.d.ts.map +1 -0
- package/dist/recover.d.ts +70 -24
- package/dist/recover.d.ts.map +1 -1
- package/dist/src-CQhZqidH.js +51593 -0
- package/dist/tokens.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +2 -3
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +2 -3
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts +2 -5
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/intentHandler.d.ts +5 -4
- package/dist/transactionIntent/handlers/intentHandler.d.ts.map +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +2 -2
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +4 -3
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactions.d.ts +1 -0
- package/dist/transactions.d.ts.map +1 -1
- package/dist/umd/trails.min.js +1371 -409
- package/dist/utils/localStorageGc.d.ts +22 -0
- package/dist/utils/localStorageGc.d.ts.map +1 -0
- package/dist/utils/validation.d.ts +14 -0
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/walletUtils.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/ChainList.d.ts +2 -0
- package/dist/widget/components/ChainList.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
- package/dist/widget/components/Earn.d.ts +2 -6
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/EarnMarkets.d.ts +9 -0
- package/dist/widget/components/EarnMarkets.d.ts.map +1 -0
- package/dist/widget/components/EarnPoolsFilters.d.ts +7 -1
- package/dist/widget/components/EarnPoolsFilters.d.ts.map +1 -1
- package/dist/widget/components/{PoolWithdraw.d.ts → EarnWithdraw.d.ts} +5 -5
- package/dist/widget/components/{PoolWithdraw.d.ts.map → EarnWithdraw.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 +1 -1
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/FiatSelector.d.ts +1 -1
- package/dist/widget/components/FiatSelector.d.ts.map +1 -1
- package/dist/widget/components/FiatSelectorButton.d.ts +1 -1
- package/dist/widget/components/FiatSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts +1 -1
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/FundingMethodSelectorButton.d.ts +1 -1
- package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/HookModalContent.d.ts.map +1 -1
- package/dist/widget/components/MeldHistory.d.ts +1 -1
- package/dist/widget/components/MeldHistory.d.ts.map +1 -1
- package/dist/widget/components/MeldTransactionStatus.d.ts +1 -1
- package/dist/widget/components/MeldTransactionStatus.d.ts.map +1 -1
- package/dist/widget/components/MeshExchangeAccountHeader.d.ts +9 -0
- package/dist/widget/components/MeshExchangeAccountHeader.d.ts.map +1 -0
- package/dist/widget/components/OnrampHistoryRow.d.ts +1 -1
- package/dist/widget/components/OnrampHistoryRow.d.ts.map +1 -1
- package/dist/widget/components/OnrampProviderConfirmation.d.ts +1 -1
- package/dist/widget/components/OnrampProviderConfirmation.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts +2 -6
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/PulsatingButton.d.ts +9 -0
- package/dist/widget/components/PulsatingButton.d.ts.map +1 -0
- package/dist/widget/components/Receipt.d.ts +1 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/Recipients.d.ts.map +1 -1
- package/dist/widget/components/Swap.d.ts +2 -6
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/TokenList.d.ts +1 -0
- package/dist/widget/components/TokenList.d.ts.map +1 -1
- package/dist/widget/components/TokenSelector.d.ts +2 -2
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/TransactionDetails.d.ts +1 -0
- package/dist/widget/components/TransactionDetails.d.ts.map +1 -1
- package/dist/widget/components/TransactionHistoryItem.d.ts +1 -0
- package/dist/widget/components/TransactionHistoryItem.d.ts.map +1 -1
- package/dist/widget/components/TransferPendingVertical.d.ts +1 -1
- package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
- package/dist/widget/components/WalletAccountHeader.d.ts +7 -0
- package/dist/widget/components/WalletAccountHeader.d.ts.map +1 -0
- package/dist/widget/components/WalletConfirmation.d.ts +2 -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.map +1 -1
- package/dist/widget/components/Withdraw.d.ts.map +1 -1
- package/dist/widget/components/earnMarketUtils.d.ts +11 -0
- package/dist/widget/components/earnMarketUtils.d.ts.map +1 -0
- package/dist/widget/components/earnNetworks.d.ts +6 -0
- package/dist/widget/components/earnNetworks.d.ts.map +1 -0
- package/dist/widget/index.d.ts +13 -0
- package/dist/widget/index.d.ts.map +1 -1
- package/dist/widget/index.js +17 -9
- package/dist/widget/modes/EarnWidget.d.ts +90 -0
- package/dist/widget/modes/EarnWidget.d.ts.map +1 -0
- package/dist/widget/modes/FundWidget.d.ts +97 -0
- package/dist/widget/modes/FundWidget.d.ts.map +1 -0
- package/dist/widget/modes/PayWidget.d.ts +80 -0
- package/dist/widget/modes/PayWidget.d.ts.map +1 -0
- package/dist/widget/modes/SwapWidget.d.ts +76 -0
- package/dist/widget/modes/SwapWidget.d.ts.map +1 -0
- package/dist/widget/modes/WithdrawWidget.d.ts +87 -0
- package/dist/widget/modes/WithdrawWidget.d.ts.map +1 -0
- package/dist/widget/providers/TrailsProvider.d.ts +3 -0
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -1
- package/dist/widget/providers/WidgetProviderTree.d.ts.map +1 -1
- package/dist/widget/shared/destinationDefaultToken.d.ts +15 -0
- package/dist/widget/shared/destinationDefaultToken.d.ts.map +1 -0
- package/dist/widget/shared/mapSharedProps.d.ts +9 -0
- package/dist/widget/shared/mapSharedProps.d.ts.map +1 -0
- package/dist/widget/shared/methodMap.d.ts +18 -0
- package/dist/widget/shared/methodMap.d.ts.map +1 -0
- package/dist/widget/shared/resolution.d.ts +23 -0
- package/dist/widget/shared/resolution.d.ts.map +1 -0
- package/dist/widget/shared/resolvePaymentSource.d.ts +36 -0
- package/dist/widget/shared/resolvePaymentSource.d.ts.map +1 -0
- package/dist/widget/shared/tokenAllowlist.d.ts +36 -0
- package/dist/widget/shared/tokenAllowlist.d.ts.map +1 -0
- package/dist/widget/shared/types.d.ts +150 -0
- package/dist/widget/shared/types.d.ts.map +1 -0
- package/dist/widget/styles.gen.d.ts +2 -0
- package/dist/widget/styles.gen.d.ts.map +1 -0
- package/dist/widget/types/commonProps.d.ts +3 -7
- package/dist/widget/types/commonProps.d.ts.map +1 -1
- package/dist/widget/utils/fundMethodSwitchState.d.ts +1 -0
- package/dist/widget/utils/fundMethodSwitchState.d.ts.map +1 -1
- package/dist/widget/utils/viewManagerGuards.d.ts +1 -1
- package/dist/widget/utils/viewManagerGuards.d.ts.map +1 -1
- package/dist/widget/widget.d.ts +23 -16
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +22 -23
- package/dist/buffer.d.ts +0 -3
- package/dist/buffer.d.ts.map +0 -1
- package/dist/ccip-CT_An6eM.js +0 -230
- package/dist/index-RfqL5Foz.js +0 -114567
- package/dist/paymasterSend.d.ts +0 -90
- package/dist/paymasterSend.d.ts.map +0 -1
- package/dist/sendUserOp.d.ts +0 -122
- package/dist/sendUserOp.d.ts.map +0 -1
- package/dist/toSimpleSmartAccount.d.ts +0 -95
- package/dist/toSimpleSmartAccount.d.ts.map +0 -1
- package/dist/transactionIntent/utils/erc20Approval.d.ts +0 -34
- package/dist/transactionIntent/utils/erc20Approval.d.ts.map +0 -1
- package/dist/utils/allowance.d.ts +0 -19
- package/dist/utils/allowance.d.ts.map +0 -1
- package/dist/widget/analytics/useWidgetAnalytics.d.ts.map +0 -1
- package/dist/widget/components/FeeBreakdown.d.ts +0 -9
- package/dist/widget/components/FeeBreakdown.d.ts.map +0 -1
- package/dist/widget/components/HideBalances.d.ts +0 -4
- package/dist/widget/components/HideBalances.d.ts.map +0 -1
- package/dist/widget/components/MeshExchangeSelection.d.ts.map +0 -1
- package/dist/widget/components/OnrampDeposit.d.ts +0 -10
- package/dist/widget/components/OnrampDeposit.d.ts.map +0 -1
- package/dist/widget/components/SwapSettings.d.ts +0 -4
- package/dist/widget/components/SwapSettings.d.ts.map +0 -1
- package/dist/widget/components/TruncatedAddress.d.ts +0 -12
- package/dist/widget/components/TruncatedAddress.d.ts.map +0 -1
- package/dist/widget/components/WalletImage.d.ts +0 -8
- package/dist/widget/components/WalletImage.d.ts.map +0 -1
- package/dist/widget/css/compiled.css +0 -26
- package/dist/widget/css/index.css +0 -686
- package/dist/widget/hooks/useAddressWalletIcon.d.ts.map +0 -1
- package/dist/widget/hooks/useAmountUsd.d.ts.map +0 -1
- package/dist/widget/hooks/useBalanceVisible.d.ts.map +0 -1
- package/dist/widget/hooks/useChainFilter.d.ts.map +0 -1
- package/dist/widget/hooks/useCheckout.d.ts.map +0 -1
- package/dist/widget/hooks/useClickTracking.d.ts.map +0 -1
- package/dist/widget/hooks/useCombinedHistory.d.ts.map +0 -1
- package/dist/widget/hooks/useConnector.d.ts.map +0 -1
- package/dist/widget/hooks/useCustomTokenSearch.d.ts.map +0 -1
- package/dist/widget/hooks/useDebounce.d.ts.map +0 -1
- package/dist/widget/hooks/useDebugScreens.d.ts.map +0 -1
- package/dist/widget/hooks/useDefaultDestinationToken.d.ts.map +0 -1
- package/dist/widget/hooks/useDefaultOriginToken.d.ts.map +0 -1
- package/dist/widget/hooks/useDepositMonitor.d.ts.map +0 -1
- package/dist/widget/hooks/useDestinationSelectedToken.d.ts.map +0 -1
- package/dist/widget/hooks/useDisplayCurrencyPreference.d.ts.map +0 -1
- package/dist/widget/hooks/useEarnPool.d.ts.map +0 -1
- package/dist/widget/hooks/useExecutingIntentsCount.d.ts.map +0 -1
- package/dist/widget/hooks/useExternalFundingReceiptSync.d.ts.map +0 -1
- package/dist/widget/hooks/useFiatOnRampCurrencies.d.ts.map +0 -1
- package/dist/widget/hooks/useFiatSelectedCurrency.d.ts.map +0 -1
- package/dist/widget/hooks/useGetIntent.d.ts.map +0 -1
- package/dist/widget/hooks/useIntentReceiptBalances.d.ts.map +0 -1
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +0 -1
- package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts +0 -7
- package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts.map +0 -1
- package/dist/widget/hooks/useIsMobile.d.ts.map +0 -1
- package/dist/widget/hooks/useIsSequenceWallet.d.ts.map +0 -1
- package/dist/widget/hooks/useLocalePreference.d.ts.map +0 -1
- package/dist/widget/hooks/useMeldTransactionHistory.d.ts.map +0 -1
- package/dist/widget/hooks/useMeldTransactionStatus.d.ts.map +0 -1
- package/dist/widget/hooks/useOnRampCountryDefaults.d.ts.map +0 -1
- package/dist/widget/hooks/useOnRampPaymentMethods.d.ts.map +0 -1
- package/dist/widget/hooks/useOnRampProviderWidget.d.ts.map +0 -1
- package/dist/widget/hooks/useOnRampQuote.d.ts.map +0 -1
- package/dist/widget/hooks/useOnRampTransactionStatus.d.ts.map +0 -1
- package/dist/widget/hooks/useOriginSelectedToken.d.ts.map +0 -1
- package/dist/widget/hooks/usePayMessage.d.ts.map +0 -1
- package/dist/widget/hooks/usePriceImpactWarning.d.ts.map +0 -1
- package/dist/widget/hooks/useQuote.d.ts +0 -378
- package/dist/widget/hooks/useQuote.d.ts.map +0 -1
- package/dist/widget/hooks/useRecentTokens.d.ts.map +0 -1
- package/dist/widget/hooks/useRecipients.d.ts.map +0 -1
- package/dist/widget/hooks/useScreenTracking.d.ts +0 -2
- package/dist/widget/hooks/useScreenTracking.d.ts.map +0 -1
- package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +0 -1
- package/dist/widget/hooks/useSelectedFundMethod.d.ts.map +0 -1
- package/dist/widget/hooks/useSelectedRecipient.d.ts.map +0 -1
- package/dist/widget/hooks/useSendForm.d.ts.map +0 -1
- package/dist/widget/hooks/useSwapAmount.d.ts.map +0 -1
- package/dist/widget/hooks/useSwapState.d.ts.map +0 -1
- package/dist/widget/hooks/useTargetAmount.d.ts.map +0 -1
- package/dist/widget/hooks/useTheme.d.ts.map +0 -1
- package/dist/widget/hooks/useTokenList.d.ts.map +0 -1
- package/dist/widget/hooks/useTrailsSendTransaction.d.ts +0 -83
- package/dist/widget/hooks/useTrailsSendTransaction.d.ts.map +0 -1
- package/dist/widget/hooks/useViewManager.d.ts.map +0 -1
- package/dist/widget/hooks/useWalletConnectUri.d.ts +0 -11
- package/dist/widget/hooks/useWalletConnectUri.d.ts.map +0 -1
- package/dist/widget/hooks/useWalletConnectionContext.d.ts.map +0 -1
- package/dist/widget/hooks/useWidgetProps.d.ts.map +0 -1
- package/dist/widget/styles.d.ts +0 -2
- package/dist/widget/styles.d.ts.map +0 -1
- package/dist/widget/types.d.ts +0 -44
- package/dist/widget/types.d.ts.map +0 -1
- package/dist/widget/utils/historyUtils.d.ts +0 -18
- package/dist/widget/utils/historyUtils.d.ts.map +0 -1
- package/src/abi.ts +0 -38
- package/src/abis/erc20.ts +0 -60
- package/src/abis/trailsHydrate.ts +0 -185
- package/src/abis/trailsRouter.ts +0 -121
- package/src/abis/trailsSweep.ts +0 -32
- package/src/abortController.ts +0 -35
- package/src/analytics.ts +0 -2029
- package/src/buffer.ts +0 -10
- package/src/chainSwitch.ts +0 -95
- package/src/chains.ts +0 -570
- package/src/config.ts +0 -118
- package/src/constants.ts +0 -239
- package/src/contractUtils.ts +0 -46
- package/src/cssUtils.ts +0 -5
- package/src/customChains.ts +0 -24
- package/src/customTokens.ts +0 -168
- package/src/decoders.ts +0 -365
- package/src/ens.ts +0 -74
- package/src/error.ts +0 -268
- package/src/estimate.ts +0 -480
- package/src/explorer.ts +0 -38
- package/src/fees.ts +0 -362
- package/src/gasless.ts +0 -638
- package/src/index.ts +0 -205
- package/src/indexerClient.ts +0 -118
- package/src/intentReceiptMonitor.ts +0 -99
- package/src/intentReceiptPoller.ts +0 -327
- package/src/intents.ts +0 -1133
- package/src/keyMachineClient.ts +0 -29
- package/src/keymachine/index.ts +0 -175
- package/src/keymachine/key-machine.gen.ts +0 -993
- package/src/localeUtils.ts +0 -244
- package/src/logger/index.ts +0 -95
- package/src/logger/useSyncLoggerDebug.ts +0 -11
- package/src/logger.ts +0 -1
- package/src/meld/components/MeldCountriesList.tsx +0 -237
- package/src/meld/components/MeldFundMethods.tsx +0 -265
- package/src/meld/components/MeldProvidersList.tsx +0 -187
- package/src/meld/components/MeldTokensList.tsx +0 -321
- package/src/meld/components/SimpleHeader.tsx +0 -35
- package/src/meld/utils/meld.ts +0 -77
- package/src/mutations.ts +0 -166
- package/src/onramp/MeshConnectFlow.tsx +0 -86
- package/src/onramp/MeshConnectIframe.tsx +0 -661
- package/src/onramp/SendFromExchangeButton.tsx +0 -81
- package/src/onramp/TrailsOnRampProvider.tsx +0 -59
- package/src/onramp/index.ts +0 -31
- package/src/onramp/meshconnect.ts +0 -277
- package/src/onramp/trailsOnramp.tsx +0 -130
- package/src/onramp-client/index.ts +0 -52
- package/src/onrampClient.ts +0 -46
- package/src/paymasterSend.ts +0 -521
- package/src/placeholder.ts +0 -92
- package/src/poolUtils.ts +0 -222
- package/src/pools.ts +0 -120
- package/src/prepareSend.ts +0 -553
- package/src/query/balance.fetchers.ts +0 -753
- package/src/query/balance.hooks.ts +0 -357
- package/src/query/balance.queries.ts +0 -307
- package/src/query/chains.hooks.ts +0 -45
- package/src/query/chains.queries.ts +0 -17
- package/src/query/client.ts +0 -20
- package/src/query/fiat.fetchers.ts +0 -33
- package/src/query/fiat.hooks.ts +0 -71
- package/src/query/fiat.queries.ts +0 -67
- package/src/query/geo.fetchers.ts +0 -100
- package/src/query/geo.hooks.ts +0 -16
- package/src/query/geo.queries.ts +0 -36
- package/src/query/helpers.ts +0 -81
- package/src/query/meld.fetchers.ts +0 -97
- package/src/query/meld.hooks.ts +0 -18
- package/src/query/meld.queries.ts +0 -184
- package/src/query/persister.ts +0 -11
- package/src/query/price.fetchers.ts +0 -53
- package/src/query/price.hooks.ts +0 -46
- package/src/query/price.queries.ts +0 -364
- package/src/query/tokenList.queries.ts +0 -118
- package/src/queryParams.ts +0 -100
- package/src/recover.ts +0 -1728
- package/src/sendUserOp.ts +0 -512
- package/src/theme.ts +0 -2
- package/src/toSimpleSmartAccount.ts +0 -567
- package/src/toast.ts +0 -110
- package/src/tokens.ts +0 -1862
- package/src/trailsClient.ts +0 -40
- package/src/transactionIntent/constants.ts +0 -15
- package/src/transactionIntent/deposits/depositOrchestrator.ts +0 -243
- package/src/transactionIntent/deposits/gaslessDeposit.ts +0 -705
- package/src/transactionIntent/deposits/index.ts +0 -3
- package/src/transactionIntent/deposits/standardDeposit.ts +0 -590
- package/src/transactionIntent/execution/index.ts +0 -1
- package/src/transactionIntent/execution/transactionState.ts +0 -38
- package/src/transactionIntent/handlers/index.ts +0 -1
- package/src/transactionIntent/handlers/intentHandler.ts +0 -1613
- package/src/transactionIntent/helpers/index.ts +0 -1
- package/src/transactionIntent/helpers/transactionStateHelpers.ts +0 -440
- package/src/transactionIntent/index.ts +0 -10
- package/src/transactionIntent/quote/feeExtractors.ts +0 -61
- package/src/transactionIntent/quote/index.ts +0 -3
- package/src/transactionIntent/quote/normalizeQuote.ts +0 -559
- package/src/transactionIntent/quote/quoteHelpers.ts +0 -117
- package/src/transactionIntent/types.ts +0 -241
- package/src/transactionIntent/utils/balanceChecker.ts +0 -103
- package/src/transactionIntent/utils/erc20Approval.ts +0 -171
- package/src/transactionIntent/utils/index.ts +0 -2
- package/src/transactionIntent/utils/resilientDepositTracker.ts +0 -171
- package/src/transactionIntent/utils/testnetHelpers.ts +0 -5
- package/src/transactionIntent/validators.ts +0 -27
- package/src/transactions.ts +0 -429
- package/src/types.d.ts +0 -16
- package/src/umd.tsx +0 -33
- package/src/utils/address.ts +0 -78
- package/src/utils/allowance.ts +0 -47
- package/src/utils/fiat.ts +0 -32
- package/src/utils/format.ts +0 -625
- package/src/utils/passthrough.ts +0 -93
- package/src/utils/time.ts +0 -118
- package/src/utils/validation.ts +0 -104
- package/src/utils.ts +0 -112
- package/src/version.ts +0 -8
- package/src/vite-env.d.ts +0 -4
- package/src/walletUtils.ts +0 -293
- package/src/wallets.ts +0 -544
- package/src/widget/analytics/useWidgetAnalytics.ts +0 -56
- package/src/widget/assets/Exchange-icon-black.svg +0 -5
- package/src/widget/assets/MetaMask-icon-fox-with-margins.svg +0 -31
- package/src/widget/assets/MetaMask-icon-fox.svg +0 -26
- package/src/widget/assets/MetaMask-logo-black.svg +0 -3
- package/src/widget/assets/MetaMask-logo-white.svg +0 -16
- package/src/widget/assets/Trails-logo-black.svg +0 -13
- package/src/widget/assets/Trails-logo-white.svg +0 -13
- package/src/widget/assets/WalletChange-black.svg +0 -5
- package/src/widget/assets/WalletConnect-logo-black.svg +0 -14
- package/src/widget/assets/WalletConnect-logo-blue.svg +0 -14
- package/src/widget/assets/WalletConnect-logo-white.svg +0 -14
- package/src/widget/assets/WalletConnect-logo.svg +0 -40
- package/src/widget/assets/aave.svg +0 -14
- package/src/widget/assets/morpho.svg +0 -14
- package/src/widget/compiled.css +0 -26
- package/src/widget/components/AccountActionsDropdown.tsx +0 -31
- package/src/widget/components/AccountIntentTransactionHistory.tsx +0 -756
- package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +0 -34
- package/src/widget/components/AccountSettings.tsx +0 -168
- package/src/widget/components/AddressOrEnsName.tsx +0 -24
- package/src/widget/components/AddressWalletIcon.tsx +0 -49
- package/src/widget/components/AllChainsIcon.tsx +0 -54
- package/src/widget/components/ChainFilterDropdown.tsx +0 -220
- package/src/widget/components/ChainImage.tsx +0 -40
- package/src/widget/components/ChainList.tsx +0 -158
- package/src/widget/components/ClassicSwap.tsx +0 -1761
- package/src/widget/components/ConfigDisplay.tsx +0 -158
- package/src/widget/components/ConnectWallet.tsx +0 -566
- package/src/widget/components/ConnectedWallets.tsx +0 -414
- package/src/widget/components/CopyButton.tsx +0 -108
- package/src/widget/components/CountryFilterDropdown.tsx +0 -179
- package/src/widget/components/DebugMenu.tsx +0 -50
- package/src/widget/components/DebugScreensList.tsx +0 -70
- package/src/widget/components/DebugToast.tsx +0 -63
- package/src/widget/components/DepositTracker.tsx +0 -326
- package/src/widget/components/DirectTransfer.tsx +0 -305
- package/src/widget/components/Disconnect.tsx +0 -68
- package/src/widget/components/DynamicInputStyles.tsx +0 -121
- package/src/widget/components/DynamicSizeInputField.tsx +0 -245
- package/src/widget/components/ENSAvatar.tsx +0 -33
- package/src/widget/components/Earn.tsx +0 -160
- package/src/widget/components/EarnPools.tsx +0 -417
- package/src/widget/components/EarnPoolsFilters.tsx +0 -165
- package/src/widget/components/ErrorAnimationIcon.tsx +0 -130
- package/src/widget/components/ErrorDisplay.tsx +0 -152
- package/src/widget/components/ExecutingIntentsBadge.tsx +0 -24
- package/src/widget/components/ExecutionStatusBadge.tsx +0 -53
- package/src/widget/components/FeeBreakdown.tsx +0 -155
- package/src/widget/components/FeeOption.tsx +0 -170
- package/src/widget/components/FeeOptions.tsx +0 -247
- package/src/widget/components/FiatSelector.tsx +0 -308
- package/src/widget/components/FiatSelectorButton.tsx +0 -68
- package/src/widget/components/Footer.tsx +0 -67
- package/src/widget/components/Fund.tsx +0 -2463
- package/src/widget/components/FundMethods.tsx +0 -423
- package/src/widget/components/FundWalletSelection.tsx +0 -60
- package/src/widget/components/FundingMethodSelectorButton.tsx +0 -106
- package/src/widget/components/GreenCheckAnimation.tsx +0 -119
- package/src/widget/components/HideBalances.tsx +0 -24
- package/src/widget/components/HighPriceImpactBlock.tsx +0 -44
- package/src/widget/components/HookModalContent.tsx +0 -377
- package/src/widget/components/Identicon.tsx +0 -228
- package/src/widget/components/LoadingSpinner.tsx +0 -9
- package/src/widget/components/MeldForm.tsx +0 -780
- package/src/widget/components/MeldHistory.tsx +0 -433
- package/src/widget/components/MeldStepsFlow.tsx +0 -1651
- package/src/widget/components/MeldTransactionStatus.tsx +0 -255
- package/src/widget/components/MeshExchangeSelection.tsx +0 -218
- package/src/widget/components/Modal.tsx +0 -86
- package/src/widget/components/OFTProgressBar.tsx +0 -89
- package/src/widget/components/OnRampProviderSelector.tsx +0 -263
- package/src/widget/components/OnrampDeposit.tsx +0 -122
- package/src/widget/components/OnrampErrorScreen.tsx +0 -163
- package/src/widget/components/OnrampHistoryRow.tsx +0 -321
- package/src/widget/components/OnrampPaymentMethods.tsx +0 -81
- package/src/widget/components/OnrampProviderConfirmation.tsx +0 -1060
- package/src/widget/components/OriginSelectionAmount.tsx +0 -144
- package/src/widget/components/OriginTransferInformation.tsx +0 -59
- package/src/widget/components/Pay.tsx +0 -1165
- package/src/widget/components/PaymentMethods.tsx +0 -198
- package/src/widget/components/PercentageMaxButtons.tsx +0 -112
- package/src/widget/components/PoolDeposit.tsx +0 -642
- package/src/widget/components/PoolWithdraw.tsx +0 -761
- package/src/widget/components/PriceImpactWarning.tsx +0 -87
- package/src/widget/components/QRCodeOptions.tsx +0 -65
- package/src/widget/components/QRCodeWalletSelect.tsx +0 -80
- package/src/widget/components/QrCode.tsx +0 -216
- package/src/widget/components/QuoteDetails.tsx +0 -1275
- package/src/widget/components/Receipt.tsx +0 -673
- package/src/widget/components/ReceiptRecoverableFunds.tsx +0 -135
- package/src/widget/components/RecentTokens.tsx +0 -66
- package/src/widget/components/RecipientSelectorButton.tsx +0 -50
- package/src/widget/components/Recipients.tsx +0 -413
- package/src/widget/components/RefundWarning.tsx +0 -61
- package/src/widget/components/RequiredPropsError.tsx +0 -33
- package/src/widget/components/ScreenHeader.tsx +0 -123
- package/src/widget/components/SearchInputField.tsx +0 -99
- package/src/widget/components/SessionTimeoutScreen.tsx +0 -103
- package/src/widget/components/ShadowPortal.tsx +0 -99
- package/src/widget/components/ShadowRootContext.tsx +0 -17
- package/src/widget/components/SimpleRecipientInputScreen.tsx +0 -91
- package/src/widget/components/SlippageToleranceSettings.tsx +0 -279
- package/src/widget/components/Swap.tsx +0 -50
- package/src/widget/components/SwapDisplay.tsx +0 -68
- package/src/widget/components/SwapSettings.tsx +0 -52
- package/src/widget/components/ThemeProvider.tsx +0 -115
- package/src/widget/components/ThemeSyncer.tsx +0 -47
- package/src/widget/components/Toast.tsx +0 -336
- package/src/widget/components/TokenDisplayNonSelectable.tsx +0 -40
- package/src/widget/components/TokenImage.tsx +0 -156
- package/src/widget/components/TokenList.tsx +0 -107
- package/src/widget/components/TokenSelector.tsx +0 -807
- package/src/widget/components/TokenSelectorButton.tsx +0 -123
- package/src/widget/components/TokenSkeleton.tsx +0 -53
- package/src/widget/components/Tooltip.tsx +0 -64
- package/src/widget/components/TrailsHookModal.tsx +0 -107
- package/src/widget/components/TransactionDetails.tsx +0 -534
- package/src/widget/components/TransactionHistoryItem.tsx +0 -767
- package/src/widget/components/TransferPendingVertical.tsx +0 -591
- package/src/widget/components/TruncatedAddress.tsx +0 -68
- package/src/widget/components/TruncatedTransactionHash.tsx +0 -74
- package/src/widget/components/UserPreferences.tsx +0 -570
- package/src/widget/components/WaasFeeOptions.tsx +0 -588
- package/src/widget/components/WalletConfirmation.tsx +0 -220
- package/src/widget/components/WalletConnect.tsx +0 -348
- package/src/widget/components/WalletConnectionPending.tsx +0 -178
- package/src/widget/components/WalletImage.tsx +0 -52
- package/src/widget/components/WalletList.tsx +0 -125
- package/src/widget/components/WidgetProviders.tsx +0 -82
- package/src/widget/components/Withdraw.tsx +0 -1106
- package/src/widget/components/YellowWarningAnimation.tsx +0 -146
- package/src/widget/hooks/useAddressWalletIcon.ts +0 -55
- package/src/widget/hooks/useAmountUsd.ts +0 -44
- package/src/widget/hooks/useBalanceVisible.tsx +0 -95
- package/src/widget/hooks/useChainFilter.tsx +0 -56
- package/src/widget/hooks/useCheckout.ts +0 -361
- package/src/widget/hooks/useClickTracking.ts +0 -74
- package/src/widget/hooks/useCombinedHistory.ts +0 -420
- package/src/widget/hooks/useConnector.tsx +0 -24
- package/src/widget/hooks/useCustomTokenSearch.tsx +0 -369
- package/src/widget/hooks/useDebounce.ts +0 -25
- package/src/widget/hooks/useDebugScreens.ts +0 -600
- package/src/widget/hooks/useDefaultDestinationToken.tsx +0 -179
- package/src/widget/hooks/useDefaultOriginToken.tsx +0 -407
- package/src/widget/hooks/useDepositMonitor.ts +0 -118
- package/src/widget/hooks/useDestinationSelectedToken.tsx +0 -310
- package/src/widget/hooks/useDisplayCurrencyPreference.tsx +0 -145
- package/src/widget/hooks/useEarnPool.tsx +0 -36
- package/src/widget/hooks/useExecutingIntentsCount.ts +0 -78
- package/src/widget/hooks/useExternalFundingReceiptSync.ts +0 -79
- package/src/widget/hooks/useFiatOnRampCurrencies.ts +0 -46
- package/src/widget/hooks/useFiatSelectedCurrency.tsx +0 -123
- package/src/widget/hooks/useGetIntent.ts +0 -54
- package/src/widget/hooks/useIntentReceiptBalances.ts +0 -141
- package/src/widget/hooks/useIntentTransactionHistory.ts +0 -790
- package/src/widget/hooks/useIsConnectedWalletSmartContract.ts +0 -43
- package/src/widget/hooks/useIsMobile.tsx +0 -50
- package/src/widget/hooks/useIsSequenceWallet.ts +0 -17
- package/src/widget/hooks/useLocalePreference.tsx +0 -187
- package/src/widget/hooks/useMeldTransactionHistory.ts +0 -184
- package/src/widget/hooks/useMeldTransactionStatus.ts +0 -707
- package/src/widget/hooks/useOnRampCountryDefaults.ts +0 -57
- package/src/widget/hooks/useOnRampPaymentMethods.ts +0 -72
- package/src/widget/hooks/useOnRampProviderWidget.ts +0 -184
- package/src/widget/hooks/useOnRampQuote.ts +0 -340
- package/src/widget/hooks/useOnRampTransactionStatus.ts +0 -196
- package/src/widget/hooks/useOriginSelectedToken.tsx +0 -253
- package/src/widget/hooks/usePayMessage.tsx +0 -496
- package/src/widget/hooks/usePriceImpactWarning.ts +0 -17
- package/src/widget/hooks/useQuote.ts +0 -1239
- package/src/widget/hooks/useRecentTokens.ts +0 -159
- package/src/widget/hooks/useRecipients.ts +0 -167
- package/src/widget/hooks/useScreenTracking.ts +0 -14
- package/src/widget/hooks/useSelectedFeeOption.tsx +0 -323
- package/src/widget/hooks/useSelectedFundMethod.tsx +0 -93
- package/src/widget/hooks/useSelectedRecipient.tsx +0 -75
- package/src/widget/hooks/useSendForm.ts +0 -1389
- package/src/widget/hooks/useSwapAmount.tsx +0 -50
- package/src/widget/hooks/useSwapState.tsx +0 -121
- package/src/widget/hooks/useTargetAmount.ts +0 -26
- package/src/widget/hooks/useTheme.tsx +0 -80
- package/src/widget/hooks/useTokenList.ts +0 -1168
- package/src/widget/hooks/useTrailsSendTransaction.ts +0 -987
- package/src/widget/hooks/useViewManager.tsx +0 -506
- package/src/widget/hooks/useWalletConnectUri.tsx +0 -307
- package/src/widget/hooks/useWalletConnectionContext.tsx +0 -128
- package/src/widget/hooks/useWidgetProps.tsx +0 -33
- package/src/widget/index.css +0 -686
- package/src/widget/index.tsx +0 -28
- package/src/widget/providers/TrailsModalProvider.tsx +0 -238
- package/src/widget/providers/TrailsProvider.tsx +0 -155
- package/src/widget/providers/UserActivityProvider.tsx +0 -78
- package/src/widget/providers/WidgetProviderTree.tsx +0 -90
- package/src/widget/styles.ts +0 -26
- package/src/widget/types/analytics.ts +0 -22
- package/src/widget/types/commonProps.ts +0 -56
- package/src/widget/types/svg.d.ts +0 -8
- package/src/widget/types.ts +0 -51
- package/src/widget/utils/countryUtils.ts +0 -89
- package/src/widget/utils/createWagmiConfig.ts +0 -43
- package/src/widget/utils/forexRateStore.ts +0 -120
- package/src/widget/utils/fundMethodSwitchState.ts +0 -27
- package/src/widget/utils/historyFilters.ts +0 -157
- package/src/widget/utils/historyUtils.ts +0 -101
- package/src/widget/utils/localeStore.ts +0 -68
- package/src/widget/utils/meldProviderUtils.ts +0 -26
- package/src/widget/utils/meshSupportedTokens.ts +0 -28
- package/src/widget/utils/onrampConfig.ts +0 -15
- package/src/widget/utils/statusLabel.ts +0 -3
- package/src/widget/utils/tokens.ts +0 -138
- package/src/widget/utils/trailsOnrampConfig.ts +0 -39
- package/src/widget/utils/transactionFailure.ts +0 -52
- package/src/widget/utils/viewManagerGuards.ts +0 -49
- package/src/widget/utils/windowUtils.ts +0 -138
- package/src/widget/widget.tsx +0 -3400
- /package/dist/{widget/hooks → hooks}/useAddressWalletIcon.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useAmountUsd.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useBalanceVisible.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useChainFilter.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useClickTracking.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useConnector.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useDebounce.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useDepositMonitor.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useDisplayCurrencyPreference.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useExecutingIntentsCount.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useFiatSelectedCurrency.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useGetIntent.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useIsMobile.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useIsSequenceWallet.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useLocalePreference.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useMeldTransactionHistory.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useMeldTransactionStatus.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useOnRampCountryDefaults.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/usePayMessage.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/usePriceImpactWarning.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useRecipients.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useSelectedFeeOption.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useSelectedRecipient.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useSwapAmount.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useTargetAmount.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useTheme.d.ts +0 -0
- /package/dist/{widget/hooks → hooks}/useWalletConnectionContext.d.ts +0 -0
package/src/widget/widget.tsx
DELETED
|
@@ -1,3400 +0,0 @@
|
|
|
1
|
-
import { elapsed, toSeconds } from "../utils/time.js"
|
|
2
|
-
import { AnimatePresence, motion } from "motion/react"
|
|
3
|
-
import React, {
|
|
4
|
-
forwardRef,
|
|
5
|
-
StrictMode,
|
|
6
|
-
useCallback,
|
|
7
|
-
useEffect,
|
|
8
|
-
useImperativeHandle,
|
|
9
|
-
useMemo,
|
|
10
|
-
useRef,
|
|
11
|
-
useState,
|
|
12
|
-
} from "react"
|
|
13
|
-
import { invalidateTokenBalancesCache } from "../query/balance.queries.js"
|
|
14
|
-
import {
|
|
15
|
-
type ProviderTreeProps,
|
|
16
|
-
IsolatedProviders,
|
|
17
|
-
DefaultProviders,
|
|
18
|
-
} from "./providers/WidgetProviderTree.js"
|
|
19
|
-
import { createWagmiConfig } from "./utils/createWagmiConfig.js"
|
|
20
|
-
import { ShadowPortal } from "./components/ShadowPortal.js"
|
|
21
|
-
import { QuoteDetails } from "./components/QuoteDetails.js"
|
|
22
|
-
import type { Chain, WalletClient, EIP1193Provider } from "viem"
|
|
23
|
-
import {
|
|
24
|
-
createWalletClient,
|
|
25
|
-
custom,
|
|
26
|
-
defineChain,
|
|
27
|
-
isAddress,
|
|
28
|
-
zeroAddress,
|
|
29
|
-
} from "viem"
|
|
30
|
-
import type { Connector } from "wagmi"
|
|
31
|
-
|
|
32
|
-
// Type for EIP-6963 connector with info property
|
|
33
|
-
interface EIP6963Connector extends Connector {
|
|
34
|
-
info?: {
|
|
35
|
-
rdns?: string
|
|
36
|
-
name?: string
|
|
37
|
-
icon?: string
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/** Transfer result data returned by an onramp provider on completion.
|
|
41
|
-
* Shape based on @meshconnect/web-link-sdk TransferFinishedPayload. */
|
|
42
|
-
interface OnrampTransferResult {
|
|
43
|
-
status: string
|
|
44
|
-
txId: string
|
|
45
|
-
fromAddress: string
|
|
46
|
-
toAddress: string
|
|
47
|
-
symbol: string
|
|
48
|
-
amount: number
|
|
49
|
-
networkId: string
|
|
50
|
-
amountInFiat?: number
|
|
51
|
-
totalAmountInFiat?: number
|
|
52
|
-
networkName?: string
|
|
53
|
-
txHash?: string
|
|
54
|
-
transferId?: string
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
import {
|
|
58
|
-
createStorage,
|
|
59
|
-
useAccount,
|
|
60
|
-
useAccountEffect,
|
|
61
|
-
useConnect,
|
|
62
|
-
useConnections,
|
|
63
|
-
useConnectors,
|
|
64
|
-
useDisconnect,
|
|
65
|
-
useSwitchAccount,
|
|
66
|
-
} from "wagmi"
|
|
67
|
-
import { getSessionId } from "../analytics.js"
|
|
68
|
-
import { getChainInfo } from "../chains.js"
|
|
69
|
-
// Config is now managed exclusively by TrailsProvider
|
|
70
|
-
import { cssObjectToString } from "../cssUtils.js"
|
|
71
|
-
import {
|
|
72
|
-
getFullErrorMessage,
|
|
73
|
-
getIsApiError,
|
|
74
|
-
getIsBalanceTooLowError,
|
|
75
|
-
getIsRateLimitedError,
|
|
76
|
-
getIsUserRejectionError,
|
|
77
|
-
getPrettifiedErrorMessage,
|
|
78
|
-
} from "../error.js"
|
|
79
|
-
import { logger } from "../logger.js"
|
|
80
|
-
import { abortControllerRegistry } from "../abortController.js"
|
|
81
|
-
import type { Pool } from "../pools.js"
|
|
82
|
-
import { usePools } from "../pools.js"
|
|
83
|
-
import type { PrepareSendQuote } from "../prepareSend.js"
|
|
84
|
-
import { isValidInteger, isValidNumeric } from "../utils/validation.js"
|
|
85
|
-
import type { Theme } from "../theme.js"
|
|
86
|
-
import type { Token } from "../tokens.js"
|
|
87
|
-
import { getWethAddress } from "../tokens.js"
|
|
88
|
-
import type { IntentTransaction } from "@0xtrails/api"
|
|
89
|
-
import {
|
|
90
|
-
getQRCodeWallets,
|
|
91
|
-
getWalletIdFromRdns,
|
|
92
|
-
wagmiConnectorToWalletId,
|
|
93
|
-
} from "@0xtrails/wallet-registry"
|
|
94
|
-
import type { TransactionState } from "../transactions.js"
|
|
95
|
-
import { useOnrampClient } from "../onrampClient.js"
|
|
96
|
-
import {
|
|
97
|
-
useWallets,
|
|
98
|
-
getWalletConnectConnector,
|
|
99
|
-
getConnectorsInternal,
|
|
100
|
-
type WalletConnector,
|
|
101
|
-
} from "../wallets.js"
|
|
102
|
-
// import { useOpenConnectModal } from "@0xsequence/connect"
|
|
103
|
-
import {
|
|
104
|
-
generateAaveDepositCalldata,
|
|
105
|
-
generateMorphoDepositCalldata,
|
|
106
|
-
} from "../poolUtils.js"
|
|
107
|
-
import { AccountIntentTransactionHistory } from "./components/AccountIntentTransactionHistory.js"
|
|
108
|
-
import { AccountSettings } from "./components/AccountSettings.js"
|
|
109
|
-
import { ChainList } from "./components/ChainList.js"
|
|
110
|
-
import { ConnectWallet } from "./components/ConnectWallet.js"
|
|
111
|
-
import { MeldStepsFlow } from "./components/MeldStepsFlow.js"
|
|
112
|
-
import { MeldHistory } from "./components/MeldHistory.js"
|
|
113
|
-
import { Disconnect } from "./components/Disconnect.js"
|
|
114
|
-
import { Earn } from "./components/Earn.js"
|
|
115
|
-
import EarnPools from "./components/EarnPools.js"
|
|
116
|
-
import { ErrorDisplay } from "./components/ErrorDisplay.js"
|
|
117
|
-
import Footer from "./components/Footer.js"
|
|
118
|
-
import { Fund } from "./components/Fund.js"
|
|
119
|
-
import { Withdraw } from "./components/Withdraw.js"
|
|
120
|
-
import FundMethods from "./components/FundMethods.js"
|
|
121
|
-
import { MeshExchangeSelection } from "./components/MeshExchangeSelection.js"
|
|
122
|
-
import OnrampPaymentMethods from "./components/OnrampPaymentMethods.js"
|
|
123
|
-
import Modal from "./components/Modal.js"
|
|
124
|
-
import { Pay } from "./components/Pay.js"
|
|
125
|
-
import DirectTransfer from "./components/DirectTransfer.js"
|
|
126
|
-
import OnrampProviderConfirmation from "./components/OnrampProviderConfirmation.js"
|
|
127
|
-
import QRCodeOptions from "./components/QRCodeOptions.js"
|
|
128
|
-
import QRCodeWalletSelect from "./components/QRCodeWalletSelect.js"
|
|
129
|
-
import Receipt from "./components/Receipt.js"
|
|
130
|
-
import { Recipients } from "./components/Recipients.js"
|
|
131
|
-
import { Swap } from "./components/Swap.js"
|
|
132
|
-
import { ThemeProvider } from "./components/ThemeProvider.js"
|
|
133
|
-
import { ThemeSyncer } from "./components/ThemeSyncer.js"
|
|
134
|
-
import TokenList from "./components/TokenList.js"
|
|
135
|
-
import OriginSelectionAmount from "./components/OriginSelectionAmount.js"
|
|
136
|
-
import TransferPending from "./components/TransferPendingVertical.js"
|
|
137
|
-
import { UserPreferences } from "./components/UserPreferences.js"
|
|
138
|
-
import WalletConfirmation from "./components/WalletConfirmation.js"
|
|
139
|
-
import WalletConnectScreen from "./components/WalletConnect.js"
|
|
140
|
-
import WalletConnectionPending from "./components/WalletConnectionPending.js"
|
|
141
|
-
import { FundWalletSelection } from "./components/FundWalletSelection.js"
|
|
142
|
-
import { WalletList } from "./components/WalletList.js"
|
|
143
|
-
import { useCheckout } from "./hooks/useCheckout.js"
|
|
144
|
-
import { useDebugScreens } from "./hooks/useDebugScreens.js"
|
|
145
|
-
import { useExternalFundingReceiptSync } from "./hooks/useExternalFundingReceiptSync.js"
|
|
146
|
-
import { getWidgetOnrampConfig } from "./utils/trailsOnrampConfig.js"
|
|
147
|
-
import type { TrailsOnRampConfig } from "../onramp/TrailsOnRampProvider.js"
|
|
148
|
-
import { trailsOnramp, type OnrampFactory } from "../onramp/trailsOnramp.js"
|
|
149
|
-
import { useScreenTracking } from "./hooks/useScreenTracking.js"
|
|
150
|
-
import { useEarnPool } from "./hooks/useEarnPool.js"
|
|
151
|
-
|
|
152
|
-
import { useIsSequenceWallet } from "./hooks/useIsSequenceWallet.js"
|
|
153
|
-
import { useOriginSelectedToken as useSelectedToken } from "./hooks/useOriginSelectedToken.js"
|
|
154
|
-
import { PriceImpactWarningProvider } from "./hooks/usePriceImpactWarning.js"
|
|
155
|
-
import { useRecentTokens } from "./hooks/useRecentTokens.js"
|
|
156
|
-
import { useSelectedFeeOption } from "./hooks/useSelectedFeeOption.js"
|
|
157
|
-
import { useSelectedFundMethod } from "./hooks/useSelectedFundMethod.js"
|
|
158
|
-
import { useSelectedRecipient } from "./hooks/useSelectedRecipient.js"
|
|
159
|
-
import type { OnCompleteProps } from "./hooks/useSendForm.js"
|
|
160
|
-
import { useTargetAmount } from "./hooks/useTargetAmount.js"
|
|
161
|
-
import { useSwapState } from "./hooks/useSwapState.js"
|
|
162
|
-
import { useWidgetAnalytics } from "./analytics/useWidgetAnalytics.js"
|
|
163
|
-
import { useWalletConnectionContext } from "./hooks/useWalletConnectionContext.js"
|
|
164
|
-
import { useWidgetProps } from "./hooks/useWidgetProps.js"
|
|
165
|
-
import { clearFundStateForMethodSwitch } from "./utils/fundMethodSwitchState.js"
|
|
166
|
-
import { useOnRampProviderWidget } from "./hooks/useOnRampProviderWidget.js"
|
|
167
|
-
import { WidgetProviders } from "./components/WidgetProviders.js"
|
|
168
|
-
import {
|
|
169
|
-
useTrails,
|
|
170
|
-
type TrailsProviderProps,
|
|
171
|
-
} from "./providers/TrailsProvider.js"
|
|
172
|
-
import { useTrailsModal } from "./providers/TrailsModalProvider.js"
|
|
173
|
-
import {
|
|
174
|
-
useViewManager,
|
|
175
|
-
useNavigationEffect,
|
|
176
|
-
useScreenGuard,
|
|
177
|
-
getInitialScreen,
|
|
178
|
-
type Screen,
|
|
179
|
-
type Mode,
|
|
180
|
-
} from "./hooks/useViewManager.js"
|
|
181
|
-
import PaymentMethods from "./components/PaymentMethods.js"
|
|
182
|
-
import type { OnrampQuote } from "./hooks/useOnRampQuote.js"
|
|
183
|
-
import {
|
|
184
|
-
addressEqual,
|
|
185
|
-
isNativeToken,
|
|
186
|
-
normalizeAddress,
|
|
187
|
-
} from "../utils/address.js"
|
|
188
|
-
import { isWalletConnectConnector } from "../walletUtils.js"
|
|
189
|
-
import type { SendOptions, SwapReturn } from "./hooks/useQuote.js"
|
|
190
|
-
import { hasAnyFailedOrAbortedTransactions } from "./utils/transactionFailure.js"
|
|
191
|
-
import {
|
|
192
|
-
shouldClearTransferFlowOnNavigate,
|
|
193
|
-
shouldRedirectToConnect,
|
|
194
|
-
} from "./utils/viewManagerGuards.js"
|
|
195
|
-
import type { FundMethod } from "../transactionIntent/types.js"
|
|
196
|
-
import { isExternalFundingMethod } from "../transactionIntent/types.js"
|
|
197
|
-
|
|
198
|
-
// Validate toToken - must be "ETH", "USDC", or a valid hex address
|
|
199
|
-
const isValidToToToken = (toToken: string | null | undefined) => {
|
|
200
|
-
if (toToken === null || toToken === undefined || toToken === "") {
|
|
201
|
-
return true // Empty values are considered valid
|
|
202
|
-
}
|
|
203
|
-
const token = String(toToken).trim()
|
|
204
|
-
if (token?.length > 0 && token?.length <= 5) {
|
|
205
|
-
return true
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return isAddress(token)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export type FundMethodListOption =
|
|
212
|
-
| "connected-wallet"
|
|
213
|
-
| "crypto-transfer"
|
|
214
|
-
| "cc-onramp"
|
|
215
|
-
| "exchange"
|
|
216
|
-
| "exchange-onramp"
|
|
217
|
-
|
|
218
|
-
export const WidgetFundMethod = {
|
|
219
|
-
Wallet: "wallet",
|
|
220
|
-
CryptoTransfer: "crypto-transfer",
|
|
221
|
-
Onramp: "onramp",
|
|
222
|
-
OnrampExchange: "onramp-exchange",
|
|
223
|
-
} as const
|
|
224
|
-
export type WidgetFundMethod =
|
|
225
|
-
(typeof WidgetFundMethod)[keyof typeof WidgetFundMethod]
|
|
226
|
-
|
|
227
|
-
export type TrailsWidgetProps = {
|
|
228
|
-
apiKey: string
|
|
229
|
-
sequenceIndexerUrl?: string
|
|
230
|
-
trailsApiUrl?: string
|
|
231
|
-
trailsAppUrl?: string
|
|
232
|
-
sequenceNodeGatewayUrl?: string
|
|
233
|
-
sequenceMetadataUrl?: string
|
|
234
|
-
sequenceApiUrl?: string
|
|
235
|
-
toAddress?: string | null
|
|
236
|
-
toAmount?: string | null
|
|
237
|
-
/** Controlled destination chain, user cannot change selection */
|
|
238
|
-
toChainId?: number | string | null
|
|
239
|
-
/** Controlled destination token, user cannot change selection */
|
|
240
|
-
toToken?: string | null
|
|
241
|
-
/** Default destination chain, user can change selection */
|
|
242
|
-
defaultToChainId?: number | string | null
|
|
243
|
-
/** Default destination token, user can change selection */
|
|
244
|
-
defaultToToken?: string | null
|
|
245
|
-
/** Default input mode for fund/withdraw modes: "fiat" starts with USD input, "token" starts with token input */
|
|
246
|
-
defaultInputMode?: "fiat" | "token"
|
|
247
|
-
toCalldata?: string | null
|
|
248
|
-
fromChainId?: number | string | null
|
|
249
|
-
fromToken?: string | null
|
|
250
|
-
fromAccount?: string | null
|
|
251
|
-
children?: React.ReactNode
|
|
252
|
-
renderInline?: boolean
|
|
253
|
-
theme?: Theme
|
|
254
|
-
mode?: Mode
|
|
255
|
-
/**
|
|
256
|
-
* Pre-select funding method used by the widget.
|
|
257
|
-
*
|
|
258
|
-
* This applies across modes (fund/pay/swap/earn) wherever funding method is used.
|
|
259
|
-
* In fund mode it also controls the initial destination flow:
|
|
260
|
-
* - "wallet" -> Funding with wallet flow
|
|
261
|
-
* - "crypto-transfer" --> Funding with QR Code or deposit to address flow
|
|
262
|
-
* - "onramp" --> Funding with onramp flow
|
|
263
|
-
* - "onramp-exchange" --> Funding with exchange flow
|
|
264
|
-
*/
|
|
265
|
-
fundMethod?: WidgetFundMethod
|
|
266
|
-
walletOptions?: string[]
|
|
267
|
-
onOriginConfirmation?: (data: {
|
|
268
|
-
txHash: string
|
|
269
|
-
chainId: number
|
|
270
|
-
sessionId: string
|
|
271
|
-
}) => void
|
|
272
|
-
onDestinationConfirmation?: (data: {
|
|
273
|
-
txHash: string
|
|
274
|
-
chainId: number
|
|
275
|
-
sessionId: string
|
|
276
|
-
}) => void
|
|
277
|
-
onCheckoutStart?: (data: { sessionId: string }) => void
|
|
278
|
-
onCheckoutQuote?: (data: {
|
|
279
|
-
sessionId: string
|
|
280
|
-
quote: PrepareSendQuote
|
|
281
|
-
}) => void
|
|
282
|
-
onCheckoutSignatureRequest?: (data: { sessionId: string }) => void
|
|
283
|
-
onCheckoutSignatureConfirmed?: (data: { sessionId: string }) => void
|
|
284
|
-
onCheckoutSignatureRejected?: (data: {
|
|
285
|
-
sessionId: string
|
|
286
|
-
error: unknown
|
|
287
|
-
}) => void
|
|
288
|
-
onCheckoutComplete?: (data: { sessionId: string }) => void
|
|
289
|
-
onCheckoutError?: (data: { sessionId: string; error: unknown }) => void
|
|
290
|
-
onCheckoutStatusUpdate?: (data: {
|
|
291
|
-
sessionId: string
|
|
292
|
-
transactionStates: TransactionState[]
|
|
293
|
-
}) => void
|
|
294
|
-
onCheckoutApprovalRequest?: (data: { sessionId: string }) => void
|
|
295
|
-
onCheckoutApprovalConfirmed?: (data: {
|
|
296
|
-
sessionId: string
|
|
297
|
-
transactionHash: `0x${string}`
|
|
298
|
-
}) => void
|
|
299
|
-
onCheckoutApprovalRejected?: (data: {
|
|
300
|
-
sessionId: string
|
|
301
|
-
error: unknown
|
|
302
|
-
}) => void
|
|
303
|
-
onOpen?: () => void
|
|
304
|
-
onClose?: () => void
|
|
305
|
-
|
|
306
|
-
walletConnectProjectId?: string
|
|
307
|
-
paymasterUrls?: Array<{ chainId: number; url: string }>
|
|
308
|
-
buttonText?: string
|
|
309
|
-
customCss?: string | Record<string, string>
|
|
310
|
-
disableCss?: boolean
|
|
311
|
-
swapProvider?: string
|
|
312
|
-
bridgeProvider?: string
|
|
313
|
-
swapProviderFallback?: boolean
|
|
314
|
-
bridgeProviderFallback?: boolean
|
|
315
|
-
slippageTolerance?: number | string
|
|
316
|
-
priceImpactWarningThresholdBps?: number
|
|
317
|
-
priceImpactWarningMessage?: string
|
|
318
|
-
priceImpactFallbackBridgeUrl?: string
|
|
319
|
-
decoupleWagmi?: boolean
|
|
320
|
-
wagmiConnectors?: Connector[]
|
|
321
|
-
debug?: boolean
|
|
322
|
-
hideDisconnect?: boolean
|
|
323
|
-
hideAddWallet?: boolean
|
|
324
|
-
/** Options for customizing fund mode behavior */
|
|
325
|
-
fundOptions?: {
|
|
326
|
-
/** Hide the Swap button in the fund screen header. Default: false */
|
|
327
|
-
hideSwap?: boolean
|
|
328
|
-
/** Array of wallet addresses to hide from the funding wallet selection. */
|
|
329
|
-
hideWallets?: string[]
|
|
330
|
-
/**
|
|
331
|
-
* Ordered list of funding methods to display.
|
|
332
|
-
*
|
|
333
|
-
* Supported readable values (mapped internally):
|
|
334
|
-
* - "connected-wallet"
|
|
335
|
-
* - "crypto-transfer"
|
|
336
|
-
* - "cc-onramp"
|
|
337
|
-
* - "exchange"
|
|
338
|
-
*
|
|
339
|
-
* Preferred values: "connected-wallet", "crypto-transfer", "exchange", "cc-onramp".
|
|
340
|
-
* Legacy alias "exchange-onramp" is still accepted.
|
|
341
|
-
*
|
|
342
|
-
* @example ["connected-wallet", "crypto-transfer"]
|
|
343
|
-
*/
|
|
344
|
-
fundMethodsList?: FundMethodListOption[]
|
|
345
|
-
/**
|
|
346
|
-
* If true, methods not in fundMethodsList are hidden.
|
|
347
|
-
*
|
|
348
|
-
* If false (default), unlisted methods are shown but disabled.
|
|
349
|
-
*
|
|
350
|
-
* Default: false.
|
|
351
|
-
*/
|
|
352
|
-
hideUnlistedFundMethods?: boolean
|
|
353
|
-
/** ISO 4217 currency code to pre-select in onramp mode (e.g. "EUR", "GBP") */
|
|
354
|
-
fiatCurrency?: string
|
|
355
|
-
/** Fiat amount to pre-populate in onramp mode */
|
|
356
|
-
fiatAmount?: string
|
|
357
|
-
}
|
|
358
|
-
toast?: boolean
|
|
359
|
-
appName?: string
|
|
360
|
-
appUrl?: string
|
|
361
|
-
appImageUrl?: string
|
|
362
|
-
appDescription?: string
|
|
363
|
-
payMessage?: string
|
|
364
|
-
isSmartWallet?: boolean
|
|
365
|
-
/**
|
|
366
|
-
* Optional onramp configuration or factory.
|
|
367
|
-
* If provided, enables exchange funding options in the widget.
|
|
368
|
-
*
|
|
369
|
-
* @example
|
|
370
|
-
* ```tsx
|
|
371
|
-
* <TrailsWidget
|
|
372
|
-
* onramp={{
|
|
373
|
-
* mesh: {
|
|
374
|
-
* environment: "production",
|
|
375
|
-
* },
|
|
376
|
-
* }}
|
|
377
|
-
* />
|
|
378
|
-
* ```
|
|
379
|
-
*/
|
|
380
|
-
onramp?:
|
|
381
|
-
| TrailsOnRampConfig
|
|
382
|
-
| ((handlers: {
|
|
383
|
-
setCurrentScreen: (screen: Screen) => void
|
|
384
|
-
onComplete?: (transferData: OnrampTransferResult) => void
|
|
385
|
-
onError?: (error: unknown) => void
|
|
386
|
-
onBack?: () => void
|
|
387
|
-
toTokenSymbol?: string
|
|
388
|
-
toTokenAmount?: string
|
|
389
|
-
toChainId?: number
|
|
390
|
-
toRecipientAddress?: string
|
|
391
|
-
toAmountUsd?: number
|
|
392
|
-
selectedExchange?: {
|
|
393
|
-
integrationId: string
|
|
394
|
-
exchangeKey: string
|
|
395
|
-
exchangeName: string
|
|
396
|
-
}
|
|
397
|
-
apiKey?: string
|
|
398
|
-
hostname?: string
|
|
399
|
-
}) => React.ReactElement)
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
export interface TrailsWidgetRef {
|
|
403
|
-
openModal: () => void
|
|
404
|
-
closeModal: () => void
|
|
405
|
-
isModalOpen: boolean
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// Create a custom hook for wallet management
|
|
409
|
-
const useWalletManager = (
|
|
410
|
-
address: string | undefined,
|
|
411
|
-
chainId: number | undefined,
|
|
412
|
-
connector: Connector | undefined,
|
|
413
|
-
) => {
|
|
414
|
-
const [walletClient, setWalletClient] = useState<WalletClient | null>(null)
|
|
415
|
-
|
|
416
|
-
useEffect(() => {
|
|
417
|
-
const connectWallet = async () => {
|
|
418
|
-
try {
|
|
419
|
-
if (!connector) {
|
|
420
|
-
return
|
|
421
|
-
}
|
|
422
|
-
if (typeof connector?.getProvider !== "function") {
|
|
423
|
-
return
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
const activeProvider =
|
|
427
|
-
(await connector.getProvider()) as EIP1193Provider
|
|
428
|
-
|
|
429
|
-
if (activeProvider && address && chainId) {
|
|
430
|
-
// Validate that the provider's accounts include the expected address
|
|
431
|
-
// This helps detect EIP-6963 multi-wallet mismatches where the wrong provider is used
|
|
432
|
-
try {
|
|
433
|
-
const providerAccounts = await activeProvider.request({
|
|
434
|
-
method: "eth_accounts",
|
|
435
|
-
})
|
|
436
|
-
const normalizedAddress = normalizeAddress(address)
|
|
437
|
-
const hasMatchingAccount = providerAccounts?.some(
|
|
438
|
-
(acc: string) => acc.toLowerCase() === normalizedAddress,
|
|
439
|
-
)
|
|
440
|
-
if (!hasMatchingAccount && providerAccounts?.length > 0) {
|
|
441
|
-
logger.console.warn(
|
|
442
|
-
`[trails-sdk] Provider mismatch detected: expected address ${address} not found in provider accounts. ` +
|
|
443
|
-
`Connector: ${connector.name}, Provider accounts: ${providerAccounts.join(", ")}. ` +
|
|
444
|
-
`This may indicate multiple wallet extensions are conflicting.`,
|
|
445
|
-
)
|
|
446
|
-
// Log additional EIP-6963 info if available
|
|
447
|
-
const connectorInfo = (connector as EIP6963Connector)?.info
|
|
448
|
-
if (connectorInfo?.rdns) {
|
|
449
|
-
logger.console.warn(
|
|
450
|
-
`[trails-sdk] Connector RDNS: ${connectorInfo.rdns}`,
|
|
451
|
-
)
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
} catch (accountsError) {
|
|
455
|
-
// eth_accounts may fail on some providers, continue anyway
|
|
456
|
-
logger.console.debug(
|
|
457
|
-
"[trails-sdk] Could not verify provider accounts:",
|
|
458
|
-
accountsError,
|
|
459
|
-
)
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
let chain = getChainInfo(chainId)
|
|
463
|
-
|
|
464
|
-
// If chain is not supported, create a minimal chain object.
|
|
465
|
-
// This allows walletClient to be created even on unsupported networks.
|
|
466
|
-
// The Problem:
|
|
467
|
-
// When Metamask is on a network not supported by the wagmi config, useWalletManager
|
|
468
|
-
// in widget.tsx calls getChainInfo(chainId), which returns null for unsupported chains.
|
|
469
|
-
// The function then returns early without creating a walletClient, so walletClient?.account is undefined,
|
|
470
|
-
// causing the "Connect your wallet" message in the button.
|
|
471
|
-
if (!chain) {
|
|
472
|
-
logger.console.warn(
|
|
473
|
-
`[trails-sdk] Chain ${chainId} not found in supported chains, creating minimal chain object`,
|
|
474
|
-
)
|
|
475
|
-
// Create a minimal chain definition for unsupported chains
|
|
476
|
-
chain = defineChain({
|
|
477
|
-
id: chainId,
|
|
478
|
-
name: `Chain ${chainId}`,
|
|
479
|
-
nativeCurrency: {
|
|
480
|
-
name: "Ether",
|
|
481
|
-
symbol: "ETH",
|
|
482
|
-
decimals: 18,
|
|
483
|
-
},
|
|
484
|
-
rpcUrls: {
|
|
485
|
-
default: {
|
|
486
|
-
http: [],
|
|
487
|
-
},
|
|
488
|
-
},
|
|
489
|
-
}) as Chain
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
const client = createWalletClient({
|
|
493
|
-
account: address as `0x${string}`,
|
|
494
|
-
chain,
|
|
495
|
-
transport: custom(activeProvider),
|
|
496
|
-
})
|
|
497
|
-
|
|
498
|
-
setWalletClient(client)
|
|
499
|
-
}
|
|
500
|
-
} catch (error) {
|
|
501
|
-
logger.console.error("[trails-sdk] Failed to connect wallet", error)
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
connectWallet().catch(logger.console.error)
|
|
505
|
-
}, [address, chainId, connector])
|
|
506
|
-
|
|
507
|
-
return walletClient
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// Create a custom hook for transaction state management
|
|
511
|
-
const useTransactionState = (
|
|
512
|
-
onOriginConfirmation?: (data: {
|
|
513
|
-
txHash: string
|
|
514
|
-
chainId: number
|
|
515
|
-
sessionId: string
|
|
516
|
-
}) => void,
|
|
517
|
-
onDestinationConfirmation?: (data: {
|
|
518
|
-
txHash: string
|
|
519
|
-
chainId: number
|
|
520
|
-
sessionId: string
|
|
521
|
-
}) => void,
|
|
522
|
-
onComplete?: (result: OnCompleteProps) => void,
|
|
523
|
-
) => {
|
|
524
|
-
const [originTxHash, setOriginTxHash] = useState("")
|
|
525
|
-
const [originChainId, setOriginChainId] = useState<number | null>(null)
|
|
526
|
-
const [destinationTxHash, setDestinationTxHash] = useState("")
|
|
527
|
-
const [destinationChainId, setDestinationChainId] = useState<number | null>(
|
|
528
|
-
null,
|
|
529
|
-
)
|
|
530
|
-
const [transactionStates, setTransactionStates] = useState<
|
|
531
|
-
TransactionState[]
|
|
532
|
-
>([])
|
|
533
|
-
|
|
534
|
-
// Add flags to prevent duplicate callback calls
|
|
535
|
-
const [originConfirmationCalled, setOriginConfirmationCalled] =
|
|
536
|
-
useState(false)
|
|
537
|
-
const [destinationConfirmationCalled, setDestinationConfirmationCalled] =
|
|
538
|
-
useState(false)
|
|
539
|
-
|
|
540
|
-
useEffect(() => {
|
|
541
|
-
if (
|
|
542
|
-
onOriginConfirmation &&
|
|
543
|
-
originTxHash &&
|
|
544
|
-
originChainId &&
|
|
545
|
-
!originConfirmationCalled
|
|
546
|
-
) {
|
|
547
|
-
try {
|
|
548
|
-
onOriginConfirmation({
|
|
549
|
-
txHash: originTxHash,
|
|
550
|
-
chainId: originChainId,
|
|
551
|
-
sessionId: getSessionId(),
|
|
552
|
-
})
|
|
553
|
-
} catch (error) {
|
|
554
|
-
logger.console.error(
|
|
555
|
-
"[trails-sdk] Error calling onOriginConfirmation:",
|
|
556
|
-
error,
|
|
557
|
-
)
|
|
558
|
-
}
|
|
559
|
-
setOriginConfirmationCalled(true)
|
|
560
|
-
}
|
|
561
|
-
}, [
|
|
562
|
-
originTxHash,
|
|
563
|
-
originChainId,
|
|
564
|
-
originConfirmationCalled,
|
|
565
|
-
onOriginConfirmation,
|
|
566
|
-
])
|
|
567
|
-
|
|
568
|
-
useEffect(() => {
|
|
569
|
-
if (
|
|
570
|
-
onDestinationConfirmation &&
|
|
571
|
-
destinationTxHash &&
|
|
572
|
-
destinationChainId &&
|
|
573
|
-
!destinationConfirmationCalled
|
|
574
|
-
) {
|
|
575
|
-
try {
|
|
576
|
-
onDestinationConfirmation({
|
|
577
|
-
txHash: destinationTxHash,
|
|
578
|
-
chainId: destinationChainId,
|
|
579
|
-
sessionId: getSessionId(),
|
|
580
|
-
})
|
|
581
|
-
} catch (error) {
|
|
582
|
-
logger.console.error(
|
|
583
|
-
"[trails-sdk] Error calling onDestinationConfirmation:",
|
|
584
|
-
error,
|
|
585
|
-
)
|
|
586
|
-
}
|
|
587
|
-
setDestinationConfirmationCalled(true)
|
|
588
|
-
}
|
|
589
|
-
}, [
|
|
590
|
-
destinationTxHash,
|
|
591
|
-
destinationChainId,
|
|
592
|
-
destinationConfirmationCalled,
|
|
593
|
-
onDestinationConfirmation,
|
|
594
|
-
])
|
|
595
|
-
|
|
596
|
-
// Monitor transaction states for completion - this runs regardless of which screen is active
|
|
597
|
-
useEffect(() => {
|
|
598
|
-
if (!transactionStates || transactionStates.length === 0) return
|
|
599
|
-
|
|
600
|
-
const allConfirmed = transactionStates.every(
|
|
601
|
-
(tx: TransactionState) => tx.state === "confirmed",
|
|
602
|
-
)
|
|
603
|
-
|
|
604
|
-
if (allConfirmed && onComplete) {
|
|
605
|
-
logger.console.log(
|
|
606
|
-
"[trails-sdk] All transactions confirmed, triggering completion",
|
|
607
|
-
)
|
|
608
|
-
|
|
609
|
-
// All transactions are confirmed, trigger completion
|
|
610
|
-
onComplete({
|
|
611
|
-
transactionStates: transactionStates,
|
|
612
|
-
})
|
|
613
|
-
}
|
|
614
|
-
}, [transactionStates, onComplete])
|
|
615
|
-
|
|
616
|
-
// Create enhanced setters that also reset confirmation flags
|
|
617
|
-
const resetOriginTxHash = useCallback((txHash: string) => {
|
|
618
|
-
setOriginTxHash(txHash)
|
|
619
|
-
if (txHash === "") {
|
|
620
|
-
setOriginConfirmationCalled(false)
|
|
621
|
-
}
|
|
622
|
-
}, [])
|
|
623
|
-
|
|
624
|
-
const resetDestinationTxHash = useCallback((txHash: string) => {
|
|
625
|
-
setDestinationTxHash(txHash)
|
|
626
|
-
if (txHash === "") {
|
|
627
|
-
setDestinationConfirmationCalled(false)
|
|
628
|
-
}
|
|
629
|
-
}, [])
|
|
630
|
-
|
|
631
|
-
return {
|
|
632
|
-
originTxHash,
|
|
633
|
-
setOriginTxHash: resetOriginTxHash,
|
|
634
|
-
originChainId,
|
|
635
|
-
setOriginChainId,
|
|
636
|
-
destinationTxHash,
|
|
637
|
-
setDestinationTxHash: resetDestinationTxHash,
|
|
638
|
-
destinationChainId,
|
|
639
|
-
setDestinationChainId,
|
|
640
|
-
transactionStates,
|
|
641
|
-
setTransactionStates,
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
const WidgetContent = forwardRef<TrailsWidgetRef>((_, ref) => {
|
|
646
|
-
const {
|
|
647
|
-
toAddress,
|
|
648
|
-
toAmount,
|
|
649
|
-
toChainId,
|
|
650
|
-
toToken,
|
|
651
|
-
toCalldata,
|
|
652
|
-
fromToken,
|
|
653
|
-
fromChainId,
|
|
654
|
-
fromAccount,
|
|
655
|
-
children,
|
|
656
|
-
renderInline = false,
|
|
657
|
-
onOriginConfirmation,
|
|
658
|
-
onDestinationConfirmation,
|
|
659
|
-
onCheckoutStart,
|
|
660
|
-
onCheckoutQuote,
|
|
661
|
-
onCheckoutSignatureRequest,
|
|
662
|
-
onCheckoutSignatureConfirmed,
|
|
663
|
-
onCheckoutSignatureRejected,
|
|
664
|
-
onCheckoutApprovalRequest,
|
|
665
|
-
onCheckoutApprovalConfirmed,
|
|
666
|
-
onCheckoutApprovalRejected,
|
|
667
|
-
onCheckoutComplete,
|
|
668
|
-
onCheckoutError,
|
|
669
|
-
onCheckoutStatusUpdate,
|
|
670
|
-
onOpen,
|
|
671
|
-
onClose,
|
|
672
|
-
paymasterUrls,
|
|
673
|
-
buttonText,
|
|
674
|
-
swapProvider,
|
|
675
|
-
bridgeProvider,
|
|
676
|
-
swapProviderFallback,
|
|
677
|
-
bridgeProviderFallback,
|
|
678
|
-
priceImpactWarningThresholdBps,
|
|
679
|
-
priceImpactWarningMessage,
|
|
680
|
-
priceImpactFallbackBridgeUrl,
|
|
681
|
-
decoupleWagmi,
|
|
682
|
-
hideDisconnect,
|
|
683
|
-
defaultInputMode,
|
|
684
|
-
fundMethod: configuredFundMethod,
|
|
685
|
-
} = useWidgetProps()
|
|
686
|
-
const { address, chainId, connector } = useAccount()
|
|
687
|
-
const connectors = useConnectors()
|
|
688
|
-
const { trailsApiKey, trailsApiUrl } = useTrails()
|
|
689
|
-
const onrampClient = useOnrampClient()
|
|
690
|
-
const qrCodeWallets = useMemo(() => getQRCodeWallets(), [])
|
|
691
|
-
// const { setOpenConnectModal } = useOpenConnectModal()
|
|
692
|
-
|
|
693
|
-
// Check if the current connector is a Sequence wallet
|
|
694
|
-
const isSequenceWallet = useIsSequenceWallet()
|
|
695
|
-
const connections = useConnections()
|
|
696
|
-
const { disconnectAsync } = useDisconnect()
|
|
697
|
-
const { switchAccount } = useSwitchAccount()
|
|
698
|
-
|
|
699
|
-
// Check if there are any connected accounts across all connectors
|
|
700
|
-
const isConnected = connections.length > 0
|
|
701
|
-
const { recentTokens, addRecentToken } = useRecentTokens(address)
|
|
702
|
-
const { wallets: allWallets } = useWallets()
|
|
703
|
-
const { selectedToken, setSelectedToken, clearSelectedToken } =
|
|
704
|
-
useSelectedToken()
|
|
705
|
-
const { onramp } = useWidgetProps()
|
|
706
|
-
const meshOnrampConfig = getWidgetOnrampConfig(onramp)
|
|
707
|
-
const onrampFactory: OnrampFactory | undefined =
|
|
708
|
-
typeof onramp === "function"
|
|
709
|
-
? (onramp as OnrampFactory)
|
|
710
|
-
: meshOnrampConfig
|
|
711
|
-
? trailsOnramp({ config: meshOnrampConfig })
|
|
712
|
-
: undefined
|
|
713
|
-
const meshEnvironment = meshOnrampConfig?.mesh?.environment ?? "production"
|
|
714
|
-
|
|
715
|
-
// Modal state is managed by TrailsModalProvider
|
|
716
|
-
const {
|
|
717
|
-
isModalOpen,
|
|
718
|
-
openModal: openTrailsModal,
|
|
719
|
-
closeModal: closeTrailsModal,
|
|
720
|
-
setHandleCloseModal,
|
|
721
|
-
pendingSelection,
|
|
722
|
-
setPendingSelection,
|
|
723
|
-
hostTransactionState,
|
|
724
|
-
setHostTransactionState,
|
|
725
|
-
hostTransactionQuote,
|
|
726
|
-
hostTransactionStates,
|
|
727
|
-
hostTransactionTimestamp,
|
|
728
|
-
resetHostTransactionState,
|
|
729
|
-
receiptActionButtonText,
|
|
730
|
-
onReceiptAction,
|
|
731
|
-
retryTransactionRef,
|
|
732
|
-
} = useTrailsModal()
|
|
733
|
-
|
|
734
|
-
// Hook for creating onramp widget sessions
|
|
735
|
-
const { createWidgetSession } = useOnRampProviderWidget()
|
|
736
|
-
|
|
737
|
-
const { trackWalletDisconnected: trackWalletDisconnectedEvent } =
|
|
738
|
-
useWidgetAnalytics({
|
|
739
|
-
address,
|
|
740
|
-
chainId,
|
|
741
|
-
connectorName: connector?.name,
|
|
742
|
-
})
|
|
743
|
-
|
|
744
|
-
// Monitor account disconnections
|
|
745
|
-
useAccountEffect({
|
|
746
|
-
onDisconnect() {
|
|
747
|
-
logger.console.log(
|
|
748
|
-
"[trails-sdk] [TrailsWidget] account disconnected via useAccountEffect",
|
|
749
|
-
)
|
|
750
|
-
logger.console.log(
|
|
751
|
-
"[trails-sdk] [TrailsWidget] window.ethereum exists:",
|
|
752
|
-
!!window.ethereum,
|
|
753
|
-
)
|
|
754
|
-
},
|
|
755
|
-
onConnect(data) {
|
|
756
|
-
logger.console.log(
|
|
757
|
-
"[trails-sdk] [TrailsWidget] account connected via useAccountEffect",
|
|
758
|
-
data,
|
|
759
|
-
)
|
|
760
|
-
},
|
|
761
|
-
})
|
|
762
|
-
|
|
763
|
-
// Handle fromAccount preselection
|
|
764
|
-
const hasInitializedFromAccount = useRef(false)
|
|
765
|
-
useEffect(() => {
|
|
766
|
-
if (hasInitializedFromAccount.current) return
|
|
767
|
-
if (!fromAccount) return
|
|
768
|
-
if (!connections.length) return
|
|
769
|
-
|
|
770
|
-
// Check if fromAccount is already the active account
|
|
771
|
-
if (address && addressEqual(address, fromAccount)) {
|
|
772
|
-
hasInitializedFromAccount.current = true
|
|
773
|
-
return
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
// Find the connector that has the fromAccount
|
|
777
|
-
const targetConnection = connections.find((conn) =>
|
|
778
|
-
conn.accounts.some((acc) => addressEqual(acc, fromAccount)),
|
|
779
|
-
)
|
|
780
|
-
|
|
781
|
-
if (targetConnection) {
|
|
782
|
-
logger.console.log(
|
|
783
|
-
"[trails-sdk] [TrailsWidget] Switching to fromAccount:",
|
|
784
|
-
fromAccount,
|
|
785
|
-
"via connector:",
|
|
786
|
-
targetConnection.connector.name,
|
|
787
|
-
)
|
|
788
|
-
|
|
789
|
-
// Switch to the target account
|
|
790
|
-
switchAccount({
|
|
791
|
-
connector: targetConnection.connector,
|
|
792
|
-
})
|
|
793
|
-
hasInitializedFromAccount.current = true
|
|
794
|
-
} else {
|
|
795
|
-
logger.console.log(
|
|
796
|
-
"[trails-sdk] [TrailsWidget] fromAccount not found in connected wallets:",
|
|
797
|
-
fromAccount,
|
|
798
|
-
)
|
|
799
|
-
}
|
|
800
|
-
}, [fromAccount, connections, address, switchAccount])
|
|
801
|
-
|
|
802
|
-
useEffect(() => {
|
|
803
|
-
logger.console.log(
|
|
804
|
-
"[trails-sdk] [TrailsWidget] isModalOpen changed:",
|
|
805
|
-
isModalOpen,
|
|
806
|
-
)
|
|
807
|
-
}, [isModalOpen])
|
|
808
|
-
const {
|
|
809
|
-
mode: currentMode,
|
|
810
|
-
configuredMode,
|
|
811
|
-
resetMode,
|
|
812
|
-
screen,
|
|
813
|
-
navigate,
|
|
814
|
-
goBack,
|
|
815
|
-
goHome,
|
|
816
|
-
canGoBack,
|
|
817
|
-
backScreen,
|
|
818
|
-
state,
|
|
819
|
-
} = useViewManager()
|
|
820
|
-
const { setSellAmount, setBuyAmount } = useSwapState()
|
|
821
|
-
|
|
822
|
-
// Abort in-flight requests when navigating away from transfer screens.
|
|
823
|
-
useNavigationEffect(({ from, to }) => {
|
|
824
|
-
if (shouldClearTransferFlowOnNavigate(from, to)) {
|
|
825
|
-
abortControllerRegistry.abortAll()
|
|
826
|
-
setPrepareSendQuote(null)
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
if (to === "fund-methods") {
|
|
830
|
-
fundMethodSelectionStartRef.current = selectedFundMethod
|
|
831
|
-
}
|
|
832
|
-
})
|
|
833
|
-
const {
|
|
834
|
-
connectionContext,
|
|
835
|
-
clearConnectionContext,
|
|
836
|
-
isRecipientSelection,
|
|
837
|
-
isFundMethodSelection,
|
|
838
|
-
} = useWalletConnectionContext()
|
|
839
|
-
const { setSelectedRecipient } = useSelectedRecipient()
|
|
840
|
-
|
|
841
|
-
// Wrapper function that clears errors when going back
|
|
842
|
-
const handleBack = () => {
|
|
843
|
-
setError(null)
|
|
844
|
-
if (canGoBack) goBack()
|
|
845
|
-
else goHome()
|
|
846
|
-
}
|
|
847
|
-
const [previousAddress, setPreviousAddress] = useState<string | undefined>(
|
|
848
|
-
address,
|
|
849
|
-
)
|
|
850
|
-
const {
|
|
851
|
-
selectedFundMethod,
|
|
852
|
-
selectedMeshExchange,
|
|
853
|
-
setSelectedFundMethod,
|
|
854
|
-
setSelectedMeshExchange,
|
|
855
|
-
} = useSelectedFundMethod()
|
|
856
|
-
const fundMethodSelectionStartRef = useRef(selectedFundMethod)
|
|
857
|
-
const clearStateForFundMethodSwitch = useCallback(
|
|
858
|
-
(nextMethod: typeof selectedFundMethod) => {
|
|
859
|
-
const previousMethod = fundMethodSelectionStartRef.current
|
|
860
|
-
const didSwitchMethods = clearFundStateForMethodSwitch(
|
|
861
|
-
previousMethod,
|
|
862
|
-
nextMethod,
|
|
863
|
-
{
|
|
864
|
-
clearSelectedToken,
|
|
865
|
-
setSellAmount,
|
|
866
|
-
setBuyAmount,
|
|
867
|
-
setPrepareSendQuote,
|
|
868
|
-
setSelectedMeshExchange,
|
|
869
|
-
},
|
|
870
|
-
)
|
|
871
|
-
|
|
872
|
-
if (didSwitchMethods) {
|
|
873
|
-
fundMethodSelectionStartRef.current = nextMethod
|
|
874
|
-
}
|
|
875
|
-
},
|
|
876
|
-
[clearSelectedToken, setSellAmount, setBuyAmount, setSelectedMeshExchange],
|
|
877
|
-
)
|
|
878
|
-
const { selectedPool, setSelectedPool } = useEarnPool()
|
|
879
|
-
const [selectedWalletId, setSelectedWalletId] = useState<string | null>(
|
|
880
|
-
() => {
|
|
881
|
-
// Initialize from localStorage if available
|
|
882
|
-
if (typeof window !== "undefined") {
|
|
883
|
-
try {
|
|
884
|
-
return localStorage.getItem("trails-last-wallet") || null
|
|
885
|
-
} catch (error) {
|
|
886
|
-
logger.console.error(
|
|
887
|
-
"[trails-sdk] Failed to read from localStorage:",
|
|
888
|
-
error,
|
|
889
|
-
)
|
|
890
|
-
return null
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
return null
|
|
894
|
-
},
|
|
895
|
-
)
|
|
896
|
-
const [isConnecting, setIsConnecting] = useState(false)
|
|
897
|
-
const [showWalletConnectionRetry, setShowWalletConnectionRetry] =
|
|
898
|
-
useState(false)
|
|
899
|
-
const [generatedCalldata, setGeneratedCalldata] = useState<
|
|
900
|
-
string | undefined
|
|
901
|
-
>(undefined)
|
|
902
|
-
const [error, setError] = useState<string | null>(null)
|
|
903
|
-
const [prepareSendQuote, setPrepareSendQuote] =
|
|
904
|
-
useState<PrepareSendQuote | null>(null)
|
|
905
|
-
const [onrampProviderQuote, setOnrampProviderQuote] =
|
|
906
|
-
useState<OnrampQuote | null>(null)
|
|
907
|
-
|
|
908
|
-
// Store widget creation parameters for retry functionality
|
|
909
|
-
const [widgetCreationParams, setWidgetCreationParams] = useState<{
|
|
910
|
-
depositAddress: string
|
|
911
|
-
userAddress: string
|
|
912
|
-
countryCode: string
|
|
913
|
-
sourceCurrencyCode: string
|
|
914
|
-
sourceAmount: string
|
|
915
|
-
destinationCurrencyCode: string
|
|
916
|
-
serviceProvider: string
|
|
917
|
-
paymentMethodType?: string
|
|
918
|
-
} | null>(null)
|
|
919
|
-
|
|
920
|
-
// Store external session ID for transaction status monitoring
|
|
921
|
-
const [externalSessionId, setExternalSessionId] = useState<string | null>(
|
|
922
|
-
null,
|
|
923
|
-
)
|
|
924
|
-
const [onrampPopupWindowRef, setOnrampPopupWindowRef] =
|
|
925
|
-
useState<Window | null>(null)
|
|
926
|
-
|
|
927
|
-
// Debug external session ID changes
|
|
928
|
-
useEffect(() => {
|
|
929
|
-
logger.console.log(
|
|
930
|
-
"[widget] externalSessionId state changed to:",
|
|
931
|
-
externalSessionId,
|
|
932
|
-
)
|
|
933
|
-
}, [externalSessionId])
|
|
934
|
-
const [qrCodeWalletId, setQrCodeWalletId] = useState<string | null>(null)
|
|
935
|
-
const [previousConnector, setPreviousConnector] = useState<Connector | null>(
|
|
936
|
-
null,
|
|
937
|
-
)
|
|
938
|
-
const [showWalletConfirmRetry, setShowWalletConfirmRetry] = useState(false)
|
|
939
|
-
const [walletConfirmRetryHandler, setWalletConfirmRetryHandler] = useState<
|
|
940
|
-
(() => Promise<void>) | null
|
|
941
|
-
>(null)
|
|
942
|
-
const [totalCompletionSeconds, setTotalCompletionSeconds] = useState<
|
|
943
|
-
number | null
|
|
944
|
-
>(null)
|
|
945
|
-
const { connectAsync } = useConnect()
|
|
946
|
-
|
|
947
|
-
const hasAppliedFundMethodNavigation = useRef<string | null>(null)
|
|
948
|
-
useEffect(() => {
|
|
949
|
-
const isWidgetActive = renderInline || isModalOpen
|
|
950
|
-
if (!isWidgetActive) {
|
|
951
|
-
hasAppliedFundMethodNavigation.current = null
|
|
952
|
-
}
|
|
953
|
-
}, [renderInline, isModalOpen])
|
|
954
|
-
|
|
955
|
-
useEffect(() => {
|
|
956
|
-
const isWidgetActive = renderInline || isModalOpen
|
|
957
|
-
if (!isWidgetActive) return
|
|
958
|
-
|
|
959
|
-
let mappedFundMethod: FundMethod | null = null
|
|
960
|
-
if (configuredFundMethod === WidgetFundMethod.Wallet) {
|
|
961
|
-
mappedFundMethod = "wallet"
|
|
962
|
-
} else if (configuredFundMethod === WidgetFundMethod.CryptoTransfer) {
|
|
963
|
-
mappedFundMethod = "direct-transfer"
|
|
964
|
-
} else if (
|
|
965
|
-
configuredFundMethod === WidgetFundMethod.Onramp &&
|
|
966
|
-
currentMode !== "pay" &&
|
|
967
|
-
currentMode !== "earn"
|
|
968
|
-
) {
|
|
969
|
-
mappedFundMethod = "onramp-meld"
|
|
970
|
-
} else if (
|
|
971
|
-
configuredFundMethod === WidgetFundMethod.OnrampExchange &&
|
|
972
|
-
currentMode !== "pay"
|
|
973
|
-
) {
|
|
974
|
-
mappedFundMethod = "onramp-mesh"
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
if (!mappedFundMethod) return
|
|
978
|
-
if (selectedFundMethod === mappedFundMethod) return
|
|
979
|
-
setSelectedFundMethod(mappedFundMethod)
|
|
980
|
-
}, [
|
|
981
|
-
configuredFundMethod,
|
|
982
|
-
selectedFundMethod,
|
|
983
|
-
setSelectedFundMethod,
|
|
984
|
-
renderInline,
|
|
985
|
-
isModalOpen,
|
|
986
|
-
currentMode,
|
|
987
|
-
])
|
|
988
|
-
|
|
989
|
-
useEffect(() => {
|
|
990
|
-
const isWidgetActive = renderInline || isModalOpen
|
|
991
|
-
if (!isWidgetActive) return
|
|
992
|
-
if (!isConnected) return
|
|
993
|
-
if (currentMode !== "fund") return
|
|
994
|
-
|
|
995
|
-
if (!configuredFundMethod) {
|
|
996
|
-
return
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
const navKey = `${configuredFundMethod}:${currentMode}:${isWidgetActive}`
|
|
1000
|
-
if (hasAppliedFundMethodNavigation.current === navKey) return
|
|
1001
|
-
hasAppliedFundMethodNavigation.current = navKey
|
|
1002
|
-
|
|
1003
|
-
if (configuredFundMethod === WidgetFundMethod.Onramp) {
|
|
1004
|
-
setSelectedFundMethod("onramp-meld")
|
|
1005
|
-
navigate("fund-form")
|
|
1006
|
-
} else if (configuredFundMethod === WidgetFundMethod.Wallet) {
|
|
1007
|
-
setSelectedFundMethod("wallet")
|
|
1008
|
-
navigate("tokens")
|
|
1009
|
-
} else if (configuredFundMethod === WidgetFundMethod.CryptoTransfer) {
|
|
1010
|
-
setSelectedFundMethod("direct-transfer")
|
|
1011
|
-
navigate("fund-form")
|
|
1012
|
-
} else if (configuredFundMethod === WidgetFundMethod.OnrampExchange) {
|
|
1013
|
-
setSelectedFundMethod("onramp-mesh")
|
|
1014
|
-
navigate("fund-form")
|
|
1015
|
-
}
|
|
1016
|
-
}, [
|
|
1017
|
-
currentMode,
|
|
1018
|
-
isConnected,
|
|
1019
|
-
configuredFundMethod,
|
|
1020
|
-
renderInline,
|
|
1021
|
-
isModalOpen,
|
|
1022
|
-
navigate,
|
|
1023
|
-
setSelectedFundMethod,
|
|
1024
|
-
])
|
|
1025
|
-
|
|
1026
|
-
useEffect(() => {
|
|
1027
|
-
if (!isConnected || screen !== "connect") return
|
|
1028
|
-
if (currentMode === "fund" && configuredFundMethod) return
|
|
1029
|
-
goHome()
|
|
1030
|
-
}, [isConnected, screen, currentMode, configuredFundMethod, goHome])
|
|
1031
|
-
|
|
1032
|
-
// Global wallet connection check — redirect to connect screen when disconnected
|
|
1033
|
-
useScreenGuard(shouldRedirectToConnect(isConnected, screen), "connect")
|
|
1034
|
-
|
|
1035
|
-
const modeToButtonText: Record<string, string> = {
|
|
1036
|
-
fund: "Fund",
|
|
1037
|
-
swap: "Swap",
|
|
1038
|
-
earn: "Earn",
|
|
1039
|
-
pay: "Pay",
|
|
1040
|
-
withdraw: "Withdraw",
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
const defaultButtonText = modeToButtonText[currentMode] ?? "Pay"
|
|
1044
|
-
|
|
1045
|
-
// Validate widget props from current props/mode only.
|
|
1046
|
-
const propValidationError = useMemo(() => {
|
|
1047
|
-
const isValidToAmount = isValidNumeric(toAmount)
|
|
1048
|
-
const isValidToChainId = isValidInteger(toChainId)
|
|
1049
|
-
const isValidToToken = isValidToToToken(toToken)
|
|
1050
|
-
const isValidToAddress = toAddress ? isAddress(toAddress) : true
|
|
1051
|
-
|
|
1052
|
-
// Validate paymasterUrls - each url must be a valid URL
|
|
1053
|
-
let isValidPaymasterUrls = true
|
|
1054
|
-
let invalidPaymasterUrl = ""
|
|
1055
|
-
if (paymasterUrls && Array.isArray(paymasterUrls)) {
|
|
1056
|
-
for (const paymaster of paymasterUrls) {
|
|
1057
|
-
try {
|
|
1058
|
-
new URL(paymaster.url)
|
|
1059
|
-
} catch {
|
|
1060
|
-
isValidPaymasterUrls = false
|
|
1061
|
-
invalidPaymasterUrl = paymaster.url
|
|
1062
|
-
break
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
if (
|
|
1068
|
-
isValidToAmount &&
|
|
1069
|
-
isValidToChainId &&
|
|
1070
|
-
isValidToToken &&
|
|
1071
|
-
isValidToAddress &&
|
|
1072
|
-
isValidPaymasterUrls
|
|
1073
|
-
) {
|
|
1074
|
-
return null
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
// Validate toAmount - must be numeric if provided
|
|
1078
|
-
if (!isValidToAmount) {
|
|
1079
|
-
logger.console.error(
|
|
1080
|
-
"[trails-sdk] Invalid toAmount prop: must be numeric. Received:",
|
|
1081
|
-
toAmount,
|
|
1082
|
-
)
|
|
1083
|
-
return "Invalid toAmount: must be a numeric value"
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
// Validate toChainId - must be numeric if provided
|
|
1087
|
-
if (!isValidToChainId) {
|
|
1088
|
-
logger.console.error(
|
|
1089
|
-
"[trails-sdk] Invalid toChainId prop: must be numeric. Received:",
|
|
1090
|
-
toChainId,
|
|
1091
|
-
)
|
|
1092
|
-
return "Invalid toChainId: must be a numeric value"
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
// Validate toToken - must be "ETH", "USDC", or a valid hex address
|
|
1096
|
-
if (!isValidToToken) {
|
|
1097
|
-
logger.console.error(
|
|
1098
|
-
"[trails-sdk] Invalid toToken prop: must be a valid token symbol or a valid hex address. Received:",
|
|
1099
|
-
toToken,
|
|
1100
|
-
)
|
|
1101
|
-
return "Invalid toToken: must be a valid token symbol or a valid hex address"
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
if (!isValidToAddress) {
|
|
1105
|
-
logger.console.error(
|
|
1106
|
-
"[trails-sdk] Invalid toAddress prop: must be a valid hex address. Received:",
|
|
1107
|
-
toAddress,
|
|
1108
|
-
)
|
|
1109
|
-
return "Invalid toAddress: must be a valid hex address"
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
// Validate paymasterUrls
|
|
1113
|
-
if (!isValidPaymasterUrls) {
|
|
1114
|
-
logger.console.error(
|
|
1115
|
-
"[trails-sdk] Invalid paymasterUrls prop: url must be a valid URL. Received:",
|
|
1116
|
-
invalidPaymasterUrl,
|
|
1117
|
-
)
|
|
1118
|
-
return "Invalid paymasterUrls: url must be a valid URL"
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
if (currentMode === "fund") {
|
|
1122
|
-
if (toAmount) {
|
|
1123
|
-
return "toAmount is not allowed in fund mode"
|
|
1124
|
-
}
|
|
1125
|
-
if (!toToken) {
|
|
1126
|
-
return "toToken is required in fund mode"
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
if (currentMode === "pay") {
|
|
1131
|
-
if (!toToken) {
|
|
1132
|
-
return "toToken is required in pay mode"
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
return null
|
|
1136
|
-
}, [toAmount, toChainId, toToken, currentMode, toAddress, paymasterUrls])
|
|
1137
|
-
|
|
1138
|
-
const displayError = propValidationError || error
|
|
1139
|
-
|
|
1140
|
-
const walletClient = useWalletManager(address, chainId, connector)
|
|
1141
|
-
|
|
1142
|
-
// Function to save wallet ID to localStorage
|
|
1143
|
-
const saveLastClickedWallet = (walletId: string) => {
|
|
1144
|
-
setSelectedWalletId(walletId)
|
|
1145
|
-
if (typeof window !== "undefined") {
|
|
1146
|
-
try {
|
|
1147
|
-
localStorage.setItem("trails-last-wallet", walletId)
|
|
1148
|
-
} catch (error) {
|
|
1149
|
-
logger.console.error(
|
|
1150
|
-
"[trails-sdk] Failed to save to localStorage:",
|
|
1151
|
-
error,
|
|
1152
|
-
)
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
const [onrampProps, setOnrampProps] = useState<{
|
|
1158
|
-
toTokenSymbol?: string
|
|
1159
|
-
toTokenAmount?: string
|
|
1160
|
-
toChainId?: number
|
|
1161
|
-
toRecipientAddress?: string
|
|
1162
|
-
toAmountUsd?: number
|
|
1163
|
-
} | null>(null)
|
|
1164
|
-
|
|
1165
|
-
// Store callback to continue send after onramp completes
|
|
1166
|
-
const [onrampContinueSend, setOnrampContinueSend] = useState<
|
|
1167
|
-
(() => Promise<void>) | null
|
|
1168
|
-
>(null)
|
|
1169
|
-
const [onrampContinueSendInProgress, setOnrampContinueSendInProgress] =
|
|
1170
|
-
useState(false)
|
|
1171
|
-
const [_meldTransactionId, _setMeldTransactionId] = useState<string | null>(
|
|
1172
|
-
null,
|
|
1173
|
-
)
|
|
1174
|
-
|
|
1175
|
-
// Hook to auto-select pool when mode is "earn" and toAddress is specified
|
|
1176
|
-
const useAutoSelectPool = (
|
|
1177
|
-
mode: Mode,
|
|
1178
|
-
toAddress?: string | null,
|
|
1179
|
-
toChainId?: number | string | null,
|
|
1180
|
-
toToken?: string | null,
|
|
1181
|
-
) => {
|
|
1182
|
-
// Only fetch pools when mode is "earn" (pools are not used in "fund" mode)
|
|
1183
|
-
const shouldFetchPools = mode === "earn"
|
|
1184
|
-
const { data: pools, loading: poolsLoading } = usePools({
|
|
1185
|
-
enabled: shouldFetchPools,
|
|
1186
|
-
})
|
|
1187
|
-
|
|
1188
|
-
useEffect(() => {
|
|
1189
|
-
if (
|
|
1190
|
-
mode === "earn" &&
|
|
1191
|
-
toAddress &&
|
|
1192
|
-
toChainId &&
|
|
1193
|
-
toToken &&
|
|
1194
|
-
pools &&
|
|
1195
|
-
pools.length > 0 &&
|
|
1196
|
-
(!selectedPool ||
|
|
1197
|
-
selectedPool.chainId !== toChainId ||
|
|
1198
|
-
(!addressEqual(selectedPool.token.address, toToken) &&
|
|
1199
|
-
selectedPool.token.symbol.toLowerCase() !== toToken.toLowerCase()))
|
|
1200
|
-
) {
|
|
1201
|
-
const targetChainId =
|
|
1202
|
-
typeof toChainId === "string" ? parseInt(toChainId, 10) : toChainId
|
|
1203
|
-
|
|
1204
|
-
// Find pool that matches the toAddress, toChainId, and toToken (underlying asset)
|
|
1205
|
-
const matchingPool = pools.find((pool) => {
|
|
1206
|
-
let addressMatch = addressEqual(pool.depositAddress, toAddress)
|
|
1207
|
-
const chainMatch = pool.chainId === targetChainId
|
|
1208
|
-
|
|
1209
|
-
// Check if toToken is an address (starts with 0x) or a symbol
|
|
1210
|
-
let tokenMatch = toToken.startsWith("0x")
|
|
1211
|
-
? addressEqual(pool.token.address, toToken)
|
|
1212
|
-
: pool.token.symbol.toLowerCase() === toToken.toLowerCase()
|
|
1213
|
-
|
|
1214
|
-
// Special handling for Aave pools: ETH can be represented as WETH
|
|
1215
|
-
if (!tokenMatch && pool.protocol.toLowerCase() === "aave") {
|
|
1216
|
-
const isEthToken = isNativeToken(toToken) || toToken === "ETH"
|
|
1217
|
-
if (isEthToken) {
|
|
1218
|
-
// Check if pool token is WETH (either by address or symbol)
|
|
1219
|
-
const isWethPool =
|
|
1220
|
-
pool.token.symbol === "WETH" ||
|
|
1221
|
-
pool.token.address.toLowerCase() ===
|
|
1222
|
-
getWethAddress(targetChainId)?.toLowerCase()
|
|
1223
|
-
tokenMatch = isWethPool
|
|
1224
|
-
if (!addressMatch) {
|
|
1225
|
-
addressMatch =
|
|
1226
|
-
pool.wrappedTokenGatewayAddress?.toLowerCase() ===
|
|
1227
|
-
normalizeAddress(toAddress)
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
return addressMatch && chainMatch && tokenMatch
|
|
1233
|
-
})
|
|
1234
|
-
|
|
1235
|
-
if (matchingPool) {
|
|
1236
|
-
logger.console.log(
|
|
1237
|
-
`[trails-sdk] Auto-selected pool for ${mode} mode toAddress:`,
|
|
1238
|
-
toAddress,
|
|
1239
|
-
"toChainId:",
|
|
1240
|
-
targetChainId,
|
|
1241
|
-
"toToken:",
|
|
1242
|
-
toToken,
|
|
1243
|
-
matchingPool,
|
|
1244
|
-
)
|
|
1245
|
-
setSelectedPool(matchingPool)
|
|
1246
|
-
} else {
|
|
1247
|
-
logger.console.log(
|
|
1248
|
-
`[trails-sdk] No matching pool found for ${mode} mode toAddress:`,
|
|
1249
|
-
toAddress,
|
|
1250
|
-
"toChainId:",
|
|
1251
|
-
targetChainId,
|
|
1252
|
-
"toToken:",
|
|
1253
|
-
toToken,
|
|
1254
|
-
)
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
}, [mode, toAddress, toChainId, toToken, pools])
|
|
1258
|
-
|
|
1259
|
-
return { poolsLoading }
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
useAutoSelectPool(currentMode, toAddress, toChainId, toToken)
|
|
1263
|
-
|
|
1264
|
-
const {
|
|
1265
|
-
setOriginTxHash,
|
|
1266
|
-
setDestinationTxHash,
|
|
1267
|
-
setDestinationChainId,
|
|
1268
|
-
setOriginChainId,
|
|
1269
|
-
transactionStates,
|
|
1270
|
-
setTransactionStates,
|
|
1271
|
-
} = useTransactionState(
|
|
1272
|
-
onOriginConfirmation,
|
|
1273
|
-
onDestinationConfirmation,
|
|
1274
|
-
handleTransferComplete,
|
|
1275
|
-
)
|
|
1276
|
-
|
|
1277
|
-
const effectivePrepareSendQuote = hostTransactionQuote ?? prepareSendQuote
|
|
1278
|
-
const effectiveTransactionStates =
|
|
1279
|
-
hostTransactionStates.length > 0 ? hostTransactionStates : transactionStates
|
|
1280
|
-
const hostCompletionSeconds = useMemo(() => {
|
|
1281
|
-
if (
|
|
1282
|
-
hostTransactionState.status !== "success" ||
|
|
1283
|
-
!hostTransactionTimestamp
|
|
1284
|
-
) {
|
|
1285
|
-
return null
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
return Math.max(0, toSeconds(elapsed(hostTransactionTimestamp)))
|
|
1289
|
-
}, [hostTransactionState.status, hostTransactionTimestamp])
|
|
1290
|
-
const displayTotalCompletionSeconds =
|
|
1291
|
-
hostCompletionSeconds ?? totalCompletionSeconds
|
|
1292
|
-
|
|
1293
|
-
// Auto-navigate from pending → receipt when any transaction is aborted or failed.
|
|
1294
|
-
// This prevents the tracker from staying on pending when non-first steps fail.
|
|
1295
|
-
const hasFailedTransactionState = hasAnyFailedOrAbortedTransactions(
|
|
1296
|
-
effectiveTransactionStates,
|
|
1297
|
-
)
|
|
1298
|
-
useScreenGuard(screen === "pending" && hasFailedTransactionState, "receipt")
|
|
1299
|
-
|
|
1300
|
-
const { checkoutOnHandlers } = useCheckout({
|
|
1301
|
-
onCheckoutStart,
|
|
1302
|
-
onCheckoutQuote,
|
|
1303
|
-
onCheckoutSignatureRequest,
|
|
1304
|
-
onCheckoutSignatureConfirmed,
|
|
1305
|
-
onCheckoutSignatureRejected,
|
|
1306
|
-
onCheckoutApprovalRequest,
|
|
1307
|
-
onCheckoutApprovalConfirmed,
|
|
1308
|
-
onCheckoutApprovalRejected,
|
|
1309
|
-
onCheckoutComplete,
|
|
1310
|
-
onCheckoutError,
|
|
1311
|
-
onCheckoutStatusUpdate,
|
|
1312
|
-
})
|
|
1313
|
-
|
|
1314
|
-
const { clearSelectedFeeOption } = useSelectedFeeOption()
|
|
1315
|
-
useExternalFundingReceiptSync({
|
|
1316
|
-
enabled:
|
|
1317
|
-
isExternalFundingMethod(selectedFundMethod) &&
|
|
1318
|
-
!!effectivePrepareSendQuote?.intentId &&
|
|
1319
|
-
(screen === "direct-transfer-screen" ||
|
|
1320
|
-
screen === "onramp-confirmation" ||
|
|
1321
|
-
screen === "pending"),
|
|
1322
|
-
intentId: effectivePrepareSendQuote?.intentId ?? undefined,
|
|
1323
|
-
fallbackTransactionStates: effectivePrepareSendQuote?.transactionStates,
|
|
1324
|
-
setTransactionStates,
|
|
1325
|
-
onStatusUpdate: checkoutOnHandlers?.triggerCheckoutStatusUpdate,
|
|
1326
|
-
onFundingObserved: () => {
|
|
1327
|
-
if (
|
|
1328
|
-
screen === "direct-transfer-screen" ||
|
|
1329
|
-
screen === "onramp-confirmation"
|
|
1330
|
-
) {
|
|
1331
|
-
navigate("pending")
|
|
1332
|
-
}
|
|
1333
|
-
},
|
|
1334
|
-
})
|
|
1335
|
-
|
|
1336
|
-
// Use the debug screens hook
|
|
1337
|
-
const { handleDebugScreenSelect } = useDebugScreens({
|
|
1338
|
-
setSelectedToken,
|
|
1339
|
-
setTransactionStates,
|
|
1340
|
-
setPrepareSendQuote,
|
|
1341
|
-
setShowWalletConfirmRetry,
|
|
1342
|
-
setSelectedWalletId,
|
|
1343
|
-
setShowWalletConnectionRetry,
|
|
1344
|
-
setError,
|
|
1345
|
-
isConnected,
|
|
1346
|
-
})
|
|
1347
|
-
|
|
1348
|
-
// Auto-detect mode changes and switch screens accordingly
|
|
1349
|
-
const poolTargetScreen: Screen =
|
|
1350
|
-
currentMode === "fund" ? "fund-form" : "send-form"
|
|
1351
|
-
useScreenGuard(
|
|
1352
|
-
!!selectedPool &&
|
|
1353
|
-
(screen === "send-form" || screen === "fund-form") &&
|
|
1354
|
-
screen !== poolTargetScreen,
|
|
1355
|
-
poolTargetScreen,
|
|
1356
|
-
)
|
|
1357
|
-
|
|
1358
|
-
useScreenTracking(address || undefined)
|
|
1359
|
-
|
|
1360
|
-
useEffect(() => {
|
|
1361
|
-
const status = hostTransactionState.status
|
|
1362
|
-
if (status === "idle") {
|
|
1363
|
-
return
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
|
-
if (!isModalOpen) {
|
|
1367
|
-
openTrailsModal()
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
switch (status) {
|
|
1371
|
-
case "awaiting-origin":
|
|
1372
|
-
navigate("select-origin-token")
|
|
1373
|
-
break
|
|
1374
|
-
case "awaiting-amount":
|
|
1375
|
-
navigate("select-origin-amount")
|
|
1376
|
-
break
|
|
1377
|
-
case "confirmation":
|
|
1378
|
-
navigate("wallet-confirmation")
|
|
1379
|
-
break
|
|
1380
|
-
case "pending":
|
|
1381
|
-
navigate("pending")
|
|
1382
|
-
break
|
|
1383
|
-
case "success":
|
|
1384
|
-
case "error":
|
|
1385
|
-
if (hostTransactionStates.length > 0) {
|
|
1386
|
-
navigate("receipt")
|
|
1387
|
-
} else {
|
|
1388
|
-
navigate("pending")
|
|
1389
|
-
}
|
|
1390
|
-
break
|
|
1391
|
-
default:
|
|
1392
|
-
navigate("pending")
|
|
1393
|
-
break
|
|
1394
|
-
}
|
|
1395
|
-
}, [
|
|
1396
|
-
hostTransactionState.status,
|
|
1397
|
-
hostTransactionStates.length,
|
|
1398
|
-
isModalOpen,
|
|
1399
|
-
openTrailsModal,
|
|
1400
|
-
navigate,
|
|
1401
|
-
])
|
|
1402
|
-
|
|
1403
|
-
// Handle account changes - navigate back to token list for specific screens
|
|
1404
|
-
useEffect(() => {
|
|
1405
|
-
if (previousAddress && address && previousAddress !== address) {
|
|
1406
|
-
logger.console.log(
|
|
1407
|
-
"[trails-sdk] Account changed from",
|
|
1408
|
-
previousAddress,
|
|
1409
|
-
"to",
|
|
1410
|
-
address,
|
|
1411
|
-
)
|
|
1412
|
-
|
|
1413
|
-
// Clear fee option preference from localStorage when wallet changes
|
|
1414
|
-
try {
|
|
1415
|
-
localStorage.removeItem("trails-fee-option-preference")
|
|
1416
|
-
} catch {
|
|
1417
|
-
// Ignore localStorage errors (e.g., in private browsing mode)
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
// Check if we're on screens that should reset when account changes
|
|
1421
|
-
const screensToReset = [
|
|
1422
|
-
"send-form",
|
|
1423
|
-
"fund-form",
|
|
1424
|
-
"swap",
|
|
1425
|
-
"withdraw",
|
|
1426
|
-
"wallet-confirmation",
|
|
1427
|
-
"earn",
|
|
1428
|
-
]
|
|
1429
|
-
|
|
1430
|
-
if (screensToReset.includes(screen)) {
|
|
1431
|
-
logger.console.log(
|
|
1432
|
-
"[trails-sdk] Resetting to tokens screen due to account change",
|
|
1433
|
-
screen,
|
|
1434
|
-
)
|
|
1435
|
-
if (!state.stack.some((e) => e.screen === "select-funding-wallet")) {
|
|
1436
|
-
const initialScreen = getInitialScreen(currentMode)
|
|
1437
|
-
navigate(initialScreen)
|
|
1438
|
-
clearSelectedToken()
|
|
1439
|
-
}
|
|
1440
|
-
setError(null)
|
|
1441
|
-
setPrepareSendQuote(null)
|
|
1442
|
-
setShowWalletConfirmRetry(false)
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
// Update previous address
|
|
1447
|
-
setPreviousAddress(address)
|
|
1448
|
-
}, [
|
|
1449
|
-
address,
|
|
1450
|
-
previousAddress,
|
|
1451
|
-
screen,
|
|
1452
|
-
currentMode,
|
|
1453
|
-
clearSelectedToken,
|
|
1454
|
-
navigate,
|
|
1455
|
-
state.stack,
|
|
1456
|
-
])
|
|
1457
|
-
|
|
1458
|
-
// Update generated calldata when amount changes in earn mode
|
|
1459
|
-
useEffect(() => {
|
|
1460
|
-
if (selectedPool && currentMode === "earn" && generatedCalldata) {
|
|
1461
|
-
// The calldata will be updated via the onAmountUpdate callback
|
|
1462
|
-
// This effect ensures we have the initial calldata set up
|
|
1463
|
-
logger.console.log(
|
|
1464
|
-
"Earn mode: Pool selected, calldata ready for amount updates",
|
|
1465
|
-
)
|
|
1466
|
-
}
|
|
1467
|
-
}, [selectedPool, currentMode, generatedCalldata])
|
|
1468
|
-
|
|
1469
|
-
const handleConnectWallet = async (
|
|
1470
|
-
walletId: string,
|
|
1471
|
-
providedConnector?: WalletConnector,
|
|
1472
|
-
) => {
|
|
1473
|
-
try {
|
|
1474
|
-
setError(null)
|
|
1475
|
-
setIsConnecting(true)
|
|
1476
|
-
|
|
1477
|
-
// Use provided connector (for EIP-6963 wallets) or look up by wallet ID
|
|
1478
|
-
let walletConnector = providedConnector
|
|
1479
|
-
let walletName = walletId
|
|
1480
|
-
|
|
1481
|
-
if (!walletConnector) {
|
|
1482
|
-
// First, try to find an EIP-6963 connector that matches this wallet ID
|
|
1483
|
-
const eip6963Connector = connectors.find((c) => {
|
|
1484
|
-
if (c.type !== "injected") return false
|
|
1485
|
-
const rdns = (c as EIP6963Connector).info?.rdns
|
|
1486
|
-
if (getWalletIdFromRdns(rdns) === walletId) {
|
|
1487
|
-
logger.console.log(
|
|
1488
|
-
`[trails-sdk] Found EIP-6963 connector for ${walletId} with rdns ${rdns}`,
|
|
1489
|
-
)
|
|
1490
|
-
return true
|
|
1491
|
-
}
|
|
1492
|
-
// Fallback to name matching for EIP-6963 wallets
|
|
1493
|
-
const connectorWalletId = wagmiConnectorToWalletId(c)
|
|
1494
|
-
return connectorWalletId === walletId && (rdns || c.uid)
|
|
1495
|
-
})
|
|
1496
|
-
|
|
1497
|
-
if (eip6963Connector) {
|
|
1498
|
-
walletConnector = eip6963Connector
|
|
1499
|
-
walletName = eip6963Connector.name
|
|
1500
|
-
logger.console.log(
|
|
1501
|
-
`[trails-sdk] Using EIP-6963 connector for ${walletId}`,
|
|
1502
|
-
)
|
|
1503
|
-
} else {
|
|
1504
|
-
// Fall back to config lookup
|
|
1505
|
-
const config = allWallets.find((w) => w.id === walletId)
|
|
1506
|
-
if (!config) {
|
|
1507
|
-
setError(`No configuration found for wallet: ${walletId}`)
|
|
1508
|
-
setIsConnecting(false)
|
|
1509
|
-
return
|
|
1510
|
-
}
|
|
1511
|
-
walletConnector = config.connector
|
|
1512
|
-
walletName = config.name
|
|
1513
|
-
logger.console.log(
|
|
1514
|
-
`[trails-sdk] Using config connector for ${walletId}`,
|
|
1515
|
-
)
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
if (!walletConnector) {
|
|
1520
|
-
setError(`No connector available for wallet: ${walletId}`)
|
|
1521
|
-
setIsConnecting(false)
|
|
1522
|
-
return
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
logger.console.log(
|
|
1526
|
-
"[trails-sdk] Initiating connection to wallet",
|
|
1527
|
-
walletId,
|
|
1528
|
-
providedConnector ? "with EIP-6963 connector" : "with config connector",
|
|
1529
|
-
)
|
|
1530
|
-
|
|
1531
|
-
// Handle sequence-waas wallet using the openConnectModal hook
|
|
1532
|
-
if (walletId === "sequence-waas") {
|
|
1533
|
-
logger.console.log("[trails-sdk] Opening Sequence WaaS connect modal")
|
|
1534
|
-
// setOpenConnectModal(true)
|
|
1535
|
-
// setIsConnecting(false)
|
|
1536
|
-
return
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
if (walletConnector !== getWalletConnectConnector()) {
|
|
1540
|
-
// Store the current active connector BEFORE connecting new wallet
|
|
1541
|
-
const originalConnector = connector
|
|
1542
|
-
|
|
1543
|
-
logger.console.log(
|
|
1544
|
-
"[trails-sdk] Initiating connection to walletId",
|
|
1545
|
-
walletId,
|
|
1546
|
-
)
|
|
1547
|
-
const result = await connectAsync({ connector: walletConnector })
|
|
1548
|
-
logger.console.log(
|
|
1549
|
-
`[trails-sdk] Successfully connected to ${walletName}`,
|
|
1550
|
-
result,
|
|
1551
|
-
)
|
|
1552
|
-
// Set the last clicked wallet after successful connection
|
|
1553
|
-
saveLastClickedWallet(walletId)
|
|
1554
|
-
|
|
1555
|
-
// Check the wallet connection context to determine behavior
|
|
1556
|
-
if (isRecipientSelection) {
|
|
1557
|
-
// User connected wallet for recipient selection - switch back to original wallet
|
|
1558
|
-
logger.console.log(
|
|
1559
|
-
"[trails-sdk] Connected wallet for recipient selection, setting as recipient:",
|
|
1560
|
-
result.accounts[0],
|
|
1561
|
-
)
|
|
1562
|
-
|
|
1563
|
-
// Set the newly connected wallet as the recipient
|
|
1564
|
-
if (result.accounts[0]) {
|
|
1565
|
-
setSelectedRecipient(result.accounts[0])
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
// Switch back to the original active wallet (if there was one)
|
|
1569
|
-
if (originalConnector && address) {
|
|
1570
|
-
try {
|
|
1571
|
-
logger.console.log(
|
|
1572
|
-
"[trails-sdk] Switching back to original active wallet:",
|
|
1573
|
-
address,
|
|
1574
|
-
)
|
|
1575
|
-
switchAccount({ connector: originalConnector })
|
|
1576
|
-
} catch (switchError) {
|
|
1577
|
-
logger.console.error(
|
|
1578
|
-
"[trails-sdk] Failed to switch back to original wallet:",
|
|
1579
|
-
switchError,
|
|
1580
|
-
)
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
// Clear the connection context
|
|
1585
|
-
clearConnectionContext()
|
|
1586
|
-
|
|
1587
|
-
// Navigate back to the origin screen (recipients)
|
|
1588
|
-
const originScreen = connectionContext.originScreen
|
|
1589
|
-
if (originScreen) {
|
|
1590
|
-
navigate(originScreen)
|
|
1591
|
-
} else {
|
|
1592
|
-
navigate("recipients")
|
|
1593
|
-
}
|
|
1594
|
-
} else if (isFundMethodSelection) {
|
|
1595
|
-
logger.console.log(
|
|
1596
|
-
"[trails-sdk] Wallet connected from funding flow, selecting as fund method",
|
|
1597
|
-
)
|
|
1598
|
-
setSelectedFundMethod("wallet")
|
|
1599
|
-
clearConnectionContext()
|
|
1600
|
-
|
|
1601
|
-
if (currentMode === "fund") {
|
|
1602
|
-
navigate("tokens", { backTarget: "fund-methods" })
|
|
1603
|
-
} else {
|
|
1604
|
-
goHome()
|
|
1605
|
-
}
|
|
1606
|
-
} else {
|
|
1607
|
-
// Normal connection - switch active wallet and navigate home
|
|
1608
|
-
logger.console.log(
|
|
1609
|
-
"[trails-sdk] Normal wallet connection, switching active wallet",
|
|
1610
|
-
)
|
|
1611
|
-
|
|
1612
|
-
// Clear the connection context
|
|
1613
|
-
clearConnectionContext()
|
|
1614
|
-
|
|
1615
|
-
logger.console.log("[trails-sdk] Wallet connected, going home")
|
|
1616
|
-
goHome()
|
|
1617
|
-
}
|
|
1618
|
-
} else if (walletConnector === getWalletConnectConnector()) {
|
|
1619
|
-
// Store the current connector as previous before switching to WalletConnect
|
|
1620
|
-
if (connector && connector.name !== "WalletConnect") {
|
|
1621
|
-
setPreviousConnector(connector)
|
|
1622
|
-
}
|
|
1623
|
-
// Route to dedicated WalletConnect screen where we show our own QR
|
|
1624
|
-
navigate("wallet-connect")
|
|
1625
|
-
setIsConnecting(false)
|
|
1626
|
-
return
|
|
1627
|
-
}
|
|
1628
|
-
setIsConnecting(false)
|
|
1629
|
-
} catch (error) {
|
|
1630
|
-
logger.console.error("[trails-sdk] Failed to connect:", error)
|
|
1631
|
-
setError(
|
|
1632
|
-
error instanceof Error ? error.message : "Failed to connect wallet",
|
|
1633
|
-
)
|
|
1634
|
-
setIsConnecting(false)
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
const handleWalletDisconnect = async () => {
|
|
1639
|
-
setError(null)
|
|
1640
|
-
|
|
1641
|
-
try {
|
|
1642
|
-
// Disconnect all connected wallets
|
|
1643
|
-
logger.console.log(
|
|
1644
|
-
"[trails-sdk] Disconnecting all connected wallets:",
|
|
1645
|
-
connections.length,
|
|
1646
|
-
)
|
|
1647
|
-
|
|
1648
|
-
// Disconnect each connection
|
|
1649
|
-
for (const connection of connections) {
|
|
1650
|
-
try {
|
|
1651
|
-
await connection.connector.disconnect()
|
|
1652
|
-
logger.console.log(
|
|
1653
|
-
"[trails-sdk] Disconnected wallet:",
|
|
1654
|
-
connection.connector.name,
|
|
1655
|
-
)
|
|
1656
|
-
} catch (error) {
|
|
1657
|
-
logger.console.error(
|
|
1658
|
-
"[trails-sdk] Failed to disconnect wallet:",
|
|
1659
|
-
connection.connector.name,
|
|
1660
|
-
error,
|
|
1661
|
-
)
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
|
|
1665
|
-
// Also call the main disconnect to ensure cleanup
|
|
1666
|
-
await disconnectAsync()
|
|
1667
|
-
trackWalletDisconnectedEvent()
|
|
1668
|
-
} catch (error) {
|
|
1669
|
-
logger.console.error("[trails-sdk] Failed to disconnect:", error)
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
navigate("connect")
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
const handleContinue = async () => {
|
|
1676
|
-
// Check if this was a recipient selection connection
|
|
1677
|
-
if (isRecipientSelection) {
|
|
1678
|
-
logger.console.log(
|
|
1679
|
-
"[trails-sdk] WalletConnect completed for recipient selection, setting as recipient:",
|
|
1680
|
-
address,
|
|
1681
|
-
)
|
|
1682
|
-
|
|
1683
|
-
// Set the newly connected wallet as the recipient
|
|
1684
|
-
if (address) {
|
|
1685
|
-
setSelectedRecipient(address)
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
// Switch back to the original active wallet (if there was one)
|
|
1689
|
-
const originalConnector = connectionContext.originalActiveConnector
|
|
1690
|
-
const originalAddress = connectionContext.originalActiveWalletAddress
|
|
1691
|
-
if (originalConnector && originalAddress) {
|
|
1692
|
-
try {
|
|
1693
|
-
logger.console.log(
|
|
1694
|
-
"[trails-sdk] Switching back to original active wallet after WalletConnect:",
|
|
1695
|
-
originalAddress,
|
|
1696
|
-
)
|
|
1697
|
-
switchAccount({ connector: originalConnector })
|
|
1698
|
-
} catch (switchError) {
|
|
1699
|
-
logger.console.error(
|
|
1700
|
-
"[trails-sdk] Failed to switch back to original wallet after WalletConnect:",
|
|
1701
|
-
switchError,
|
|
1702
|
-
)
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
|
|
1706
|
-
// Clear the connection context
|
|
1707
|
-
clearConnectionContext()
|
|
1708
|
-
|
|
1709
|
-
// Navigate back to the origin screen (recipients)
|
|
1710
|
-
const originScreen = connectionContext.originScreen
|
|
1711
|
-
if (originScreen) {
|
|
1712
|
-
navigate(originScreen)
|
|
1713
|
-
} else {
|
|
1714
|
-
navigate("recipients")
|
|
1715
|
-
}
|
|
1716
|
-
} else if (isFundMethodSelection) {
|
|
1717
|
-
logger.console.log(
|
|
1718
|
-
"[trails-sdk] WalletConnect completed from funding flow, selecting as fund method",
|
|
1719
|
-
)
|
|
1720
|
-
setSelectedFundMethod("wallet")
|
|
1721
|
-
clearConnectionContext()
|
|
1722
|
-
|
|
1723
|
-
if (currentMode === "fund") {
|
|
1724
|
-
navigate("tokens", { backTarget: "fund-methods" })
|
|
1725
|
-
} else {
|
|
1726
|
-
goHome()
|
|
1727
|
-
}
|
|
1728
|
-
} else {
|
|
1729
|
-
// Normal flow - navigate based on mode
|
|
1730
|
-
if (currentMode === "swap") {
|
|
1731
|
-
navigate("swap")
|
|
1732
|
-
} else if (currentMode === "earn") {
|
|
1733
|
-
navigate("earn")
|
|
1734
|
-
} else if (currentMode === "fund") {
|
|
1735
|
-
navigate("fund-methods")
|
|
1736
|
-
} else if (currentMode === "pay") {
|
|
1737
|
-
navigate("send-form")
|
|
1738
|
-
} else {
|
|
1739
|
-
navigate("account-settings")
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
const handleTokenSelect = (token: Token) => {
|
|
1745
|
-
try {
|
|
1746
|
-
setError(null)
|
|
1747
|
-
setSelectedToken(token)
|
|
1748
|
-
|
|
1749
|
-
// Check if there's a pending selection request from useTrailsSendTransaction
|
|
1750
|
-
if (pendingSelection) {
|
|
1751
|
-
if (pendingSelection.requireAmountInput) {
|
|
1752
|
-
setHostTransactionState((prev) => ({
|
|
1753
|
-
...prev,
|
|
1754
|
-
status: "awaiting-amount",
|
|
1755
|
-
}))
|
|
1756
|
-
handleTrackToken(token)
|
|
1757
|
-
return
|
|
1758
|
-
}
|
|
1759
|
-
const originAddress = token.contractAddress || zeroAddress
|
|
1760
|
-
const chainId = token.chainId ?? 0
|
|
1761
|
-
try {
|
|
1762
|
-
pendingSelection.resolve({
|
|
1763
|
-
fromTokenAddress: originAddress,
|
|
1764
|
-
fromChainId: chainId,
|
|
1765
|
-
})
|
|
1766
|
-
} catch (error) {
|
|
1767
|
-
logger.console.error(
|
|
1768
|
-
"[trails-sdk] Error resolving pending selection:",
|
|
1769
|
-
error,
|
|
1770
|
-
)
|
|
1771
|
-
pendingSelection.reject(error as Error)
|
|
1772
|
-
} finally {
|
|
1773
|
-
setPendingSelection(undefined)
|
|
1774
|
-
}
|
|
1775
|
-
handleTrackToken(token)
|
|
1776
|
-
return
|
|
1777
|
-
}
|
|
1778
|
-
|
|
1779
|
-
// For earn mode, check if we have toAddress and toChainId specified
|
|
1780
|
-
if (currentMode === "earn") {
|
|
1781
|
-
if (toAddress && toChainId) {
|
|
1782
|
-
// Skip earn-pools and go directly to send-form when toAddress and toChainId are specified
|
|
1783
|
-
navigate("send-form")
|
|
1784
|
-
} else if (selectedPool) {
|
|
1785
|
-
// If a pool is already selected (auto-selected or manually), go to send-form
|
|
1786
|
-
navigate("send-form")
|
|
1787
|
-
} else {
|
|
1788
|
-
// Go to earn-pools for pool selection when no specific destination is set
|
|
1789
|
-
navigate("earn-pools")
|
|
1790
|
-
}
|
|
1791
|
-
} else if (currentMode === "swap") {
|
|
1792
|
-
navigate("swap")
|
|
1793
|
-
} else {
|
|
1794
|
-
navigate(currentMode === "fund" ? "fund-form" : "send-form")
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
handleTrackToken(token)
|
|
1798
|
-
} catch (err) {
|
|
1799
|
-
setError(err instanceof Error ? err.message : "An unknown error occurred")
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
const handleRecentTokenSelect = (token: Token) => {
|
|
1804
|
-
handleTokenSelect(token)
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
const handleTrackToken = (token: Token) => {
|
|
1808
|
-
// Track the token in recent tokens
|
|
1809
|
-
const chainInfo = getChainInfo(token.chainId)
|
|
1810
|
-
const decimals = token.decimals || 18
|
|
1811
|
-
// Convert to Token for addRecentToken (which now accepts Token)
|
|
1812
|
-
const trailsToken: Token = {
|
|
1813
|
-
symbol: token.symbol,
|
|
1814
|
-
name: token.name,
|
|
1815
|
-
decimals: decimals,
|
|
1816
|
-
contractAddress: token.contractAddress,
|
|
1817
|
-
tokenId: `${token.symbol}-${chainInfo?.name || token.chainId}`,
|
|
1818
|
-
chainId: token.chainId,
|
|
1819
|
-
chainName: chainInfo?.name || `Chain ${token.chainId}`,
|
|
1820
|
-
imageUrl: token.imageUrl,
|
|
1821
|
-
}
|
|
1822
|
-
addRecentToken(trailsToken)
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
const handleOriginAmountSubmit = (amount: string) => {
|
|
1826
|
-
if (pendingSelection && selectedToken) {
|
|
1827
|
-
try {
|
|
1828
|
-
pendingSelection.resolve({
|
|
1829
|
-
fromTokenAddress: selectedToken.contractAddress || zeroAddress,
|
|
1830
|
-
fromChainId: selectedToken.chainId ?? 0,
|
|
1831
|
-
fromAmount: amount,
|
|
1832
|
-
})
|
|
1833
|
-
setPendingSelection(undefined)
|
|
1834
|
-
} catch (error) {
|
|
1835
|
-
logger.console.error(
|
|
1836
|
-
"[trails-sdk] Error resolving pending selection amount:",
|
|
1837
|
-
error,
|
|
1838
|
-
)
|
|
1839
|
-
pendingSelection.reject(error as Error)
|
|
1840
|
-
setPendingSelection(undefined)
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
|
|
1845
|
-
const handleOnSend = async (amount: string, recipient: string) => {
|
|
1846
|
-
logger.console.log("[trails-sdk] handleOnSend", amount, recipient)
|
|
1847
|
-
|
|
1848
|
-
// Check if there's a pending selection request from useTrailsSendTransaction
|
|
1849
|
-
if (pendingSelection && selectedToken) {
|
|
1850
|
-
try {
|
|
1851
|
-
// Convert amount to token units (it's already in token units from the form)
|
|
1852
|
-
const amountInTokenUnits = amount
|
|
1853
|
-
|
|
1854
|
-
// Resolve the pending selection with the selected token and amount
|
|
1855
|
-
pendingSelection.resolve({
|
|
1856
|
-
fromTokenAddress: selectedToken.contractAddress || zeroAddress,
|
|
1857
|
-
fromChainId: selectedToken.chainId ?? 0,
|
|
1858
|
-
fromAmount: amountInTokenUnits,
|
|
1859
|
-
})
|
|
1860
|
-
|
|
1861
|
-
setPendingSelection(undefined)
|
|
1862
|
-
return
|
|
1863
|
-
} catch (error) {
|
|
1864
|
-
logger.console.error(
|
|
1865
|
-
"[trails-sdk] Error resolving pending selection:",
|
|
1866
|
-
error,
|
|
1867
|
-
)
|
|
1868
|
-
if (pendingSelection) {
|
|
1869
|
-
pendingSelection.reject(error as Error)
|
|
1870
|
-
setPendingSelection(undefined)
|
|
1871
|
-
}
|
|
1872
|
-
return
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
// Normal flow: onSend is just a notification callback that the origin transaction was sent
|
|
1877
|
-
// The actual transaction sending is handled by useSendForm internally
|
|
1878
|
-
// Return resolved promise to ensure async function completes properly
|
|
1879
|
-
return Promise.resolve()
|
|
1880
|
-
}
|
|
1881
|
-
|
|
1882
|
-
const handleSendAnother = () => {
|
|
1883
|
-
invalidateTokenBalancesCache()
|
|
1884
|
-
resetState()
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
const resetState = useCallback(() => {
|
|
1888
|
-
setSelectedFundMethod("wallet")
|
|
1889
|
-
setSelectedPool(null)
|
|
1890
|
-
setSelectedWalletId(null)
|
|
1891
|
-
setIsConnecting(false)
|
|
1892
|
-
setShowWalletConnectionRetry(false)
|
|
1893
|
-
setGeneratedCalldata(undefined)
|
|
1894
|
-
setOriginTxHash("")
|
|
1895
|
-
setOriginChainId(null)
|
|
1896
|
-
setDestinationTxHash("")
|
|
1897
|
-
setDestinationChainId(null)
|
|
1898
|
-
setTransactionStates([])
|
|
1899
|
-
setPrepareSendQuote(null)
|
|
1900
|
-
setTotalCompletionSeconds(null)
|
|
1901
|
-
// Clear selected fee option, but localStorage preference is preserved
|
|
1902
|
-
// Auto-selection will use the preference when fee options render next time
|
|
1903
|
-
clearSelectedFeeOption()
|
|
1904
|
-
resetHostTransactionState()
|
|
1905
|
-
goHome()
|
|
1906
|
-
}, [
|
|
1907
|
-
setSelectedFundMethod,
|
|
1908
|
-
setDestinationTxHash,
|
|
1909
|
-
setDestinationChainId,
|
|
1910
|
-
setTransactionStates,
|
|
1911
|
-
setOriginTxHash,
|
|
1912
|
-
setOriginChainId,
|
|
1913
|
-
setSelectedPool,
|
|
1914
|
-
goHome,
|
|
1915
|
-
clearSelectedFeeOption,
|
|
1916
|
-
resetHostTransactionState,
|
|
1917
|
-
])
|
|
1918
|
-
|
|
1919
|
-
// When pendingSelection exists (from useTrailsSendTransaction),
|
|
1920
|
-
// open the modal and navigate to select-origin-token screen
|
|
1921
|
-
useEffect(() => {
|
|
1922
|
-
if (pendingSelection) {
|
|
1923
|
-
// Open modal if not already open
|
|
1924
|
-
if (!isModalOpen) {
|
|
1925
|
-
openTrailsModal()
|
|
1926
|
-
}
|
|
1927
|
-
// Navigate to select-origin-token screen
|
|
1928
|
-
if (screen !== "select-origin-token") {
|
|
1929
|
-
navigate("select-origin-token")
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
}, [pendingSelection, isModalOpen, screen, navigate, openTrailsModal])
|
|
1933
|
-
|
|
1934
|
-
const onOpenRef = useRef(onOpen)
|
|
1935
|
-
onOpenRef.current = onOpen
|
|
1936
|
-
const onCloseRef = useRef(onClose)
|
|
1937
|
-
onCloseRef.current = onClose
|
|
1938
|
-
const pendingSelectionRef = useRef(pendingSelection)
|
|
1939
|
-
pendingSelectionRef.current = pendingSelection
|
|
1940
|
-
const prepareSendQuoteRef = useRef(prepareSendQuote)
|
|
1941
|
-
prepareSendQuoteRef.current = prepareSendQuote
|
|
1942
|
-
const screenRef = useRef(screen)
|
|
1943
|
-
screenRef.current = screen
|
|
1944
|
-
|
|
1945
|
-
const initialActiveConnectorRef = useRef<any>(null)
|
|
1946
|
-
const initialActiveAddressRef = useRef<string | null>(null)
|
|
1947
|
-
|
|
1948
|
-
const handleOpenModal = useCallback(() => {
|
|
1949
|
-
if (!decoupleWagmi) {
|
|
1950
|
-
initialActiveConnectorRef.current = connector ?? null
|
|
1951
|
-
initialActiveAddressRef.current = address ?? null
|
|
1952
|
-
}
|
|
1953
|
-
openTrailsModal()
|
|
1954
|
-
onOpenRef.current?.()
|
|
1955
|
-
}, [openTrailsModal, decoupleWagmi, connector, address])
|
|
1956
|
-
|
|
1957
|
-
const handleCloseModal = useCallback(() => {
|
|
1958
|
-
const pending = pendingSelectionRef.current
|
|
1959
|
-
if (pending) {
|
|
1960
|
-
logger.console.log(
|
|
1961
|
-
"[trails-sdk] handleCloseModal called, rejecting pending selection",
|
|
1962
|
-
)
|
|
1963
|
-
pending.reject(new Error("Modal closed by user"))
|
|
1964
|
-
setPendingSelection(undefined)
|
|
1965
|
-
} else {
|
|
1966
|
-
logger.console.log(
|
|
1967
|
-
"[trails-sdk] handleCloseModal called, no pending selection",
|
|
1968
|
-
)
|
|
1969
|
-
}
|
|
1970
|
-
|
|
1971
|
-
if (!decoupleWagmi && initialActiveConnectorRef.current) {
|
|
1972
|
-
const originalStillConnected = connections.some(
|
|
1973
|
-
(c) => c.connector.id === initialActiveConnectorRef.current?.id,
|
|
1974
|
-
)
|
|
1975
|
-
if (
|
|
1976
|
-
originalStillConnected &&
|
|
1977
|
-
initialActiveConnectorRef.current.id !== connector?.id
|
|
1978
|
-
) {
|
|
1979
|
-
logger.console.log(
|
|
1980
|
-
"[trails-sdk] Restoring host app active wallet:",
|
|
1981
|
-
initialActiveAddressRef.current,
|
|
1982
|
-
)
|
|
1983
|
-
switchAccount({ connector: initialActiveConnectorRef.current })
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
initialActiveConnectorRef.current = null
|
|
1987
|
-
initialActiveAddressRef.current = null
|
|
1988
|
-
|
|
1989
|
-
logger.console.log("[trails-sdk] handleCloseModal called, closing modal")
|
|
1990
|
-
closeTrailsModal()
|
|
1991
|
-
resetState()
|
|
1992
|
-
resetHostTransactionState()
|
|
1993
|
-
onCloseRef.current?.()
|
|
1994
|
-
}, [
|
|
1995
|
-
closeTrailsModal,
|
|
1996
|
-
resetState,
|
|
1997
|
-
resetHostTransactionState,
|
|
1998
|
-
setPendingSelection,
|
|
1999
|
-
decoupleWagmi,
|
|
2000
|
-
connections,
|
|
2001
|
-
connector,
|
|
2002
|
-
switchAccount,
|
|
2003
|
-
])
|
|
2004
|
-
|
|
2005
|
-
// Register handleCloseModal with TrailsModalProvider so ScreenHeader can use it
|
|
2006
|
-
useEffect(() => {
|
|
2007
|
-
setHandleCloseModal(handleCloseModal)
|
|
2008
|
-
return () => {
|
|
2009
|
-
setHandleCloseModal(null)
|
|
2010
|
-
}
|
|
2011
|
-
}, [handleCloseModal, setHandleCloseModal])
|
|
2012
|
-
|
|
2013
|
-
// Expose modal control methods via ref
|
|
2014
|
-
useImperativeHandle(
|
|
2015
|
-
ref,
|
|
2016
|
-
() => ({
|
|
2017
|
-
openModal: handleOpenModal,
|
|
2018
|
-
closeModal: handleCloseModal,
|
|
2019
|
-
isModalOpen,
|
|
2020
|
-
}),
|
|
2021
|
-
[isModalOpen, handleOpenModal, handleCloseModal],
|
|
2022
|
-
)
|
|
2023
|
-
|
|
2024
|
-
function handleWalletConfirmComplete() {
|
|
2025
|
-
navigate("pending")
|
|
2026
|
-
}
|
|
2027
|
-
|
|
2028
|
-
function handleElapsedTime(totalCompletionSeconds: number = 0) {
|
|
2029
|
-
setTotalCompletionSeconds(totalCompletionSeconds)
|
|
2030
|
-
}
|
|
2031
|
-
|
|
2032
|
-
function handleTransferComplete({ transactionStates }: OnCompleteProps) {
|
|
2033
|
-
logger.console.log(
|
|
2034
|
-
"[trails-sdk] handleTransferComplete called",
|
|
2035
|
-
transactionStates,
|
|
2036
|
-
)
|
|
2037
|
-
|
|
2038
|
-
const firstTransactionState = transactionStates[0]
|
|
2039
|
-
const lastTransactionState = transactionStates[transactionStates.length - 1]
|
|
2040
|
-
|
|
2041
|
-
if (
|
|
2042
|
-
firstTransactionState?.transactionHash &&
|
|
2043
|
-
firstTransactionState?.chainId
|
|
2044
|
-
) {
|
|
2045
|
-
setOriginTxHash(firstTransactionState.transactionHash)
|
|
2046
|
-
setOriginChainId(firstTransactionState.chainId)
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
|
-
if (
|
|
2050
|
-
lastTransactionState?.transactionHash ||
|
|
2051
|
-
((lastTransactionState as unknown as IntentTransaction)?.txnHash &&
|
|
2052
|
-
lastTransactionState?.chainId)
|
|
2053
|
-
) {
|
|
2054
|
-
setDestinationTxHash(
|
|
2055
|
-
lastTransactionState?.transactionHash ||
|
|
2056
|
-
(lastTransactionState as unknown as IntentTransaction)?.txnHash ||
|
|
2057
|
-
"",
|
|
2058
|
-
)
|
|
2059
|
-
setDestinationChainId(lastTransactionState?.chainId)
|
|
2060
|
-
}
|
|
2061
|
-
|
|
2062
|
-
navigate("receipt")
|
|
2063
|
-
}
|
|
2064
|
-
|
|
2065
|
-
async function handleOnrampComplete(transferData: OnrampTransferResult) {
|
|
2066
|
-
logger.console.log("[trails-sdk] Onramp transfer completed:", transferData)
|
|
2067
|
-
logger.console.log(
|
|
2068
|
-
"[trails-sdk] Using real transaction states from prepareSendQuote",
|
|
2069
|
-
)
|
|
2070
|
-
logger.console.log("[trails-sdk] handleOnrampComplete state:", {
|
|
2071
|
-
hasOnrampContinueSend: !!onrampContinueSend,
|
|
2072
|
-
hasPrepareSendQuote: !!effectivePrepareSendQuote,
|
|
2073
|
-
screen,
|
|
2074
|
-
onrampContinueSendInProgress,
|
|
2075
|
-
})
|
|
2076
|
-
|
|
2077
|
-
// Invalidate token balances cache after onramp completion
|
|
2078
|
-
logger.console.log(
|
|
2079
|
-
"[CACHE-FLOW] Onramp completed, invalidating token balances cache",
|
|
2080
|
-
)
|
|
2081
|
-
invalidateTokenBalancesCache()
|
|
2082
|
-
|
|
2083
|
-
// Prevent multiple simultaneous calls
|
|
2084
|
-
if (onrampContinueSendInProgress) {
|
|
2085
|
-
logger.console.warn(
|
|
2086
|
-
"[trails-sdk] onrampContinueSend already in progress, ignoring duplicate call",
|
|
2087
|
-
)
|
|
2088
|
-
return
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
|
-
// Navigate away from onramp screen immediately
|
|
2092
|
-
logger.console.log("[trails-sdk] Navigating away from onramp screen")
|
|
2093
|
-
navigate("pending")
|
|
2094
|
-
|
|
2095
|
-
// Continue with the send flow after onramp completes
|
|
2096
|
-
if (onrampContinueSend) {
|
|
2097
|
-
logger.console.log(
|
|
2098
|
-
"[trails-sdk] Continuing send flow after onramp completion",
|
|
2099
|
-
)
|
|
2100
|
-
setOnrampContinueSendInProgress(true)
|
|
2101
|
-
try {
|
|
2102
|
-
await onrampContinueSend()
|
|
2103
|
-
logger.console.log(
|
|
2104
|
-
"[trails-sdk] onrampContinueSend completed successfully",
|
|
2105
|
-
)
|
|
2106
|
-
} catch (error) {
|
|
2107
|
-
logger.console.error(
|
|
2108
|
-
"[trails-sdk] Error continuing send after onramp:",
|
|
2109
|
-
error,
|
|
2110
|
-
)
|
|
2111
|
-
handleSendError(error as Error)
|
|
2112
|
-
} finally {
|
|
2113
|
-
setOnrampContinueSend(null)
|
|
2114
|
-
setOnrampContinueSendInProgress(false)
|
|
2115
|
-
}
|
|
2116
|
-
} else {
|
|
2117
|
-
// Fallback: just show pending screen if no continue callback
|
|
2118
|
-
logger.console.log(
|
|
2119
|
-
"[trails-sdk] No onrampContinueSend callback, showing pending screen",
|
|
2120
|
-
)
|
|
2121
|
-
if (effectivePrepareSendQuote) {
|
|
2122
|
-
logger.console.log(
|
|
2123
|
-
"[trails-sdk] Setting transaction states from prepareSendQuote",
|
|
2124
|
-
)
|
|
2125
|
-
setTransactionStates(effectivePrepareSendQuote.transactionStates)
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
}
|
|
2129
|
-
|
|
2130
|
-
async function _handleOnrampDepositComplete() {
|
|
2131
|
-
logger.console.log(
|
|
2132
|
-
"[trails-sdk] Deposit confirmed in OnrampDeposit, starting intent execution",
|
|
2133
|
-
)
|
|
2134
|
-
|
|
2135
|
-
// Invalidate token balances cache after deposit is complete
|
|
2136
|
-
logger.console.log(
|
|
2137
|
-
"[CACHE-FLOW] Onramp deposit complete, invalidating token balances cache",
|
|
2138
|
-
)
|
|
2139
|
-
invalidateTokenBalancesCache()
|
|
2140
|
-
|
|
2141
|
-
// Prevent multiple simultaneous calls
|
|
2142
|
-
if (onrampContinueSendInProgress) {
|
|
2143
|
-
logger.console.warn(
|
|
2144
|
-
"[trails-sdk] onrampContinueSend already in progress, ignoring duplicate call",
|
|
2145
|
-
)
|
|
2146
|
-
return
|
|
2147
|
-
}
|
|
2148
|
-
|
|
2149
|
-
// Navigate to pending screen immediately
|
|
2150
|
-
logger.console.log("[trails-sdk] Navigating to pending screen")
|
|
2151
|
-
navigate("pending")
|
|
2152
|
-
|
|
2153
|
-
// Continue with the send flow after deposit is confirmed
|
|
2154
|
-
if (onrampContinueSend) {
|
|
2155
|
-
logger.console.log(
|
|
2156
|
-
"[trails-sdk] Continuing send flow after deposit confirmation",
|
|
2157
|
-
)
|
|
2158
|
-
setOnrampContinueSendInProgress(true)
|
|
2159
|
-
try {
|
|
2160
|
-
await onrampContinueSend()
|
|
2161
|
-
logger.console.log(
|
|
2162
|
-
"[trails-sdk] onrampContinueSend completed successfully",
|
|
2163
|
-
)
|
|
2164
|
-
} catch (error) {
|
|
2165
|
-
logger.console.error(
|
|
2166
|
-
"[trails-sdk] Error continuing send after deposit confirmation:",
|
|
2167
|
-
error,
|
|
2168
|
-
)
|
|
2169
|
-
handleSendError(error as Error)
|
|
2170
|
-
} finally {
|
|
2171
|
-
setOnrampContinueSend(null)
|
|
2172
|
-
setOnrampContinueSendInProgress(false)
|
|
2173
|
-
}
|
|
2174
|
-
} else {
|
|
2175
|
-
logger.console.warn(
|
|
2176
|
-
"[trails-sdk] No onrampContinueSend callback available",
|
|
2177
|
-
)
|
|
2178
|
-
}
|
|
2179
|
-
}
|
|
2180
|
-
|
|
2181
|
-
function handleTransactionStateChange(
|
|
2182
|
-
_transactionStates: TransactionState[],
|
|
2183
|
-
) {
|
|
2184
|
-
logger.console.log(
|
|
2185
|
-
"[trails-sdk] transactionStates from widget",
|
|
2186
|
-
_transactionStates,
|
|
2187
|
-
)
|
|
2188
|
-
setTransactionStates([..._transactionStates])
|
|
2189
|
-
}
|
|
2190
|
-
|
|
2191
|
-
const handleSelectWalletConnect = () => {
|
|
2192
|
-
// Store the current connector as previous before switching to WalletConnect
|
|
2193
|
-
if (connector && connector.name !== "WalletConnect") {
|
|
2194
|
-
setPreviousConnector(connector)
|
|
2195
|
-
}
|
|
2196
|
-
setSelectedWalletId(null)
|
|
2197
|
-
navigate("wallet-connect")
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
const handleReconnectPreviousWallet = async () => {
|
|
2201
|
-
if (previousConnector) {
|
|
2202
|
-
try {
|
|
2203
|
-
logger.console.log(
|
|
2204
|
-
"[trails-sdk] Reconnecting to previous wallet:",
|
|
2205
|
-
previousConnector.name,
|
|
2206
|
-
)
|
|
2207
|
-
|
|
2208
|
-
try {
|
|
2209
|
-
await connectAsync({ connector: previousConnector })
|
|
2210
|
-
} catch (error) {
|
|
2211
|
-
logger.console.error(
|
|
2212
|
-
"[trails-sdk] Failed to reconnect to previous wallet:",
|
|
2213
|
-
error,
|
|
2214
|
-
)
|
|
2215
|
-
}
|
|
2216
|
-
setPreviousConnector(null) // Clear the stored connector
|
|
2217
|
-
} catch (error) {
|
|
2218
|
-
logger.console.error(
|
|
2219
|
-
"[trails-sdk] Failed to reconnect to previous wallet:",
|
|
2220
|
-
error,
|
|
2221
|
-
)
|
|
2222
|
-
// If reconnection fails, go back to fund methods
|
|
2223
|
-
navigate("fund-methods")
|
|
2224
|
-
}
|
|
2225
|
-
} else {
|
|
2226
|
-
// If no previous connector, go back to fund methods
|
|
2227
|
-
navigate("fund-methods")
|
|
2228
|
-
}
|
|
2229
|
-
}
|
|
2230
|
-
|
|
2231
|
-
// Generate deposit calldata based on pool protocol
|
|
2232
|
-
const generateDepositCalldata = (pool: Pool, amount: string) => {
|
|
2233
|
-
try {
|
|
2234
|
-
logger.console.log(
|
|
2235
|
-
`Generating deposit calldata for ${pool.protocol} pool:`,
|
|
2236
|
-
pool.name,
|
|
2237
|
-
)
|
|
2238
|
-
|
|
2239
|
-
if (!walletClient) {
|
|
2240
|
-
throw new Error("Wallet client not found")
|
|
2241
|
-
}
|
|
2242
|
-
|
|
2243
|
-
switch (pool.protocol.toLowerCase()) {
|
|
2244
|
-
case "aave":
|
|
2245
|
-
return generateAaveDepositCalldata(walletClient, pool, amount)
|
|
2246
|
-
case "morpho":
|
|
2247
|
-
return generateMorphoDepositCalldata(walletClient, amount)
|
|
2248
|
-
default:
|
|
2249
|
-
logger.console.warn(`Unsupported protocol: ${pool.protocol}`)
|
|
2250
|
-
return undefined
|
|
2251
|
-
}
|
|
2252
|
-
} catch (error) {
|
|
2253
|
-
logger.console.error("Error generating deposit calldata:", error)
|
|
2254
|
-
return undefined
|
|
2255
|
-
}
|
|
2256
|
-
}
|
|
2257
|
-
|
|
2258
|
-
const handleSendError = (error: Error | string | null) => {
|
|
2259
|
-
if (error) {
|
|
2260
|
-
logger.console.error("[trails-sdk] Error sending transaction", error)
|
|
2261
|
-
}
|
|
2262
|
-
const errorMessage = getFullErrorMessage(error)
|
|
2263
|
-
const isRejected = getIsUserRejectionError(error)
|
|
2264
|
-
const isBalanceTooLow = getIsBalanceTooLowError(error)
|
|
2265
|
-
const isApiErr = getIsApiError(error)
|
|
2266
|
-
const isRateLimited = getIsRateLimitedError(error)
|
|
2267
|
-
|
|
2268
|
-
if (isRateLimited) {
|
|
2269
|
-
// no-op
|
|
2270
|
-
} else if (isRejected) {
|
|
2271
|
-
setShowWalletConfirmRetry(true)
|
|
2272
|
-
} else if (isBalanceTooLow || isApiErr) {
|
|
2273
|
-
setShowWalletConfirmRetry(true)
|
|
2274
|
-
setError(errorMessage)
|
|
2275
|
-
} else {
|
|
2276
|
-
setError(errorMessage)
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
|
|
2280
|
-
const handleConnectError = (error: Error | string | null) => {
|
|
2281
|
-
if (error) {
|
|
2282
|
-
logger.console.error("[trails-sdk] Error connecting wallet", error)
|
|
2283
|
-
}
|
|
2284
|
-
setError(error instanceof Error ? error.message : error)
|
|
2285
|
-
}
|
|
2286
|
-
|
|
2287
|
-
const handleTokenListError = (error: Error | string | null) => {
|
|
2288
|
-
if (error) {
|
|
2289
|
-
logger.console.error("[trails-sdk] Error selecting token", error)
|
|
2290
|
-
}
|
|
2291
|
-
setError(error instanceof Error ? error.message : error)
|
|
2292
|
-
}
|
|
2293
|
-
|
|
2294
|
-
const handleWaitingForWalletConfirm = (
|
|
2295
|
-
quote: PrepareSendQuote,
|
|
2296
|
-
sendFn?: ((options?: SendOptions) => Promise<SwapReturn | null>) | null,
|
|
2297
|
-
) => {
|
|
2298
|
-
setShowWalletConfirmRetry(false)
|
|
2299
|
-
setPrepareSendQuote(quote ?? null)
|
|
2300
|
-
// Navigate to QR wallet selection when using QR code funding method
|
|
2301
|
-
if (selectedFundMethod === "direct-transfer") {
|
|
2302
|
-
if (!sendFn) {
|
|
2303
|
-
handleSendError(
|
|
2304
|
-
"Unable to continue: direct-transfer send function is missing.",
|
|
2305
|
-
)
|
|
2306
|
-
return
|
|
2307
|
-
}
|
|
2308
|
-
|
|
2309
|
-
setError(null)
|
|
2310
|
-
|
|
2311
|
-
void (async () => {
|
|
2312
|
-
try {
|
|
2313
|
-
await sendFn()
|
|
2314
|
-
navigate("direct-transfer-screen", { backTarget: screen })
|
|
2315
|
-
} catch (error) {
|
|
2316
|
-
handleSendError(error as Error | string | null)
|
|
2317
|
-
}
|
|
2318
|
-
})()
|
|
2319
|
-
return
|
|
2320
|
-
}
|
|
2321
|
-
|
|
2322
|
-
if (selectedFundMethod === "onramp-mesh") {
|
|
2323
|
-
return
|
|
2324
|
-
}
|
|
2325
|
-
|
|
2326
|
-
navigate("wallet-confirmation")
|
|
2327
|
-
}
|
|
2328
|
-
|
|
2329
|
-
const handleWaitingOnrampConfirm = (
|
|
2330
|
-
quote: PrepareSendQuote,
|
|
2331
|
-
onrampProviderQuote?: OnrampQuote | null,
|
|
2332
|
-
params?: {
|
|
2333
|
-
depositAddress: string
|
|
2334
|
-
userAddress: string
|
|
2335
|
-
countryCode: string
|
|
2336
|
-
sourceCurrencyCode: string
|
|
2337
|
-
sourceAmount: string
|
|
2338
|
-
destinationCurrencyCode: string
|
|
2339
|
-
serviceProvider: string
|
|
2340
|
-
paymentMethodType?: string
|
|
2341
|
-
},
|
|
2342
|
-
sessionId?: string,
|
|
2343
|
-
popupWindowRef?: Window | null,
|
|
2344
|
-
) => {
|
|
2345
|
-
logger.console.log(
|
|
2346
|
-
"[trails-sdk] handleWaitingOnrampConfirm called with sessionId:",
|
|
2347
|
-
sessionId,
|
|
2348
|
-
)
|
|
2349
|
-
setPrepareSendQuote(quote ?? null)
|
|
2350
|
-
setOnrampProviderQuote(onrampProviderQuote ?? null)
|
|
2351
|
-
setOnrampPopupWindowRef(popupWindowRef ?? null)
|
|
2352
|
-
if (params) {
|
|
2353
|
-
setWidgetCreationParams(params)
|
|
2354
|
-
}
|
|
2355
|
-
if (sessionId) {
|
|
2356
|
-
logger.console.log("[trails-sdk] Using provided sessionId:", sessionId)
|
|
2357
|
-
setExternalSessionId(sessionId)
|
|
2358
|
-
} else {
|
|
2359
|
-
logger.console.error(
|
|
2360
|
-
"[trails-sdk] No sessionId provided - this should never happen for onramp flows",
|
|
2361
|
-
)
|
|
2362
|
-
setExternalSessionId(null)
|
|
2363
|
-
}
|
|
2364
|
-
navigate("onramp-confirmation")
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
|
-
async function handleWalletConfirmRetry() {
|
|
2368
|
-
if (!walletConfirmRetryHandler) {
|
|
2369
|
-
return
|
|
2370
|
-
}
|
|
2371
|
-
|
|
2372
|
-
try {
|
|
2373
|
-
setError(null)
|
|
2374
|
-
setShowWalletConfirmRetry(false)
|
|
2375
|
-
await walletConfirmRetryHandler()
|
|
2376
|
-
} catch (error) {
|
|
2377
|
-
logger.console.error(
|
|
2378
|
-
"[trails-sdk] Error retrying wallet confirmation",
|
|
2379
|
-
error,
|
|
2380
|
-
)
|
|
2381
|
-
}
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
const { targetAmountUsd, targetAmountUsdFormatted } = useTargetAmount()
|
|
2385
|
-
|
|
2386
|
-
const renderScreenContent = () => {
|
|
2387
|
-
switch (screen) {
|
|
2388
|
-
case "connect": {
|
|
2389
|
-
const showDisconnect = !decoupleWagmi && !hideDisconnect
|
|
2390
|
-
return (
|
|
2391
|
-
<ConnectWallet
|
|
2392
|
-
onConnect={(walletId, connector) => {
|
|
2393
|
-
// If a specific connector was provided (like EIP-6963), use it
|
|
2394
|
-
// Otherwise fall back to the wallet config
|
|
2395
|
-
let walletConnector = connector
|
|
2396
|
-
let isEIP6963Connector = false
|
|
2397
|
-
|
|
2398
|
-
// Check if this is an EIP-6963 connector
|
|
2399
|
-
if (connector) {
|
|
2400
|
-
isEIP6963Connector = !!(
|
|
2401
|
-
(connector as EIP6963Connector)?.info?.rdns || connector?.uid
|
|
2402
|
-
)
|
|
2403
|
-
}
|
|
2404
|
-
|
|
2405
|
-
// Only look up in config if no connector was provided
|
|
2406
|
-
if (!walletConnector) {
|
|
2407
|
-
const config = allWallets.find((w) => w.id === walletId)
|
|
2408
|
-
walletConnector = config?.connector
|
|
2409
|
-
}
|
|
2410
|
-
|
|
2411
|
-
// Check if we need to show WalletConnect QR
|
|
2412
|
-
// Don't show QR if we have an EIP-6963 connector or injected connector
|
|
2413
|
-
const shouldShowQR =
|
|
2414
|
-
!isEIP6963Connector && isWalletConnectConnector(walletConnector)
|
|
2415
|
-
|
|
2416
|
-
if (shouldShowQR) {
|
|
2417
|
-
saveLastClickedWallet(walletId)
|
|
2418
|
-
navigate("wallet-connect")
|
|
2419
|
-
} else {
|
|
2420
|
-
saveLastClickedWallet(walletId)
|
|
2421
|
-
// Preserve the existing back route from the navigation stack
|
|
2422
|
-
const backRoute = backScreen
|
|
2423
|
-
const safeBackRoute =
|
|
2424
|
-
backRoute === "wallet-confirmation" ? undefined : backRoute
|
|
2425
|
-
navigate("wallet-connection-pending", {
|
|
2426
|
-
backTarget: safeBackRoute || undefined,
|
|
2427
|
-
})
|
|
2428
|
-
// Auto-trigger connection - pass the actual connector
|
|
2429
|
-
setTimeout(() => {
|
|
2430
|
-
handleConnectWallet(walletId, walletConnector)
|
|
2431
|
-
}, 100)
|
|
2432
|
-
}
|
|
2433
|
-
}}
|
|
2434
|
-
onDisconnect={handleWalletDisconnect}
|
|
2435
|
-
onContinue={handleContinue}
|
|
2436
|
-
onError={handleConnectError}
|
|
2437
|
-
lastClickedWallet={selectedWalletId}
|
|
2438
|
-
showDisconnect={showDisconnect}
|
|
2439
|
-
/>
|
|
2440
|
-
)
|
|
2441
|
-
}
|
|
2442
|
-
case "fund-methods":
|
|
2443
|
-
return (
|
|
2444
|
-
<FundMethods
|
|
2445
|
-
headerContent={
|
|
2446
|
-
currentMode === "pay" || currentMode === "earn"
|
|
2447
|
-
? "Choose a payment method"
|
|
2448
|
-
: "Choose a funding method"
|
|
2449
|
-
}
|
|
2450
|
-
onBack={() => {
|
|
2451
|
-
if (currentMode !== configuredMode) {
|
|
2452
|
-
resetMode()
|
|
2453
|
-
return
|
|
2454
|
-
}
|
|
2455
|
-
|
|
2456
|
-
if (canGoBack) {
|
|
2457
|
-
goBack()
|
|
2458
|
-
return
|
|
2459
|
-
}
|
|
2460
|
-
|
|
2461
|
-
goHome()
|
|
2462
|
-
}}
|
|
2463
|
-
onramp={onrampFactory}
|
|
2464
|
-
onSelectWalletConnect={handleSelectWalletConnect}
|
|
2465
|
-
onSelectConnectedAccount={() => {
|
|
2466
|
-
clearStateForFundMethodSwitch("wallet")
|
|
2467
|
-
setSelectedFundMethod("wallet")
|
|
2468
|
-
if (currentMode === "fund") {
|
|
2469
|
-
navigate("select-origin-token", { backTarget: "fund-methods" })
|
|
2470
|
-
} else {
|
|
2471
|
-
goHome()
|
|
2472
|
-
}
|
|
2473
|
-
}}
|
|
2474
|
-
onSelectTransferCrypto={() => {
|
|
2475
|
-
clearStateForFundMethodSwitch("direct-transfer")
|
|
2476
|
-
setSelectedFundMethod("direct-transfer")
|
|
2477
|
-
if (currentMode === "fund") {
|
|
2478
|
-
navigate("fund-form", { backTarget: "fund-methods" })
|
|
2479
|
-
} else {
|
|
2480
|
-
goHome()
|
|
2481
|
-
}
|
|
2482
|
-
}}
|
|
2483
|
-
onSelectOnrampMeld={() => {
|
|
2484
|
-
clearStateForFundMethodSwitch("onramp-meld")
|
|
2485
|
-
if (currentMode === "fund") {
|
|
2486
|
-
navigate("fund-form")
|
|
2487
|
-
} else {
|
|
2488
|
-
goHome()
|
|
2489
|
-
}
|
|
2490
|
-
}}
|
|
2491
|
-
onSelectOnrampExchange={() => {
|
|
2492
|
-
clearSelectedToken()
|
|
2493
|
-
setSellAmount("")
|
|
2494
|
-
setBuyAmount("")
|
|
2495
|
-
setPrepareSendQuote(null)
|
|
2496
|
-
setSelectedMeshExchange(null)
|
|
2497
|
-
clearStateForFundMethodSwitch("onramp-mesh")
|
|
2498
|
-
if (currentMode === "fund") {
|
|
2499
|
-
navigate("mesh-exchanges")
|
|
2500
|
-
} else {
|
|
2501
|
-
goHome()
|
|
2502
|
-
}
|
|
2503
|
-
}}
|
|
2504
|
-
/>
|
|
2505
|
-
)
|
|
2506
|
-
case "mesh-exchanges":
|
|
2507
|
-
return (
|
|
2508
|
-
<MeshExchangeSelection
|
|
2509
|
-
onBack={() => navigate("fund-methods")}
|
|
2510
|
-
onSelectExchange={async (exchange) => {
|
|
2511
|
-
if (
|
|
2512
|
-
selectedToken &&
|
|
2513
|
-
selectedToken.chainId !== undefined &&
|
|
2514
|
-
trailsApiKey &&
|
|
2515
|
-
trailsApiUrl
|
|
2516
|
-
) {
|
|
2517
|
-
try {
|
|
2518
|
-
const response = await onrampClient.getMeshSupportedTokens({
|
|
2519
|
-
environment: meshEnvironment,
|
|
2520
|
-
integrationId: exchange.integrationId,
|
|
2521
|
-
chainIds: [selectedToken.chainId.toString()],
|
|
2522
|
-
})
|
|
2523
|
-
|
|
2524
|
-
const isSupported = (response.tokens || []).some(
|
|
2525
|
-
(token) =>
|
|
2526
|
-
Number(token.chainId) === selectedToken.chainId &&
|
|
2527
|
-
token.symbol?.toUpperCase() ===
|
|
2528
|
-
selectedToken.symbol?.toUpperCase(),
|
|
2529
|
-
)
|
|
2530
|
-
|
|
2531
|
-
if (!isSupported) {
|
|
2532
|
-
clearSelectedToken()
|
|
2533
|
-
setSellAmount("")
|
|
2534
|
-
setBuyAmount("")
|
|
2535
|
-
setPrepareSendQuote(null)
|
|
2536
|
-
}
|
|
2537
|
-
} catch (error) {
|
|
2538
|
-
logger.console.warn(
|
|
2539
|
-
"[trails-sdk] Failed to validate Mesh exchange token support, clearing selected token:",
|
|
2540
|
-
error,
|
|
2541
|
-
)
|
|
2542
|
-
clearSelectedToken()
|
|
2543
|
-
setSellAmount("")
|
|
2544
|
-
setBuyAmount("")
|
|
2545
|
-
setPrepareSendQuote(null)
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
|
|
2549
|
-
setSelectedFundMethod("onramp-mesh")
|
|
2550
|
-
setSelectedMeshExchange(exchange)
|
|
2551
|
-
navigate("fund-form", { backTarget: "mesh-exchanges" })
|
|
2552
|
-
}}
|
|
2553
|
-
/>
|
|
2554
|
-
)
|
|
2555
|
-
case "payment-methods":
|
|
2556
|
-
return (
|
|
2557
|
-
<PaymentMethods
|
|
2558
|
-
onBack={() => goHome()}
|
|
2559
|
-
onSelectWalletConnect={handleSelectWalletConnect}
|
|
2560
|
-
onSelectConnectedAccount={() => {
|
|
2561
|
-
clearStateForFundMethodSwitch("wallet")
|
|
2562
|
-
setSelectedFundMethod("wallet")
|
|
2563
|
-
goHome()
|
|
2564
|
-
}}
|
|
2565
|
-
onSelectQrCode={() => {
|
|
2566
|
-
navigate("qrcode-options", { backTarget: "payment-methods" })
|
|
2567
|
-
}}
|
|
2568
|
-
/>
|
|
2569
|
-
)
|
|
2570
|
-
case "select-funding-wallet":
|
|
2571
|
-
return <FundWalletSelection />
|
|
2572
|
-
case "onramp-payment-methods":
|
|
2573
|
-
return <OnrampPaymentMethods onBack={() => navigate("fund-methods")} />
|
|
2574
|
-
case "qrcode-options":
|
|
2575
|
-
return (
|
|
2576
|
-
<QRCodeOptions
|
|
2577
|
-
onBack={handleBack}
|
|
2578
|
-
onSelectWalletConnect={handleSelectWalletConnect}
|
|
2579
|
-
onSelectQRCode={() => {
|
|
2580
|
-
clearStateForFundMethodSwitch("direct-transfer")
|
|
2581
|
-
setSelectedFundMethod("direct-transfer")
|
|
2582
|
-
if (currentMode === "fund") {
|
|
2583
|
-
navigate("fund-form")
|
|
2584
|
-
} else {
|
|
2585
|
-
goHome()
|
|
2586
|
-
}
|
|
2587
|
-
}}
|
|
2588
|
-
/>
|
|
2589
|
-
)
|
|
2590
|
-
case "tokens":
|
|
2591
|
-
return (
|
|
2592
|
-
<TokenList
|
|
2593
|
-
onContinue={handleTokenSelect}
|
|
2594
|
-
onBack={handleBack}
|
|
2595
|
-
targetAmountUsd={targetAmountUsd}
|
|
2596
|
-
targetAmountUsdFormatted={targetAmountUsdFormatted}
|
|
2597
|
-
onError={handleTokenListError}
|
|
2598
|
-
recentTokens={recentTokens}
|
|
2599
|
-
onRecentTokenSelect={handleRecentTokenSelect}
|
|
2600
|
-
fundMethod={selectedFundMethod}
|
|
2601
|
-
renderInline={renderInline}
|
|
2602
|
-
onNavigateToFundMethods={() => navigate("fund-methods")}
|
|
2603
|
-
/>
|
|
2604
|
-
)
|
|
2605
|
-
case "select-origin-token":
|
|
2606
|
-
return (
|
|
2607
|
-
<TokenList
|
|
2608
|
-
onContinue={handleTokenSelect}
|
|
2609
|
-
onBack={handleBack}
|
|
2610
|
-
targetAmountUsd={null}
|
|
2611
|
-
targetAmountUsdFormatted={null}
|
|
2612
|
-
onError={handleTokenListError}
|
|
2613
|
-
recentTokens={recentTokens}
|
|
2614
|
-
onRecentTokenSelect={handleRecentTokenSelect}
|
|
2615
|
-
fundMethod={null}
|
|
2616
|
-
renderInline={false}
|
|
2617
|
-
/>
|
|
2618
|
-
)
|
|
2619
|
-
case "select-origin-amount":
|
|
2620
|
-
return (
|
|
2621
|
-
<OriginSelectionAmount
|
|
2622
|
-
token={selectedToken}
|
|
2623
|
-
onBack={() => navigate("select-origin-token")}
|
|
2624
|
-
onCancel={handleCloseModal}
|
|
2625
|
-
onSubmit={handleOriginAmountSubmit}
|
|
2626
|
-
/>
|
|
2627
|
-
)
|
|
2628
|
-
case "send-form":
|
|
2629
|
-
return (
|
|
2630
|
-
<Pay
|
|
2631
|
-
onBack={undefined}
|
|
2632
|
-
selectedToken={selectedToken}
|
|
2633
|
-
onSend={handleOnSend}
|
|
2634
|
-
onWaitingForWalletConfirm={handleWaitingForWalletConfirm}
|
|
2635
|
-
onConfirm={() => navigate("pending")}
|
|
2636
|
-
onComplete={handleTransferComplete}
|
|
2637
|
-
account={walletClient?.account}
|
|
2638
|
-
toRecipient={
|
|
2639
|
-
selectedPool
|
|
2640
|
-
? selectedPool.depositAddress
|
|
2641
|
-
: toAddress || undefined
|
|
2642
|
-
}
|
|
2643
|
-
toAmount={toAmount || undefined}
|
|
2644
|
-
toChainId={
|
|
2645
|
-
selectedPool
|
|
2646
|
-
? selectedPool.chainId
|
|
2647
|
-
: toChainId
|
|
2648
|
-
? Number(toChainId)
|
|
2649
|
-
: undefined
|
|
2650
|
-
}
|
|
2651
|
-
toToken={
|
|
2652
|
-
selectedPool ? selectedPool.token.address : toToken || undefined
|
|
2653
|
-
}
|
|
2654
|
-
toCalldata={
|
|
2655
|
-
selectedPool ? generatedCalldata : toCalldata || undefined
|
|
2656
|
-
}
|
|
2657
|
-
walletClient={walletClient ?? undefined}
|
|
2658
|
-
isSequenceWallet={isSequenceWallet}
|
|
2659
|
-
onTransactionStateChange={handleTransactionStateChange}
|
|
2660
|
-
onError={handleSendError}
|
|
2661
|
-
paymasterUrls={paymasterUrls}
|
|
2662
|
-
setWalletConfirmRetryHandler={setWalletConfirmRetryHandler}
|
|
2663
|
-
swapProvider={swapProvider}
|
|
2664
|
-
bridgeProvider={bridgeProvider}
|
|
2665
|
-
swapProviderFallback={swapProviderFallback}
|
|
2666
|
-
bridgeProviderFallback={bridgeProviderFallback}
|
|
2667
|
-
fundMethod={selectedFundMethod}
|
|
2668
|
-
onAmountUpdate={(amount: string) => {
|
|
2669
|
-
if (
|
|
2670
|
-
selectedPool &&
|
|
2671
|
-
currentMode === "earn" &&
|
|
2672
|
-
amount &&
|
|
2673
|
-
amount !== ""
|
|
2674
|
-
) {
|
|
2675
|
-
try {
|
|
2676
|
-
const updatedCalldata = generateDepositCalldata(
|
|
2677
|
-
selectedPool,
|
|
2678
|
-
amount,
|
|
2679
|
-
)
|
|
2680
|
-
logger.console.log(
|
|
2681
|
-
"Updated calldata:",
|
|
2682
|
-
updatedCalldata,
|
|
2683
|
-
amount,
|
|
2684
|
-
)
|
|
2685
|
-
setGeneratedCalldata(updatedCalldata)
|
|
2686
|
-
} catch (error) {
|
|
2687
|
-
logger.console.error("Error updating calldata:", error)
|
|
2688
|
-
setGeneratedCalldata(undefined)
|
|
2689
|
-
}
|
|
2690
|
-
} else {
|
|
2691
|
-
setGeneratedCalldata(undefined)
|
|
2692
|
-
}
|
|
2693
|
-
}}
|
|
2694
|
-
checkoutOnHandlers={checkoutOnHandlers}
|
|
2695
|
-
recentTokens={recentTokens}
|
|
2696
|
-
onRecentTokenSelect={handleRecentTokenSelect}
|
|
2697
|
-
onTrackToken={handleTrackToken}
|
|
2698
|
-
/>
|
|
2699
|
-
)
|
|
2700
|
-
case "fund-form":
|
|
2701
|
-
return (
|
|
2702
|
-
<Fund
|
|
2703
|
-
selectedToken={selectedToken}
|
|
2704
|
-
onSend={handleOnSend}
|
|
2705
|
-
onWaitingForWalletConfirm={handleWaitingForWalletConfirm}
|
|
2706
|
-
onrampPropsCallback={setOnrampProps}
|
|
2707
|
-
screenNavigationCallback={navigate}
|
|
2708
|
-
onWaitingForOnrampConfirm={handleWaitingOnrampConfirm}
|
|
2709
|
-
onConfirm={() => navigate("pending")}
|
|
2710
|
-
onComplete={handleTransferComplete}
|
|
2711
|
-
account={walletClient?.account}
|
|
2712
|
-
toAmount={toAmount || undefined}
|
|
2713
|
-
toRecipient={toAddress || undefined}
|
|
2714
|
-
toChainId={toChainId ? Number(toChainId) : undefined}
|
|
2715
|
-
toToken={toToken || undefined}
|
|
2716
|
-
toCalldata={toCalldata || undefined}
|
|
2717
|
-
walletClient={walletClient ?? undefined}
|
|
2718
|
-
isSequenceWallet={isSequenceWallet}
|
|
2719
|
-
onTransactionStateChange={handleTransactionStateChange}
|
|
2720
|
-
onError={handleSendError}
|
|
2721
|
-
paymasterUrls={paymasterUrls}
|
|
2722
|
-
setWalletConfirmRetryHandler={setWalletConfirmRetryHandler}
|
|
2723
|
-
swapProvider={swapProvider}
|
|
2724
|
-
bridgeProvider={bridgeProvider}
|
|
2725
|
-
swapProviderFallback={swapProviderFallback}
|
|
2726
|
-
bridgeProviderFallback={bridgeProviderFallback}
|
|
2727
|
-
fundMethod={selectedFundMethod}
|
|
2728
|
-
checkoutOnHandlers={checkoutOnHandlers}
|
|
2729
|
-
recentTokens={recentTokens}
|
|
2730
|
-
onRecentTokenSelect={handleRecentTokenSelect}
|
|
2731
|
-
onTrackToken={handleTrackToken}
|
|
2732
|
-
exactInputOnly={true}
|
|
2733
|
-
defaultInputMode={defaultInputMode}
|
|
2734
|
-
/>
|
|
2735
|
-
)
|
|
2736
|
-
case "onramp-confirmation":
|
|
2737
|
-
return (
|
|
2738
|
-
<OnrampProviderConfirmation
|
|
2739
|
-
onBack={handleBack}
|
|
2740
|
-
onRetry={() => {
|
|
2741
|
-
// Go back to fund screen to regenerate widget session
|
|
2742
|
-
navigate("fund-form")
|
|
2743
|
-
}}
|
|
2744
|
-
onIntentExecuted={() => {
|
|
2745
|
-
// Navigate to pending screen when intent is executed
|
|
2746
|
-
navigate("pending")
|
|
2747
|
-
}}
|
|
2748
|
-
quote={effectivePrepareSendQuote}
|
|
2749
|
-
onRampQuote={onrampProviderQuote}
|
|
2750
|
-
widgetCreationParams={widgetCreationParams}
|
|
2751
|
-
onCreateWidgetSession={createWidgetSession}
|
|
2752
|
-
externalSessionId={externalSessionId}
|
|
2753
|
-
popupWindowRef={onrampPopupWindowRef}
|
|
2754
|
-
/>
|
|
2755
|
-
)
|
|
2756
|
-
case "wallet-confirmation": {
|
|
2757
|
-
// For hook-initiated transactions, use retryEnabled from hostTransactionState
|
|
2758
|
-
const isHookInitiated = hostTransactionState.status !== "idle"
|
|
2759
|
-
const retryEnabled = isHookInitiated
|
|
2760
|
-
? (hostTransactionState.retryEnabled ?? false)
|
|
2761
|
-
: showWalletConfirmRetry
|
|
2762
|
-
|
|
2763
|
-
// For hook-initiated retry, call the retry function from ref
|
|
2764
|
-
const handleHookRetry = () => {
|
|
2765
|
-
if (retryTransactionRef.current) {
|
|
2766
|
-
// Reset retry flag before retrying
|
|
2767
|
-
setHostTransactionState((prev) => ({
|
|
2768
|
-
...prev,
|
|
2769
|
-
retryEnabled: false,
|
|
2770
|
-
}))
|
|
2771
|
-
retryTransactionRef.current()
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
|
|
2775
|
-
return (
|
|
2776
|
-
<WalletConfirmation
|
|
2777
|
-
onBack={handleBack}
|
|
2778
|
-
onComplete={handleWalletConfirmComplete}
|
|
2779
|
-
retryEnabled={retryEnabled}
|
|
2780
|
-
onRetry={
|
|
2781
|
-
isHookInitiated ? handleHookRetry : handleWalletConfirmRetry
|
|
2782
|
-
}
|
|
2783
|
-
quote={effectivePrepareSendQuote}
|
|
2784
|
-
onRampQuote={onrampProviderQuote}
|
|
2785
|
-
/>
|
|
2786
|
-
)
|
|
2787
|
-
}
|
|
2788
|
-
case "qr-code-wallet-select":
|
|
2789
|
-
return (
|
|
2790
|
-
<QRCodeWalletSelect
|
|
2791
|
-
onBack={handleBack}
|
|
2792
|
-
onSelect={(walletId) => {
|
|
2793
|
-
setQrCodeWalletId(walletId)
|
|
2794
|
-
navigate("direct-transfer-screen")
|
|
2795
|
-
}}
|
|
2796
|
-
selectedWalletId={qrCodeWalletId}
|
|
2797
|
-
/>
|
|
2798
|
-
)
|
|
2799
|
-
case "direct-transfer-screen":
|
|
2800
|
-
return (
|
|
2801
|
-
<DirectTransfer
|
|
2802
|
-
onBack={() => {
|
|
2803
|
-
if (currentMode === "fund") {
|
|
2804
|
-
navigate("fund-form")
|
|
2805
|
-
} else {
|
|
2806
|
-
goHome()
|
|
2807
|
-
}
|
|
2808
|
-
}}
|
|
2809
|
-
onChangeWallet={() => navigate("qr-code-wallet-select")}
|
|
2810
|
-
quote={effectivePrepareSendQuote}
|
|
2811
|
-
selectedWalletId={qrCodeWalletId}
|
|
2812
|
-
walletOptions={qrCodeWallets}
|
|
2813
|
-
onIntentExecuted={() => navigate("pending")}
|
|
2814
|
-
/>
|
|
2815
|
-
)
|
|
2816
|
-
case "pending":
|
|
2817
|
-
return (
|
|
2818
|
-
<TransferPending
|
|
2819
|
-
onElapsedTime={handleElapsedTime}
|
|
2820
|
-
transactionStates={effectiveTransactionStates}
|
|
2821
|
-
quote={effectivePrepareSendQuote}
|
|
2822
|
-
onRampQuote={onrampProviderQuote}
|
|
2823
|
-
fundMethod={selectedFundMethod}
|
|
2824
|
-
timestamp={hostTransactionTimestamp ?? undefined}
|
|
2825
|
-
onContinue={() => {
|
|
2826
|
-
logger.console.log("[trails-sdk] onContinue called")
|
|
2827
|
-
navigate("receipt")
|
|
2828
|
-
}}
|
|
2829
|
-
/>
|
|
2830
|
-
)
|
|
2831
|
-
case "receipt": {
|
|
2832
|
-
// For hook-initiated transactions, use custom receipt action if provided
|
|
2833
|
-
const isHookInitiated = hostTransactionState.status !== "idle"
|
|
2834
|
-
const receiptOnSendAnother = isHookInitiated
|
|
2835
|
-
? (onReceiptAction ?? undefined)
|
|
2836
|
-
: handleSendAnother
|
|
2837
|
-
const receiptActionText = isHookInitiated
|
|
2838
|
-
? (receiptActionButtonText ?? undefined)
|
|
2839
|
-
: undefined
|
|
2840
|
-
|
|
2841
|
-
return (
|
|
2842
|
-
<Receipt
|
|
2843
|
-
onSendAnother={receiptOnSendAnother}
|
|
2844
|
-
onClose={handleCloseModal}
|
|
2845
|
-
renderInline={renderInline}
|
|
2846
|
-
transactionStates={effectiveTransactionStates}
|
|
2847
|
-
totalCompletionSeconds={displayTotalCompletionSeconds ?? undefined}
|
|
2848
|
-
quote={effectivePrepareSendQuote}
|
|
2849
|
-
showCloseButton={false}
|
|
2850
|
-
actionButtonText={receiptActionText}
|
|
2851
|
-
onRampQuote={onrampProviderQuote}
|
|
2852
|
-
/>
|
|
2853
|
-
)
|
|
2854
|
-
}
|
|
2855
|
-
case "onramp-mesh":
|
|
2856
|
-
logger.console.log("[trails-sdk] Rendering onramp screen", {
|
|
2857
|
-
onrampFactory: !!onrampFactory,
|
|
2858
|
-
onrampProps,
|
|
2859
|
-
})
|
|
2860
|
-
|
|
2861
|
-
// Check if onramp factory function is provided
|
|
2862
|
-
if (!onrampFactory) {
|
|
2863
|
-
// Factory not provided - show fallback UI
|
|
2864
|
-
return (
|
|
2865
|
-
<div className="flex flex-col h-full p-4">
|
|
2866
|
-
<div className="flex items-center mb-4">
|
|
2867
|
-
<button
|
|
2868
|
-
type="button"
|
|
2869
|
-
onClick={handleBack}
|
|
2870
|
-
className="flex h-8 w-8 justify-center items-center rounded-full bg-gray-50 dark:bg-gray-700 cursor-pointer transition-colors text-gray-900 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-600 mr-2"
|
|
2871
|
-
title="Back"
|
|
2872
|
-
>
|
|
2873
|
-
←
|
|
2874
|
-
</button>
|
|
2875
|
-
<h2 className="text-lg font-semibold text-gray-900 dark:text-white">
|
|
2876
|
-
Exchange Funding
|
|
2877
|
-
</h2>
|
|
2878
|
-
</div>
|
|
2879
|
-
<div className="flex-1 flex items-center justify-center">
|
|
2880
|
-
<div className="text-center p-4 border border-solid border-gray-200 dark:border-gray-700 rounded-lg">
|
|
2881
|
-
<p className="text-gray-600 dark:text-gray-400 mb-2">
|
|
2882
|
-
Exchange funding is not available.
|
|
2883
|
-
</p>
|
|
2884
|
-
<p className="text-sm text-gray-500 dark:text-gray-500">
|
|
2885
|
-
Please provide an onramp factory function to enable this
|
|
2886
|
-
feature.
|
|
2887
|
-
</p>
|
|
2888
|
-
</div>
|
|
2889
|
-
</div>
|
|
2890
|
-
</div>
|
|
2891
|
-
)
|
|
2892
|
-
}
|
|
2893
|
-
|
|
2894
|
-
// Call the factory function with handlers to get the component
|
|
2895
|
-
try {
|
|
2896
|
-
return (
|
|
2897
|
-
<div className="flex flex-col h-full">
|
|
2898
|
-
<div className="flex-1 min-h-0">
|
|
2899
|
-
{onrampFactory({
|
|
2900
|
-
setCurrentScreen: (screen) => {
|
|
2901
|
-
navigate(screen as Screen)
|
|
2902
|
-
},
|
|
2903
|
-
onComplete: (transferData) => {
|
|
2904
|
-
void handleOnrampComplete(
|
|
2905
|
-
transferData as OnrampTransferResult,
|
|
2906
|
-
)
|
|
2907
|
-
},
|
|
2908
|
-
onError: (error) => {
|
|
2909
|
-
logger.console.error("[trails-sdk] Onramp error:", error)
|
|
2910
|
-
},
|
|
2911
|
-
onBack: handleBack,
|
|
2912
|
-
toTokenSymbol: onrampProps?.toTokenSymbol,
|
|
2913
|
-
toTokenAmount: onrampProps?.toTokenAmount,
|
|
2914
|
-
toChainId: onrampProps?.toChainId,
|
|
2915
|
-
toRecipientAddress: onrampProps?.toRecipientAddress,
|
|
2916
|
-
toAmountUsd: onrampProps?.toAmountUsd,
|
|
2917
|
-
selectedExchange: selectedMeshExchange || undefined,
|
|
2918
|
-
apiKey: trailsApiKey,
|
|
2919
|
-
hostname: trailsApiUrl,
|
|
2920
|
-
})}
|
|
2921
|
-
</div>
|
|
2922
|
-
{effectivePrepareSendQuote && (
|
|
2923
|
-
<div className="mt-4">
|
|
2924
|
-
<QuoteDetails
|
|
2925
|
-
quote={effectivePrepareSendQuote}
|
|
2926
|
-
showContent={true}
|
|
2927
|
-
compact={true}
|
|
2928
|
-
/>
|
|
2929
|
-
</div>
|
|
2930
|
-
)}
|
|
2931
|
-
</div>
|
|
2932
|
-
)
|
|
2933
|
-
} catch (error) {
|
|
2934
|
-
logger.console.error("[trails-sdk] Error rendering onramp:", error)
|
|
2935
|
-
return (
|
|
2936
|
-
<div className="flex flex-col h-full p-4">
|
|
2937
|
-
<div className="flex items-center mb-4">
|
|
2938
|
-
<button
|
|
2939
|
-
type="button"
|
|
2940
|
-
onClick={handleBack}
|
|
2941
|
-
className="flex h-8 w-8 justify-center items-center rounded-full bg-gray-50 dark:bg-gray-700 cursor-pointer transition-colors text-gray-900 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-600 mr-2"
|
|
2942
|
-
title="Back"
|
|
2943
|
-
>
|
|
2944
|
-
←
|
|
2945
|
-
</button>
|
|
2946
|
-
<h2 className="text-lg font-semibold text-gray-900 dark:text-white">
|
|
2947
|
-
Exchange Funding
|
|
2948
|
-
</h2>
|
|
2949
|
-
</div>
|
|
2950
|
-
<div className="flex-1 flex items-center justify-center">
|
|
2951
|
-
<div className="text-center p-4 border border-solid border-red-200 dark:border-red-700 rounded-lg">
|
|
2952
|
-
<p className="text-red-600 dark:text-red-400 mb-2">
|
|
2953
|
-
Error loading exchange funding.
|
|
2954
|
-
</p>
|
|
2955
|
-
<p className="text-sm text-red-500 dark:text-red-500">
|
|
2956
|
-
{error instanceof Error ? error.message : "Unknown error"}
|
|
2957
|
-
</p>
|
|
2958
|
-
</div>
|
|
2959
|
-
</div>
|
|
2960
|
-
</div>
|
|
2961
|
-
)
|
|
2962
|
-
}
|
|
2963
|
-
case "onramp-meld":
|
|
2964
|
-
return <MeldStepsFlow onBack={handleBack} />
|
|
2965
|
-
case "wallet-connect":
|
|
2966
|
-
return (
|
|
2967
|
-
<WalletConnectScreen
|
|
2968
|
-
onBack={handleBack}
|
|
2969
|
-
onContinue={handleContinue}
|
|
2970
|
-
onReconnectPreviousWallet={handleReconnectPreviousWallet}
|
|
2971
|
-
selectedWalletId={selectedWalletId || undefined}
|
|
2972
|
-
/>
|
|
2973
|
-
)
|
|
2974
|
-
case "wallet-list":
|
|
2975
|
-
return (
|
|
2976
|
-
<WalletList
|
|
2977
|
-
onBack={handleBack}
|
|
2978
|
-
onWalletSelect={(walletId) => {
|
|
2979
|
-
logger.console.log(
|
|
2980
|
-
"[trails-sdk] Wallet selected from wallet-list:",
|
|
2981
|
-
walletId,
|
|
2982
|
-
)
|
|
2983
|
-
|
|
2984
|
-
if (
|
|
2985
|
-
isWalletConnectConnector(
|
|
2986
|
-
allWallets.find((w) => w.id === walletId)?.connector as
|
|
2987
|
-
| Connector
|
|
2988
|
-
| undefined,
|
|
2989
|
-
)
|
|
2990
|
-
) {
|
|
2991
|
-
saveLastClickedWallet(walletId)
|
|
2992
|
-
logger.console.log(
|
|
2993
|
-
"[trails-sdk] WalletConnect selected, going to wallet-connect screen",
|
|
2994
|
-
)
|
|
2995
|
-
navigate("wallet-connect")
|
|
2996
|
-
} else {
|
|
2997
|
-
saveLastClickedWallet(walletId)
|
|
2998
|
-
logger.console.log(
|
|
2999
|
-
"[trails-sdk] Regular wallet selected, going to wallet-connection-pending",
|
|
3000
|
-
)
|
|
3001
|
-
// Don't reset the redirect flag - user has already been through initial flow
|
|
3002
|
-
setTimeout(() => {
|
|
3003
|
-
// Preserve the existing back route from the navigation stack
|
|
3004
|
-
const backRoute = backScreen
|
|
3005
|
-
const safeBackRoute =
|
|
3006
|
-
backRoute === "wallet-confirmation" ? undefined : backRoute
|
|
3007
|
-
navigate("wallet-connection-pending", {
|
|
3008
|
-
backTarget: safeBackRoute || undefined,
|
|
3009
|
-
})
|
|
3010
|
-
}, 100)
|
|
3011
|
-
// Auto-trigger connection
|
|
3012
|
-
setTimeout(() => {
|
|
3013
|
-
handleConnectWallet(walletId, undefined)
|
|
3014
|
-
}, 100)
|
|
3015
|
-
}
|
|
3016
|
-
}}
|
|
3017
|
-
walletOptions={allWallets.map((wallet) => ({
|
|
3018
|
-
id: wallet.id,
|
|
3019
|
-
name: wallet.name,
|
|
3020
|
-
icon: wallet.icon,
|
|
3021
|
-
}))}
|
|
3022
|
-
/>
|
|
3023
|
-
)
|
|
3024
|
-
case "earn":
|
|
3025
|
-
return (
|
|
3026
|
-
<Earn
|
|
3027
|
-
onContinue={() => navigate("send-form")}
|
|
3028
|
-
account={walletClient?.account}
|
|
3029
|
-
walletClient={walletClient ?? undefined}
|
|
3030
|
-
onTransactionStateChange={handleTransactionStateChange}
|
|
3031
|
-
onError={handleSendError}
|
|
3032
|
-
onWaitingForWalletConfirm={handleWaitingForWalletConfirm}
|
|
3033
|
-
onConfirm={() => navigate("pending")}
|
|
3034
|
-
onComplete={handleTransferComplete}
|
|
3035
|
-
onSend={handleOnSend}
|
|
3036
|
-
paymasterUrls={paymasterUrls}
|
|
3037
|
-
setWalletConfirmRetryHandler={setWalletConfirmRetryHandler}
|
|
3038
|
-
swapProvider={swapProvider}
|
|
3039
|
-
bridgeProvider={bridgeProvider}
|
|
3040
|
-
swapProviderFallback={swapProviderFallback}
|
|
3041
|
-
bridgeProviderFallback={bridgeProviderFallback}
|
|
3042
|
-
fundMethod={selectedFundMethod}
|
|
3043
|
-
checkoutOnHandlers={checkoutOnHandlers}
|
|
3044
|
-
recentTokens={recentTokens}
|
|
3045
|
-
onRecentTokenSelect={handleRecentTokenSelect}
|
|
3046
|
-
onTrackToken={handleTrackToken}
|
|
3047
|
-
/>
|
|
3048
|
-
)
|
|
3049
|
-
case "earn-pools":
|
|
3050
|
-
return (
|
|
3051
|
-
<EarnPools
|
|
3052
|
-
onBack={handleBack}
|
|
3053
|
-
onPoolSelect={(pool) => {
|
|
3054
|
-
logger.console.log("Selected pool:", pool)
|
|
3055
|
-
setSelectedPool(pool)
|
|
3056
|
-
navigate("send-form")
|
|
3057
|
-
}}
|
|
3058
|
-
/>
|
|
3059
|
-
)
|
|
3060
|
-
case "swap":
|
|
3061
|
-
return (
|
|
3062
|
-
<Swap
|
|
3063
|
-
onSend={handleOnSend}
|
|
3064
|
-
onWaitingForWalletConfirm={handleWaitingForWalletConfirm}
|
|
3065
|
-
onWaitingForOnrampConfirm={handleWaitingOnrampConfirm}
|
|
3066
|
-
onConfirm={() => navigate("pending")}
|
|
3067
|
-
onComplete={handleTransferComplete}
|
|
3068
|
-
selectedToken={selectedToken}
|
|
3069
|
-
account={walletClient?.account}
|
|
3070
|
-
toRecipient={toAddress || undefined}
|
|
3071
|
-
toAmount={toAmount || undefined}
|
|
3072
|
-
toChainId={toChainId ? Number(toChainId) : undefined}
|
|
3073
|
-
toToken={toToken || undefined}
|
|
3074
|
-
toCalldata={toCalldata || undefined}
|
|
3075
|
-
walletClient={walletClient ?? undefined}
|
|
3076
|
-
isSequenceWallet={isSequenceWallet}
|
|
3077
|
-
onTransactionStateChange={handleTransactionStateChange}
|
|
3078
|
-
onError={handleSendError}
|
|
3079
|
-
paymasterUrls={paymasterUrls}
|
|
3080
|
-
setWalletConfirmRetryHandler={setWalletConfirmRetryHandler}
|
|
3081
|
-
swapProvider={swapProvider}
|
|
3082
|
-
bridgeProvider={bridgeProvider}
|
|
3083
|
-
swapProviderFallback={swapProviderFallback}
|
|
3084
|
-
bridgeProviderFallback={bridgeProviderFallback}
|
|
3085
|
-
fundMethod={selectedFundMethod}
|
|
3086
|
-
onAmountUpdate={undefined}
|
|
3087
|
-
checkoutOnHandlers={checkoutOnHandlers}
|
|
3088
|
-
recentTokens={recentTokens}
|
|
3089
|
-
onRecentTokenSelect={handleRecentTokenSelect}
|
|
3090
|
-
onTrackToken={handleTrackToken}
|
|
3091
|
-
/>
|
|
3092
|
-
)
|
|
3093
|
-
case "withdraw":
|
|
3094
|
-
return (
|
|
3095
|
-
<Withdraw
|
|
3096
|
-
onSend={handleOnSend}
|
|
3097
|
-
onWaitingForWalletConfirm={handleWaitingForWalletConfirm}
|
|
3098
|
-
onConfirm={() => navigate("pending")}
|
|
3099
|
-
onComplete={handleTransferComplete}
|
|
3100
|
-
selectedToken={selectedToken}
|
|
3101
|
-
account={walletClient?.account}
|
|
3102
|
-
toRecipient={toAddress || undefined}
|
|
3103
|
-
toAmount={toAmount || undefined}
|
|
3104
|
-
toChainId={toChainId ? Number(toChainId) : undefined}
|
|
3105
|
-
toToken={toToken || undefined}
|
|
3106
|
-
toCalldata={toCalldata || undefined}
|
|
3107
|
-
fromToken={fromToken || undefined}
|
|
3108
|
-
fromChainId={fromChainId ? Number(fromChainId) : undefined}
|
|
3109
|
-
walletClient={walletClient ?? undefined}
|
|
3110
|
-
isSequenceWallet={isSequenceWallet}
|
|
3111
|
-
onTransactionStateChange={handleTransactionStateChange}
|
|
3112
|
-
onError={handleSendError}
|
|
3113
|
-
paymasterUrls={paymasterUrls}
|
|
3114
|
-
setWalletConfirmRetryHandler={setWalletConfirmRetryHandler}
|
|
3115
|
-
swapProvider={swapProvider}
|
|
3116
|
-
bridgeProvider={bridgeProvider}
|
|
3117
|
-
swapProviderFallback={swapProviderFallback}
|
|
3118
|
-
bridgeProviderFallback={bridgeProviderFallback}
|
|
3119
|
-
checkoutOnHandlers={checkoutOnHandlers}
|
|
3120
|
-
recentTokens={recentTokens}
|
|
3121
|
-
onTrackToken={handleTrackToken}
|
|
3122
|
-
defaultInputMode={defaultInputMode}
|
|
3123
|
-
/>
|
|
3124
|
-
)
|
|
3125
|
-
case "wallet-connection-pending":
|
|
3126
|
-
return (
|
|
3127
|
-
<WalletConnectionPending
|
|
3128
|
-
onBack={handleBack}
|
|
3129
|
-
onRetry={() => {
|
|
3130
|
-
if (selectedWalletId) {
|
|
3131
|
-
setShowWalletConnectionRetry(false)
|
|
3132
|
-
handleConnectWallet(selectedWalletId)
|
|
3133
|
-
}
|
|
3134
|
-
}}
|
|
3135
|
-
selectedWalletId={selectedWalletId || ""}
|
|
3136
|
-
isConnecting={isConnecting}
|
|
3137
|
-
error={displayError}
|
|
3138
|
-
showRetry={showWalletConnectionRetry}
|
|
3139
|
-
/>
|
|
3140
|
-
)
|
|
3141
|
-
case "account-history":
|
|
3142
|
-
return (
|
|
3143
|
-
<AccountIntentTransactionHistory
|
|
3144
|
-
accountAddress={address}
|
|
3145
|
-
onBack={handleBack}
|
|
3146
|
-
/>
|
|
3147
|
-
)
|
|
3148
|
-
case "meld-history":
|
|
3149
|
-
return (
|
|
3150
|
-
<MeldHistory limit={20} autoRefetch={false} onBack={handleBack} />
|
|
3151
|
-
)
|
|
3152
|
-
case "account-settings":
|
|
3153
|
-
// Note: Global wallet connection check in widget.tsx ensures user is connected
|
|
3154
|
-
return <AccountSettings onBack={handleBack} />
|
|
3155
|
-
case "user-preferences":
|
|
3156
|
-
return <UserPreferences onBack={handleBack} />
|
|
3157
|
-
case "chain-list":
|
|
3158
|
-
return <ChainList onBack={() => navigate("tokens")} />
|
|
3159
|
-
case "recipients":
|
|
3160
|
-
return <Recipients onBack={handleBack} />
|
|
3161
|
-
case "disconnect":
|
|
3162
|
-
return (
|
|
3163
|
-
<Disconnect
|
|
3164
|
-
onBack={handleBack}
|
|
3165
|
-
disconnectHandler={handleWalletDisconnect}
|
|
3166
|
-
/>
|
|
3167
|
-
)
|
|
3168
|
-
}
|
|
3169
|
-
|
|
3170
|
-
const unhandledScreen: never = screen
|
|
3171
|
-
throw new Error(`[trails-sdk] Unhandled screen state: ${unhandledScreen}`)
|
|
3172
|
-
}
|
|
3173
|
-
|
|
3174
|
-
const renderScreen = () => {
|
|
3175
|
-
return (
|
|
3176
|
-
<PriceImpactWarningProvider
|
|
3177
|
-
value={{
|
|
3178
|
-
thresholdBps: priceImpactWarningThresholdBps,
|
|
3179
|
-
warningMessage: priceImpactWarningMessage,
|
|
3180
|
-
fallbackBridgeUrl: priceImpactFallbackBridgeUrl,
|
|
3181
|
-
}}
|
|
3182
|
-
>
|
|
3183
|
-
<motion.div
|
|
3184
|
-
initial={{ opacity: 0, scale: 0.95 }}
|
|
3185
|
-
animate={{ opacity: 1, scale: 1 }}
|
|
3186
|
-
exit={{ opacity: 0, scale: 0.95 }}
|
|
3187
|
-
transition={{
|
|
3188
|
-
type: "spring",
|
|
3189
|
-
stiffness: 200,
|
|
3190
|
-
damping: 30,
|
|
3191
|
-
mass: 1,
|
|
3192
|
-
}}
|
|
3193
|
-
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"
|
|
3194
|
-
layout
|
|
3195
|
-
layoutId="modal-container"
|
|
3196
|
-
onClick={(e: React.MouseEvent) => e.stopPropagation()}
|
|
3197
|
-
>
|
|
3198
|
-
<AnimatePresence mode="wait">
|
|
3199
|
-
<motion.div
|
|
3200
|
-
key={screen}
|
|
3201
|
-
initial={{ opacity: 0, x: 20 }}
|
|
3202
|
-
animate={{ opacity: 1, x: 0 }}
|
|
3203
|
-
exit={{ opacity: 0, x: -20 }}
|
|
3204
|
-
transition={{
|
|
3205
|
-
type: "spring",
|
|
3206
|
-
stiffness: 500,
|
|
3207
|
-
damping: 30,
|
|
3208
|
-
mass: 0.6,
|
|
3209
|
-
}}
|
|
3210
|
-
className="flex-1 flex flex-col w-full min-w-0"
|
|
3211
|
-
layout
|
|
3212
|
-
>
|
|
3213
|
-
{renderScreenContent()}
|
|
3214
|
-
{/* Error Display */}
|
|
3215
|
-
{displayError && (
|
|
3216
|
-
<div className="mt-2">
|
|
3217
|
-
<ErrorDisplay
|
|
3218
|
-
errorPrettified={getPrettifiedErrorMessage(
|
|
3219
|
-
displayError,
|
|
3220
|
-
"An error occurred",
|
|
3221
|
-
)}
|
|
3222
|
-
error={displayError}
|
|
3223
|
-
severity="error"
|
|
3224
|
-
/>
|
|
3225
|
-
</div>
|
|
3226
|
-
)}
|
|
3227
|
-
</motion.div>
|
|
3228
|
-
</AnimatePresence>
|
|
3229
|
-
<Footer onDebugScreenSelect={handleDebugScreenSelect} />
|
|
3230
|
-
</motion.div>
|
|
3231
|
-
</PriceImpactWarningProvider>
|
|
3232
|
-
)
|
|
3233
|
-
}
|
|
3234
|
-
|
|
3235
|
-
if (renderInline) {
|
|
3236
|
-
return renderScreen()
|
|
3237
|
-
}
|
|
3238
|
-
|
|
3239
|
-
return (
|
|
3240
|
-
<div className="flex flex-col items-center justify-center space-y-8 py-12">
|
|
3241
|
-
{!children ? (
|
|
3242
|
-
<motion.button
|
|
3243
|
-
whileHover={{ scale: 1.02 }}
|
|
3244
|
-
whileTap={{ scale: 0.98 }}
|
|
3245
|
-
onClick={handleOpenModal}
|
|
3246
|
-
className="trails-modal-button cursor-pointer font-semibold py-3 px-6 trails-font"
|
|
3247
|
-
>
|
|
3248
|
-
{buttonText || defaultButtonText}
|
|
3249
|
-
</motion.button>
|
|
3250
|
-
) : (
|
|
3251
|
-
<motion.div
|
|
3252
|
-
whileHover={{ scale: 1.02 }}
|
|
3253
|
-
whileTap={{ scale: 0.98 }}
|
|
3254
|
-
className="flex flex-col items-center justify-center"
|
|
3255
|
-
onClick={handleOpenModal}
|
|
3256
|
-
>
|
|
3257
|
-
{children}
|
|
3258
|
-
</motion.div>
|
|
3259
|
-
)}
|
|
3260
|
-
|
|
3261
|
-
<AnimatePresence>
|
|
3262
|
-
{isModalOpen && (
|
|
3263
|
-
<Modal isOpen={isModalOpen} onClose={handleCloseModal}>
|
|
3264
|
-
{renderScreen()}
|
|
3265
|
-
</Modal>
|
|
3266
|
-
)}
|
|
3267
|
-
</AnimatePresence>
|
|
3268
|
-
</div>
|
|
3269
|
-
)
|
|
3270
|
-
})
|
|
3271
|
-
|
|
3272
|
-
const WidgetInner = forwardRef<TrailsWidgetRef, TrailsWidgetProps>(
|
|
3273
|
-
(props, ref) => {
|
|
3274
|
-
return (
|
|
3275
|
-
<WidgetProviders props={props}>
|
|
3276
|
-
<ThemeSyncer />
|
|
3277
|
-
<WidgetContent ref={ref} />
|
|
3278
|
-
</WidgetProviders>
|
|
3279
|
-
)
|
|
3280
|
-
},
|
|
3281
|
-
)
|
|
3282
|
-
|
|
3283
|
-
export const TrailsWidget = forwardRef<TrailsWidgetRef, TrailsWidgetProps>(
|
|
3284
|
-
(props, ref) => {
|
|
3285
|
-
// Validate required props
|
|
3286
|
-
if (!props.apiKey) {
|
|
3287
|
-
throw new Error("apiKey is required")
|
|
3288
|
-
}
|
|
3289
|
-
|
|
3290
|
-
// Memoize connectors separately to ensure stable references
|
|
3291
|
-
const connectors = React.useMemo(() => {
|
|
3292
|
-
if (!Array.isArray(props.wagmiConnectors)) {
|
|
3293
|
-
return getConnectorsInternal(props.apiKey, props.trailsApiUrl)
|
|
3294
|
-
}
|
|
3295
|
-
|
|
3296
|
-
if (
|
|
3297
|
-
props.wagmiConnectors.some((connector) =>
|
|
3298
|
-
isWalletConnectConnector(connector),
|
|
3299
|
-
)
|
|
3300
|
-
) {
|
|
3301
|
-
return props.wagmiConnectors
|
|
3302
|
-
}
|
|
3303
|
-
|
|
3304
|
-
logger.console.warn(
|
|
3305
|
-
"[trails-sdk] wagmiConnectors is missing WalletConnect connector; appending internal WalletConnect connector to avoid broken QR flow",
|
|
3306
|
-
)
|
|
3307
|
-
// TODO: Remove this append fallback in a future major release. The correct long-term behavior may be to hide WalletConnect options when consumers intentionally omit the connector.
|
|
3308
|
-
return [...props.wagmiConnectors, getWalletConnectConnector()]
|
|
3309
|
-
}, [props.apiKey, props.trailsApiUrl, props.wagmiConnectors])
|
|
3310
|
-
|
|
3311
|
-
// Create stable wagmi config using useMemo with minimal dependencies
|
|
3312
|
-
const wagmiConfig = React.useMemo(() => {
|
|
3313
|
-
// Use custom storage when decoupleWagmi is true to avoid conflicts with parent app's wagmi
|
|
3314
|
-
// When decoupled, we DON'T want to persist connections to avoid infinite loops on reconnect
|
|
3315
|
-
const storage = props.decoupleWagmi
|
|
3316
|
-
? createStorage({
|
|
3317
|
-
storage: {
|
|
3318
|
-
getItem: () => null,
|
|
3319
|
-
setItem: () => {},
|
|
3320
|
-
removeItem: () => {},
|
|
3321
|
-
},
|
|
3322
|
-
key: "trails-widget-decoupled-wagmi",
|
|
3323
|
-
})
|
|
3324
|
-
: undefined
|
|
3325
|
-
|
|
3326
|
-
return createWagmiConfig({
|
|
3327
|
-
apiKey: props.apiKey,
|
|
3328
|
-
nodeGatewayUrl: props.sequenceNodeGatewayUrl,
|
|
3329
|
-
connectors,
|
|
3330
|
-
storage,
|
|
3331
|
-
})
|
|
3332
|
-
}, [
|
|
3333
|
-
props.apiKey,
|
|
3334
|
-
props.decoupleWagmi,
|
|
3335
|
-
props.sequenceNodeGatewayUrl,
|
|
3336
|
-
connectors,
|
|
3337
|
-
])
|
|
3338
|
-
|
|
3339
|
-
const trailsConfig: TrailsProviderProps["config"] = {
|
|
3340
|
-
trailsApiKey: props.apiKey,
|
|
3341
|
-
trailsApiUrl: props.trailsApiUrl,
|
|
3342
|
-
trailsAppUrl: props.trailsAppUrl,
|
|
3343
|
-
sequenceApiUrl: props.sequenceApiUrl,
|
|
3344
|
-
sequenceIndexerUrl: props.sequenceIndexerUrl,
|
|
3345
|
-
sequenceNodeGatewayUrl: props.sequenceNodeGatewayUrl,
|
|
3346
|
-
sequenceMetadataUrl: props.sequenceMetadataUrl,
|
|
3347
|
-
walletConnectProjectId: props.walletConnectProjectId,
|
|
3348
|
-
slippageTolerance: props.slippageTolerance
|
|
3349
|
-
? String(props.slippageTolerance)
|
|
3350
|
-
: undefined,
|
|
3351
|
-
debug: props.debug,
|
|
3352
|
-
}
|
|
3353
|
-
|
|
3354
|
-
logger.console.log("trailsConfig", trailsConfig)
|
|
3355
|
-
|
|
3356
|
-
const widgetContent = (
|
|
3357
|
-
<ThemeProvider initialTheme={props.theme}>
|
|
3358
|
-
<WidgetInner {...props} ref={ref} />
|
|
3359
|
-
</ThemeProvider>
|
|
3360
|
-
)
|
|
3361
|
-
|
|
3362
|
-
const providerTreeProps: ProviderTreeProps = {
|
|
3363
|
-
widgetContent,
|
|
3364
|
-
wagmiConfig,
|
|
3365
|
-
trailsConfig,
|
|
3366
|
-
}
|
|
3367
|
-
|
|
3368
|
-
const content = props.decoupleWagmi ? (
|
|
3369
|
-
<IsolatedProviders {...providerTreeProps} />
|
|
3370
|
-
) : (
|
|
3371
|
-
<DefaultProviders {...providerTreeProps} />
|
|
3372
|
-
)
|
|
3373
|
-
|
|
3374
|
-
const customCss =
|
|
3375
|
-
props.customCss instanceof Object
|
|
3376
|
-
? cssObjectToString(props.customCss)
|
|
3377
|
-
: props.customCss
|
|
3378
|
-
|
|
3379
|
-
if (props.disableCss) {
|
|
3380
|
-
return <StrictMode>{content}</StrictMode>
|
|
3381
|
-
}
|
|
3382
|
-
|
|
3383
|
-
return (
|
|
3384
|
-
<ShadowPortal customCss={customCss}>
|
|
3385
|
-
<StrictMode>{content}</StrictMode>
|
|
3386
|
-
</ShadowPortal>
|
|
3387
|
-
)
|
|
3388
|
-
},
|
|
3389
|
-
)
|
|
3390
|
-
|
|
3391
|
-
// Export standalone functions for modal control
|
|
3392
|
-
export const createModalController = (
|
|
3393
|
-
ref: React.RefObject<TrailsWidgetRef>,
|
|
3394
|
-
) => ({
|
|
3395
|
-
openModal: () => ref.current?.openModal?.(),
|
|
3396
|
-
closeModal: () => ref.current?.closeModal?.(),
|
|
3397
|
-
isModalOpen: ref.current?.isModalOpen ?? false,
|
|
3398
|
-
})
|
|
3399
|
-
|
|
3400
|
-
export default TrailsWidget
|