0xtrails 0.13.2 → 0.14.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/trailsHydrate.d.ts +5 -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/{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-C1NhDLF_.js +4 -0
- package/dist/chains-CcoarGia.js +658 -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/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 +1 -1
- 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 +2 -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 +439 -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 +6 -11
- 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 +2 -2
- package/dist/hooks/useTokenList.d.ts.map +1 -0
- package/dist/{widget/hooks → hooks}/useTrailsSendTransaction.d.ts +1 -1
- 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 +6 -0
- package/dist/hydrate/index.d.ts.map +1 -0
- package/dist/hydrate/index.js +11 -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/types.d.ts +19 -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-Cr9eaeDK.js +654 -0
- package/dist/index.d.ts +19 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +157 -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 +25 -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/prepareSend.d.ts +3 -2
- package/dist/prepareSend.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-4HYDQv2T.js +48798 -0
- 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 +4 -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 +3 -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 +1370 -410
- package/dist/utils/localStorageGc.d.ts +22 -0
- package/dist/utils/localStorageGc.d.ts.map +1 -0
- package/dist/walletUtils.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.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/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/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/PoolWithdraw.d.ts +2 -2
- package/dist/widget/components/PoolWithdraw.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 +1 -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/index.d.ts +13 -0
- package/dist/widget/index.d.ts.map +1 -1
- package/dist/widget/index.js +16 -8
- package/dist/widget/modes/EarnWidget.d.ts +83 -0
- package/dist/widget/modes/EarnWidget.d.ts.map +1 -0
- package/dist/widget/modes/FundWidget.d.ts +103 -0
- package/dist/widget/modes/FundWidget.d.ts.map +1 -0
- package/dist/widget/modes/PayWidget.d.ts +86 -0
- package/dist/widget/modes/PayWidget.d.ts.map +1 -0
- package/dist/widget/modes/SwapWidget.d.ts +82 -0
- package/dist/widget/modes/SwapWidget.d.ts.map +1 -0
- package/dist/widget/modes/WithdrawWidget.d.ts +71 -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/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 +22 -0
- package/dist/widget/shared/resolution.d.ts.map +1 -0
- package/dist/widget/shared/resolvePaymentSource.d.ts +34 -0
- package/dist/widget/shared/resolvePaymentSource.d.ts.map +1 -0
- package/dist/widget/shared/types.d.ts +94 -0
- package/dist/widget/shared/types.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 +21 -16
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +17 -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.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/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
|
@@ -1,2463 +0,0 @@
|
|
|
1
|
-
import { useQuery } from "@tanstack/react-query"
|
|
2
|
-
import { ArrowLeftRight } from "lucide-react"
|
|
3
|
-
import type React from "react"
|
|
4
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
|
5
|
-
import { trackOnrampWidgetSession } from "../../analytics.js"
|
|
6
|
-
import { isPositiveNumber, toSafeNumber } from "../../utils/validation.js"
|
|
7
|
-
import { getChainInfo } from "../../chains.js"
|
|
8
|
-
import { FIAT_CURRENCY_SYMBOLS, USDC_BASE } from "../../constants.js"
|
|
9
|
-
import { getFullErrorMessage, getPrettifiedErrorMessage } from "../../error.js"
|
|
10
|
-
import { logger } from "../../logger.js"
|
|
11
|
-
import { MeldProvidersList } from "../../meld/components/MeldProvidersList.js"
|
|
12
|
-
import { TradeType } from "../../prepareSend.js"
|
|
13
|
-
import {
|
|
14
|
-
formatUsdAmountDisplay,
|
|
15
|
-
formatUsdAmountLocaleDisplay,
|
|
16
|
-
} from "../../utils/format.js"
|
|
17
|
-
import { useSupportedTokens, type Token } from "../../tokens.js"
|
|
18
|
-
import type { FundMethod } from "../../transactionIntent/types.js"
|
|
19
|
-
import { isPassthroughEligible } from "../../utils/passthrough.js"
|
|
20
|
-
import { useWidgetProps } from "../hooks/useWidgetProps.js"
|
|
21
|
-
import { getMatchingMeshSupportedTokens } from "../utils/meshSupportedTokens.js"
|
|
22
|
-
import { getActiveMeshEnvironment } from "../utils/onrampConfig.js"
|
|
23
|
-
import { getWidgetOnrampConfig } from "../utils/trailsOnrampConfig.js"
|
|
24
|
-
import type { Screen } from "../hooks/useViewManager.js"
|
|
25
|
-
import { useViewManager } from "../hooks/useViewManager.js"
|
|
26
|
-
import { useDefaultDestinationToken } from "../hooks/useDefaultDestinationToken.js"
|
|
27
|
-
import { useDefaultOriginToken } from "../hooks/useDefaultOriginToken.js"
|
|
28
|
-
import { useDestinationSelectedToken } from "../hooks/useDestinationSelectedToken.js"
|
|
29
|
-
import { useExchangeRate } from "../../query/fiat.hooks.js"
|
|
30
|
-
import { useFiatOnRampCurrencies } from "../hooks/useFiatOnRampCurrencies.js"
|
|
31
|
-
import { useFiatSelectedCurrency } from "../hooks/useFiatSelectedCurrency.js"
|
|
32
|
-
import { useOnRampCountryDefaults } from "../hooks/useOnRampCountryDefaults.js"
|
|
33
|
-
import { useOnRampProviderWidget } from "../hooks/useOnRampProviderWidget.js"
|
|
34
|
-
import type { OnrampQuote } from "../hooks/useOnRampQuote.js"
|
|
35
|
-
import { useOnRampQuote } from "../hooks/useOnRampQuote.js"
|
|
36
|
-
import { useOriginSelectedToken } from "../hooks/useOriginSelectedToken.js"
|
|
37
|
-
import type { ProcessedFeeOption } from "../hooks/useSelectedFeeOption.js"
|
|
38
|
-
import { useSelectedFundMethod } from "../hooks/useSelectedFundMethod.js"
|
|
39
|
-
import { useSelectedRecipient } from "../hooks/useSelectedRecipient.js"
|
|
40
|
-
import { useSendForm, type OnCompleteProps } from "../hooks/useSendForm.js"
|
|
41
|
-
import { useSwapState } from "../hooks/useSwapState.js"
|
|
42
|
-
import { useAccountTokenBalanceOnchain } from "../../query/balance.hooks.js"
|
|
43
|
-
import type { BaseProps, OnrampConfirmCallback } from "../types/commonProps.js"
|
|
44
|
-
import { isWithinCooldown, SECOND_MS } from "../../utils/time.js"
|
|
45
|
-
import { forexRateStore } from "../utils/forexRateStore.js"
|
|
46
|
-
import { openPopup, setPopupUrl, closePopup } from "../utils/windowUtils.js"
|
|
47
|
-
import { ChainList } from "./ChainList.js"
|
|
48
|
-
import { DynamicSizeInputField } from "./DynamicSizeInputField.js"
|
|
49
|
-
import { ErrorDisplay } from "./ErrorDisplay.js"
|
|
50
|
-
import { isFeeOptionDisabled } from "./FeeOption.js"
|
|
51
|
-
import { FeeOptions } from "./FeeOptions.js"
|
|
52
|
-
import { FiatSelector } from "./FiatSelector.js"
|
|
53
|
-
import { FiatSelectorButton } from "./FiatSelectorButton.js"
|
|
54
|
-
import { OnRampProviderSelector } from "./OnRampProviderSelector.js"
|
|
55
|
-
import { PercentageMaxButtons } from "./PercentageMaxButtons.js"
|
|
56
|
-
import { QuoteDetails } from "./QuoteDetails.js"
|
|
57
|
-
import { RecipientSelectorButton } from "./RecipientSelectorButton.js"
|
|
58
|
-
import { RefundWarning } from "./RefundWarning.js"
|
|
59
|
-
import { ScreenHeader } from "./ScreenHeader.js"
|
|
60
|
-
import { TokenSelector } from "./TokenSelector.js"
|
|
61
|
-
import { TokenSelectorButton } from "./TokenSelectorButton.js"
|
|
62
|
-
import LoadingSpinner from "./LoadingSpinner.js"
|
|
63
|
-
|
|
64
|
-
import { addressEqual } from "../../utils/address.js"
|
|
65
|
-
import { useOnrampClient } from "../../onrampClient.js"
|
|
66
|
-
interface FundProps extends BaseProps {
|
|
67
|
-
onWaitingForOnrampConfirm?: OnrampConfirmCallback
|
|
68
|
-
title?: string
|
|
69
|
-
exactInputOnly?: boolean
|
|
70
|
-
onrampPropsCallback?: (props: any) => void
|
|
71
|
-
screenNavigationCallback?: (screen: Screen) => void
|
|
72
|
-
/** Default input mode: "fiat" starts with USD input, "token" starts with token input */
|
|
73
|
-
defaultInputMode?: "fiat" | "token"
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const Fund: React.FC<FundProps> = ({
|
|
77
|
-
selectedToken: initialSelectedToken,
|
|
78
|
-
onSend,
|
|
79
|
-
onConfirm,
|
|
80
|
-
onComplete,
|
|
81
|
-
account,
|
|
82
|
-
toRecipient,
|
|
83
|
-
toAmount,
|
|
84
|
-
toChainId,
|
|
85
|
-
toToken,
|
|
86
|
-
toCalldata,
|
|
87
|
-
walletClient,
|
|
88
|
-
onTransactionStateChange,
|
|
89
|
-
onError,
|
|
90
|
-
onWaitingForWalletConfirm,
|
|
91
|
-
onrampPropsCallback,
|
|
92
|
-
screenNavigationCallback,
|
|
93
|
-
onWaitingForOnrampConfirm,
|
|
94
|
-
paymasterUrls,
|
|
95
|
-
setWalletConfirmRetryHandler,
|
|
96
|
-
swapProvider,
|
|
97
|
-
bridgeProvider,
|
|
98
|
-
swapProviderFallback,
|
|
99
|
-
bridgeProviderFallback,
|
|
100
|
-
fundMethod,
|
|
101
|
-
onAmountUpdate,
|
|
102
|
-
checkoutOnHandlers,
|
|
103
|
-
recentTokens,
|
|
104
|
-
onTrackToken,
|
|
105
|
-
isSequenceWallet = false,
|
|
106
|
-
exactInputOnly = true, // Fund mode is always exact input only
|
|
107
|
-
defaultInputMode,
|
|
108
|
-
}) => {
|
|
109
|
-
const { mode, navigate } = useViewManager()
|
|
110
|
-
const widgetProps = useWidgetProps()
|
|
111
|
-
const {
|
|
112
|
-
fundOptions,
|
|
113
|
-
onramp: onrampFactory,
|
|
114
|
-
apiKey,
|
|
115
|
-
trailsApiUrl,
|
|
116
|
-
} = widgetProps
|
|
117
|
-
const onrampClient = useOnrampClient()
|
|
118
|
-
const {
|
|
119
|
-
selectedToken: originToken,
|
|
120
|
-
setSelectedToken: setOriginToken,
|
|
121
|
-
hasManualSelection: hasManualOriginSelection,
|
|
122
|
-
setHasManualSelection: setHasManualOriginSelection,
|
|
123
|
-
} = useOriginSelectedToken()
|
|
124
|
-
const {
|
|
125
|
-
selectedToken: destinationToken,
|
|
126
|
-
setSelectedToken: setDestinationToken,
|
|
127
|
-
hasManualSelection: hasManualDestinationSelection,
|
|
128
|
-
setHasManualSelection: setHasManualDestinationSelection,
|
|
129
|
-
isControlledByProps: isDestinationControlledByProps,
|
|
130
|
-
} = useDestinationSelectedToken()
|
|
131
|
-
const { paymentMethod, selectedMeshExchange } = useSelectedFundMethod()
|
|
132
|
-
const meshOnrampConfig = getWidgetOnrampConfig(onrampFactory)
|
|
133
|
-
const meshEnvironment = getActiveMeshEnvironment(meshOnrampConfig)
|
|
134
|
-
const meshEnabled = !!meshOnrampConfig?.mesh
|
|
135
|
-
const meshAllowedExchanges = meshOnrampConfig?.mesh?.exchanges ?? null
|
|
136
|
-
const activeMeshIntegrationIds = selectedMeshExchange
|
|
137
|
-
? [selectedMeshExchange.integrationId]
|
|
138
|
-
: null
|
|
139
|
-
const activeMeshExchangeKeys = selectedMeshExchange
|
|
140
|
-
? null
|
|
141
|
-
: meshAllowedExchanges
|
|
142
|
-
const isCoinbaseMeshOnramp =
|
|
143
|
-
fundMethod === "onramp-mesh" &&
|
|
144
|
-
(selectedMeshExchange?.exchangeKey === "coinbase" ||
|
|
145
|
-
selectedMeshExchange?.exchangeKey === "coinbaseRamp")
|
|
146
|
-
|
|
147
|
-
// Check if fee options will be shown (not needed for onramp/direct-transfer modes)
|
|
148
|
-
const skipFeeBalanceFetch =
|
|
149
|
-
fundMethod === "onramp-meld" ||
|
|
150
|
-
fundMethod === "direct-transfer" ||
|
|
151
|
-
fundMethod === "onramp-mesh"
|
|
152
|
-
|
|
153
|
-
// Get origin token with fresh balance for fee option checks
|
|
154
|
-
// Skip fetching if fee options won't be shown
|
|
155
|
-
const {
|
|
156
|
-
token: freshOriginToken,
|
|
157
|
-
isLoadingBalance: isLoadingFreshOriginBalance,
|
|
158
|
-
} = useAccountTokenBalanceOnchain(originToken, account?.address, {
|
|
159
|
-
disabled: skipFeeBalanceFetch,
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
const { selectedRecipient, setSelectedRecipient } = useSelectedRecipient()
|
|
163
|
-
const {
|
|
164
|
-
selectedCurrency: selectedFiatCurrency,
|
|
165
|
-
setSelectedCurrency: setSelectedFiatCurrency,
|
|
166
|
-
hasManualSelection: hasManualFiatSelection,
|
|
167
|
-
setHasManualSelection: setHasManualFiatSelection,
|
|
168
|
-
fiatAmount: sellFiatAmount,
|
|
169
|
-
setFiatAmount: setSellFiatAmount,
|
|
170
|
-
} = useFiatSelectedCurrency()
|
|
171
|
-
const [showFiatSelector, setShowFiatSelector] = useState(false)
|
|
172
|
-
const [selectedCountryCode, setSelectedCountryCode] = useState<string | null>(
|
|
173
|
-
null,
|
|
174
|
-
)
|
|
175
|
-
const [showProviderSelector, setShowProviderSelector] = useState(false)
|
|
176
|
-
const [selectedOnrampProvider, setSelectedOnrampProvider] =
|
|
177
|
-
useState<OnrampQuote | null>(null)
|
|
178
|
-
|
|
179
|
-
// Add debounced state for Meld quote fetching
|
|
180
|
-
const [debouncedSellFiatAmount, setDebouncedSellFiatAmount] =
|
|
181
|
-
useState(sellFiatAmount)
|
|
182
|
-
const debounceTimerRef = useRef<NodeJS.Timeout | null>(null)
|
|
183
|
-
|
|
184
|
-
// Check if onramp is active
|
|
185
|
-
const isMeldOnRampActive = fundMethod === "onramp-meld"
|
|
186
|
-
|
|
187
|
-
// Derive the origin token for useSendForm at render time.
|
|
188
|
-
// When onramp is active the origin is always USDC on Base (what the
|
|
189
|
-
// onramp provider delivers). We derive this instead of relying on the
|
|
190
|
-
// useEffect below because the effect runs *after* render, leaving
|
|
191
|
-
// originToken null on the first pass and preventing the quote from firing.
|
|
192
|
-
const effectiveOriginToken = isMeldOnRampActive ? USDC_BASE : originToken
|
|
193
|
-
|
|
194
|
-
// Unified state for tracking USD display mode (works for both token and fiat)
|
|
195
|
-
// In onramp mode, always default to the selected fiat currency (not USD/$)
|
|
196
|
-
const [isEnteringFiat, setIsEnteringFiat] = useState(
|
|
197
|
-
!isMeldOnRampActive && defaultInputMode === "fiat",
|
|
198
|
-
)
|
|
199
|
-
// Separate state for display value to handle USD toggle properly
|
|
200
|
-
const [inputDisplayValue, setInputDisplayValue] = useState("")
|
|
201
|
-
const lastInputModeRef = useRef(false)
|
|
202
|
-
// Track if user is actively typing to prevent conversion loops
|
|
203
|
-
const [isUserTyping, setIsUserTyping] = useState(false)
|
|
204
|
-
const typingTimeoutRef = useRef<NodeJS.Timeout | null>(null)
|
|
205
|
-
|
|
206
|
-
useEffect(() => {
|
|
207
|
-
return () => {
|
|
208
|
-
if (typingTimeoutRef.current) {
|
|
209
|
-
clearTimeout(typingTimeoutRef.current)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}, [])
|
|
213
|
-
|
|
214
|
-
// Get country defaults when onramp is active
|
|
215
|
-
const {
|
|
216
|
-
countryCode: detectedCountryCode,
|
|
217
|
-
defaultCurrencyCode,
|
|
218
|
-
isLoading: isLoadingCountryDefaults,
|
|
219
|
-
} = useOnRampCountryDefaults({
|
|
220
|
-
enabled: isMeldOnRampActive,
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
// Use selected country if available, otherwise use detected country
|
|
224
|
-
const effectiveCountryCode = selectedCountryCode || detectedCountryCode
|
|
225
|
-
|
|
226
|
-
// Fetch fiat currencies when onramp is active
|
|
227
|
-
const { fiatCurrencies, isLoading: isLoadingFiatCurrencies } =
|
|
228
|
-
useFiatOnRampCurrencies({
|
|
229
|
-
countryCode: effectiveCountryCode || "US",
|
|
230
|
-
enabled: isMeldOnRampActive && !!effectiveCountryCode,
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
// Auto-select default currency when onramp is active: use location-based currency first,
|
|
234
|
-
// only fall back to USD when location fetch is done and no default currency was returned
|
|
235
|
-
useEffect(() => {
|
|
236
|
-
if (
|
|
237
|
-
isMeldOnRampActive &&
|
|
238
|
-
!selectedFiatCurrency &&
|
|
239
|
-
fiatCurrencies.length > 0 &&
|
|
240
|
-
!isLoadingCountryDefaults &&
|
|
241
|
-
!isLoadingFiatCurrencies &&
|
|
242
|
-
!hasManualFiatSelection
|
|
243
|
-
) {
|
|
244
|
-
// Prefer location-based currency; only then fall back to USD
|
|
245
|
-
const currencyCodeToSelect = defaultCurrencyCode ?? "USD"
|
|
246
|
-
|
|
247
|
-
const defaultCurrency = fiatCurrencies.find(
|
|
248
|
-
(currency) => currency.currencyCode === currencyCodeToSelect,
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
if (defaultCurrency) {
|
|
252
|
-
logger.console.log(
|
|
253
|
-
"[Fund] Auto-selecting default currency:",
|
|
254
|
-
defaultCurrency,
|
|
255
|
-
defaultCurrencyCode
|
|
256
|
-
? "(from location)"
|
|
257
|
-
: "(fallback to USD - location not available)",
|
|
258
|
-
)
|
|
259
|
-
setSelectedFiatCurrency(defaultCurrency)
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}, [
|
|
263
|
-
isMeldOnRampActive,
|
|
264
|
-
selectedFiatCurrency,
|
|
265
|
-
defaultCurrencyCode,
|
|
266
|
-
fiatCurrencies,
|
|
267
|
-
isLoadingCountryDefaults,
|
|
268
|
-
isLoadingFiatCurrencies,
|
|
269
|
-
hasManualFiatSelection,
|
|
270
|
-
setSelectedFiatCurrency,
|
|
271
|
-
])
|
|
272
|
-
|
|
273
|
-
const lastAppliedConfiguredFiatRef = useRef<string | null>(null)
|
|
274
|
-
useEffect(() => {
|
|
275
|
-
if (!isMeldOnRampActive) {
|
|
276
|
-
lastAppliedConfiguredFiatRef.current = null
|
|
277
|
-
}
|
|
278
|
-
}, [isMeldOnRampActive])
|
|
279
|
-
|
|
280
|
-
useEffect(() => {
|
|
281
|
-
if (!isMeldOnRampActive || isLoadingFiatCurrencies) return
|
|
282
|
-
if (fiatCurrencies.length === 0) return
|
|
283
|
-
const configuredFiatCurrency = fundOptions?.fiatCurrency?.trim() || ""
|
|
284
|
-
const configuredFiatAmount = fundOptions?.fiatAmount?.trim() || ""
|
|
285
|
-
const configKey = `${configuredFiatCurrency.toUpperCase()}|${configuredFiatAmount}`
|
|
286
|
-
if (lastAppliedConfiguredFiatRef.current === configKey) return
|
|
287
|
-
lastAppliedConfiguredFiatRef.current = configKey
|
|
288
|
-
|
|
289
|
-
if (configuredFiatCurrency) {
|
|
290
|
-
const match = fiatCurrencies.find(
|
|
291
|
-
(c) =>
|
|
292
|
-
c.currencyCode.toUpperCase() === configuredFiatCurrency.toUpperCase(),
|
|
293
|
-
)
|
|
294
|
-
if (match) {
|
|
295
|
-
setSelectedFiatCurrency(match)
|
|
296
|
-
setHasManualFiatSelection(true)
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (configuredFiatAmount) {
|
|
301
|
-
setSellFiatAmount(configuredFiatAmount)
|
|
302
|
-
setInputDisplayValue(configuredFiatAmount)
|
|
303
|
-
}
|
|
304
|
-
}, [
|
|
305
|
-
isMeldOnRampActive,
|
|
306
|
-
isLoadingFiatCurrencies,
|
|
307
|
-
fiatCurrencies,
|
|
308
|
-
fundOptions?.fiatCurrency,
|
|
309
|
-
fundOptions?.fiatAmount,
|
|
310
|
-
setSelectedFiatCurrency,
|
|
311
|
-
setHasManualFiatSelection,
|
|
312
|
-
setSellFiatAmount,
|
|
313
|
-
])
|
|
314
|
-
|
|
315
|
-
const normalizedConfiguredFiatCurrency =
|
|
316
|
-
fundOptions?.fiatCurrency?.trim().toUpperCase() || null
|
|
317
|
-
const isConfiguredFiatCurrencyApplied =
|
|
318
|
-
!!normalizedConfiguredFiatCurrency &&
|
|
319
|
-
!!selectedFiatCurrency &&
|
|
320
|
-
selectedFiatCurrency.currencyCode.toUpperCase() ===
|
|
321
|
-
normalizedConfiguredFiatCurrency
|
|
322
|
-
const isFiatCurrencyLocked =
|
|
323
|
-
isMeldOnRampActive && isConfiguredFiatCurrencyApplied
|
|
324
|
-
const isFiatAmountLocked = isMeldOnRampActive && !!fundOptions?.fiatAmount
|
|
325
|
-
|
|
326
|
-
// Use a ref to track user actions to prevent race conditions with async state updates
|
|
327
|
-
const userActionRef = useRef({
|
|
328
|
-
hasManualDestinationSelection: false,
|
|
329
|
-
lastOriginSelectionTime: 0,
|
|
330
|
-
lastDestinationSelectionTime: 0,
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
// Use separated default token selection hooks
|
|
334
|
-
const { defaultOriginToken, isLoading: isLoadingOriginDefaults } =
|
|
335
|
-
useDefaultOriginToken()
|
|
336
|
-
|
|
337
|
-
const { defaultDestinationToken, isLoading: isLoadingDestinationDefaults } =
|
|
338
|
-
useDefaultDestinationToken(originToken)
|
|
339
|
-
|
|
340
|
-
const originChainId =
|
|
341
|
-
effectiveOriginToken?.chainId ?? initialSelectedToken?.chainId ?? null
|
|
342
|
-
const {
|
|
343
|
-
tradeType: globalTradeType,
|
|
344
|
-
setTradeType,
|
|
345
|
-
sellAmount,
|
|
346
|
-
setSellAmount,
|
|
347
|
-
buyAmount,
|
|
348
|
-
setBuyAmount,
|
|
349
|
-
resetSwapState,
|
|
350
|
-
enterFormMode,
|
|
351
|
-
} = useSwapState()
|
|
352
|
-
|
|
353
|
-
// Determine the form mode based on fund method
|
|
354
|
-
const currentFormMode = useMemo(() => {
|
|
355
|
-
if (fundMethod === "onramp-meld") return "fund-onramp-meld" as const
|
|
356
|
-
if (fundMethod === "onramp-mesh") return "fund-onramp-mesh" as const
|
|
357
|
-
if (fundMethod === "direct-transfer") return "fund-direct-transfer" as const
|
|
358
|
-
return "fund-wallet" as const
|
|
359
|
-
}, [fundMethod])
|
|
360
|
-
|
|
361
|
-
// Reset swap state only when switching between different form modes
|
|
362
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: Stable setters, only react to currentFormMode changes
|
|
363
|
-
useEffect(() => {
|
|
364
|
-
const didReset = enterFormMode(currentFormMode)
|
|
365
|
-
if (didReset) {
|
|
366
|
-
// Also clear fiat amount and display value when mode changes
|
|
367
|
-
setSellFiatAmount("")
|
|
368
|
-
setInputDisplayValue("")
|
|
369
|
-
}
|
|
370
|
-
}, [currentFormMode])
|
|
371
|
-
|
|
372
|
-
// Initialize input display value from cached amounts on mount
|
|
373
|
-
// This ensures the display syncs with context values when returning from settings/history etc
|
|
374
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: Only run on mount to initialize display
|
|
375
|
-
useEffect(() => {
|
|
376
|
-
if (isMeldOnRampActive && sellFiatAmount) {
|
|
377
|
-
setInputDisplayValue(sellFiatAmount)
|
|
378
|
-
} else if (!isMeldOnRampActive && sellAmount) {
|
|
379
|
-
setInputDisplayValue(sellAmount)
|
|
380
|
-
}
|
|
381
|
-
}, [])
|
|
382
|
-
|
|
383
|
-
const tradeType = globalTradeType || TradeType.EXACT_INPUT
|
|
384
|
-
const [isCreatingWidgetSession, setIsCreatingWidgetSession] = useState(false)
|
|
385
|
-
const [widgetError, setWidgetError] = useState<string | null>(null)
|
|
386
|
-
|
|
387
|
-
const handleCompleteAndClearAmounts = useCallback(
|
|
388
|
-
(result: OnCompleteProps) => {
|
|
389
|
-
setInputDisplayValue("")
|
|
390
|
-
setSellFiatAmount("")
|
|
391
|
-
resetSwapState()
|
|
392
|
-
onComplete(result)
|
|
393
|
-
},
|
|
394
|
-
[onComplete, resetSwapState, setSellFiatAmount],
|
|
395
|
-
)
|
|
396
|
-
|
|
397
|
-
// Initialize and update selected recipient from toRecipient prop (but don't auto-set to account address)
|
|
398
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: selectedRecipient is intentionally excluded to avoid infinite loops
|
|
399
|
-
useEffect(() => {
|
|
400
|
-
logger.console.log("[trails-sdk] Fund toRecipient prop effect:", {
|
|
401
|
-
toRecipient,
|
|
402
|
-
selectedRecipient,
|
|
403
|
-
accountAddress: account?.address,
|
|
404
|
-
})
|
|
405
|
-
|
|
406
|
-
if (toRecipient) {
|
|
407
|
-
// Always sync with toRecipient prop when it changes
|
|
408
|
-
logger.console.log(
|
|
409
|
-
"[trails-sdk] Fund Setting selectedRecipient to toRecipient:",
|
|
410
|
-
toRecipient,
|
|
411
|
-
)
|
|
412
|
-
setSelectedRecipient(toRecipient)
|
|
413
|
-
}
|
|
414
|
-
// Don't auto-set to account.address - let user select via RecipientSelectorButton
|
|
415
|
-
}, [toRecipient, setSelectedRecipient])
|
|
416
|
-
|
|
417
|
-
// Calculate effective recipient for useSendForm (same pattern as Pay.tsx)
|
|
418
|
-
// Use selectedRecipient if set, otherwise toRecipient prop, otherwise account address as fallback
|
|
419
|
-
const effectiveRecipient =
|
|
420
|
-
selectedRecipient || toRecipient || account?.address
|
|
421
|
-
|
|
422
|
-
const effectiveFundMethod: FundMethod | undefined = isMeldOnRampActive
|
|
423
|
-
? "onramp-meld"
|
|
424
|
-
: (fundMethod as FundMethod | undefined)
|
|
425
|
-
|
|
426
|
-
// Add debounce effect for sellFiatAmount
|
|
427
|
-
useEffect(() => {
|
|
428
|
-
// Clear existing timer
|
|
429
|
-
if (debounceTimerRef.current) {
|
|
430
|
-
clearTimeout(debounceTimerRef.current)
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
// Set new timer for 500ms debounce
|
|
434
|
-
debounceTimerRef.current = setTimeout(() => {
|
|
435
|
-
setDebouncedSellFiatAmount(sellFiatAmount)
|
|
436
|
-
}, 500)
|
|
437
|
-
|
|
438
|
-
// Cleanup on unmount or when sellFiatAmount changes
|
|
439
|
-
return () => {
|
|
440
|
-
if (debounceTimerRef.current) {
|
|
441
|
-
clearTimeout(debounceTimerRef.current)
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}, [sellFiatAmount])
|
|
445
|
-
|
|
446
|
-
// Get onramp quote when onramp is active (using debounced amount)
|
|
447
|
-
const {
|
|
448
|
-
quotes: onrampQuotes,
|
|
449
|
-
selectedQuote: autoSelectedOnrampQuote,
|
|
450
|
-
isLoading: isLoadingOnrampQuote,
|
|
451
|
-
error: onrampQuoteError,
|
|
452
|
-
onrampTrackingData,
|
|
453
|
-
} = useOnRampQuote({
|
|
454
|
-
amount: debouncedSellFiatAmount,
|
|
455
|
-
sourceCurrencyCode: selectedFiatCurrency?.currencyCode,
|
|
456
|
-
destinationCurrencyCode: "USDC_BASE",
|
|
457
|
-
countryCode: effectiveCountryCode || undefined,
|
|
458
|
-
walletAddress: account?.address || "",
|
|
459
|
-
paymentMethodType: paymentMethod?.id,
|
|
460
|
-
enabled:
|
|
461
|
-
isMeldOnRampActive &&
|
|
462
|
-
!!debouncedSellFiatAmount &&
|
|
463
|
-
!!selectedFiatCurrency &&
|
|
464
|
-
!!effectiveCountryCode &&
|
|
465
|
-
!!effectiveRecipient,
|
|
466
|
-
})
|
|
467
|
-
|
|
468
|
-
const {
|
|
469
|
-
amount,
|
|
470
|
-
amountRaw,
|
|
471
|
-
balanceFormatted,
|
|
472
|
-
balanceRaw,
|
|
473
|
-
tokenDecimals,
|
|
474
|
-
balanceLocaleDisplay,
|
|
475
|
-
balanceUsdDisplay,
|
|
476
|
-
balanceUsdLocaleDisplay,
|
|
477
|
-
handleSubmit,
|
|
478
|
-
isSubmitting,
|
|
479
|
-
isLoadingQuote,
|
|
480
|
-
selectedDestToken,
|
|
481
|
-
setSelectedDestinationChain,
|
|
482
|
-
setSelectedDestToken,
|
|
483
|
-
buttonText,
|
|
484
|
-
destinationTokenAddress,
|
|
485
|
-
isValidCustomToken,
|
|
486
|
-
prepareSendQuote,
|
|
487
|
-
processedFeeOptions,
|
|
488
|
-
selectedFeeOption,
|
|
489
|
-
setSelectedFeeOption,
|
|
490
|
-
sendFn,
|
|
491
|
-
sourceTokenPrices,
|
|
492
|
-
} = useSendForm({
|
|
493
|
-
account,
|
|
494
|
-
toAmount: tradeType === TradeType.EXACT_OUTPUT ? buyAmount : toAmount,
|
|
495
|
-
fromAmount: tradeType === TradeType.EXACT_INPUT ? sellAmount : undefined,
|
|
496
|
-
toRecipient: effectiveRecipient,
|
|
497
|
-
toChainId,
|
|
498
|
-
toToken,
|
|
499
|
-
toCalldata,
|
|
500
|
-
walletClient,
|
|
501
|
-
onTransactionStateChange,
|
|
502
|
-
onError,
|
|
503
|
-
onWaitingForWalletConfirm,
|
|
504
|
-
onWaitingForOnrampConfirm,
|
|
505
|
-
paymasterUrls,
|
|
506
|
-
onSend,
|
|
507
|
-
onConfirm,
|
|
508
|
-
onComplete: handleCompleteAndClearAmounts,
|
|
509
|
-
selectedToken: effectiveOriginToken as any,
|
|
510
|
-
setWalletConfirmRetryHandler,
|
|
511
|
-
tradeType: tradeType,
|
|
512
|
-
swapProvider,
|
|
513
|
-
bridgeProvider,
|
|
514
|
-
swapProviderFallback,
|
|
515
|
-
bridgeProviderFallback,
|
|
516
|
-
fundMethod: effectiveFundMethod,
|
|
517
|
-
mode,
|
|
518
|
-
checkoutOnHandlers,
|
|
519
|
-
onrampTrackingData: isMeldOnRampActive ? onrampTrackingData : null,
|
|
520
|
-
// Skip fee balance fetching for onramp/direct-transfer modes where fee options aren't shown
|
|
521
|
-
skipFeeBalanceFetch:
|
|
522
|
-
effectiveFundMethod === "onramp-meld" ||
|
|
523
|
-
effectiveFundMethod === "direct-transfer" ||
|
|
524
|
-
effectiveFundMethod === "onramp-mesh",
|
|
525
|
-
onNavigateToOnrampMesh:
|
|
526
|
-
onrampPropsCallback && screenNavigationCallback
|
|
527
|
-
? (props) => {
|
|
528
|
-
// Set the onramp props and navigate to onramp-mesh screen
|
|
529
|
-
onrampPropsCallback(props)
|
|
530
|
-
screenNavigationCallback("onramp-mesh")
|
|
531
|
-
}
|
|
532
|
-
: undefined,
|
|
533
|
-
})
|
|
534
|
-
|
|
535
|
-
const {
|
|
536
|
-
data: isMeshRouteSupported = true,
|
|
537
|
-
isLoading: isLoadingMeshRouteSupport,
|
|
538
|
-
} = useQuery({
|
|
539
|
-
queryKey: [
|
|
540
|
-
"mesh-route-support",
|
|
541
|
-
meshEnvironment,
|
|
542
|
-
activeMeshExchangeKeys,
|
|
543
|
-
prepareSendQuote?.originChain?.id,
|
|
544
|
-
prepareSendQuote?.originToken?.symbol,
|
|
545
|
-
trailsApiUrl,
|
|
546
|
-
apiKey,
|
|
547
|
-
],
|
|
548
|
-
queryFn: async () => {
|
|
549
|
-
const response = await onrampClient.getMeshSupportedTokens({
|
|
550
|
-
environment: meshEnvironment,
|
|
551
|
-
})
|
|
552
|
-
|
|
553
|
-
const allowedTokens = !activeMeshExchangeKeys?.length
|
|
554
|
-
? !activeMeshIntegrationIds?.length
|
|
555
|
-
? response.tokens || []
|
|
556
|
-
: (response.tokens || []).filter((token) =>
|
|
557
|
-
(token.integrationIds || []).some((integrationId) =>
|
|
558
|
-
activeMeshIntegrationIds.includes(integrationId),
|
|
559
|
-
),
|
|
560
|
-
)
|
|
561
|
-
: (response.tokens || []).filter((token) =>
|
|
562
|
-
(token.exchangeKeys || []).some((exchangeKey) =>
|
|
563
|
-
activeMeshExchangeKeys.includes(exchangeKey),
|
|
564
|
-
),
|
|
565
|
-
)
|
|
566
|
-
|
|
567
|
-
return (
|
|
568
|
-
getMatchingMeshSupportedTokens(
|
|
569
|
-
allowedTokens,
|
|
570
|
-
prepareSendQuote?.originChain?.id,
|
|
571
|
-
prepareSendQuote?.originToken?.symbol,
|
|
572
|
-
).length > 0
|
|
573
|
-
)
|
|
574
|
-
},
|
|
575
|
-
enabled:
|
|
576
|
-
fundMethod === "onramp-mesh" &&
|
|
577
|
-
meshEnabled &&
|
|
578
|
-
!!prepareSendQuote?.originChain?.id &&
|
|
579
|
-
!!prepareSendQuote?.originToken?.symbol &&
|
|
580
|
-
!!apiKey &&
|
|
581
|
-
!!trailsApiUrl,
|
|
582
|
-
staleTime: 24 * 60 * 60 * 1000,
|
|
583
|
-
gcTime: 24 * 60 * 60 * 1000,
|
|
584
|
-
refetchOnMount: false,
|
|
585
|
-
refetchOnWindowFocus: false,
|
|
586
|
-
refetchOnReconnect: false,
|
|
587
|
-
})
|
|
588
|
-
|
|
589
|
-
const selectedOnrampProviderQuote =
|
|
590
|
-
selectedOnrampProvider || autoSelectedOnrampQuote
|
|
591
|
-
|
|
592
|
-
const shouldValidateFeeOption =
|
|
593
|
-
fundMethod !== "direct-transfer" && fundMethod !== "onramp-mesh"
|
|
594
|
-
|
|
595
|
-
const isAwaitingTrailsQuote =
|
|
596
|
-
isMeldOnRampActive && !!selectedOnrampProviderQuote && !prepareSendQuote
|
|
597
|
-
|
|
598
|
-
// Get exchange rate for fiat to USD conversion
|
|
599
|
-
// Use the selected fiat currency for real-time conversion as user types
|
|
600
|
-
const {
|
|
601
|
-
exchangeRate: fiatToUsdExchangeRate,
|
|
602
|
-
isLoading: isLoadingFiatToUsdExchangeRate,
|
|
603
|
-
} = useExchangeRate({
|
|
604
|
-
fromCurrency: "USD",
|
|
605
|
-
toCurrency:
|
|
606
|
-
isMeldOnRampActive && selectedFiatCurrency?.currencyCode
|
|
607
|
-
? selectedFiatCurrency.currencyCode
|
|
608
|
-
: "USD",
|
|
609
|
-
disabled:
|
|
610
|
-
!isMeldOnRampActive ||
|
|
611
|
-
!selectedFiatCurrency ||
|
|
612
|
-
selectedFiatCurrency?.currencyCode === "USD",
|
|
613
|
-
})
|
|
614
|
-
|
|
615
|
-
// Sync input display with cached values when switching to/from onramp mode
|
|
616
|
-
const lastOnrampModeRef = useRef(isMeldOnRampActive)
|
|
617
|
-
|
|
618
|
-
useEffect(() => {
|
|
619
|
-
// Only sync when mode actually changes
|
|
620
|
-
if (lastOnrampModeRef.current !== isMeldOnRampActive) {
|
|
621
|
-
lastOnrampModeRef.current = isMeldOnRampActive
|
|
622
|
-
|
|
623
|
-
if (isMeldOnRampActive && sellFiatAmount) {
|
|
624
|
-
// When switching to onramp mode, sync with cached fiat amount
|
|
625
|
-
setInputDisplayValue(sellFiatAmount)
|
|
626
|
-
} else if (!isMeldOnRampActive && sellAmount) {
|
|
627
|
-
// When switching from onramp mode, sync with cached token amount
|
|
628
|
-
setInputDisplayValue(sellAmount)
|
|
629
|
-
} else {
|
|
630
|
-
// Clear input if no cached value for the new mode
|
|
631
|
-
setInputDisplayValue("")
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}, [isMeldOnRampActive, sellFiatAmount, sellAmount])
|
|
635
|
-
|
|
636
|
-
// Get the token price for USD conversions
|
|
637
|
-
const tokenPriceUsd = sourceTokenPrices?.[0]?.priceUsd || 0
|
|
638
|
-
|
|
639
|
-
// Sync display value ONLY when toggle button is clicked (mode actually changes)
|
|
640
|
-
useEffect(() => {
|
|
641
|
-
if (lastInputModeRef.current !== isEnteringFiat) {
|
|
642
|
-
lastInputModeRef.current = isEnteringFiat
|
|
643
|
-
|
|
644
|
-
// Don't do any conversion if user is typing
|
|
645
|
-
if (isUserTyping) {
|
|
646
|
-
return
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
if (isMeldOnRampActive && sellFiatAmount) {
|
|
650
|
-
// Fiat mode
|
|
651
|
-
const fiatAmount = toSafeNumber(sellFiatAmount)
|
|
652
|
-
if (fiatAmount > 0) {
|
|
653
|
-
// Only update if there's an actual amount
|
|
654
|
-
if (isEnteringFiat && fiatToUsdExchangeRate) {
|
|
655
|
-
// Switching to USD mode - show USD value
|
|
656
|
-
const usdAmount = fiatAmount / fiatToUsdExchangeRate
|
|
657
|
-
// Format to 2 decimals and remove unnecessary trailing zeros
|
|
658
|
-
const formatted = Number(usdAmount.toFixed(2)).toString()
|
|
659
|
-
setInputDisplayValue(formatted)
|
|
660
|
-
} else {
|
|
661
|
-
// Switching to local currency mode - show fiat value
|
|
662
|
-
const formatted = Number(fiatAmount.toFixed(2)).toString()
|
|
663
|
-
setInputDisplayValue(formatted)
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
} else if (!isMeldOnRampActive && sellAmount) {
|
|
667
|
-
// Token mode
|
|
668
|
-
const tokenAmount = toSafeNumber(sellAmount)
|
|
669
|
-
if (tokenAmount > 0) {
|
|
670
|
-
// Only update if there's an actual amount
|
|
671
|
-
if (isEnteringFiat && tokenPriceUsd > 0) {
|
|
672
|
-
// Switching to fiat mode - show preferred currency value
|
|
673
|
-
const usdAmount = tokenAmount * tokenPriceUsd
|
|
674
|
-
|
|
675
|
-
// Apply forex rate if available to convert USD to preferred currency
|
|
676
|
-
const rateData = forexRateStore.getRate()
|
|
677
|
-
const displayValue =
|
|
678
|
-
rateData && rateData.currency !== "USD"
|
|
679
|
-
? usdAmount * rateData.rate
|
|
680
|
-
: usdAmount
|
|
681
|
-
|
|
682
|
-
// Format to 2 decimals and remove unnecessary trailing zeros
|
|
683
|
-
const formatted = Number(displayValue.toFixed(2)).toString()
|
|
684
|
-
logger.console.log(
|
|
685
|
-
"[TRAILS EFFECT] Setting display value in useEffect:",
|
|
686
|
-
formatted,
|
|
687
|
-
"from USD:",
|
|
688
|
-
usdAmount,
|
|
689
|
-
"with rate:",
|
|
690
|
-
rateData?.rate,
|
|
691
|
-
)
|
|
692
|
-
setInputDisplayValue(formatted)
|
|
693
|
-
} else {
|
|
694
|
-
// Show token amount - remove unnecessary trailing zeros
|
|
695
|
-
// First round to 8 decimals to avoid floating point issues
|
|
696
|
-
const rounded = Math.round(tokenAmount * 100000000) / 100000000
|
|
697
|
-
setInputDisplayValue(rounded.toString())
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}, [
|
|
703
|
-
isEnteringFiat,
|
|
704
|
-
fiatToUsdExchangeRate,
|
|
705
|
-
sellFiatAmount,
|
|
706
|
-
sellAmount,
|
|
707
|
-
isMeldOnRampActive,
|
|
708
|
-
tokenPriceUsd,
|
|
709
|
-
isUserTyping,
|
|
710
|
-
])
|
|
711
|
-
|
|
712
|
-
// Reset mode only when currency actually changes (but respect defaultInputMode)
|
|
713
|
-
const prevFiatCurrencyRef = useRef(selectedFiatCurrency)
|
|
714
|
-
useEffect(() => {
|
|
715
|
-
// Only reset if currency actually changed (not on initial mount)
|
|
716
|
-
if (
|
|
717
|
-
selectedFiatCurrency &&
|
|
718
|
-
prevFiatCurrencyRef.current !== selectedFiatCurrency
|
|
719
|
-
) {
|
|
720
|
-
// Reset to default mode when currency changes
|
|
721
|
-
setIsEnteringFiat(defaultInputMode === "fiat")
|
|
722
|
-
lastInputModeRef.current = defaultInputMode === "fiat"
|
|
723
|
-
}
|
|
724
|
-
prevFiatCurrencyRef.current = selectedFiatCurrency
|
|
725
|
-
}, [selectedFiatCurrency, defaultInputMode]) // Only reset mode on currency change
|
|
726
|
-
|
|
727
|
-
// Update display value when amount changes (but don't reset mode)
|
|
728
|
-
useEffect(() => {
|
|
729
|
-
if (selectedFiatCurrency && !isUserTyping && !isEnteringFiat) {
|
|
730
|
-
// Only update display if not in USD mode and not typing
|
|
731
|
-
// Don't update if the user has cleared the input (inputDisplayValue is empty but sellFiatAmount has value)
|
|
732
|
-
if (
|
|
733
|
-
inputDisplayValue !== "" &&
|
|
734
|
-
sellFiatAmount !== "" &&
|
|
735
|
-
sellFiatAmount !== undefined &&
|
|
736
|
-
sellFiatAmount !== null
|
|
737
|
-
) {
|
|
738
|
-
setInputDisplayValue(sellFiatAmount)
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
}, [
|
|
742
|
-
selectedFiatCurrency,
|
|
743
|
-
sellFiatAmount,
|
|
744
|
-
isUserTyping,
|
|
745
|
-
isEnteringFiat,
|
|
746
|
-
inputDisplayValue,
|
|
747
|
-
])
|
|
748
|
-
|
|
749
|
-
// Reset mode only when token actually changes (but respect defaultInputMode)
|
|
750
|
-
const prevOriginTokenRef = useRef(originToken)
|
|
751
|
-
useEffect(() => {
|
|
752
|
-
// Only reset if token actually changed (not on initial mount)
|
|
753
|
-
if (
|
|
754
|
-
originToken &&
|
|
755
|
-
!isMeldOnRampActive &&
|
|
756
|
-
prevOriginTokenRef.current !== originToken
|
|
757
|
-
) {
|
|
758
|
-
// Reset to default mode when token changes
|
|
759
|
-
setIsEnteringFiat(defaultInputMode === "fiat")
|
|
760
|
-
lastInputModeRef.current = defaultInputMode === "fiat"
|
|
761
|
-
}
|
|
762
|
-
prevOriginTokenRef.current = originToken
|
|
763
|
-
}, [originToken, isMeldOnRampActive, defaultInputMode]) // Only reset mode on token change
|
|
764
|
-
|
|
765
|
-
// Update display value when amount changes (but don't reset mode)
|
|
766
|
-
useEffect(() => {
|
|
767
|
-
if (
|
|
768
|
-
originToken &&
|
|
769
|
-
!isMeldOnRampActive &&
|
|
770
|
-
!isUserTyping &&
|
|
771
|
-
!isEnteringFiat
|
|
772
|
-
) {
|
|
773
|
-
// Only update display if not in USD mode and not typing
|
|
774
|
-
// Don't update if the user has cleared the input (inputDisplayValue is empty but sellAmount has value)
|
|
775
|
-
if (
|
|
776
|
-
inputDisplayValue !== "" &&
|
|
777
|
-
sellAmount !== "" &&
|
|
778
|
-
sellAmount !== undefined &&
|
|
779
|
-
sellAmount !== null
|
|
780
|
-
) {
|
|
781
|
-
setInputDisplayValue(sellAmount)
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
}, [
|
|
785
|
-
originToken,
|
|
786
|
-
isMeldOnRampActive,
|
|
787
|
-
sellAmount,
|
|
788
|
-
isUserTyping,
|
|
789
|
-
isEnteringFiat,
|
|
790
|
-
inputDisplayValue,
|
|
791
|
-
])
|
|
792
|
-
|
|
793
|
-
// Hook to create onramp widget session
|
|
794
|
-
const {
|
|
795
|
-
createWidgetSession,
|
|
796
|
-
isLoading: isLoadingWidgetSession,
|
|
797
|
-
error: widgetSessionError,
|
|
798
|
-
} = useOnRampProviderWidget()
|
|
799
|
-
|
|
800
|
-
const [showSourceTokenSelector, setShowSourceTokenSelector] = useState(false)
|
|
801
|
-
const [showDestinationTokenSelector, setShowDestinationTokenSelector] =
|
|
802
|
-
useState(false)
|
|
803
|
-
|
|
804
|
-
const { supportedTokens } = useSupportedTokens({
|
|
805
|
-
disabled: !toToken,
|
|
806
|
-
})
|
|
807
|
-
|
|
808
|
-
// Use a ref to track if we've already auto-selected from toToken prop
|
|
809
|
-
const lastAutoSelectedRef = useRef<string | null>(null)
|
|
810
|
-
|
|
811
|
-
// Initialize destination token from toToken prop (similar to Pay.tsx)
|
|
812
|
-
// This should override any cached/manual selections when toToken is provided
|
|
813
|
-
useEffect(() => {
|
|
814
|
-
const currentKey = `${toToken}-${toChainId}`
|
|
815
|
-
|
|
816
|
-
if (
|
|
817
|
-
toToken &&
|
|
818
|
-
toChainId &&
|
|
819
|
-
supportedTokens?.length > 0 &&
|
|
820
|
-
lastAutoSelectedRef.current !== currentKey
|
|
821
|
-
) {
|
|
822
|
-
// Find the destination token from props
|
|
823
|
-
const destinationToken = supportedTokens?.find(
|
|
824
|
-
(token) =>
|
|
825
|
-
token.chainId === Number(toChainId) &&
|
|
826
|
-
(addressEqual(token.contractAddress, toToken) ||
|
|
827
|
-
token.symbol.toLowerCase() === toToken.toLowerCase()),
|
|
828
|
-
)
|
|
829
|
-
|
|
830
|
-
if (destinationToken) {
|
|
831
|
-
logger.console.log(
|
|
832
|
-
"[trails-sdk] Fund: Setting destination token from toToken prop:",
|
|
833
|
-
destinationToken,
|
|
834
|
-
)
|
|
835
|
-
|
|
836
|
-
setDestinationToken(destinationToken)
|
|
837
|
-
setSelectedDestToken(destinationToken)
|
|
838
|
-
|
|
839
|
-
// Set the destination chain
|
|
840
|
-
const chainInfo = getChainInfo(Number(toChainId))
|
|
841
|
-
if (chainInfo) {
|
|
842
|
-
setSelectedDestinationChain(chainInfo)
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
// Mark this combination as processed
|
|
846
|
-
lastAutoSelectedRef.current = currentKey
|
|
847
|
-
|
|
848
|
-
// Don't mark as manually selected - this is from props
|
|
849
|
-
// This allows the token to be properly set from props without interference
|
|
850
|
-
}
|
|
851
|
-
} else if (!toToken && hasManualDestinationSelection) {
|
|
852
|
-
// Clear manual selection flag when toToken prop is removed
|
|
853
|
-
// This allows default selection to work again
|
|
854
|
-
setHasManualDestinationSelection(false)
|
|
855
|
-
userActionRef.current.hasManualDestinationSelection = false
|
|
856
|
-
lastAutoSelectedRef.current = null
|
|
857
|
-
}
|
|
858
|
-
}, [
|
|
859
|
-
toToken,
|
|
860
|
-
toChainId,
|
|
861
|
-
supportedTokens,
|
|
862
|
-
setDestinationToken,
|
|
863
|
-
setSelectedDestToken,
|
|
864
|
-
setSelectedDestinationChain,
|
|
865
|
-
hasManualDestinationSelection,
|
|
866
|
-
setHasManualDestinationSelection,
|
|
867
|
-
])
|
|
868
|
-
|
|
869
|
-
// Fund mode is always exact input only - enforce this
|
|
870
|
-
useEffect(() => {
|
|
871
|
-
if (exactInputOnly) {
|
|
872
|
-
setTradeType(TradeType.EXACT_INPUT)
|
|
873
|
-
setBuyAmount("") // Clear any buy amount
|
|
874
|
-
}
|
|
875
|
-
}, [exactInputOnly, setTradeType, setBuyAmount])
|
|
876
|
-
|
|
877
|
-
// Handle sell amount input changes
|
|
878
|
-
const handleSellAmountChange = useCallback(
|
|
879
|
-
(value: string) => {
|
|
880
|
-
// Don't process single "0" or values starting with "0."
|
|
881
|
-
// Only strip leading zeros from values like "00", "01", "005" etc.
|
|
882
|
-
let processedValue = value
|
|
883
|
-
if (
|
|
884
|
-
value !== "0" &&
|
|
885
|
-
value.length > 1 &&
|
|
886
|
-
value.startsWith("0") &&
|
|
887
|
-
value[1] !== "."
|
|
888
|
-
) {
|
|
889
|
-
processedValue = value.replace(/^0+/, "") || "0"
|
|
890
|
-
}
|
|
891
|
-
setTradeType(TradeType.EXACT_INPUT)
|
|
892
|
-
setSellAmount(processedValue)
|
|
893
|
-
},
|
|
894
|
-
[setTradeType, setSellAmount],
|
|
895
|
-
)
|
|
896
|
-
|
|
897
|
-
// Handle sell input focus
|
|
898
|
-
const handleSellInputFocus = useCallback(() => {
|
|
899
|
-
// Copy displayed value for editing
|
|
900
|
-
if (
|
|
901
|
-
tradeType === TradeType.EXACT_OUTPUT &&
|
|
902
|
-
prepareSendQuote?.originAmountDisplay &&
|
|
903
|
-
!sellAmount
|
|
904
|
-
) {
|
|
905
|
-
setSellAmount(prepareSendQuote.originAmountDisplay)
|
|
906
|
-
}
|
|
907
|
-
}, [
|
|
908
|
-
tradeType,
|
|
909
|
-
prepareSendQuote?.originAmountDisplay,
|
|
910
|
-
sellAmount,
|
|
911
|
-
setSellAmount,
|
|
912
|
-
])
|
|
913
|
-
|
|
914
|
-
// Check if we received a quote from on ramp for USDC BASE, if so set the origin token amount to the quote.destinationAmount
|
|
915
|
-
// This will trigger useSendForm to get the trails quote
|
|
916
|
-
// Subtract 0.25 USDC from the amount to cover fees
|
|
917
|
-
useEffect(() => {
|
|
918
|
-
if (
|
|
919
|
-
isMeldOnRampActive &&
|
|
920
|
-
selectedOnrampProviderQuote &&
|
|
921
|
-
effectiveOriginToken &&
|
|
922
|
-
effectiveOriginToken.contractAddress
|
|
923
|
-
) {
|
|
924
|
-
// Subtract 0.25 USDC from the destination amount to cover fees
|
|
925
|
-
const destinationAmount = Number(
|
|
926
|
-
selectedOnrampProviderQuote.destinationAmount,
|
|
927
|
-
)
|
|
928
|
-
const adjustedAmount = Math.max(0, destinationAmount - 0.25)
|
|
929
|
-
|
|
930
|
-
logger.console.log("[trails-sdk] Adjusting onramp amount for fees:", {
|
|
931
|
-
originalAmount: destinationAmount,
|
|
932
|
-
adjustedAmount,
|
|
933
|
-
feeSubtracted: 0.25,
|
|
934
|
-
})
|
|
935
|
-
|
|
936
|
-
setSellAmount(adjustedAmount.toString())
|
|
937
|
-
setTradeType(TradeType.EXACT_INPUT)
|
|
938
|
-
}
|
|
939
|
-
}, [
|
|
940
|
-
isMeldOnRampActive,
|
|
941
|
-
selectedOnrampProviderQuote,
|
|
942
|
-
effectiveOriginToken,
|
|
943
|
-
setSellAmount,
|
|
944
|
-
setTradeType,
|
|
945
|
-
])
|
|
946
|
-
|
|
947
|
-
// Update amounts when quote is received
|
|
948
|
-
// Always update the calculated field based on the current trade type
|
|
949
|
-
useEffect(() => {
|
|
950
|
-
if (!prepareSendQuote) return
|
|
951
|
-
|
|
952
|
-
if (
|
|
953
|
-
tradeType === TradeType.EXACT_OUTPUT &&
|
|
954
|
-
prepareSendQuote.originAmountDisplay
|
|
955
|
-
) {
|
|
956
|
-
// In EXACT_OUTPUT mode, update sellAmount from the quote
|
|
957
|
-
setSellAmount(prepareSendQuote.originAmountDisplay)
|
|
958
|
-
} else if (
|
|
959
|
-
tradeType === TradeType.EXACT_INPUT &&
|
|
960
|
-
prepareSendQuote.destinationAmountDisplay
|
|
961
|
-
) {
|
|
962
|
-
// In EXACT_INPUT mode, update buyAmount from the quote
|
|
963
|
-
setBuyAmount(prepareSendQuote.destinationAmountDisplay)
|
|
964
|
-
}
|
|
965
|
-
}, [prepareSendQuote, tradeType, setSellAmount, setBuyAmount])
|
|
966
|
-
|
|
967
|
-
// Call onAmountUpdate when amountRaw changes
|
|
968
|
-
useEffect(() => {
|
|
969
|
-
if (onAmountUpdate) {
|
|
970
|
-
onAmountUpdate(amountRaw)
|
|
971
|
-
}
|
|
972
|
-
}, [amountRaw, onAmountUpdate])
|
|
973
|
-
|
|
974
|
-
// Reset the flag so auto-selection can work as a fallback if has manual origin token is cleared
|
|
975
|
-
useEffect(() => {
|
|
976
|
-
if (hasManualOriginSelection && !originToken && !isLoadingOriginDefaults) {
|
|
977
|
-
logger.console.log(
|
|
978
|
-
"[trails-sdk] Resetting hasManualOriginSelection - token was cleared",
|
|
979
|
-
)
|
|
980
|
-
setHasManualOriginSelection(false)
|
|
981
|
-
}
|
|
982
|
-
}, [
|
|
983
|
-
hasManualOriginSelection,
|
|
984
|
-
originToken,
|
|
985
|
-
isLoadingOriginDefaults,
|
|
986
|
-
setHasManualOriginSelection,
|
|
987
|
-
])
|
|
988
|
-
|
|
989
|
-
useEffect(() => {
|
|
990
|
-
if (hasManualOriginSelection || !isCoinbaseMeshOnramp) {
|
|
991
|
-
return
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
const isUsdcBaseSelected =
|
|
995
|
-
!!originToken &&
|
|
996
|
-
originToken.chainId === USDC_BASE.chainId &&
|
|
997
|
-
addressEqual(originToken.contractAddress, USDC_BASE.contractAddress)
|
|
998
|
-
|
|
999
|
-
if (!isUsdcBaseSelected) {
|
|
1000
|
-
logger.console.log(
|
|
1001
|
-
"[Fund] Preselecting USDC on Base for Coinbase Mesh onramp",
|
|
1002
|
-
)
|
|
1003
|
-
setOriginToken(USDC_BASE as Token)
|
|
1004
|
-
}
|
|
1005
|
-
}, [
|
|
1006
|
-
hasManualOriginSelection,
|
|
1007
|
-
isCoinbaseMeshOnramp,
|
|
1008
|
-
originToken,
|
|
1009
|
-
setOriginToken,
|
|
1010
|
-
])
|
|
1011
|
-
|
|
1012
|
-
// Auto-select origin token using separated hook
|
|
1013
|
-
useEffect(() => {
|
|
1014
|
-
if (
|
|
1015
|
-
fundMethod !== "onramp-mesh" &&
|
|
1016
|
-
!originToken &&
|
|
1017
|
-
!isLoadingOriginDefaults &&
|
|
1018
|
-
defaultOriginToken &&
|
|
1019
|
-
!hasManualOriginSelection
|
|
1020
|
-
) {
|
|
1021
|
-
logger.console.log(
|
|
1022
|
-
"[trails-sdk] Auto-selecting origin token:",
|
|
1023
|
-
defaultOriginToken,
|
|
1024
|
-
)
|
|
1025
|
-
setOriginToken(defaultOriginToken as any)
|
|
1026
|
-
}
|
|
1027
|
-
}, [
|
|
1028
|
-
originToken,
|
|
1029
|
-
isLoadingOriginDefaults,
|
|
1030
|
-
defaultOriginToken,
|
|
1031
|
-
setOriginToken,
|
|
1032
|
-
hasManualOriginSelection,
|
|
1033
|
-
fundMethod,
|
|
1034
|
-
])
|
|
1035
|
-
|
|
1036
|
-
// Auto-select destination token using separated hook
|
|
1037
|
-
// IMPORTANT: Only auto-select if user hasn't made manual selections and toToken prop is not provided
|
|
1038
|
-
useEffect(() => {
|
|
1039
|
-
// Skip auto-selection if toToken prop is provided
|
|
1040
|
-
if (toToken) {
|
|
1041
|
-
return
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
// hasManualOriginSelection is now persisted in context across component mounts
|
|
1045
|
-
const hasRecentOriginSelection =
|
|
1046
|
-
hasManualOriginSelection ||
|
|
1047
|
-
isWithinCooldown(userActionRef.current.lastOriginSelectionTime, SECOND_MS)
|
|
1048
|
-
|
|
1049
|
-
const hasRecentDestSelection =
|
|
1050
|
-
userActionRef.current.hasManualDestinationSelection ||
|
|
1051
|
-
hasManualDestinationSelection ||
|
|
1052
|
-
isWithinCooldown(
|
|
1053
|
-
userActionRef.current.lastDestinationSelectionTime,
|
|
1054
|
-
SECOND_MS,
|
|
1055
|
-
)
|
|
1056
|
-
|
|
1057
|
-
if (
|
|
1058
|
-
!destinationToken &&
|
|
1059
|
-
!isLoadingDestinationDefaults &&
|
|
1060
|
-
defaultDestinationToken &&
|
|
1061
|
-
!hasRecentDestSelection &&
|
|
1062
|
-
!hasRecentOriginSelection // Don't auto-select destination if user recently selected origin
|
|
1063
|
-
) {
|
|
1064
|
-
logger.console.log(
|
|
1065
|
-
"[trails-sdk] Auto-selecting destination token:",
|
|
1066
|
-
defaultDestinationToken,
|
|
1067
|
-
)
|
|
1068
|
-
setDestinationToken(defaultDestinationToken as any)
|
|
1069
|
-
setSelectedDestToken(defaultDestinationToken as any)
|
|
1070
|
-
|
|
1071
|
-
// Also set the destination chain
|
|
1072
|
-
const chainInfo = getChainInfo(defaultDestinationToken.chainId)
|
|
1073
|
-
if (chainInfo) {
|
|
1074
|
-
setSelectedDestinationChain(chainInfo)
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
}, [
|
|
1078
|
-
destinationToken,
|
|
1079
|
-
isLoadingDestinationDefaults,
|
|
1080
|
-
defaultDestinationToken,
|
|
1081
|
-
hasManualDestinationSelection,
|
|
1082
|
-
hasManualOriginSelection,
|
|
1083
|
-
setDestinationToken,
|
|
1084
|
-
setSelectedDestToken,
|
|
1085
|
-
setSelectedDestinationChain,
|
|
1086
|
-
toToken, // Add toToken as dependency to skip when provided
|
|
1087
|
-
])
|
|
1088
|
-
|
|
1089
|
-
// Auto-focus the input field when component mounts
|
|
1090
|
-
useEffect(() => {
|
|
1091
|
-
if (inputRef.current) {
|
|
1092
|
-
inputRef.current.focus()
|
|
1093
|
-
}
|
|
1094
|
-
}, [])
|
|
1095
|
-
|
|
1096
|
-
const inputRef = useRef<HTMLInputElement>(null)
|
|
1097
|
-
|
|
1098
|
-
const [showSourceChainList, setShowSourceChainList] = useState(false)
|
|
1099
|
-
const [showDestinationChainList, setShowDestinationChainList] =
|
|
1100
|
-
useState(false)
|
|
1101
|
-
|
|
1102
|
-
// Sync destination token from hook with useSendForm
|
|
1103
|
-
// This ensures the destination token auto-selection flows into useSendForm
|
|
1104
|
-
useEffect(() => {
|
|
1105
|
-
if (destinationToken) {
|
|
1106
|
-
logger.console.log(
|
|
1107
|
-
"[trails-sdk] Syncing destination token to useSendForm:",
|
|
1108
|
-
destinationToken,
|
|
1109
|
-
)
|
|
1110
|
-
setSelectedDestToken(destinationToken as any)
|
|
1111
|
-
}
|
|
1112
|
-
}, [destinationToken, setSelectedDestToken])
|
|
1113
|
-
|
|
1114
|
-
useEffect(() => {
|
|
1115
|
-
// Skip if not controlled by props or no resolved token
|
|
1116
|
-
if (!isDestinationControlledByProps || !selectedDestToken || !toToken) {
|
|
1117
|
-
return
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
// Check if the resolved token matches what we're looking for
|
|
1121
|
-
const chainIdMatches = selectedDestToken.chainId === Number(toChainId)
|
|
1122
|
-
const tokenMatches =
|
|
1123
|
-
selectedDestToken.contractAddress?.toLowerCase() ===
|
|
1124
|
-
toToken.toLowerCase() ||
|
|
1125
|
-
selectedDestToken.symbol?.toLowerCase() === toToken.toLowerCase()
|
|
1126
|
-
|
|
1127
|
-
// Only sync if the token matches the toToken prop
|
|
1128
|
-
if (chainIdMatches && tokenMatches) {
|
|
1129
|
-
const globalMatches =
|
|
1130
|
-
destinationToken &&
|
|
1131
|
-
destinationToken.chainId === selectedDestToken.chainId &&
|
|
1132
|
-
destinationToken.contractAddress?.toLowerCase() ===
|
|
1133
|
-
selectedDestToken.contractAddress?.toLowerCase()
|
|
1134
|
-
|
|
1135
|
-
if (!globalMatches) {
|
|
1136
|
-
logger.console.log(
|
|
1137
|
-
"[trails-sdk] Fund: Syncing resolved token from useSendForm to global provider:",
|
|
1138
|
-
selectedDestToken.symbol,
|
|
1139
|
-
)
|
|
1140
|
-
setDestinationToken(selectedDestToken)
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
}, [
|
|
1144
|
-
isDestinationControlledByProps,
|
|
1145
|
-
selectedDestToken,
|
|
1146
|
-
destinationToken,
|
|
1147
|
-
setDestinationToken,
|
|
1148
|
-
toToken,
|
|
1149
|
-
toChainId,
|
|
1150
|
-
])
|
|
1151
|
-
|
|
1152
|
-
// Handle source token selection from full-screen selector
|
|
1153
|
-
const handleSourceTokenSelectorSelect = useCallback(
|
|
1154
|
-
(token: Token) => {
|
|
1155
|
-
// Only reset input fields if switching from one token to a different one
|
|
1156
|
-
// Don't reset when selecting a token for the first time (originToken is null)
|
|
1157
|
-
const isDifferentToken =
|
|
1158
|
-
!!originToken && originToken.symbol !== token.symbol
|
|
1159
|
-
if (isDifferentToken) {
|
|
1160
|
-
setSellAmount("")
|
|
1161
|
-
setBuyAmount("")
|
|
1162
|
-
setInputDisplayValue("")
|
|
1163
|
-
setTradeType(TradeType.EXACT_INPUT)
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
setOriginToken(token)
|
|
1167
|
-
setShowSourceTokenSelector(false)
|
|
1168
|
-
|
|
1169
|
-
// Mark as manual selection to prevent auto-selection override
|
|
1170
|
-
setHasManualOriginSelection(true)
|
|
1171
|
-
userActionRef.current.lastOriginSelectionTime = Date.now()
|
|
1172
|
-
|
|
1173
|
-
onTrackToken?.(token)
|
|
1174
|
-
logger.console.log("[trails-sdk] selected origin token", token)
|
|
1175
|
-
},
|
|
1176
|
-
[
|
|
1177
|
-
setOriginToken,
|
|
1178
|
-
setHasManualOriginSelection,
|
|
1179
|
-
onTrackToken,
|
|
1180
|
-
originToken,
|
|
1181
|
-
setSellAmount,
|
|
1182
|
-
setBuyAmount,
|
|
1183
|
-
setTradeType,
|
|
1184
|
-
],
|
|
1185
|
-
)
|
|
1186
|
-
|
|
1187
|
-
// Handle destination token selection from full-screen selector
|
|
1188
|
-
const handleDestinationTokenSelectorSelect = useCallback(
|
|
1189
|
-
(token: Token) => {
|
|
1190
|
-
setDestinationToken(token)
|
|
1191
|
-
setSelectedDestToken(token)
|
|
1192
|
-
|
|
1193
|
-
// Update destination chain
|
|
1194
|
-
const chainInfo = getChainInfo(token.chainId)
|
|
1195
|
-
if (chainInfo) {
|
|
1196
|
-
setSelectedDestinationChain(chainInfo)
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
setShowDestinationTokenSelector(false)
|
|
1200
|
-
|
|
1201
|
-
// Mark as manual selection to prevent auto-selection override
|
|
1202
|
-
setHasManualDestinationSelection(true)
|
|
1203
|
-
userActionRef.current.hasManualDestinationSelection = true
|
|
1204
|
-
userActionRef.current.lastDestinationSelectionTime = Date.now()
|
|
1205
|
-
|
|
1206
|
-
onTrackToken?.(token)
|
|
1207
|
-
logger.console.log("[trails-sdk] selected destination token", token)
|
|
1208
|
-
},
|
|
1209
|
-
[
|
|
1210
|
-
setDestinationToken,
|
|
1211
|
-
setSelectedDestToken,
|
|
1212
|
-
setSelectedDestinationChain,
|
|
1213
|
-
setHasManualDestinationSelection,
|
|
1214
|
-
onTrackToken,
|
|
1215
|
-
],
|
|
1216
|
-
)
|
|
1217
|
-
|
|
1218
|
-
// Handle recent token selection
|
|
1219
|
-
const handleRecentTokenSelect = useCallback(
|
|
1220
|
-
(token: any) => {
|
|
1221
|
-
if (showSourceTokenSelector) {
|
|
1222
|
-
handleSourceTokenSelectorSelect(token)
|
|
1223
|
-
} else if (showDestinationTokenSelector) {
|
|
1224
|
-
handleDestinationTokenSelectorSelect(token)
|
|
1225
|
-
}
|
|
1226
|
-
},
|
|
1227
|
-
[
|
|
1228
|
-
showSourceTokenSelector,
|
|
1229
|
-
showDestinationTokenSelector,
|
|
1230
|
-
handleSourceTokenSelectorSelect,
|
|
1231
|
-
handleDestinationTokenSelectorSelect,
|
|
1232
|
-
],
|
|
1233
|
-
)
|
|
1234
|
-
|
|
1235
|
-
// Show provider selector screen
|
|
1236
|
-
if (showProviderSelector) {
|
|
1237
|
-
return (
|
|
1238
|
-
<MeldProvidersList
|
|
1239
|
-
onBack={() => setShowProviderSelector(false)}
|
|
1240
|
-
onSelectProvider={(provider) => {
|
|
1241
|
-
setSelectedOnrampProvider(provider as OnrampQuote)
|
|
1242
|
-
setShowProviderSelector(false)
|
|
1243
|
-
}}
|
|
1244
|
-
selectedProvider={selectedOnrampProviderQuote}
|
|
1245
|
-
providers={onrampQuotes}
|
|
1246
|
-
isLoading={isLoadingOnrampQuote}
|
|
1247
|
-
/>
|
|
1248
|
-
)
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
// Show fiat selector screen
|
|
1252
|
-
if (showFiatSelector) {
|
|
1253
|
-
return (
|
|
1254
|
-
<div className="space-y-2">
|
|
1255
|
-
<ScreenHeader
|
|
1256
|
-
onBack={() => setShowFiatSelector(false)}
|
|
1257
|
-
headerContent="Select Currency"
|
|
1258
|
-
headerContentAlign="left"
|
|
1259
|
-
/>
|
|
1260
|
-
<FiatSelector
|
|
1261
|
-
onCurrencySelect={(currency) => {
|
|
1262
|
-
setSelectedFiatCurrency(currency)
|
|
1263
|
-
setShowFiatSelector(false)
|
|
1264
|
-
setHasManualFiatSelection(true)
|
|
1265
|
-
}}
|
|
1266
|
-
onAutoSelect={(currency) => {
|
|
1267
|
-
// Auto-select doesn't close the selector, just sets the currency
|
|
1268
|
-
setSelectedFiatCurrency(currency)
|
|
1269
|
-
}}
|
|
1270
|
-
onSelectCountry={(countryCode) => {
|
|
1271
|
-
setSelectedCountryCode(countryCode)
|
|
1272
|
-
}}
|
|
1273
|
-
onError={onError}
|
|
1274
|
-
selectedCurrency={selectedFiatCurrency}
|
|
1275
|
-
/>
|
|
1276
|
-
</div>
|
|
1277
|
-
)
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
// Show source chain list screen
|
|
1281
|
-
if (showSourceChainList) {
|
|
1282
|
-
return (
|
|
1283
|
-
<ChainList
|
|
1284
|
-
onBack={() => {
|
|
1285
|
-
setShowSourceChainList(false)
|
|
1286
|
-
setShowSourceTokenSelector(true)
|
|
1287
|
-
}}
|
|
1288
|
-
/>
|
|
1289
|
-
)
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
// Show source token selector screen
|
|
1293
|
-
if (showSourceTokenSelector) {
|
|
1294
|
-
return (
|
|
1295
|
-
<div className="space-y-2">
|
|
1296
|
-
<ScreenHeader
|
|
1297
|
-
onBack={() => setShowSourceTokenSelector(false)}
|
|
1298
|
-
headerContent="Select From Token"
|
|
1299
|
-
headerContentAlign="left"
|
|
1300
|
-
/>
|
|
1301
|
-
<TokenSelector
|
|
1302
|
-
onTokenSelect={handleSourceTokenSelectorSelect}
|
|
1303
|
-
onError={onError}
|
|
1304
|
-
showContinueButton={false}
|
|
1305
|
-
compactMode={false}
|
|
1306
|
-
allSupportedTokens={false}
|
|
1307
|
-
fundMethod={fundMethod}
|
|
1308
|
-
chainListScreen={true}
|
|
1309
|
-
onNavigateToChainList={() => {
|
|
1310
|
-
setShowSourceTokenSelector(false)
|
|
1311
|
-
setShowSourceChainList(true)
|
|
1312
|
-
}}
|
|
1313
|
-
recentTokens={recentTokens}
|
|
1314
|
-
onRecentTokenSelect={handleRecentTokenSelect}
|
|
1315
|
-
/>
|
|
1316
|
-
</div>
|
|
1317
|
-
)
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
// Show destination chain list screen
|
|
1321
|
-
if (showDestinationChainList) {
|
|
1322
|
-
return (
|
|
1323
|
-
<ChainList
|
|
1324
|
-
onBack={() => {
|
|
1325
|
-
setShowDestinationChainList(false)
|
|
1326
|
-
setShowDestinationTokenSelector(true)
|
|
1327
|
-
}}
|
|
1328
|
-
/>
|
|
1329
|
-
)
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
// Show destination token selector screen
|
|
1333
|
-
if (showDestinationTokenSelector) {
|
|
1334
|
-
return (
|
|
1335
|
-
<div className="space-y-2">
|
|
1336
|
-
<ScreenHeader
|
|
1337
|
-
onBack={() => setShowDestinationTokenSelector(false)}
|
|
1338
|
-
headerContent="Select To Token"
|
|
1339
|
-
headerContentAlign="left"
|
|
1340
|
-
/>
|
|
1341
|
-
<TokenSelector
|
|
1342
|
-
onTokenSelect={handleDestinationTokenSelectorSelect}
|
|
1343
|
-
onError={onError}
|
|
1344
|
-
showContinueButton={false}
|
|
1345
|
-
compactMode={false}
|
|
1346
|
-
allSupportedTokens={true}
|
|
1347
|
-
fundMethod={fundMethod}
|
|
1348
|
-
chainListScreen={true}
|
|
1349
|
-
onNavigateToChainList={() => {
|
|
1350
|
-
setShowDestinationTokenSelector(false)
|
|
1351
|
-
setShowDestinationChainList(true)
|
|
1352
|
-
}}
|
|
1353
|
-
recentTokens={recentTokens}
|
|
1354
|
-
onRecentTokenSelect={handleRecentTokenSelect}
|
|
1355
|
-
/>
|
|
1356
|
-
</div>
|
|
1357
|
-
)
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
return (
|
|
1361
|
-
<div className="space-y-2">
|
|
1362
|
-
<ScreenHeader
|
|
1363
|
-
onBack={() => navigate("fund-methods")}
|
|
1364
|
-
headerContent="Fund"
|
|
1365
|
-
headerContentAlign="left"
|
|
1366
|
-
showAccountActions={true}
|
|
1367
|
-
customActions={
|
|
1368
|
-
fundOptions?.hideSwap ? undefined : (
|
|
1369
|
-
<button
|
|
1370
|
-
type="button"
|
|
1371
|
-
onClick={() => navigate("swap", { backTarget: "fund-form" })}
|
|
1372
|
-
className="flex h-8 px-3 justify-center items-center gap-1.5 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"
|
|
1373
|
-
title="Swap"
|
|
1374
|
-
>
|
|
1375
|
-
<ArrowLeftRight className="h-4 w-4" />
|
|
1376
|
-
<span className="text-sm font-medium">Swap</span>
|
|
1377
|
-
</button>
|
|
1378
|
-
)
|
|
1379
|
-
}
|
|
1380
|
-
/>
|
|
1381
|
-
|
|
1382
|
-
<form
|
|
1383
|
-
onSubmit={async (e) => {
|
|
1384
|
-
e.preventDefault()
|
|
1385
|
-
|
|
1386
|
-
logger.console.log(
|
|
1387
|
-
"[trails-sdk] Creating widget session",
|
|
1388
|
-
isMeldOnRampActive,
|
|
1389
|
-
)
|
|
1390
|
-
// Handle onramp flow separately
|
|
1391
|
-
if (
|
|
1392
|
-
isMeldOnRampActive &&
|
|
1393
|
-
selectedOnrampProviderQuote &&
|
|
1394
|
-
selectedFiatCurrency
|
|
1395
|
-
) {
|
|
1396
|
-
const {
|
|
1397
|
-
popup,
|
|
1398
|
-
blocked,
|
|
1399
|
-
error: popupError,
|
|
1400
|
-
} = openPopup("meld-widget", 450, 700)
|
|
1401
|
-
|
|
1402
|
-
if (blocked) {
|
|
1403
|
-
setWidgetError(
|
|
1404
|
-
popupError ||
|
|
1405
|
-
"Popup blocked. Please allow popups for this site.",
|
|
1406
|
-
)
|
|
1407
|
-
onError(popupError || "Popup blocked")
|
|
1408
|
-
return
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
try {
|
|
1412
|
-
setIsCreatingWidgetSession(true)
|
|
1413
|
-
setWidgetError(null)
|
|
1414
|
-
|
|
1415
|
-
logger.console.log(
|
|
1416
|
-
"[trails-sdk] prepareSendQuote",
|
|
1417
|
-
prepareSendQuote,
|
|
1418
|
-
)
|
|
1419
|
-
|
|
1420
|
-
// Commit the intent immediately when user clicks continue
|
|
1421
|
-
// Call sendFn to trigger the commit without deposit
|
|
1422
|
-
if (sendFn) {
|
|
1423
|
-
logger.console.log(
|
|
1424
|
-
"[trails-sdk] Committing intent for onramp-meld flow",
|
|
1425
|
-
)
|
|
1426
|
-
|
|
1427
|
-
try {
|
|
1428
|
-
// Call sendFn without depositTransactionHash to just commit
|
|
1429
|
-
// The crossChain handler will commit but not execute/wait for deposit
|
|
1430
|
-
await sendFn({
|
|
1431
|
-
selectedFeeOption: selectedFeeOption ?? null,
|
|
1432
|
-
})
|
|
1433
|
-
|
|
1434
|
-
logger.console.log(
|
|
1435
|
-
"[trails-sdk] Intent committed for onramp-meld",
|
|
1436
|
-
)
|
|
1437
|
-
} catch (error) {
|
|
1438
|
-
logger.console.error(
|
|
1439
|
-
"[trails-sdk] Failed to commit intent:",
|
|
1440
|
-
error,
|
|
1441
|
-
)
|
|
1442
|
-
// Continue anyway
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
// Create widget session
|
|
1447
|
-
const widgetSessionResponse = await createWidgetSession({
|
|
1448
|
-
depositAddress: prepareSendQuote?.originDepositAddress || "",
|
|
1449
|
-
userAddress: account?.address || "",
|
|
1450
|
-
countryCode: effectiveCountryCode || "",
|
|
1451
|
-
sourceCurrencyCode: selectedFiatCurrency.currencyCode,
|
|
1452
|
-
sourceAmount: sellFiatAmount,
|
|
1453
|
-
destinationCurrencyCode: "USDC_BASE",
|
|
1454
|
-
serviceProvider: selectedOnrampProviderQuote.serviceProvider,
|
|
1455
|
-
paymentMethodType:
|
|
1456
|
-
selectedOnrampProviderQuote.paymentMethodType,
|
|
1457
|
-
lockFields: [
|
|
1458
|
-
"cryptoCurrency",
|
|
1459
|
-
"destinationCurrencyCode",
|
|
1460
|
-
"sourceCurrencyCode",
|
|
1461
|
-
"walletAddress",
|
|
1462
|
-
],
|
|
1463
|
-
})
|
|
1464
|
-
|
|
1465
|
-
logger.console.log(
|
|
1466
|
-
"[Fund] Widget session response:",
|
|
1467
|
-
widgetSessionResponse,
|
|
1468
|
-
)
|
|
1469
|
-
const { widgetUrl, id, externalSessionId } = widgetSessionResponse
|
|
1470
|
-
|
|
1471
|
-
// Track widget session
|
|
1472
|
-
trackOnrampWidgetSession({
|
|
1473
|
-
sessionId: onrampTrackingData?.sessionId || externalSessionId,
|
|
1474
|
-
provider:
|
|
1475
|
-
selectedOnrampProviderQuote?.serviceProvider || "Meld",
|
|
1476
|
-
widgetUrl,
|
|
1477
|
-
depositAddress: prepareSendQuote?.originDepositAddress || "",
|
|
1478
|
-
userAddress: account?.address?.toLowerCase() || "",
|
|
1479
|
-
countryCode: effectiveCountryCode || "",
|
|
1480
|
-
sourceCurrencyCode: selectedFiatCurrency?.currencyCode || "",
|
|
1481
|
-
sourceAmount: sellFiatAmount,
|
|
1482
|
-
destinationCurrencyCode: "USDC_BASE",
|
|
1483
|
-
paymentMethodType:
|
|
1484
|
-
selectedOnrampProviderQuote?.paymentMethodType || "",
|
|
1485
|
-
})
|
|
1486
|
-
|
|
1487
|
-
if (!setPopupUrl(popup, widgetUrl)) {
|
|
1488
|
-
throw new Error("Payment window was closed. Please try again.")
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
logger.console.log("[Fund] Opened onramp widget in popup", {
|
|
1492
|
-
widgetUrl,
|
|
1493
|
-
meldTransactionId: id,
|
|
1494
|
-
})
|
|
1495
|
-
|
|
1496
|
-
if (onWaitingForOnrampConfirm && prepareSendQuote) {
|
|
1497
|
-
// Pass both quote and widget creation parameters
|
|
1498
|
-
logger.console.log(
|
|
1499
|
-
"[Fund] Calling onWaitingForOnrampConfirm with externalSessionId:",
|
|
1500
|
-
externalSessionId,
|
|
1501
|
-
)
|
|
1502
|
-
onWaitingForOnrampConfirm(
|
|
1503
|
-
prepareSendQuote,
|
|
1504
|
-
selectedOnrampProviderQuote,
|
|
1505
|
-
{
|
|
1506
|
-
depositAddress:
|
|
1507
|
-
prepareSendQuote?.originDepositAddress || "",
|
|
1508
|
-
userAddress: account?.address?.toLowerCase() || "",
|
|
1509
|
-
countryCode: effectiveCountryCode || "",
|
|
1510
|
-
sourceCurrencyCode: selectedFiatCurrency.currencyCode,
|
|
1511
|
-
sourceAmount: sellFiatAmount,
|
|
1512
|
-
destinationCurrencyCode: "USDC_BASE",
|
|
1513
|
-
serviceProvider:
|
|
1514
|
-
selectedOnrampProviderQuote.serviceProvider,
|
|
1515
|
-
paymentMethodType:
|
|
1516
|
-
selectedOnrampProviderQuote.paymentMethodType,
|
|
1517
|
-
},
|
|
1518
|
-
externalSessionId,
|
|
1519
|
-
popup,
|
|
1520
|
-
)
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
await handleSubmit(e)
|
|
1524
|
-
} catch (err) {
|
|
1525
|
-
closePopup(popup)
|
|
1526
|
-
logger.console.error("[Fund] Error creating widget session", err)
|
|
1527
|
-
const errorMessage =
|
|
1528
|
-
err instanceof Error
|
|
1529
|
-
? err.message
|
|
1530
|
-
: "Failed to create widget session"
|
|
1531
|
-
setWidgetError(errorMessage)
|
|
1532
|
-
onError(errorMessage)
|
|
1533
|
-
} finally {
|
|
1534
|
-
setIsCreatingWidgetSession(false)
|
|
1535
|
-
}
|
|
1536
|
-
return
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
logger.console.log("[trails-sdk] Calling handleSubmit from Fund")
|
|
1540
|
-
handleSubmit(e)
|
|
1541
|
-
}}
|
|
1542
|
-
className="space-y-1"
|
|
1543
|
-
>
|
|
1544
|
-
{/* Input Section - Amount Only */}
|
|
1545
|
-
<div className="pt-4 pb-4 trails-border-radius-container p-3 flex flex-col border border-gray-200 dark:border-gray-700 rounded-lg relative">
|
|
1546
|
-
{/* Amount Input - Centered */}
|
|
1547
|
-
<div className="flex items-center justify-center">
|
|
1548
|
-
<div className="flex items-center justify-center space-x-2">
|
|
1549
|
-
<DynamicSizeInputField
|
|
1550
|
-
ref={inputRef}
|
|
1551
|
-
value={inputDisplayValue}
|
|
1552
|
-
disabled={isFiatAmountLocked}
|
|
1553
|
-
onChange={(e) => {
|
|
1554
|
-
const value = e.target.value
|
|
1555
|
-
|
|
1556
|
-
// Mark that user is typing
|
|
1557
|
-
setIsUserTyping(true)
|
|
1558
|
-
|
|
1559
|
-
// Clear any existing timeout
|
|
1560
|
-
if (typingTimeoutRef.current) {
|
|
1561
|
-
clearTimeout(typingTimeoutRef.current)
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
// Clear typing flag after a short delay
|
|
1565
|
-
typingTimeoutRef.current = setTimeout(() => {
|
|
1566
|
-
setIsUserTyping(false)
|
|
1567
|
-
}, 300)
|
|
1568
|
-
|
|
1569
|
-
// Allow empty string
|
|
1570
|
-
if (value === "") {
|
|
1571
|
-
setInputDisplayValue("")
|
|
1572
|
-
if (isMeldOnRampActive) {
|
|
1573
|
-
setSellFiatAmount("")
|
|
1574
|
-
} else {
|
|
1575
|
-
setSellAmount("")
|
|
1576
|
-
}
|
|
1577
|
-
return
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1580
|
-
if (isMeldOnRampActive) {
|
|
1581
|
-
// Fiat/onramp mode
|
|
1582
|
-
// Validate decimal places (max 2 decimals)
|
|
1583
|
-
const decimalMatch = value.match(/^\d*\.?\d{0,2}$/)
|
|
1584
|
-
if (!decimalMatch) {
|
|
1585
|
-
return // Don't update if invalid format
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
// Update display value - preserve the exact user input
|
|
1589
|
-
setInputDisplayValue(value)
|
|
1590
|
-
|
|
1591
|
-
// Just set the values directly without complex processing
|
|
1592
|
-
if (isEnteringFiat && fiatToUsdExchangeRate) {
|
|
1593
|
-
// User is entering preferred currency, convert to selected onramp currency for backend
|
|
1594
|
-
const inputAmount = toSafeNumber(value)
|
|
1595
|
-
|
|
1596
|
-
// First convert from preferred currency to USD if needed
|
|
1597
|
-
const rateData = forexRateStore.getRate()
|
|
1598
|
-
const usdAmount =
|
|
1599
|
-
rateData && rateData.currency !== "USD"
|
|
1600
|
-
? inputAmount / rateData.rate
|
|
1601
|
-
: inputAmount
|
|
1602
|
-
|
|
1603
|
-
// Then convert USD to selected onramp currency
|
|
1604
|
-
const convertedAmount = usdAmount * fiatToUsdExchangeRate
|
|
1605
|
-
setSellFiatAmount(convertedAmount.toString())
|
|
1606
|
-
} else {
|
|
1607
|
-
// User is entering in selected currency directly
|
|
1608
|
-
setSellFiatAmount(value)
|
|
1609
|
-
}
|
|
1610
|
-
} else {
|
|
1611
|
-
// Token mode
|
|
1612
|
-
// Validate decimal places (max 8 for tokens, max 2 for USD)
|
|
1613
|
-
const maxDecimals = isEnteringFiat ? 2 : 8
|
|
1614
|
-
const decimalRegex = new RegExp(
|
|
1615
|
-
`^\\d*\\.?\\d{0,${maxDecimals}}$`,
|
|
1616
|
-
)
|
|
1617
|
-
const decimalMatch = value.match(decimalRegex)
|
|
1618
|
-
if (!decimalMatch) {
|
|
1619
|
-
return // Don't update if invalid format
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
// Update display value - preserve the exact user input
|
|
1623
|
-
setInputDisplayValue(value)
|
|
1624
|
-
|
|
1625
|
-
// Just pass the value directly to handleSellAmountChange
|
|
1626
|
-
// Let it handle any necessary processing
|
|
1627
|
-
if (isEnteringFiat && tokenPriceUsd > 0) {
|
|
1628
|
-
// User is entering fiat, convert to token amount for backend
|
|
1629
|
-
// First convert from preferred currency to USD if needed
|
|
1630
|
-
const inputAmount = toSafeNumber(value)
|
|
1631
|
-
const rateData = forexRateStore.getRate()
|
|
1632
|
-
const usdAmount =
|
|
1633
|
-
rateData && rateData.currency !== "USD"
|
|
1634
|
-
? inputAmount / rateData.rate
|
|
1635
|
-
: inputAmount
|
|
1636
|
-
const tokenAmount = usdAmount / tokenPriceUsd
|
|
1637
|
-
handleSellAmountChange(tokenAmount.toString())
|
|
1638
|
-
} else {
|
|
1639
|
-
// User is entering token amount directly - pass it as-is
|
|
1640
|
-
handleSellAmountChange(value)
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
}}
|
|
1644
|
-
onFocus={handleSellInputFocus}
|
|
1645
|
-
isLoading={
|
|
1646
|
-
isLoadingQuote && tradeType === TradeType.EXACT_OUTPUT
|
|
1647
|
-
}
|
|
1648
|
-
variant="default"
|
|
1649
|
-
inputSize="large"
|
|
1650
|
-
textAlign="center"
|
|
1651
|
-
isFiatInput={isMeldOnRampActive || isEnteringFiat}
|
|
1652
|
-
currencySymbol={
|
|
1653
|
-
isEnteringFiat
|
|
1654
|
-
? (() => {
|
|
1655
|
-
// Get the current currency from forexRateStore
|
|
1656
|
-
const rateData = forexRateStore.getRate()
|
|
1657
|
-
const currency = rateData?.currency || "USD"
|
|
1658
|
-
// Return the appropriate symbol for the currency
|
|
1659
|
-
return (
|
|
1660
|
-
FIAT_CURRENCY_SYMBOLS[
|
|
1661
|
-
currency as keyof typeof FIAT_CURRENCY_SYMBOLS
|
|
1662
|
-
] || "$"
|
|
1663
|
-
)
|
|
1664
|
-
})()
|
|
1665
|
-
: isMeldOnRampActive
|
|
1666
|
-
? selectedFiatCurrency?.currencyCode
|
|
1667
|
-
: originToken?.symbol
|
|
1668
|
-
}
|
|
1669
|
-
/>
|
|
1670
|
-
{isLoadingQuote && tradeType === TradeType.EXACT_OUTPUT && (
|
|
1671
|
-
<LoadingSpinner />
|
|
1672
|
-
)}
|
|
1673
|
-
</div>
|
|
1674
|
-
</div>
|
|
1675
|
-
|
|
1676
|
-
{/* USD Value - hidden while onramp location/currency is loading to avoid showing undefined */}
|
|
1677
|
-
{isMeldOnRampActive &&
|
|
1678
|
-
(isLoadingCountryDefaults || isLoadingFiatCurrencies) ? (
|
|
1679
|
-
<div className="mt-2 text-center text-sm text-gray-500 dark:text-gray-400">
|
|
1680
|
-
Loading...
|
|
1681
|
-
</div>
|
|
1682
|
-
) : (
|
|
1683
|
-
<div className="mt-2 text-center text-sm">
|
|
1684
|
-
{isMeldOnRampActive ? (
|
|
1685
|
-
// Onramp mode - clickable USD toggle (only show when rate is ready to avoid undefined)
|
|
1686
|
-
selectedFiatCurrency?.currencyCode === "USD" ? (
|
|
1687
|
-
// If already USD, no toggle needed
|
|
1688
|
-
inputDisplayValue && Number(inputDisplayValue) > 0 ? (
|
|
1689
|
-
<div
|
|
1690
|
-
className="text-xs text-gray-500 dark:text-gray-400 notranslate"
|
|
1691
|
-
translate="no"
|
|
1692
|
-
>
|
|
1693
|
-
≈ {formatUsdAmountDisplay(Number(inputDisplayValue))}
|
|
1694
|
-
</div>
|
|
1695
|
-
) : null
|
|
1696
|
-
) : fiatToUsdExchangeRate != null &&
|
|
1697
|
-
!isLoadingFiatToUsdExchangeRate ? (
|
|
1698
|
-
// Clickable toggle between USD and selected currency
|
|
1699
|
-
<div className="flex justify-center">
|
|
1700
|
-
<button
|
|
1701
|
-
type="button"
|
|
1702
|
-
disabled={isFiatAmountLocked}
|
|
1703
|
-
onClick={() => {
|
|
1704
|
-
// When toggling USD mode, convert the current display value
|
|
1705
|
-
const newMode = !isEnteringFiat
|
|
1706
|
-
setIsEnteringFiat(newMode)
|
|
1707
|
-
|
|
1708
|
-
// Convert the current display to the new mode
|
|
1709
|
-
if (inputDisplayValue) {
|
|
1710
|
-
const currentValue = parseFloat(inputDisplayValue)
|
|
1711
|
-
if (isPositiveNumber(currentValue)) {
|
|
1712
|
-
if (newMode && fiatToUsdExchangeRate) {
|
|
1713
|
-
// Switching to USD mode - convert from local currency
|
|
1714
|
-
const usdValue =
|
|
1715
|
-
currentValue / fiatToUsdExchangeRate
|
|
1716
|
-
setInputDisplayValue(
|
|
1717
|
-
Number(usdValue.toFixed(2)).toString(),
|
|
1718
|
-
)
|
|
1719
|
-
} else if (!newMode && fiatToUsdExchangeRate) {
|
|
1720
|
-
// Switching to local currency mode - convert from USD
|
|
1721
|
-
const localValue =
|
|
1722
|
-
currentValue * fiatToUsdExchangeRate
|
|
1723
|
-
setInputDisplayValue(
|
|
1724
|
-
Number(localValue.toFixed(2)).toString(),
|
|
1725
|
-
)
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
}}
|
|
1730
|
-
className={`text-xs transition-colors flex items-center gap-1 ${
|
|
1731
|
-
isFiatAmountLocked
|
|
1732
|
-
? "text-gray-400 cursor-not-allowed"
|
|
1733
|
-
: "text-blue-500 hover:text-blue-600 cursor-pointer"
|
|
1734
|
-
}`}
|
|
1735
|
-
title={
|
|
1736
|
-
selectedFiatCurrency
|
|
1737
|
-
? `${selectedFiatCurrency.currencyCode}`
|
|
1738
|
-
: ""
|
|
1739
|
-
}
|
|
1740
|
-
>
|
|
1741
|
-
<svg
|
|
1742
|
-
aria-hidden="true"
|
|
1743
|
-
width="16"
|
|
1744
|
-
height="16"
|
|
1745
|
-
viewBox="0 0 16 16"
|
|
1746
|
-
fill="none"
|
|
1747
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
1748
|
-
>
|
|
1749
|
-
<path
|
|
1750
|
-
d="M3.16669 6.5L5.50002 4.16667M5.50002 4.16667L7.83335 6.5M5.50002 4.16667L5.50002 11.8333"
|
|
1751
|
-
stroke="#3B82F6"
|
|
1752
|
-
strokeWidth="1.5"
|
|
1753
|
-
strokeLinecap="round"
|
|
1754
|
-
strokeLinejoin="round"
|
|
1755
|
-
/>
|
|
1756
|
-
<path
|
|
1757
|
-
d="M12.8334 9.5L10.5 11.8333M10.5 11.8333L8.16669 9.5M10.5 11.8333L10.5 4.16667"
|
|
1758
|
-
stroke="#3B82F6"
|
|
1759
|
-
strokeWidth="1.5"
|
|
1760
|
-
strokeLinecap="round"
|
|
1761
|
-
strokeLinejoin="round"
|
|
1762
|
-
/>
|
|
1763
|
-
</svg>
|
|
1764
|
-
{(() => {
|
|
1765
|
-
const inputValue = toSafeNumber(inputDisplayValue)
|
|
1766
|
-
|
|
1767
|
-
if (isEnteringFiat) {
|
|
1768
|
-
// Currently entering in USD, show the local currency value
|
|
1769
|
-
const localAmount = inputValue * fiatToUsdExchangeRate
|
|
1770
|
-
const localDisplay =
|
|
1771
|
-
localAmount > 0
|
|
1772
|
-
? `${localAmount.toFixed(2)} ${selectedFiatCurrency?.currencyCode}`
|
|
1773
|
-
: `0.00 ${selectedFiatCurrency?.currencyCode}`
|
|
1774
|
-
|
|
1775
|
-
return (
|
|
1776
|
-
<span
|
|
1777
|
-
className="notranslate"
|
|
1778
|
-
translate="no"
|
|
1779
|
-
title={localDisplay}
|
|
1780
|
-
>
|
|
1781
|
-
≈ {localDisplay}
|
|
1782
|
-
</span>
|
|
1783
|
-
)
|
|
1784
|
-
} else {
|
|
1785
|
-
// Currently entering in local currency, show USD value
|
|
1786
|
-
const usdAmount = inputValue / fiatToUsdExchangeRate
|
|
1787
|
-
const displayValue = formatUsdAmountDisplay(usdAmount)
|
|
1788
|
-
const localeValue =
|
|
1789
|
-
formatUsdAmountLocaleDisplay(usdAmount)
|
|
1790
|
-
|
|
1791
|
-
return (
|
|
1792
|
-
<span
|
|
1793
|
-
className="notranslate"
|
|
1794
|
-
translate="no"
|
|
1795
|
-
title={displayValue}
|
|
1796
|
-
>
|
|
1797
|
-
≈ {localeValue}
|
|
1798
|
-
</span>
|
|
1799
|
-
)
|
|
1800
|
-
}
|
|
1801
|
-
})()}
|
|
1802
|
-
</button>
|
|
1803
|
-
</div>
|
|
1804
|
-
) : null
|
|
1805
|
-
) : (
|
|
1806
|
-
// Regular mode - clickable USD/token value swap
|
|
1807
|
-
<div className="flex justify-center">
|
|
1808
|
-
<button
|
|
1809
|
-
type="button"
|
|
1810
|
-
onClick={() => {
|
|
1811
|
-
// When toggling USD mode, convert the current display value
|
|
1812
|
-
const newMode = !isEnteringFiat
|
|
1813
|
-
logger.console.log(
|
|
1814
|
-
"[TRAILS TOGGLE] Starting toggle, newMode (entering fiat):",
|
|
1815
|
-
newMode,
|
|
1816
|
-
)
|
|
1817
|
-
logger.console.log(
|
|
1818
|
-
"[TRAILS TOGGLE] Current inputDisplayValue:",
|
|
1819
|
-
inputDisplayValue,
|
|
1820
|
-
)
|
|
1821
|
-
logger.console.log(
|
|
1822
|
-
"[TRAILS TOGGLE] tokenPriceUsd:",
|
|
1823
|
-
tokenPriceUsd,
|
|
1824
|
-
)
|
|
1825
|
-
|
|
1826
|
-
setIsEnteringFiat(newMode)
|
|
1827
|
-
|
|
1828
|
-
// Convert the current display to the new mode
|
|
1829
|
-
if (inputDisplayValue && tokenPriceUsd > 0) {
|
|
1830
|
-
const currentValue = parseFloat(inputDisplayValue)
|
|
1831
|
-
logger.console.log(
|
|
1832
|
-
"[TRAILS TOGGLE] Parsed currentValue:",
|
|
1833
|
-
currentValue,
|
|
1834
|
-
)
|
|
1835
|
-
|
|
1836
|
-
if (isPositiveNumber(currentValue)) {
|
|
1837
|
-
const rateData = forexRateStore.getRate()
|
|
1838
|
-
logger.console.log(
|
|
1839
|
-
"[TRAILS TOGGLE] ForexRate data:",
|
|
1840
|
-
rateData,
|
|
1841
|
-
)
|
|
1842
|
-
|
|
1843
|
-
if (newMode) {
|
|
1844
|
-
// Switching to fiat mode - convert from token amount to preferred currency
|
|
1845
|
-
const usdValue = currentValue * tokenPriceUsd
|
|
1846
|
-
logger.console.log(
|
|
1847
|
-
"[TRAILS TOGGLE] Token->Fiat: usdValue (token * price):",
|
|
1848
|
-
usdValue,
|
|
1849
|
-
)
|
|
1850
|
-
|
|
1851
|
-
// Apply forex rate if available to convert USD to preferred currency
|
|
1852
|
-
const displayValue =
|
|
1853
|
-
rateData && rateData.currency !== "USD"
|
|
1854
|
-
? usdValue * rateData.rate
|
|
1855
|
-
: usdValue
|
|
1856
|
-
logger.console.log(
|
|
1857
|
-
"[TRAILS TOGGLE] Token->Fiat: displayValue after forex:",
|
|
1858
|
-
displayValue,
|
|
1859
|
-
)
|
|
1860
|
-
logger.console.log(
|
|
1861
|
-
"[TRAILS TOGGLE] Token->Fiat: forex rate used:",
|
|
1862
|
-
rateData?.rate || "none (USD)",
|
|
1863
|
-
)
|
|
1864
|
-
|
|
1865
|
-
const finalValue = Number(
|
|
1866
|
-
displayValue.toFixed(2),
|
|
1867
|
-
).toString()
|
|
1868
|
-
logger.console.log(
|
|
1869
|
-
"[TRAILS TOGGLE] Token->Fiat: Setting input to:",
|
|
1870
|
-
finalValue,
|
|
1871
|
-
)
|
|
1872
|
-
setInputDisplayValue(finalValue)
|
|
1873
|
-
} else {
|
|
1874
|
-
// Switching to token mode - convert from preferred currency to token
|
|
1875
|
-
// First convert from preferred currency to USD if needed
|
|
1876
|
-
const usdValue =
|
|
1877
|
-
rateData && rateData.currency !== "USD"
|
|
1878
|
-
? currentValue / rateData.rate
|
|
1879
|
-
: currentValue
|
|
1880
|
-
logger.console.log(
|
|
1881
|
-
"[TRAILS TOGGLE] Fiat->Token: usdValue (input / rate):",
|
|
1882
|
-
usdValue,
|
|
1883
|
-
)
|
|
1884
|
-
logger.console.log(
|
|
1885
|
-
"[TRAILS TOGGLE] Fiat->Token: forex rate used:",
|
|
1886
|
-
rateData?.rate || "none (USD)",
|
|
1887
|
-
)
|
|
1888
|
-
|
|
1889
|
-
const tokenValue = usdValue / tokenPriceUsd
|
|
1890
|
-
logger.console.log(
|
|
1891
|
-
"[TRAILS TOGGLE] Fiat->Token: tokenValue (usd / price):",
|
|
1892
|
-
tokenValue,
|
|
1893
|
-
)
|
|
1894
|
-
|
|
1895
|
-
// Round to 8 decimals to avoid floating point issues
|
|
1896
|
-
const rounded =
|
|
1897
|
-
Math.round(tokenValue * 100000000) / 100000000
|
|
1898
|
-
setInputDisplayValue(rounded.toString())
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
}}
|
|
1903
|
-
className="text-base text-blue-500 hover:text-blue-600 transition-colors cursor-pointer flex items-center gap-2 py-1.5"
|
|
1904
|
-
title={
|
|
1905
|
-
originToken
|
|
1906
|
-
? `Toggle between USD and ${originToken.symbol}`
|
|
1907
|
-
: ""
|
|
1908
|
-
}
|
|
1909
|
-
>
|
|
1910
|
-
<svg
|
|
1911
|
-
aria-hidden="true"
|
|
1912
|
-
width="20"
|
|
1913
|
-
height="20"
|
|
1914
|
-
viewBox="0 0 16 16"
|
|
1915
|
-
fill="none"
|
|
1916
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
1917
|
-
>
|
|
1918
|
-
<path
|
|
1919
|
-
d="M3.16669 6.5L5.50002 4.16667M5.50002 4.16667L7.83335 6.5M5.50002 4.16667L5.50002 11.8333"
|
|
1920
|
-
stroke="#3B82F6"
|
|
1921
|
-
strokeWidth="1.5"
|
|
1922
|
-
strokeLinecap="round"
|
|
1923
|
-
strokeLinejoin="round"
|
|
1924
|
-
/>
|
|
1925
|
-
<path
|
|
1926
|
-
d="M12.8334 9.5L10.5 11.8333M10.5 11.8333L8.16669 9.5M10.5 11.8333L10.5 4.16667"
|
|
1927
|
-
stroke="#3B82F6"
|
|
1928
|
-
strokeWidth="1.5"
|
|
1929
|
-
strokeLinecap="round"
|
|
1930
|
-
strokeLinejoin="round"
|
|
1931
|
-
/>
|
|
1932
|
-
</svg>
|
|
1933
|
-
{(() => {
|
|
1934
|
-
const inputValue = toSafeNumber(inputDisplayValue)
|
|
1935
|
-
logger.console.log(
|
|
1936
|
-
"[TRAILS DISPLAY] isEnteringFiat:",
|
|
1937
|
-
isEnteringFiat,
|
|
1938
|
-
)
|
|
1939
|
-
logger.console.log(
|
|
1940
|
-
"[TRAILS DISPLAY] inputValue:",
|
|
1941
|
-
inputValue,
|
|
1942
|
-
)
|
|
1943
|
-
|
|
1944
|
-
if (isEnteringFiat) {
|
|
1945
|
-
// Currently entering in preferred currency, show the token amount
|
|
1946
|
-
// First convert from preferred currency to USD if needed
|
|
1947
|
-
const rateData = forexRateStore.getRate()
|
|
1948
|
-
logger.console.log(
|
|
1949
|
-
"[TRAILS DISPLAY] ForexRate data:",
|
|
1950
|
-
rateData,
|
|
1951
|
-
)
|
|
1952
|
-
|
|
1953
|
-
const usdValue =
|
|
1954
|
-
rateData && rateData.currency !== "USD"
|
|
1955
|
-
? inputValue / rateData.rate
|
|
1956
|
-
: inputValue
|
|
1957
|
-
logger.console.log(
|
|
1958
|
-
"[TRAILS DISPLAY] Fiat mode - usdValue (input / rate):",
|
|
1959
|
-
usdValue,
|
|
1960
|
-
)
|
|
1961
|
-
|
|
1962
|
-
const tokenAmount =
|
|
1963
|
-
tokenPriceUsd > 0 ? usdValue / tokenPriceUsd : 0
|
|
1964
|
-
logger.console.log(
|
|
1965
|
-
"[TRAILS DISPLAY] Fiat mode - tokenAmount:",
|
|
1966
|
-
tokenAmount,
|
|
1967
|
-
)
|
|
1968
|
-
|
|
1969
|
-
const tokenDisplay =
|
|
1970
|
-
tokenAmount > 0
|
|
1971
|
-
? `${tokenAmount.toFixed(8)} ${originToken?.symbol || ""}`
|
|
1972
|
-
: `0 ${originToken?.symbol || ""}`
|
|
1973
|
-
|
|
1974
|
-
return (
|
|
1975
|
-
<span title={tokenDisplay}>≈ {tokenDisplay}</span>
|
|
1976
|
-
)
|
|
1977
|
-
} else {
|
|
1978
|
-
// Currently entering in token amount, show USD value
|
|
1979
|
-
const usdAmount = inputValue * tokenPriceUsd
|
|
1980
|
-
logger.console.log(
|
|
1981
|
-
"[TRAILS DISPLAY] Token mode - usdAmount:",
|
|
1982
|
-
usdAmount,
|
|
1983
|
-
)
|
|
1984
|
-
|
|
1985
|
-
const displayValue = formatUsdAmountDisplay(usdAmount)
|
|
1986
|
-
const localeValue =
|
|
1987
|
-
formatUsdAmountLocaleDisplay(usdAmount)
|
|
1988
|
-
logger.console.log(
|
|
1989
|
-
"[TRAILS DISPLAY] Token mode - displayValue:",
|
|
1990
|
-
displayValue,
|
|
1991
|
-
)
|
|
1992
|
-
logger.console.log(
|
|
1993
|
-
"[TRAILS DISPLAY] Token mode - localeValue:",
|
|
1994
|
-
localeValue,
|
|
1995
|
-
)
|
|
1996
|
-
|
|
1997
|
-
return <span title={displayValue}>≈ {localeValue}</span>
|
|
1998
|
-
}
|
|
1999
|
-
})()}
|
|
2000
|
-
</button>
|
|
2001
|
-
</div>
|
|
2002
|
-
)}
|
|
2003
|
-
</div>
|
|
2004
|
-
)}
|
|
2005
|
-
|
|
2006
|
-
{/* Percentage/USD Amount Buttons */}
|
|
2007
|
-
{isMeldOnRampActive ? (
|
|
2008
|
-
// USD Amount Buttons for onramp - convert from USD to selected currency
|
|
2009
|
-
<div className="mt-3 flex justify-center items-center space-x-2">
|
|
2010
|
-
<button
|
|
2011
|
-
type="button"
|
|
2012
|
-
disabled={isFiatAmountLocked}
|
|
2013
|
-
className={`py-0.5 px-1.5 text-xs font-medium rounded-full transition-colors trails-bg-percentage-button trails-text-percentage-button ${
|
|
2014
|
-
isFiatAmountLocked
|
|
2015
|
-
? "opacity-50 cursor-not-allowed"
|
|
2016
|
-
: "cursor-pointer trails-hover-percentage-button"
|
|
2017
|
-
}`}
|
|
2018
|
-
onClick={() => {
|
|
2019
|
-
if (selectedFiatCurrency?.currencyCode === "USD") {
|
|
2020
|
-
setSellFiatAmount("25")
|
|
2021
|
-
setInputDisplayValue("25")
|
|
2022
|
-
} else if (fiatToUsdExchangeRate) {
|
|
2023
|
-
// Convert $25 USD to the selected currency
|
|
2024
|
-
const convertedAmount = 25 * fiatToUsdExchangeRate
|
|
2025
|
-
setSellFiatAmount(convertedAmount.toFixed(2))
|
|
2026
|
-
|
|
2027
|
-
// Update display based on current mode
|
|
2028
|
-
if (isEnteringFiat) {
|
|
2029
|
-
setInputDisplayValue("25")
|
|
2030
|
-
} else {
|
|
2031
|
-
setInputDisplayValue(convertedAmount.toString())
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
}}
|
|
2035
|
-
>
|
|
2036
|
-
$25
|
|
2037
|
-
</button>
|
|
2038
|
-
<button
|
|
2039
|
-
type="button"
|
|
2040
|
-
disabled={isFiatAmountLocked}
|
|
2041
|
-
className={`py-0.5 px-1.5 text-xs font-medium rounded-full transition-colors trails-bg-percentage-button trails-text-percentage-button ${
|
|
2042
|
-
isFiatAmountLocked
|
|
2043
|
-
? "opacity-50 cursor-not-allowed"
|
|
2044
|
-
: "cursor-pointer trails-hover-percentage-button"
|
|
2045
|
-
}`}
|
|
2046
|
-
onClick={() => {
|
|
2047
|
-
if (selectedFiatCurrency?.currencyCode === "USD") {
|
|
2048
|
-
setSellFiatAmount("50")
|
|
2049
|
-
setInputDisplayValue("50")
|
|
2050
|
-
} else if (fiatToUsdExchangeRate) {
|
|
2051
|
-
// Convert $50 USD to the selected currency
|
|
2052
|
-
const convertedAmount = 50 * fiatToUsdExchangeRate
|
|
2053
|
-
setSellFiatAmount(convertedAmount.toFixed(2))
|
|
2054
|
-
|
|
2055
|
-
// Update display based on current mode
|
|
2056
|
-
if (isEnteringFiat) {
|
|
2057
|
-
setInputDisplayValue("50")
|
|
2058
|
-
} else {
|
|
2059
|
-
setInputDisplayValue(convertedAmount.toString())
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
}}
|
|
2063
|
-
>
|
|
2064
|
-
$50
|
|
2065
|
-
</button>
|
|
2066
|
-
<button
|
|
2067
|
-
type="button"
|
|
2068
|
-
disabled={isFiatAmountLocked}
|
|
2069
|
-
className={`py-0.5 px-1.5 text-xs font-medium rounded-full transition-colors trails-bg-percentage-button trails-text-percentage-button ${
|
|
2070
|
-
isFiatAmountLocked
|
|
2071
|
-
? "opacity-50 cursor-not-allowed"
|
|
2072
|
-
: "cursor-pointer trails-hover-percentage-button"
|
|
2073
|
-
}`}
|
|
2074
|
-
onClick={() => {
|
|
2075
|
-
if (selectedFiatCurrency?.currencyCode === "USD") {
|
|
2076
|
-
setSellFiatAmount("100")
|
|
2077
|
-
setInputDisplayValue("100")
|
|
2078
|
-
} else if (fiatToUsdExchangeRate) {
|
|
2079
|
-
// Convert $100 USD to the selected currency
|
|
2080
|
-
const convertedAmount = 100 * fiatToUsdExchangeRate
|
|
2081
|
-
setSellFiatAmount(convertedAmount.toFixed(2))
|
|
2082
|
-
|
|
2083
|
-
// Update display based on current mode
|
|
2084
|
-
if (isEnteringFiat) {
|
|
2085
|
-
setInputDisplayValue("100")
|
|
2086
|
-
} else {
|
|
2087
|
-
setInputDisplayValue(convertedAmount.toString())
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
}}
|
|
2091
|
-
>
|
|
2092
|
-
$100
|
|
2093
|
-
</button>
|
|
2094
|
-
</div>
|
|
2095
|
-
) : originToken &&
|
|
2096
|
-
balanceFormatted &&
|
|
2097
|
-
fundMethod !== "direct-transfer" &&
|
|
2098
|
-
fundMethod !== "onramp-mesh" ? (
|
|
2099
|
-
<div className="mt-3 flex justify-center items-center space-x-2">
|
|
2100
|
-
<PercentageMaxButtons
|
|
2101
|
-
userBalance={balanceFormatted}
|
|
2102
|
-
userBalanceRaw={balanceRaw}
|
|
2103
|
-
decimals={tokenDecimals}
|
|
2104
|
-
isNativeToken={originToken.isNativeToken ?? false}
|
|
2105
|
-
gasCostFormatted={prepareSendQuote?.gasCostFormatted}
|
|
2106
|
-
chainId={originChainId || undefined}
|
|
2107
|
-
onAmountSelect={(amount) => {
|
|
2108
|
-
setTradeType(TradeType.EXACT_INPUT)
|
|
2109
|
-
setSellAmount(amount)
|
|
2110
|
-
setBuyAmount("")
|
|
2111
|
-
if (isEnteringFiat && tokenPriceUsd > 0) {
|
|
2112
|
-
const usdAmount = parseFloat(amount) * tokenPriceUsd
|
|
2113
|
-
setInputDisplayValue(
|
|
2114
|
-
Number(usdAmount.toFixed(2)).toString(),
|
|
2115
|
-
)
|
|
2116
|
-
} else {
|
|
2117
|
-
setInputDisplayValue(amount)
|
|
2118
|
-
}
|
|
2119
|
-
}}
|
|
2120
|
-
className="opacity-100"
|
|
2121
|
-
/>
|
|
2122
|
-
</div>
|
|
2123
|
-
) : null}
|
|
2124
|
-
</div>
|
|
2125
|
-
|
|
2126
|
-
{/* Sending and Receiving Section */}
|
|
2127
|
-
<div className="mt-4 pt-4 pb-4 trails-border-radius-container p-3 mb-4 border border-gray-200 dark:border-gray-700 rounded-lg">
|
|
2128
|
-
{/* Sending and Receiving Labels */}
|
|
2129
|
-
<div className="flex items-center justify-between mb-3 px-1">
|
|
2130
|
-
<span
|
|
2131
|
-
className="text-sm font-medium text-black dark:text-white"
|
|
2132
|
-
style={{ minWidth: "138px" }}
|
|
2133
|
-
>
|
|
2134
|
-
Sending
|
|
2135
|
-
</span>
|
|
2136
|
-
<div className="w-7 flex-shrink-0"></div> {/* Spacer for arrow */}
|
|
2137
|
-
{toRecipient ? (
|
|
2138
|
-
<span
|
|
2139
|
-
className="text-sm font-medium text-black dark:text-white"
|
|
2140
|
-
style={{ minWidth: "138px" }}
|
|
2141
|
-
>
|
|
2142
|
-
Receiving
|
|
2143
|
-
</span>
|
|
2144
|
-
) : (
|
|
2145
|
-
<RecipientSelectorButton selectedRecipient={selectedRecipient} />
|
|
2146
|
-
)}
|
|
2147
|
-
</div>
|
|
2148
|
-
|
|
2149
|
-
{/* Token Selectors with Arrow */}
|
|
2150
|
-
<div className="flex items-center justify-between space-x-2">
|
|
2151
|
-
{/* Origin Token Selector */}
|
|
2152
|
-
<div className="min-w-[138px] flex flex-col mr-0">
|
|
2153
|
-
{isMeldOnRampActive ? (
|
|
2154
|
-
<FiatSelectorButton
|
|
2155
|
-
currency={selectedFiatCurrency}
|
|
2156
|
-
onSelect={() => setShowFiatSelector(true)}
|
|
2157
|
-
unselectable={isFiatCurrencyLocked}
|
|
2158
|
-
/>
|
|
2159
|
-
) : prepareSendQuote?.noSufficientBalance ? (
|
|
2160
|
-
// Show "Add funds" button when user has insufficient balance
|
|
2161
|
-
<button
|
|
2162
|
-
type="button"
|
|
2163
|
-
onClick={() => {
|
|
2164
|
-
// Navigate to payment selection screen
|
|
2165
|
-
navigate("fund-methods")
|
|
2166
|
-
}}
|
|
2167
|
-
className="w-full flex items-center justify-center space-x-1.5 trails-border-radius-input px-2.5 py-1.5 border transition-all duration-200 bg-blue-500 hover:bg-blue-600 border-blue-500 text-white cursor-pointer"
|
|
2168
|
-
>
|
|
2169
|
-
<span className="font-medium text-sm text-white">
|
|
2170
|
-
Add funds
|
|
2171
|
-
</span>
|
|
2172
|
-
</button>
|
|
2173
|
-
) : !originToken ? (
|
|
2174
|
-
// No token selected, show "Select Token" button
|
|
2175
|
-
<button
|
|
2176
|
-
type="button"
|
|
2177
|
-
onClick={() => {
|
|
2178
|
-
setShowSourceTokenSelector(true)
|
|
2179
|
-
}}
|
|
2180
|
-
className="w-full flex items-center justify-center space-x-1.5 trails-border-radius-input px-2.5 py-1.5 border transition-all duration-200 bg-blue-500 hover:bg-blue-600 border-blue-500 text-white cursor-pointer"
|
|
2181
|
-
>
|
|
2182
|
-
<span className="font-medium text-sm text-white">
|
|
2183
|
-
Select Token
|
|
2184
|
-
</span>
|
|
2185
|
-
</button>
|
|
2186
|
-
) : (
|
|
2187
|
-
<TokenSelectorButton
|
|
2188
|
-
token={originToken}
|
|
2189
|
-
chainId={originChainId}
|
|
2190
|
-
onSelect={() => setShowSourceTokenSelector(true)}
|
|
2191
|
-
fullWidth={true}
|
|
2192
|
-
/>
|
|
2193
|
-
)}
|
|
2194
|
-
</div>
|
|
2195
|
-
|
|
2196
|
-
{/* Arrow Icon in Circle - 28x28 */}
|
|
2197
|
-
<div className="flex-shrink-0 mr-0">
|
|
2198
|
-
<div className="w-7 h-7 rounded-full bg-gray-100 dark:bg-gray-800 flex items-center justify-center">
|
|
2199
|
-
<svg
|
|
2200
|
-
aria-hidden="true"
|
|
2201
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
2202
|
-
width="16"
|
|
2203
|
-
height="16"
|
|
2204
|
-
viewBox="0 0 16 16"
|
|
2205
|
-
fill="none"
|
|
2206
|
-
>
|
|
2207
|
-
<path
|
|
2208
|
-
d="M7.52861 2.86201C7.78895 2.60166 8.21096 2.60166 8.47131 2.86201L13.138 7.52868C13.3983 7.78903 13.3983 8.21104 13.138 8.47138L8.47131 13.1381C8.21096 13.3984 7.78895 13.3984 7.52861 13.1381C7.26826 12.8777 7.26826 12.4557 7.52861 12.1953L11.0573 8.6667H3.33329C2.9651 8.6667 2.66663 8.36822 2.66663 8.00003C2.66663 7.63184 2.9651 7.33336 3.33329 7.33336H11.0573L7.52861 3.80472C7.26826 3.54437 7.26826 3.12236 7.52861 2.86201Z"
|
|
2209
|
-
fill="black"
|
|
2210
|
-
/>
|
|
2211
|
-
</svg>
|
|
2212
|
-
</div>
|
|
2213
|
-
</div>
|
|
2214
|
-
|
|
2215
|
-
{/* Destination Token Selector */}
|
|
2216
|
-
<div className="min-w-[138px] flex">
|
|
2217
|
-
<TokenSelectorButton
|
|
2218
|
-
token={selectedDestToken}
|
|
2219
|
-
chainId={(selectedDestToken as any)?.chainId}
|
|
2220
|
-
onSelect={() => setShowDestinationTokenSelector(true)}
|
|
2221
|
-
unselectable={!!toToken}
|
|
2222
|
-
fullWidth={true}
|
|
2223
|
-
/>
|
|
2224
|
-
</div>
|
|
2225
|
-
</div>
|
|
2226
|
-
|
|
2227
|
-
{/* Token Balance Display or Insufficient Funds Warning */}
|
|
2228
|
-
{(!fundMethod || fundMethod === "wallet") && originToken && (
|
|
2229
|
-
<div className="mt-3 pl-1 text-xs text-left">
|
|
2230
|
-
{prepareSendQuote?.noSufficientBalance ? (
|
|
2231
|
-
<span style={{ color: "#F97316" }}>
|
|
2232
|
-
Insufficient funds
|
|
2233
|
-
{balanceFormatted
|
|
2234
|
-
? `. Have ${balanceFormatted} ${originToken.symbol}`
|
|
2235
|
-
: ""}
|
|
2236
|
-
</span>
|
|
2237
|
-
) : balanceFormatted ? (
|
|
2238
|
-
<>
|
|
2239
|
-
<span
|
|
2240
|
-
className="text-black dark:text-white notranslate"
|
|
2241
|
-
translate="no"
|
|
2242
|
-
>
|
|
2243
|
-
Balance:
|
|
2244
|
-
</span>
|
|
2245
|
-
<span
|
|
2246
|
-
className="text-gray-500 dark:text-gray-400 notranslate"
|
|
2247
|
-
translate="no"
|
|
2248
|
-
>
|
|
2249
|
-
{" "}
|
|
2250
|
-
{balanceLocaleDisplay || balanceFormatted}{" "}
|
|
2251
|
-
{originToken.symbol}
|
|
2252
|
-
{balanceUsdDisplay ? (
|
|
2253
|
-
<span className="notranslate" translate="no">
|
|
2254
|
-
{" "}
|
|
2255
|
-
({balanceUsdLocaleDisplay || balanceUsdDisplay})
|
|
2256
|
-
</span>
|
|
2257
|
-
) : null}
|
|
2258
|
-
</span>
|
|
2259
|
-
</>
|
|
2260
|
-
) : null}
|
|
2261
|
-
</div>
|
|
2262
|
-
)}
|
|
2263
|
-
</div>
|
|
2264
|
-
{/* Exchange/Contract Warning */}
|
|
2265
|
-
<RefundWarning
|
|
2266
|
-
fundMethod={fundMethod}
|
|
2267
|
-
isSenderContractOnOrigin={false}
|
|
2268
|
-
isSenderContractOnDestination={false}
|
|
2269
|
-
isSequenceWallet={isSequenceWallet}
|
|
2270
|
-
/>
|
|
2271
|
-
|
|
2272
|
-
{/* Fee Options */}
|
|
2273
|
-
{!isMeldOnRampActive &&
|
|
2274
|
-
fundMethod !== "direct-transfer" &&
|
|
2275
|
-
fundMethod !== "onramp-mesh" && (
|
|
2276
|
-
<FeeOptions
|
|
2277
|
-
processedFeeOptions={processedFeeOptions || []}
|
|
2278
|
-
selectedFeeOption={selectedFeeOption}
|
|
2279
|
-
setSelectedFeeOption={(feeOption) =>
|
|
2280
|
-
setSelectedFeeOption(feeOption)
|
|
2281
|
-
}
|
|
2282
|
-
chainId={originToken?.chainId}
|
|
2283
|
-
isRefetching={isLoadingQuote}
|
|
2284
|
-
originTokenInfo={{
|
|
2285
|
-
originToken: freshOriginToken ?? originToken!,
|
|
2286
|
-
originTokenBalance:
|
|
2287
|
-
freshOriginToken?.balance ?? originToken?.balance ?? "0",
|
|
2288
|
-
originTokenAmount: sellAmount,
|
|
2289
|
-
isLoadingBalance: isLoadingFreshOriginBalance,
|
|
2290
|
-
}}
|
|
2291
|
-
/>
|
|
2292
|
-
)}
|
|
2293
|
-
|
|
2294
|
-
{/* Onramp Provider Selector */}
|
|
2295
|
-
{isMeldOnRampActive &&
|
|
2296
|
-
!isLoadingOnrampQuote &&
|
|
2297
|
-
!isLoadingQuote &&
|
|
2298
|
-
prepareSendQuote &&
|
|
2299
|
-
onrampQuotes &&
|
|
2300
|
-
onrampQuotes.length > 0 && (
|
|
2301
|
-
<OnRampProviderSelector
|
|
2302
|
-
providers={onrampQuotes}
|
|
2303
|
-
selectedProvider={selectedOnrampProviderQuote}
|
|
2304
|
-
trailsQuote={prepareSendQuote}
|
|
2305
|
-
setSelectedProvider={(provider) => {
|
|
2306
|
-
setSelectedOnrampProvider(provider as OnrampQuote)
|
|
2307
|
-
}}
|
|
2308
|
-
isRefetching={isLoadingOnrampQuote}
|
|
2309
|
-
/>
|
|
2310
|
-
)}
|
|
2311
|
-
|
|
2312
|
-
{/* Quote Details - only show for non-onramp quotes */}
|
|
2313
|
-
{prepareSendQuote && !isLoadingQuote && !isLoadingOnrampQuote && (
|
|
2314
|
-
<div className="mb-4">
|
|
2315
|
-
<QuoteDetails
|
|
2316
|
-
quote={prepareSendQuote}
|
|
2317
|
-
fiatToUsdExchangeRate={fiatToUsdExchangeRate}
|
|
2318
|
-
onRampQuote={selectedOnrampProviderQuote}
|
|
2319
|
-
showContent={true}
|
|
2320
|
-
swapMode={false}
|
|
2321
|
-
isRefetching={isLoadingQuote}
|
|
2322
|
-
showInsufficientFunds={false}
|
|
2323
|
-
isPassthrough={isPassthroughEligible(
|
|
2324
|
-
prepareSendQuote.passthroughEligible,
|
|
2325
|
-
selectedFeeOption,
|
|
2326
|
-
processedFeeOptions,
|
|
2327
|
-
)}
|
|
2328
|
-
/>
|
|
2329
|
-
</div>
|
|
2330
|
-
)}
|
|
2331
|
-
|
|
2332
|
-
{/* Onramp Quote Error */}
|
|
2333
|
-
{isMeldOnRampActive && onrampQuoteError && (
|
|
2334
|
-
<div className="mt-4">
|
|
2335
|
-
<ErrorDisplay
|
|
2336
|
-
errorPrettified={getPrettifiedErrorMessage(
|
|
2337
|
-
onrampQuoteError,
|
|
2338
|
-
"Error loading quote",
|
|
2339
|
-
)}
|
|
2340
|
-
error={getFullErrorMessage(onrampQuoteError)}
|
|
2341
|
-
severity="error"
|
|
2342
|
-
/>
|
|
2343
|
-
</div>
|
|
2344
|
-
)}
|
|
2345
|
-
|
|
2346
|
-
{/* Widget/Popup Error */}
|
|
2347
|
-
{widgetError && (
|
|
2348
|
-
<div className="mt-4">
|
|
2349
|
-
<ErrorDisplay
|
|
2350
|
-
errorPrettified={widgetError}
|
|
2351
|
-
error={widgetError}
|
|
2352
|
-
severity="error"
|
|
2353
|
-
/>
|
|
2354
|
-
</div>
|
|
2355
|
-
)}
|
|
2356
|
-
|
|
2357
|
-
<button
|
|
2358
|
-
type="submit"
|
|
2359
|
-
disabled={
|
|
2360
|
-
isMeldOnRampActive
|
|
2361
|
-
? !sellAmount ||
|
|
2362
|
-
isSubmitting ||
|
|
2363
|
-
isCreatingWidgetSession ||
|
|
2364
|
-
!selectedFiatCurrency ||
|
|
2365
|
-
!selectedDestToken ||
|
|
2366
|
-
!effectiveCountryCode ||
|
|
2367
|
-
!effectiveRecipient ||
|
|
2368
|
-
isLoadingOnrampQuote ||
|
|
2369
|
-
isLoadingWidgetSession ||
|
|
2370
|
-
!selectedOnrampProviderQuote ||
|
|
2371
|
-
!!onrampQuoteError ||
|
|
2372
|
-
!!widgetSessionError ||
|
|
2373
|
-
isLoadingQuote ||
|
|
2374
|
-
isAwaitingTrailsQuote ||
|
|
2375
|
-
!prepareSendQuote
|
|
2376
|
-
: !amount ||
|
|
2377
|
-
isSubmitting ||
|
|
2378
|
-
!destinationTokenAddress ||
|
|
2379
|
-
!isValidCustomToken ||
|
|
2380
|
-
isLoadingQuote ||
|
|
2381
|
-
!prepareSendQuote ||
|
|
2382
|
-
(fundMethod === "onramp-mesh" &&
|
|
2383
|
-
(isLoadingMeshRouteSupport || !isMeshRouteSupported)) ||
|
|
2384
|
-
(!isMeldOnRampActive &&
|
|
2385
|
-
fundMethod !== "direct-transfer" &&
|
|
2386
|
-
prepareSendQuote?.noSufficientBalance) ||
|
|
2387
|
-
(shouldValidateFeeOption &&
|
|
2388
|
-
(selectedFeeOption
|
|
2389
|
-
? isFeeOptionDisabled(
|
|
2390
|
-
selectedFeeOption as ProcessedFeeOption,
|
|
2391
|
-
{
|
|
2392
|
-
originToken: freshOriginToken ?? originToken!,
|
|
2393
|
-
originTokenBalance:
|
|
2394
|
-
freshOriginToken?.balance ??
|
|
2395
|
-
originToken?.balance ??
|
|
2396
|
-
"0",
|
|
2397
|
-
originTokenAmount: sellAmount,
|
|
2398
|
-
},
|
|
2399
|
-
)
|
|
2400
|
-
: false))
|
|
2401
|
-
}
|
|
2402
|
-
className="w-full font-semibold py-4 px-4 trails-border-radius-button transition-colors bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white disabled:text-gray-500 disabled:cursor-not-allowed cursor-pointer relative"
|
|
2403
|
-
>
|
|
2404
|
-
{isSubmitting || isCreatingWidgetSession || isLoadingWidgetSession ? (
|
|
2405
|
-
<div className="flex items-center justify-center">
|
|
2406
|
-
<LoadingSpinner />
|
|
2407
|
-
<span>
|
|
2408
|
-
{isCreatingWidgetSession || isLoadingWidgetSession
|
|
2409
|
-
? "Creating session..."
|
|
2410
|
-
: buttonText}
|
|
2411
|
-
</span>
|
|
2412
|
-
</div>
|
|
2413
|
-
) : isMeldOnRampActive &&
|
|
2414
|
-
!prepareSendQuote &&
|
|
2415
|
-
!selectedOnrampProviderQuote &&
|
|
2416
|
-
(onrampQuoteError || widgetSessionError || widgetError) ? (
|
|
2417
|
-
"Error Loading Quote"
|
|
2418
|
-
) : fundMethod !== "direct-transfer" &&
|
|
2419
|
-
prepareSendQuote?.noSufficientBalance ? (
|
|
2420
|
-
"Insufficient Balance"
|
|
2421
|
-
) : fundMethod === "onramp-mesh" && isLoadingMeshRouteSupport ? (
|
|
2422
|
-
<div className="flex items-center justify-center">
|
|
2423
|
-
<LoadingSpinner className="mr-2" />
|
|
2424
|
-
<span>Checking exchange funding...</span>
|
|
2425
|
-
</div>
|
|
2426
|
-
) : fundMethod === "onramp-mesh" &&
|
|
2427
|
-
prepareSendQuote &&
|
|
2428
|
-
!isMeshRouteSupported ? (
|
|
2429
|
-
"Exchange funding unavailable"
|
|
2430
|
-
) : isMeldOnRampActive && !sellFiatAmount ? (
|
|
2431
|
-
"Enter amount"
|
|
2432
|
-
) : !isMeldOnRampActive && !sellAmount ? (
|
|
2433
|
-
"Enter amount"
|
|
2434
|
-
) : isMeldOnRampActive &&
|
|
2435
|
-
(isLoadingOnrampQuote ||
|
|
2436
|
-
isLoadingQuote ||
|
|
2437
|
-
isAwaitingTrailsQuote ||
|
|
2438
|
-
(selectedOnrampProviderQuote && !prepareSendQuote)) ? (
|
|
2439
|
-
<div className="flex items-center justify-center">
|
|
2440
|
-
<LoadingSpinner className="mr-2" />
|
|
2441
|
-
<span>Getting quote...</span>
|
|
2442
|
-
</div>
|
|
2443
|
-
) : isMeldOnRampActive &&
|
|
2444
|
-
!isLoadingOnrampQuote &&
|
|
2445
|
-
!isLoadingQuote &&
|
|
2446
|
-
!isAwaitingTrailsQuote &&
|
|
2447
|
-
prepareSendQuote ? (
|
|
2448
|
-
"Continue"
|
|
2449
|
-
) : buttonText === "Getting quote..." ? (
|
|
2450
|
-
<div className="flex items-center justify-center">
|
|
2451
|
-
<LoadingSpinner className="mr-2" />
|
|
2452
|
-
<span>{buttonText}</span>
|
|
2453
|
-
</div>
|
|
2454
|
-
) : (
|
|
2455
|
-
buttonText
|
|
2456
|
-
)}
|
|
2457
|
-
</button>
|
|
2458
|
-
</form>
|
|
2459
|
-
</div>
|
|
2460
|
-
)
|
|
2461
|
-
}
|
|
2462
|
-
|
|
2463
|
-
export { Fund }
|