0xtrails 0.6.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aave.d.ts +10 -2
- package/dist/aave.d.ts.map +1 -1
- package/dist/analytics.d.ts +26 -0
- package/dist/analytics.d.ts.map +1 -1
- package/dist/{ccip-CbJrlK-L.js → ccip-fConRNoG.js} +21 -21
- package/dist/chains.d.ts +23 -8
- package/dist/chains.d.ts.map +1 -1
- package/dist/constants.d.ts +5 -5
- package/dist/constants.d.ts.map +1 -1
- package/dist/customTokens.d.ts +12 -0
- package/dist/customTokens.d.ts.map +1 -0
- package/dist/decoders.d.ts +2 -2
- package/dist/decoders.d.ts.map +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/fees.d.ts +37 -2
- package/dist/fees.d.ts.map +1 -1
- package/dist/gasless.d.ts +15 -36
- package/dist/gasless.d.ts.map +1 -1
- package/dist/{index-w7_dK4c5.js → index-BbajxCG_.js} +59269 -77146
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +828 -359
- package/dist/indexerClient.d.ts.map +1 -1
- package/dist/intentReceiptMonitor.d.ts +1 -1
- package/dist/intentReceiptMonitor.d.ts.map +1 -1
- package/dist/intentReceiptPoller.d.ts +1 -1
- package/dist/intentReceiptPoller.d.ts.map +1 -1
- package/dist/intents.d.ts +3 -2
- package/dist/intents.d.ts.map +1 -1
- package/dist/mode.d.ts +1 -1
- package/dist/mode.d.ts.map +1 -1
- package/dist/mutations.d.ts +2 -2
- package/dist/mutations.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +2 -2
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prices.d.ts +1 -1
- package/dist/prices.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +2 -2
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/time.d.ts +6 -0
- package/dist/time.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts +40 -25
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/tokens.d.ts +54 -14
- package/dist/tokens.d.ts.map +1 -1
- package/dist/trailsClient.d.ts +1 -1
- package/dist/trailsClient.d.ts.map +1 -1
- package/dist/trailsRouter.d.ts +2 -1
- package/dist/trailsRouter.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +3 -2
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +2 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/execution/transactionState.d.ts +1 -1
- package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +5 -3
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +5 -3
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/quote/feeExtractors.d.ts +1 -6
- package/dist/transactionIntent/quote/feeExtractors.d.ts.map +1 -1
- package/dist/transactionIntent/quote/normalizeQuote.d.ts +4 -2
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +28 -5
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactionIntent/utils/testnetHelpers.d.ts +0 -1
- package/dist/transactionIntent/utils/testnetHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/validators.d.ts +0 -2
- package/dist/transactionIntent/validators.d.ts.map +1 -1
- package/dist/transactions.d.ts +2 -2
- package/dist/transactions.d.ts.map +1 -1
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/wallets.d.ts +1 -0
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/AddressWalletIcon.d.ts +6 -0
- package/dist/widget/components/AddressWalletIcon.d.ts.map +1 -0
- package/dist/widget/components/ChainFilterDropdown.d.ts +2 -6
- package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
- package/dist/widget/components/ChainImage.d.ts.map +1 -1
- package/dist/widget/components/ChainList.d.ts +0 -5
- package/dist/widget/components/ChainList.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts +6 -6
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
- package/dist/widget/components/DebugMenu.d.ts +1 -1
- package/dist/widget/components/DebugMenu.d.ts.map +1 -1
- package/dist/widget/components/DebugScreensList.d.ts.map +1 -1
- package/dist/widget/components/DepositTracker.d.ts.map +1 -1
- package/dist/widget/components/Earn.d.ts +5 -5
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/FeeOption.d.ts +1 -1
- package/dist/widget/components/FeeOption.d.ts.map +1 -1
- package/dist/widget/components/FeeOptions.d.ts +2 -2
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/Footer.d.ts +1 -1
- package/dist/widget/components/Footer.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts +5 -5
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts +0 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/FundSwap.d.ts +6 -6
- package/dist/widget/components/FundSwap.d.ts.map +1 -1
- package/dist/widget/components/HookModalContent.d.ts +8 -0
- package/dist/widget/components/HookModalContent.d.ts.map +1 -0
- package/dist/widget/components/OriginSelectionAmount.d.ts +11 -0
- package/dist/widget/components/OriginSelectionAmount.d.ts.map +1 -0
- package/dist/widget/components/Pay.d.ts +5 -5
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts +5 -5
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/PoolWithdraw.d.ts +3 -3
- package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts +2 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/RecentTokens.d.ts +4 -4
- package/dist/widget/components/RecentTokens.d.ts.map +1 -1
- package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/ShadowPortal.d.ts +6 -0
- package/dist/widget/components/ShadowPortal.d.ts.map +1 -0
- package/dist/widget/components/Swap.d.ts +6 -6
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/ThemeProvider.d.ts +1 -1
- package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
- package/dist/widget/components/TokenList.d.ts +3 -4
- package/dist/widget/components/TokenList.d.ts.map +1 -1
- package/dist/widget/components/TokenSelector.d.ts +3 -4
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/Tooltip.d.ts +6 -1
- package/dist/widget/components/Tooltip.d.ts.map +1 -1
- package/dist/widget/components/TrailsHookModal.d.ts +10 -0
- package/dist/widget/components/TrailsHookModal.d.ts.map +1 -0
- package/dist/widget/components/WaasFeeOptions.d.ts +3 -0
- package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
- package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/components/WidgetProviders.d.ts +14 -0
- package/dist/widget/components/WidgetProviders.d.ts.map +1 -0
- package/dist/widget/css/compiled.css +1 -1
- package/dist/widget/hooks/useAddressWalletIcon.d.ts +10 -0
- package/dist/widget/hooks/useAddressWalletIcon.d.ts.map +1 -0
- package/dist/widget/hooks/useBalanceVisible.d.ts +1 -1
- package/dist/widget/hooks/useBalanceVisible.d.ts.map +1 -1
- package/dist/widget/hooks/useChainFilter.d.ts +1 -1
- package/dist/widget/hooks/useChainFilter.d.ts.map +1 -1
- package/dist/widget/hooks/useCheckout.d.ts +13 -1
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useConnector.d.ts +4 -0
- package/dist/widget/hooks/useConnector.d.ts.map +1 -0
- package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
- package/dist/widget/hooks/useCustomTokenFetch.d.ts +19 -0
- package/dist/widget/hooks/useCustomTokenFetch.d.ts.map +1 -0
- package/dist/widget/hooks/useCustomTokenSearch.d.ts +20 -0
- package/dist/widget/hooks/useCustomTokenSearch.d.ts.map +1 -0
- package/dist/widget/hooks/useDebounce.d.ts +10 -0
- package/dist/widget/hooks/useDebounce.d.ts.map +1 -0
- package/dist/widget/hooks/useDebugScreens.d.ts +7 -2
- package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts +3 -19
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
- package/dist/widget/hooks/useDestinationSelectedToken.d.ts +1 -14
- package/dist/widget/hooks/useDestinationSelectedToken.d.ts.map +1 -1
- package/dist/widget/hooks/useEarnPool.d.ts +1 -1
- package/dist/widget/hooks/useEarnPool.d.ts.map +1 -1
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useIsMobile.d.ts +5 -0
- package/dist/widget/hooks/useIsMobile.d.ts.map +1 -0
- package/dist/widget/hooks/useMode.d.ts +2 -2
- package/dist/widget/hooks/useMode.d.ts.map +1 -1
- package/dist/widget/hooks/useOriginSelectedToken.d.ts +2 -15
- package/dist/widget/hooks/useOriginSelectedToken.d.ts.map +1 -1
- package/dist/widget/hooks/usePayMessage.d.ts.map +1 -1
- package/dist/widget/hooks/usePriceImpactWarning.d.ts +1 -1
- package/dist/widget/hooks/usePriceImpactWarning.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +173 -4
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useRecentTokens.d.ts +3 -3
- package/dist/widget/hooks/useRecentTokens.d.ts.map +1 -1
- package/dist/widget/hooks/useRecipients.d.ts +1 -1
- package/dist/widget/hooks/useRecipients.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFeeOption.d.ts +2 -2
- package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFundMethod.d.ts +1 -1
- package/dist/widget/hooks/useSelectedFundMethod.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedRecipient.d.ts +1 -1
- package/dist/widget/hooks/useSelectedRecipient.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +9 -31
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useSwapAmount.d.ts +1 -1
- package/dist/widget/hooks/useSwapAmount.d.ts.map +1 -1
- package/dist/widget/hooks/useTheme.d.ts +1 -1
- package/dist/widget/hooks/useTheme.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts +7 -31
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/hooks/useTrailsSendTransaction.d.ts +83 -0
- package/dist/widget/hooks/useTrailsSendTransaction.d.ts.map +1 -0
- package/dist/widget/hooks/useWalletConnectUri.d.ts +11 -0
- package/dist/widget/hooks/useWalletConnectUri.d.ts.map +1 -0
- package/dist/widget/hooks/useWidgetProps.d.ts +5 -0
- package/dist/widget/hooks/useWidgetProps.d.ts.map +1 -1
- package/dist/widget/index.d.ts +2 -0
- package/dist/widget/index.d.ts.map +1 -1
- package/dist/widget/index.js +8 -5
- package/dist/widget/providers/TrailsModalProvider.d.ts +65 -0
- package/dist/widget/providers/TrailsModalProvider.d.ts.map +1 -0
- package/dist/widget/providers/TrailsProvider.d.ts +1 -1
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -1
- package/dist/widget/types.d.ts +11 -18
- package/dist/widget/types.d.ts.map +1 -1
- package/dist/widget/widget.d.ts +20 -11
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +45 -49
- package/src/aave.ts +387 -138
- package/src/analytics.ts +208 -2
- package/src/chains.ts +65 -64
- package/src/constants.ts +18 -14
- package/src/customTokens.ts +151 -0
- package/src/decoders.ts +4 -7
- package/src/error.ts +7 -3
- package/src/fees.ts +239 -125
- package/src/gasless.ts +54 -108
- package/src/index.ts +29 -9
- package/src/indexerClient.ts +2 -0
- package/src/intentReceiptMonitor.ts +1 -4
- package/src/intentReceiptPoller.ts +2 -2
- package/src/intents.ts +16 -5
- package/src/mode.ts +1 -1
- package/src/mutations.ts +7 -3
- package/src/prepareSend.ts +19 -14
- package/src/prices.ts +1 -1
- package/src/sequenceWallet.ts +2 -2
- package/src/time.ts +28 -0
- package/src/tokenBalances.ts +348 -153
- package/src/tokens.ts +393 -142
- package/src/trailsClient.ts +1 -1
- package/src/trailsRouter.ts +4 -5
- package/src/transactionIntent/deposits/depositOrchestrator.ts +6 -2
- package/src/transactionIntent/deposits/gaslessDeposit.ts +13 -7
- package/src/transactionIntent/deposits/standardDeposit.ts +1 -1
- package/src/transactionIntent/execution/transactionState.ts +1 -1
- package/src/transactionIntent/handlers/crossChain.ts +75 -37
- package/src/transactionIntent/handlers/sameChainSameToken.ts +66 -20
- package/src/transactionIntent/quote/feeExtractors.ts +1 -29
- package/src/transactionIntent/quote/normalizeQuote.ts +99 -7
- package/src/transactionIntent/quote/quoteHelpers.ts +1 -1
- package/src/transactionIntent/types.ts +31 -6
- package/src/transactionIntent/utils/testnetHelpers.ts +0 -5
- package/src/transactionIntent/validators.ts +0 -30
- package/src/transactions.ts +3 -3
- package/src/utils.ts +18 -0
- package/src/wallets.ts +32 -10
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistory.tsx +2 -1
- package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +2 -2
- package/src/widget/components/AddressWalletIcon.tsx +29 -0
- package/src/widget/components/ChainFilterDropdown.tsx +2 -8
- package/src/widget/components/ChainImage.tsx +8 -5
- package/src/widget/components/ChainList.tsx +6 -8
- package/src/widget/components/ClassicSwap.tsx +93 -85
- package/src/widget/components/ConnectWallet.tsx +1 -2
- package/src/widget/components/ConnectedWallets.tsx +17 -4
- package/src/widget/components/DebugMenu.tsx +2 -2
- package/src/widget/components/DebugScreensList.tsx +0 -1
- package/src/widget/components/DepositTracker.tsx +20 -34
- package/src/widget/components/Earn.tsx +7 -6
- package/src/widget/components/FeeOption.tsx +4 -4
- package/src/widget/components/FeeOptions.tsx +19 -39
- package/src/widget/components/Footer.tsx +1 -1
- package/src/widget/components/Fund.tsx +23 -119
- package/src/widget/components/FundMethods.tsx +9 -6
- package/src/widget/components/FundSwap.tsx +6 -5
- package/src/widget/components/FundingMethodSelectorButton.tsx +2 -2
- package/src/widget/components/HookModalContent.tsx +306 -0
- package/src/widget/components/Modal.tsx +1 -1
- package/src/widget/components/OriginSelectionAmount.tsx +135 -0
- package/src/widget/components/Pay.tsx +66 -124
- package/src/widget/components/PoolDeposit.tsx +11 -55
- package/src/widget/components/PoolWithdraw.tsx +3 -3
- package/src/widget/components/QuoteDetails.tsx +473 -728
- package/src/widget/components/Receipt.tsx +74 -7
- package/src/widget/components/RecentTokens.tsx +8 -8
- package/src/widget/components/RecipientSelectorButton.tsx +4 -2
- package/src/widget/components/ScreenHeader.tsx +2 -2
- package/src/widget/components/SearchInputField.tsx +1 -1
- package/src/widget/components/ShadowPortal.tsx +58 -0
- package/src/widget/components/Swap.tsx +6 -5
- package/src/widget/components/ThemeProvider.tsx +1 -1
- package/src/widget/components/TokenList.tsx +3 -4
- package/src/widget/components/TokenSelector.tsx +211 -80
- package/src/widget/components/Tooltip.tsx +18 -7
- package/src/widget/components/TrailsHookModal.tsx +118 -0
- package/src/widget/components/WaasFeeOptions.tsx +333 -138
- package/src/widget/components/WalletConfirmation.tsx +7 -2
- package/src/widget/components/WalletConnect.tsx +197 -235
- package/src/widget/components/WidgetProviders.tsx +75 -0
- package/src/widget/hooks/useAddressWalletIcon.ts +53 -0
- package/src/widget/hooks/useBalanceVisible.tsx +1 -1
- package/src/widget/hooks/useChainFilter.tsx +1 -1
- package/src/widget/hooks/useCheckout.ts +13 -1
- package/src/widget/hooks/useConnector.tsx +18 -0
- package/src/widget/hooks/useCurrentScreen.tsx +3 -3
- package/src/widget/hooks/useCustomTokenFetch.tsx +72 -0
- package/src/widget/hooks/useCustomTokenSearch.tsx +402 -0
- package/src/widget/hooks/useDebounce.ts +25 -0
- package/src/widget/hooks/useDebugScreens.ts +26 -10
- package/src/widget/hooks/useDefaultTokenSelection.tsx +99 -143
- package/src/widget/hooks/useDestinationSelectedToken.tsx +1 -14
- package/src/widget/hooks/useEarnPool.tsx +1 -1
- package/src/widget/hooks/useIntentTransactionHistory.ts +20 -11
- package/src/widget/hooks/useIsMobile.tsx +50 -0
- package/src/widget/hooks/useMode.ts +2 -3
- package/src/widget/hooks/useOriginSelectedToken.tsx +2 -15
- package/src/widget/hooks/usePayMessage.tsx +31 -11
- package/src/widget/hooks/usePriceImpactWarning.ts +1 -1
- package/src/widget/hooks/useQuote.ts +189 -6
- package/src/widget/hooks/useRecentTokens.ts +6 -6
- package/src/widget/hooks/useRecipients.ts +1 -1
- package/src/widget/hooks/useSelectedFeeOption.tsx +2 -2
- package/src/widget/hooks/useSelectedFundMethod.tsx +1 -1
- package/src/widget/hooks/useSelectedRecipient.tsx +1 -1
- package/src/widget/hooks/useSendForm.ts +328 -152
- package/src/widget/hooks/useSwapAmount.tsx +1 -1
- package/src/widget/hooks/useTheme.tsx +1 -1
- package/src/widget/hooks/useTokenList.ts +672 -400
- package/src/widget/hooks/useTrailsSendTransaction.ts +949 -0
- package/src/widget/hooks/useWalletConnectUri.tsx +228 -0
- package/src/widget/hooks/useWidgetProps.tsx +3 -1
- package/src/widget/index.tsx +12 -0
- package/src/widget/providers/TrailsModalProvider.tsx +195 -0
- package/src/widget/providers/TrailsProvider.tsx +9 -3
- package/src/widget/types.ts +12 -20
- package/src/widget/widget.tsx +598 -385
- package/dist/cctp.d.ts +0 -3
- package/dist/cctp.d.ts.map +0 -1
- package/dist/lifi.d.ts +0 -4
- package/dist/lifi.d.ts.map +0 -1
- package/dist/meshconnect.d.ts +0 -171
- package/dist/meshconnect.d.ts.map +0 -1
- package/dist/relaySdk.d.ts +0 -87
- package/dist/relaySdk.d.ts.map +0 -1
- package/dist/widget/components/MeshConnectExchanges.d.ts +0 -7
- package/dist/widget/components/MeshConnectExchanges.d.ts.map +0 -1
- package/dist/widget/components/MeshConnectFlow.d.ts +0 -13
- package/dist/widget/components/MeshConnectFlow.d.ts.map +0 -1
- package/dist/widget/components/MeshConnectIframe.d.ts +0 -15
- package/dist/widget/components/MeshConnectIframe.d.ts.map +0 -1
- package/dist/widget/components/Receive.d.ts +0 -12
- package/dist/widget/components/Receive.d.ts.map +0 -1
- package/dist/widget/hooks/useSelectedMeshExchange.d.ts +0 -14
- package/dist/widget/hooks/useSelectedMeshExchange.d.ts.map +0 -1
- package/src/cctp.ts +0 -54
- package/src/lifi.ts +0 -108
- package/src/meshconnect.ts +0 -531
- package/src/relaySdk.ts +0 -703
- package/src/widget/components/MeshConnectExchanges.tsx +0 -290
- package/src/widget/components/MeshConnectFlow.tsx +0 -90
- package/src/widget/components/MeshConnectIframe.tsx +0 -500
- package/src/widget/components/Receive.tsx +0 -175
- package/src/widget/hooks/useSelectedMeshExchange.tsx +0 -46
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import React, { useEffect,
|
|
2
|
-
import { useAccount, useConnect
|
|
3
|
-
import { walletConnect } from "wagmi/connectors"
|
|
1
|
+
import React, { useEffect, useMemo, useState } from "react"
|
|
2
|
+
import { useAccount, useConnect } from "wagmi"
|
|
4
3
|
import { QrCode } from "./QrCode.js"
|
|
5
4
|
import { TruncatedAddress } from "./TruncatedAddress.js"
|
|
6
|
-
import { useTrails } from "../providers/TrailsProvider.js"
|
|
7
5
|
import { ScreenHeader } from "./ScreenHeader.js"
|
|
8
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
getWalletIcon,
|
|
8
|
+
getWalletName,
|
|
9
|
+
useWalletConfigs,
|
|
10
|
+
} from "../../wallets.js"
|
|
11
|
+
import { useIsMobile } from "../hooks/useIsMobile.js"
|
|
12
|
+
import { useWalletConnectUri } from "../hooks/useWalletConnectUri.js"
|
|
13
|
+
import { useConnector } from "../hooks/useConnector.js"
|
|
9
14
|
import { logger } from "../../logger.js"
|
|
10
15
|
|
|
11
16
|
export interface WalletConnectProps {
|
|
@@ -16,49 +21,39 @@ export interface WalletConnectProps {
|
|
|
16
21
|
selectedWalletId?: string
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
// Local singleton to avoid multiple Core initializations from this screen
|
|
20
|
-
let wcConnectorSingleton: ReturnType<typeof walletConnect> | null = null
|
|
21
|
-
function getWalletConnectConnector(projectId: string) {
|
|
22
|
-
if (!wcConnectorSingleton) {
|
|
23
|
-
logger.console.log(
|
|
24
|
-
"[trails-sdk] [WalletConnect] Creating new connector with projectId:",
|
|
25
|
-
projectId,
|
|
26
|
-
)
|
|
27
|
-
wcConnectorSingleton = walletConnect({
|
|
28
|
-
projectId: projectId,
|
|
29
|
-
showQrModal: false,
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
return wcConnectorSingleton
|
|
33
|
-
}
|
|
34
|
-
|
|
35
24
|
export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
36
25
|
onBack,
|
|
37
26
|
onContinue,
|
|
38
27
|
projectId: projectIdProp,
|
|
39
|
-
onReconnectPreviousWallet,
|
|
40
28
|
selectedWalletId,
|
|
41
29
|
}) => {
|
|
42
|
-
const
|
|
43
|
-
const projectId = projectIdProp || config.walletConnectProjectId
|
|
44
|
-
const { connect, connectors, status } = useConnect() as any
|
|
45
|
-
const { disconnect } = useDisconnect()
|
|
30
|
+
const { status, connectAsync } = useConnect() as any
|
|
46
31
|
const { isConnected, address, connector } = useAccount()
|
|
47
|
-
const [
|
|
48
|
-
const [
|
|
49
|
-
const
|
|
50
|
-
const
|
|
32
|
+
const [showUri, setShowUri] = useState(false)
|
|
33
|
+
const [showQrCodeMobile, setShowQrCodeMobile] = useState(false)
|
|
34
|
+
const [copied, setCopied] = useState(false)
|
|
35
|
+
const isMobile = useIsMobile()
|
|
36
|
+
const walletConfigs = useWalletConfigs()
|
|
51
37
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
38
|
+
const copyToClipboard = async (text: string) => {
|
|
39
|
+
try {
|
|
40
|
+
await navigator.clipboard.writeText(text)
|
|
41
|
+
setCopied(true)
|
|
42
|
+
setTimeout(() => setCopied(false), 2000)
|
|
43
|
+
} catch (error) {
|
|
44
|
+
logger.console.error("Failed to copy to clipboard:", error)
|
|
56
45
|
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Use the WalletConnect URI hook to manage connection and URI
|
|
49
|
+
const { walletConnectUri: wcUri, isConnecting } =
|
|
50
|
+
useWalletConnectUri(projectIdProp)
|
|
51
|
+
|
|
52
|
+
// Get connector for the selected wallet
|
|
53
|
+
const coinbaseConnector = useConnector(
|
|
54
|
+
selectedWalletId === "coinbase" ? "coinbaseWalletSDK" : "",
|
|
55
|
+
)
|
|
57
56
|
|
|
58
|
-
debounceTimeoutRef.current = setTimeout(() => {
|
|
59
|
-
setWcUri(uri)
|
|
60
|
-
}, 500) // 300ms debounce delay
|
|
61
|
-
}, [])
|
|
62
57
|
const isWalletConnectConnector = React.useMemo(() => {
|
|
63
58
|
return connector?.name === "WalletConnect" && isConnected
|
|
64
59
|
}, [connector, isConnected])
|
|
@@ -66,10 +61,6 @@ export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
|
66
61
|
// Track if we were connected when the component mounted
|
|
67
62
|
const wasConnectedOnMount = React.useRef(isConnected)
|
|
68
63
|
|
|
69
|
-
const wcConnectorFromConfig = connectors.find((c: any) =>
|
|
70
|
-
(c.id || "").toLowerCase().includes("walletconnect"),
|
|
71
|
-
)
|
|
72
|
-
|
|
73
64
|
// Only auto-navigate back if we successfully connect a new wallet
|
|
74
65
|
// Don't auto-navigate if user was already connected when they entered this screen
|
|
75
66
|
useEffect(() => {
|
|
@@ -83,152 +74,97 @@ export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
|
83
74
|
}
|
|
84
75
|
}, [isConnected, status, onBack])
|
|
85
76
|
|
|
86
|
-
const handleConnect = useCallback(
|
|
87
|
-
async (force: boolean = false) => {
|
|
88
|
-
logger.console.log("[trails-sdk] [WalletConnect] handleConnect", {
|
|
89
|
-
status,
|
|
90
|
-
wcUri,
|
|
91
|
-
isWalletConnectConnector,
|
|
92
|
-
})
|
|
93
|
-
if ((status === "pending" || status === "success") && !force) return
|
|
94
|
-
|
|
95
|
-
const makeConnector = () => getWalletConnectConnector(projectId!)
|
|
96
|
-
const connector = wcConnectorFromConfig || makeConnector()
|
|
97
|
-
|
|
98
|
-
logger.console.log(
|
|
99
|
-
"[trails-sdk] [WalletConnect] wcConnectorFromConfig",
|
|
100
|
-
wcConnectorFromConfig,
|
|
101
|
-
)
|
|
102
|
-
logger.console.log("[trails-sdk] [WalletConnect] connector", connector)
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
logger.console.log(
|
|
106
|
-
"[trails-sdk] [WalletConnect] Starting connection...",
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
// Set up message listener for display_uri events (like ConnectKit does)
|
|
110
|
-
const handleMessage = (message: any) => {
|
|
111
|
-
const { type, data } = message
|
|
112
|
-
logger.console.log(
|
|
113
|
-
"[trails-sdk] [WalletConnect] Message received:",
|
|
114
|
-
type,
|
|
115
|
-
data,
|
|
116
|
-
)
|
|
117
|
-
if (type === "display_uri") {
|
|
118
|
-
logger.console.log(
|
|
119
|
-
"[trails-sdk] [WalletConnect] Setting URI from display_uri event:",
|
|
120
|
-
data,
|
|
121
|
-
)
|
|
122
|
-
debouncedSetWcUri(data)
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Set up disconnect handler to regenerate QR code
|
|
127
|
-
const handleDisconnect = async () => {
|
|
128
|
-
logger.console.log(
|
|
129
|
-
"[trails-sdk] [WalletConnect] Disconnected, regenerating QR code",
|
|
130
|
-
)
|
|
131
|
-
debouncedSetWcUri(null)
|
|
132
|
-
// Try to reconnect
|
|
133
|
-
try {
|
|
134
|
-
await connect({ connector })
|
|
135
|
-
} catch (error: any) {
|
|
136
|
-
logger.console.error(
|
|
137
|
-
"[trails-sdk] [WalletConnect] Reconnection error:",
|
|
138
|
-
error,
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Add listeners to connector emitter
|
|
144
|
-
if ((connector as any).emitter) {
|
|
145
|
-
logger.console.log(
|
|
146
|
-
"[trails-sdk] [WalletConnect] Adding listeners to connector emitter",
|
|
147
|
-
)
|
|
148
|
-
;(connector as any).emitter.on("message", handleMessage)
|
|
149
|
-
;(connector as any).emitter.on("disconnect", handleDisconnect)
|
|
150
|
-
|
|
151
|
-
// Store listeners for cleanup
|
|
152
|
-
listenerRef.current = () => {
|
|
153
|
-
;(connector as any).emitter.off("message", handleMessage)
|
|
154
|
-
;(connector as any).emitter.off("disconnect", handleDisconnect)
|
|
155
|
-
}
|
|
156
|
-
} else {
|
|
157
|
-
logger.console.log(
|
|
158
|
-
"[trails-sdk] [WalletConnect] No emitter found on connector",
|
|
159
|
-
)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
await connect({ connector })
|
|
163
|
-
} catch (err) {
|
|
164
|
-
logger.console.error("[trails-sdk] [WalletConnect] connect error", err)
|
|
165
|
-
// If user rejected, try to regenerate QR code
|
|
166
|
-
if ((err as any).code === 4001) {
|
|
167
|
-
logger.console.log(
|
|
168
|
-
"[trails-sdk] [WalletConnect] User rejected, regenerating QR code",
|
|
169
|
-
)
|
|
170
|
-
debouncedSetWcUri(null)
|
|
171
|
-
// Try to reconnect after a short delay
|
|
172
|
-
setTimeout(() => {
|
|
173
|
-
handleConnect()
|
|
174
|
-
}, 0)
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
[
|
|
179
|
-
connect,
|
|
180
|
-
wcConnectorFromConfig,
|
|
181
|
-
projectId,
|
|
182
|
-
status,
|
|
183
|
-
wcUri,
|
|
184
|
-
isWalletConnectConnector,
|
|
185
|
-
debouncedSetWcUri,
|
|
186
|
-
],
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
// Auto-start WalletConnect connection when component mounts (if not already connected via WalletConnect)
|
|
190
|
-
useEffect(() => {
|
|
191
|
-
if (!isWalletConnectConnector && !wcUri && status !== "pending") {
|
|
192
|
-
logger.console.log(
|
|
193
|
-
"[trails-sdk] [WalletConnect] Auto-starting connection on mount",
|
|
194
|
-
)
|
|
195
|
-
handleConnect()
|
|
196
|
-
}
|
|
197
|
-
}, [isWalletConnectConnector, wcUri, status, handleConnect])
|
|
198
|
-
|
|
199
|
-
// Force QR code regeneration when wcUri is cleared
|
|
200
|
-
useEffect(() => {
|
|
201
|
-
if (!wcUri && !isWalletConnectConnector && status !== "pending") {
|
|
202
|
-
logger.console.log(
|
|
203
|
-
"[trails-sdk] [WalletConnect] URI cleared, regenerating QR code",
|
|
204
|
-
)
|
|
205
|
-
handleConnect()
|
|
206
|
-
}
|
|
207
|
-
}, [wcUri, isWalletConnectConnector, status, handleConnect])
|
|
208
|
-
|
|
209
|
-
useEffect(() => {
|
|
210
|
-
return () => {
|
|
211
|
-
try {
|
|
212
|
-
// Clean up the listener function if it exists
|
|
213
|
-
if (listenerRef.current) {
|
|
214
|
-
listenerRef.current()
|
|
215
|
-
}
|
|
216
|
-
// Clean up debounce timeout
|
|
217
|
-
if (debounceTimeoutRef.current) {
|
|
218
|
-
clearTimeout(debounceTimeoutRef.current)
|
|
219
|
-
}
|
|
220
|
-
} catch {}
|
|
221
|
-
}
|
|
222
|
-
}, [])
|
|
223
|
-
|
|
224
77
|
const title = useMemo(() => {
|
|
225
78
|
const walletName = getWalletName(selectedWalletId)
|
|
226
79
|
if (walletName && walletName !== "WalletConnect") {
|
|
80
|
+
if (isMobile) {
|
|
81
|
+
return `Connect to ${walletName}`
|
|
82
|
+
}
|
|
227
83
|
return `Scan code to connect to ${walletName}`
|
|
228
84
|
}
|
|
229
85
|
|
|
230
86
|
return `Connect with WalletConnect`
|
|
231
|
-
}, [selectedWalletId])
|
|
87
|
+
}, [selectedWalletId, isMobile])
|
|
88
|
+
|
|
89
|
+
// Shared QR code component
|
|
90
|
+
const qrCodeComponent = wcUri ? (
|
|
91
|
+
<QrCode
|
|
92
|
+
url={wcUri}
|
|
93
|
+
size={300}
|
|
94
|
+
imageUrl={
|
|
95
|
+
getWalletIcon(selectedWalletId) || getWalletIcon("walletconnect")
|
|
96
|
+
}
|
|
97
|
+
/>
|
|
98
|
+
) : null
|
|
99
|
+
|
|
100
|
+
// Shared URI display component
|
|
101
|
+
const uriDisplayComponent = (
|
|
102
|
+
<>
|
|
103
|
+
<button
|
|
104
|
+
type="button"
|
|
105
|
+
onClick={() => setShowUri(!showUri)}
|
|
106
|
+
className="mt-3 text-xs text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:underline cursor-pointer flex items-center gap-1"
|
|
107
|
+
>
|
|
108
|
+
{showUri ? "Hide URI" : "Show URI"}
|
|
109
|
+
<svg
|
|
110
|
+
className={`w-3 h-3 transition-transform ${showUri ? "rotate-180" : ""}`}
|
|
111
|
+
fill="none"
|
|
112
|
+
stroke="currentColor"
|
|
113
|
+
viewBox="0 0 24 24"
|
|
114
|
+
>
|
|
115
|
+
<path
|
|
116
|
+
strokeLinecap="round"
|
|
117
|
+
strokeLinejoin="round"
|
|
118
|
+
strokeWidth={2}
|
|
119
|
+
d="M19 9l-7 7-7-7"
|
|
120
|
+
/>
|
|
121
|
+
</svg>
|
|
122
|
+
</button>
|
|
123
|
+
{showUri && (
|
|
124
|
+
<div className="mt-2 flex items-center gap-2 w-full sm:max-w-sm">
|
|
125
|
+
<p className="text-xs text-gray-600 dark:text-gray-400 break-all flex-1">
|
|
126
|
+
{wcUri}
|
|
127
|
+
</p>
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
onClick={() => copyToClipboard(wcUri || "")}
|
|
131
|
+
className="flex-shrink-0 px-2 py-1 text-xs text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 rounded transition-colors cursor-pointer"
|
|
132
|
+
title={copied ? "Copied!" : "Copy to clipboard"}
|
|
133
|
+
>
|
|
134
|
+
{copied ? (
|
|
135
|
+
<svg
|
|
136
|
+
className="w-4 h-4 text-green-600 dark:text-green-400"
|
|
137
|
+
fill="none"
|
|
138
|
+
stroke="currentColor"
|
|
139
|
+
viewBox="0 0 24 24"
|
|
140
|
+
>
|
|
141
|
+
<path
|
|
142
|
+
strokeLinecap="round"
|
|
143
|
+
strokeLinejoin="round"
|
|
144
|
+
strokeWidth={2}
|
|
145
|
+
d="M5 13l4 4L19 7"
|
|
146
|
+
/>
|
|
147
|
+
</svg>
|
|
148
|
+
) : (
|
|
149
|
+
<svg
|
|
150
|
+
className="w-4 h-4"
|
|
151
|
+
fill="none"
|
|
152
|
+
stroke="currentColor"
|
|
153
|
+
viewBox="0 0 24 24"
|
|
154
|
+
>
|
|
155
|
+
<path
|
|
156
|
+
strokeLinecap="round"
|
|
157
|
+
strokeLinejoin="round"
|
|
158
|
+
strokeWidth={2}
|
|
159
|
+
d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
|
|
160
|
+
/>
|
|
161
|
+
</svg>
|
|
162
|
+
)}
|
|
163
|
+
</button>
|
|
164
|
+
</div>
|
|
165
|
+
)}
|
|
166
|
+
</>
|
|
167
|
+
)
|
|
232
168
|
|
|
233
169
|
return (
|
|
234
170
|
<div className="flex flex-col h-full">
|
|
@@ -240,7 +176,7 @@ export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
|
240
176
|
/>
|
|
241
177
|
|
|
242
178
|
<div className="flex-1 flex items-center justify-center">
|
|
243
|
-
<div className="text-center p-6 w-full max-w-sm trails-border-radius-container trails-bg-secondary">
|
|
179
|
+
<div className="text-center p-6 w-full sm:max-w-sm sm:mx-auto trails-border-radius-container trails-bg-secondary">
|
|
244
180
|
{isWalletConnectConnector ? (
|
|
245
181
|
<div className="flex flex-col items-center">
|
|
246
182
|
<div className="w-16 h-16 bg-green-100 dark:bg-green-900 rounded-full flex items-center justify-center mb-4">
|
|
@@ -275,46 +211,52 @@ export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
|
275
211
|
>
|
|
276
212
|
Continue
|
|
277
213
|
</button>
|
|
278
|
-
<button
|
|
279
|
-
type="button"
|
|
280
|
-
onClick={() => {
|
|
281
|
-
disconnect()
|
|
282
|
-
debouncedSetWcUri(null)
|
|
283
|
-
setShowUri(false)
|
|
284
|
-
setTimeout(() => {
|
|
285
|
-
if (onReconnectPreviousWallet) {
|
|
286
|
-
onReconnectPreviousWallet()
|
|
287
|
-
}
|
|
288
|
-
}, 0)
|
|
289
|
-
setTimeout(() => {
|
|
290
|
-
handleConnect(true)
|
|
291
|
-
}, 1000)
|
|
292
|
-
}}
|
|
293
|
-
className="px-4 py-2 text-sm transition-all duration-200 cursor-pointer hover:scale-[1.02] shadow-sm hover:shadow-md trails-border-radius-button font-medium trails-bg-secondary trails-text-secondary trails-border-color"
|
|
294
|
-
>
|
|
295
|
-
Disconnect
|
|
296
|
-
</button>
|
|
297
214
|
</div>
|
|
298
215
|
</div>
|
|
299
|
-
) : (
|
|
300
|
-
|
|
301
|
-
{
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
216
|
+
) : wcUri ? (
|
|
217
|
+
<div className="flex flex-col items-center">
|
|
218
|
+
{/* Mobile: Show Connect button with collapsible QR code */}
|
|
219
|
+
{isMobile &&
|
|
220
|
+
selectedWalletId &&
|
|
221
|
+
walletConfigs[selectedWalletId]?.getWalletConnectDeepLink ? (
|
|
222
|
+
<div className="flex flex-col items-center w-full">
|
|
223
|
+
{selectedWalletId.toLowerCase().includes("coinbase") &&
|
|
224
|
+
coinbaseConnector ? (
|
|
225
|
+
<button
|
|
226
|
+
type="button"
|
|
227
|
+
onClick={async () => {
|
|
228
|
+
try {
|
|
229
|
+
await connectAsync({
|
|
230
|
+
connector: coinbaseConnector,
|
|
231
|
+
})
|
|
232
|
+
if (onContinue) {
|
|
233
|
+
onContinue()
|
|
234
|
+
}
|
|
235
|
+
} catch (error) {
|
|
236
|
+
logger.console.error(error)
|
|
237
|
+
}
|
|
238
|
+
}}
|
|
239
|
+
className="w-full px-4 py-3 text-base transition-all duration-200 cursor-pointer hover:scale-[1.02] shadow-sm hover:shadow-md trails-border-radius-button font-medium trails-primary-button-bg trails-primary-button-text bg-blue-500 hover:bg-blue-600 text-white text-center"
|
|
240
|
+
>
|
|
241
|
+
Connect
|
|
242
|
+
</button>
|
|
243
|
+
) : (
|
|
244
|
+
<a
|
|
245
|
+
href={walletConfigs[selectedWalletId]
|
|
246
|
+
.getWalletConnectDeepLink!(wcUri)}
|
|
247
|
+
className="w-full px-4 py-3 text-base transition-all duration-200 cursor-pointer hover:scale-[1.02] shadow-sm hover:shadow-md trails-border-radius-button font-medium trails-primary-button-bg trails-primary-button-text bg-blue-500 hover:bg-blue-600 text-white text-center"
|
|
248
|
+
>
|
|
249
|
+
Connect
|
|
250
|
+
</a>
|
|
251
|
+
)}
|
|
311
252
|
<button
|
|
312
|
-
|
|
313
|
-
|
|
253
|
+
type="button"
|
|
254
|
+
onClick={() => setShowQrCodeMobile(!showQrCodeMobile)}
|
|
255
|
+
className="mt-3 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 cursor-pointer flex items-center gap-1"
|
|
314
256
|
>
|
|
315
|
-
|
|
257
|
+
or scan QR code
|
|
316
258
|
<svg
|
|
317
|
-
className={`w-
|
|
259
|
+
className={`w-4 h-4 transition-transform ${showQrCodeMobile ? "rotate-180" : ""}`}
|
|
318
260
|
fill="none"
|
|
319
261
|
stroke="currentColor"
|
|
320
262
|
viewBox="0 0 24 24"
|
|
@@ -327,31 +269,51 @@ export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
|
327
269
|
/>
|
|
328
270
|
</svg>
|
|
329
271
|
</button>
|
|
330
|
-
{
|
|
331
|
-
<
|
|
332
|
-
{
|
|
333
|
-
|
|
272
|
+
{showQrCodeMobile && (
|
|
273
|
+
<div className="mt-4 flex flex-col items-center w-full">
|
|
274
|
+
{qrCodeComponent}
|
|
275
|
+
{uriDisplayComponent}
|
|
276
|
+
{isConnecting && wcUri && (
|
|
277
|
+
<p className="mt-3 text-xs text-gray-600 dark:text-gray-400">
|
|
278
|
+
Waiting for confirmation…
|
|
279
|
+
</p>
|
|
280
|
+
)}
|
|
281
|
+
</div>
|
|
334
282
|
)}
|
|
335
283
|
</div>
|
|
336
284
|
) : (
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
285
|
+
/* Desktop: Show QR code with URI toggle */
|
|
286
|
+
<>
|
|
287
|
+
{qrCodeComponent}
|
|
288
|
+
<div className="mt-2">{uriDisplayComponent}</div>
|
|
289
|
+
{isConnecting && wcUri && (
|
|
290
|
+
<div className="mt-3 text-xs text-gray-600 dark:text-gray-400">
|
|
291
|
+
<span>Waiting for confirmation…</span>
|
|
344
292
|
</div>
|
|
293
|
+
)}
|
|
294
|
+
</>
|
|
295
|
+
)}
|
|
296
|
+
</div>
|
|
297
|
+
) : (
|
|
298
|
+
<div className="flex flex-col items-center">
|
|
299
|
+
{isMobile ? (
|
|
300
|
+
<div className="flex flex-col items-center">
|
|
301
|
+
<div className="animate-spin rounded-full h-8 w-8 border-solid border-b-2 border-blue-600"></div>
|
|
302
|
+
<p className="mt-2 text-sm text-gray-600 dark:text-gray-400">
|
|
303
|
+
Loading link...
|
|
304
|
+
</p>
|
|
305
|
+
</div>
|
|
306
|
+
) : (
|
|
307
|
+
<div className="w-[300px] h-[300px] bg-gray-200 dark:bg-gray-700 rounded-lg flex items-center justify-center trails-border-radius-container">
|
|
308
|
+
<div className="text-center">
|
|
309
|
+
<div className="animate-spin rounded-full h-8 w-8 border-solid border-b-2 border-blue-600 mx-auto mb-2"></div>
|
|
310
|
+
<p className="text-sm text-gray-600 dark:text-gray-400">
|
|
311
|
+
Generating QR code...
|
|
312
|
+
</p>
|
|
345
313
|
</div>
|
|
346
314
|
</div>
|
|
347
315
|
)}
|
|
348
|
-
|
|
349
|
-
<div className="mt-3 text-xs text-gray-600 dark:text-gray-400">
|
|
350
|
-
{status === "pending" && wcUri && (
|
|
351
|
-
<span>Waiting for confirmation…</span>
|
|
352
|
-
)}
|
|
353
|
-
</div>
|
|
354
|
-
</>
|
|
316
|
+
</div>
|
|
355
317
|
)}
|
|
356
318
|
</div>
|
|
357
319
|
</div>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ReactNode } from "react"
|
|
2
|
+
import type { TrailsWidgetProps } from "../widget.js"
|
|
3
|
+
import { WidgetPropsProvider } from "../hooks/useWidgetProps.js"
|
|
4
|
+
import { ToastProvider } from "./Toast.js"
|
|
5
|
+
import { CurrentScreenProvider } from "../hooks/useCurrentScreen.js"
|
|
6
|
+
import { BackProvider } from "../hooks/useBack.js"
|
|
7
|
+
import { WalletConnectionProvider } from "../hooks/useWalletConnectionContext.js"
|
|
8
|
+
import { OriginSelectedTokenProvider } from "../hooks/useOriginSelectedToken.js"
|
|
9
|
+
import { DestinationSelectedTokenProvider } from "../hooks/useDestinationSelectedToken.js"
|
|
10
|
+
import { SelectedFeeOptionProvider } from "../hooks/useSelectedFeeOption.js"
|
|
11
|
+
import { SelectedRecipientProvider } from "../hooks/useSelectedRecipient.js"
|
|
12
|
+
import { SwapAmountProvider } from "../hooks/useSwapAmount.js"
|
|
13
|
+
import { ChainFilterProvider } from "../hooks/useChainFilter.js"
|
|
14
|
+
import { BalanceVisibleProvider } from "../hooks/useBalanceVisible.js"
|
|
15
|
+
import { ThemeProvider as ThemePreferenceProvider } from "../hooks/useTheme.js"
|
|
16
|
+
import { SelectedFundMethodProvider } from "../hooks/useSelectedFundMethod.js"
|
|
17
|
+
import { EarnPoolProvider } from "../hooks/useEarnPool.js"
|
|
18
|
+
import { DefaultTokenSelectionProvider } from "../hooks/useDefaultTokenSelection.js"
|
|
19
|
+
|
|
20
|
+
// Default props for hook modal (minimal required config)
|
|
21
|
+
const DEFAULT_HOOK_MODAL_PROPS: TrailsWidgetProps = {
|
|
22
|
+
apiKey: "",
|
|
23
|
+
renderInline: false,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface WidgetProvidersProps {
|
|
27
|
+
children: ReactNode
|
|
28
|
+
props?: TrailsWidgetProps
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Shared provider tree component that wraps all widget-level providers.
|
|
33
|
+
* Used by both WidgetInner (full widget) and TrailsHookModal (standalone hook modal).
|
|
34
|
+
* This ensures identical behavior regardless of how the modal is rendered.
|
|
35
|
+
*/
|
|
36
|
+
export function WidgetProviders({
|
|
37
|
+
children,
|
|
38
|
+
props = DEFAULT_HOOK_MODAL_PROPS,
|
|
39
|
+
}: WidgetProvidersProps) {
|
|
40
|
+
return (
|
|
41
|
+
<WidgetPropsProvider props={props}>
|
|
42
|
+
<ToastProvider>
|
|
43
|
+
<CurrentScreenProvider initialScreen="home">
|
|
44
|
+
<BackProvider>
|
|
45
|
+
<WalletConnectionProvider>
|
|
46
|
+
<OriginSelectedTokenProvider>
|
|
47
|
+
<DestinationSelectedTokenProvider>
|
|
48
|
+
<SelectedFeeOptionProvider>
|
|
49
|
+
<SelectedRecipientProvider>
|
|
50
|
+
<SwapAmountProvider>
|
|
51
|
+
<ChainFilterProvider>
|
|
52
|
+
<BalanceVisibleProvider>
|
|
53
|
+
<ThemePreferenceProvider>
|
|
54
|
+
<SelectedFundMethodProvider>
|
|
55
|
+
<EarnPoolProvider>
|
|
56
|
+
<DefaultTokenSelectionProvider>
|
|
57
|
+
{children}
|
|
58
|
+
</DefaultTokenSelectionProvider>
|
|
59
|
+
</EarnPoolProvider>
|
|
60
|
+
</SelectedFundMethodProvider>
|
|
61
|
+
</ThemePreferenceProvider>
|
|
62
|
+
</BalanceVisibleProvider>
|
|
63
|
+
</ChainFilterProvider>
|
|
64
|
+
</SwapAmountProvider>
|
|
65
|
+
</SelectedRecipientProvider>
|
|
66
|
+
</SelectedFeeOptionProvider>
|
|
67
|
+
</DestinationSelectedTokenProvider>
|
|
68
|
+
</OriginSelectedTokenProvider>
|
|
69
|
+
</WalletConnectionProvider>
|
|
70
|
+
</BackProvider>
|
|
71
|
+
</CurrentScreenProvider>
|
|
72
|
+
</ToastProvider>
|
|
73
|
+
</WidgetPropsProvider>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useMemo } from "react"
|
|
2
|
+
import { useWallets, wagmiConnectorToWalletId } from "../../wallets.js"
|
|
3
|
+
import { type Connector, useConnections } from "wagmi"
|
|
4
|
+
import type { Address } from "viem"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook to get the wallet icon for an connected address
|
|
8
|
+
* @param address - The address to get the wallet icon for
|
|
9
|
+
* @param connector - The connector to get the wallet icon for
|
|
10
|
+
* @returns The wallet icon for the address
|
|
11
|
+
*/
|
|
12
|
+
export const useConnectedAddressWalletIcon = (
|
|
13
|
+
address: Address,
|
|
14
|
+
connector: Connector | undefined,
|
|
15
|
+
) => {
|
|
16
|
+
const connections = useConnections()
|
|
17
|
+
const { wallets: allWallets } = useWallets()
|
|
18
|
+
|
|
19
|
+
const addressWalletIcon = useMemo(() => {
|
|
20
|
+
if (!address || !allWallets || allWallets.length === 0) {
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const walletMap = new Map()
|
|
25
|
+
|
|
26
|
+
connections.forEach((connection) => {
|
|
27
|
+
// Process each account in the connection
|
|
28
|
+
connection.accounts.forEach((account) => {
|
|
29
|
+
if (account && !walletMap.has(account)) {
|
|
30
|
+
const walletId = wagmiConnectorToWalletId(connection.connector)
|
|
31
|
+
const walletConfig = allWallets.find(
|
|
32
|
+
(wallet) => wallet.id === walletId,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
walletMap.set(account, {
|
|
36
|
+
address: account,
|
|
37
|
+
connector: connection.connector,
|
|
38
|
+
walletConfig,
|
|
39
|
+
walletId,
|
|
40
|
+
isActive:
|
|
41
|
+
connection.connector.id === connector?.id && account === address,
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const connectedWallets = Array.from(walletMap.values())
|
|
48
|
+
return connectedWallets.find((wallet) => wallet.address === address)
|
|
49
|
+
?.walletConfig?.icon
|
|
50
|
+
}, [address, connector, connections, allWallets])
|
|
51
|
+
|
|
52
|
+
return addressWalletIcon
|
|
53
|
+
}
|
|
@@ -82,7 +82,7 @@ export const BalanceVisibleProvider: React.FC<BalanceVisibleProviderProps> = ({
|
|
|
82
82
|
)
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
export
|
|
85
|
+
export function useBalanceVisible(): BalanceVisibleContextType {
|
|
86
86
|
const context = useContext(BalanceVisibleContext)
|
|
87
87
|
|
|
88
88
|
if (context === undefined) {
|
|
@@ -45,7 +45,7 @@ export const ChainFilterProvider: React.FC<ChainFilterProviderProps> = ({
|
|
|
45
45
|
)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export
|
|
48
|
+
export function useChainFilter(): ChainFilterContextType {
|
|
49
49
|
const context = useContext(ChainFilterContext)
|
|
50
50
|
|
|
51
51
|
if (context === undefined) {
|