0xtrails 0.0.1 → 0.0.2
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/LICENSE +202 -0
- package/README.md +42 -0
- package/dist/abi.d.ts +37 -0
- package/dist/abi.d.ts.map +1 -0
- package/dist/abi.js +36 -0
- package/dist/apiClient.d.ts +9 -0
- package/dist/apiClient.d.ts.map +1 -0
- package/dist/apiClient.js +18 -0
- package/dist/buffer.d.ts +3 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +8 -0
- package/dist/cctp.d.ts +84 -0
- package/dist/cctp.d.ts.map +1 -0
- package/dist/cctp.js +401 -0
- package/dist/chainSwitch.d.ts +7 -0
- package/dist/chainSwitch.d.ts.map +1 -0
- package/dist/chainSwitch.js +33 -0
- package/dist/chains.d.ts +13 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +95 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +16 -0
- package/dist/encoders.d.ts +7 -0
- package/dist/encoders.d.ts.map +1 -0
- package/dist/encoders.js +8 -0
- package/dist/error.d.ts +2 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +12 -0
- package/dist/explorer.d.ts +12 -0
- package/dist/explorer.d.ts.map +1 -0
- package/dist/explorer.js +18 -0
- package/dist/gasless.d.ts +116 -0
- package/dist/gasless.d.ts.map +1 -0
- package/dist/gasless.js +297 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/indexerClient.d.ts +9 -0
- package/dist/indexerClient.d.ts.map +1 -0
- package/dist/indexerClient.js +18 -0
- package/dist/intents.d.ts +83 -0
- package/dist/intents.d.ts.map +1 -0
- package/dist/intents.js +288 -0
- package/dist/metaTxnMonitor.d.ts +14 -0
- package/dist/metaTxnMonitor.d.ts.map +1 -0
- package/dist/metaTxnMonitor.js +121 -0
- package/dist/metaTxns.d.ts +6 -0
- package/dist/metaTxns.d.ts.map +1 -0
- package/dist/metaTxns.js +4 -0
- package/dist/paymasterSend.d.ts +90 -0
- package/dist/paymasterSend.d.ts.map +1 -0
- package/dist/paymasterSend.js +329 -0
- package/dist/preconditions.d.ts +11 -0
- package/dist/preconditions.d.ts.map +1 -0
- package/dist/preconditions.js +29 -0
- package/dist/prepareSend.d.ts +102 -0
- package/dist/prepareSend.d.ts.map +1 -0
- package/dist/prepareSend.js +1080 -0
- package/dist/prices.d.ts +18 -0
- package/dist/prices.d.ts.map +1 -0
- package/dist/prices.js +142 -0
- package/dist/queryParams.d.ts +9 -0
- package/dist/queryParams.d.ts.map +1 -0
- package/dist/queryParams.js +66 -0
- package/dist/relaySdk.d.ts +65 -0
- package/dist/relaySdk.d.ts.map +1 -0
- package/dist/relaySdk.js +314 -0
- package/dist/relayer.d.ts +23 -0
- package/dist/relayer.d.ts.map +1 -0
- package/dist/relayer.js +230 -0
- package/dist/sendUserOp.d.ts +140 -0
- package/dist/sendUserOp.d.ts.map +1 -0
- package/dist/sendUserOp.js +388 -0
- package/dist/sequenceWallet.d.ts +79 -0
- package/dist/sequenceWallet.d.ts.map +1 -0
- package/dist/sequenceWallet.js +374 -0
- package/dist/theme.d.ts +3 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +1 -0
- package/dist/toSimpleSmartAccount.d.ts +95 -0
- package/dist/toSimpleSmartAccount.d.ts.map +1 -0
- package/dist/toSimpleSmartAccount.js +373 -0
- package/dist/tokenBalances.d.ts +118 -0
- package/dist/tokenBalances.d.ts.map +1 -0
- package/dist/tokenBalances.js +492 -0
- package/dist/tokens.d.ts +50 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +356 -0
- package/dist/trails.d.ts +128 -0
- package/dist/trails.d.ts.map +1 -0
- package/dist/trails.js +1031 -0
- package/dist/umd/trails.min.js +12610 -0
- package/dist/umd/trails.min.js.map +1 -0
- package/dist/umd.d.ts +24 -0
- package/dist/umd.d.ts.map +1 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +9 -0
- package/dist/widget/ConstantsUtil-B-_-u8aQ.js +6 -0
- package/dist/widget/add-hVLs3ldJ.js +20 -0
- package/dist/widget/all-wallets-Cwxnx4BT.js +11 -0
- package/dist/widget/app-store-CAAVQjW0.js +22 -0
- package/dist/widget/apple-C3BSbglw.js +23 -0
- package/dist/widget/arrow-bottom-circle-BGU9MmsZ.js +16 -0
- package/dist/widget/arrow-bottom-hS_SA8Gp.js +13 -0
- package/dist/widget/arrow-left-CJZanWz7.js +13 -0
- package/dist/widget/arrow-right-C1qL8EMd.js +13 -0
- package/dist/widget/arrow-top-CbuCmbQs.js +13 -0
- package/dist/widget/bank-CXBEEGbb.js +19 -0
- package/dist/widget/bin-Dqzv3zCZ.js +9 -0
- package/dist/widget/bitcoin-4y3sovZp.js +18 -0
- package/dist/widget/browser-DyOl4_8m.js +1413 -0
- package/dist/widget/browser-t7Fh0sEU.js +19 -0
- package/dist/widget/card-Bo4CZkTs.js +19 -0
- package/dist/widget/ccip-BynehMIN.js +232 -0
- package/dist/widget/checkmark-DV6OKvnY.js +16 -0
- package/dist/widget/checkmark-bold-CAp1-IQ2.js +13 -0
- package/dist/widget/chevron-bottom-BjzsVzk9.js +13 -0
- package/dist/widget/chevron-left-CQZBDCiR.js +13 -0
- package/dist/widget/chevron-right-Dhg4zeZM.js +13 -0
- package/dist/widget/chevron-top-CDQmfJef.js +13 -0
- package/dist/widget/chrome-store-BNaC_b6w.js +66 -0
- package/dist/widget/circle-BC_GBj91.js +9 -0
- package/dist/widget/clock-BmF8-4a0.js +13 -0
- package/dist/widget/close-Bf61nZ8o.js +13 -0
- package/dist/widget/coinPlaceholder-7cZW2058.js +13 -0
- package/dist/widget/compass-CFC3yhnW.js +13 -0
- package/dist/widget/components/ChainImage.d.ts +8 -0
- package/dist/widget/components/ChainImage.d.ts.map +1 -0
- package/dist/widget/components/ChainImage.js +6 -0
- package/dist/widget/components/ConnectWallet.d.ts +18 -0
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -0
- package/dist/widget/components/ConnectWallet.js +66 -0
- package/dist/widget/components/DebugScreensDropdown.d.ts +9 -0
- package/dist/widget/components/DebugScreensDropdown.d.ts.map +1 -0
- package/dist/widget/components/DebugScreensDropdown.js +40 -0
- package/dist/widget/components/FeeOptions.d.ts +17 -0
- package/dist/widget/components/FeeOptions.d.ts.map +1 -0
- package/dist/widget/components/FeeOptions.js +65 -0
- package/dist/widget/components/Footer.d.ts +9 -0
- package/dist/widget/components/Footer.d.ts.map +1 -0
- package/dist/widget/components/Footer.js +13 -0
- package/dist/widget/components/GreenCheckAnimation.d.ts +2 -0
- package/dist/widget/components/GreenCheckAnimation.d.ts.map +1 -0
- package/dist/widget/components/GreenCheckAnimation.js +74 -0
- package/dist/widget/components/Modal.d.ts +11 -0
- package/dist/widget/components/Modal.d.ts.map +1 -0
- package/dist/widget/components/Modal.js +36 -0
- package/dist/widget/components/Receipt.d.ts +13 -0
- package/dist/widget/components/Receipt.d.ts.map +1 -0
- package/dist/widget/components/Receipt.js +36 -0
- package/dist/widget/components/SendForm.d.ts +44 -0
- package/dist/widget/components/SendForm.d.ts.map +1 -0
- package/dist/widget/components/SendForm.js +177 -0
- package/dist/widget/components/TokenImage.d.ts +10 -0
- package/dist/widget/components/TokenImage.d.ts.map +1 -0
- package/dist/widget/components/TokenImage.js +8 -0
- package/dist/widget/components/TokenList.d.ts +16 -0
- package/dist/widget/components/TokenList.d.ts.map +1 -0
- package/dist/widget/components/TokenList.js +39 -0
- package/dist/widget/components/TransferPending.d.ts +11 -0
- package/dist/widget/components/TransferPending.d.ts.map +1 -0
- package/dist/widget/components/TransferPending.js +77 -0
- package/dist/widget/components/TransferPendingVertical.d.ts +18 -0
- package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -0
- package/dist/widget/components/TransferPendingVertical.js +183 -0
- package/dist/widget/components/WalletConfirmation.d.ts +18 -0
- package/dist/widget/components/WalletConfirmation.d.ts.map +1 -0
- package/dist/widget/components/WalletConfirmation.js +22 -0
- package/dist/widget/config.d.ts +4 -0
- package/dist/widget/config.d.ts.map +1 -0
- package/dist/widget/config.js +3 -0
- package/dist/widget/copy-e0xXvKN0.js +20 -0
- package/dist/widget/cursor-CqM3v0xJ.js +8 -0
- package/dist/widget/cursor-transparent-CUQpdsCG.js +17 -0
- package/dist/widget/desktop-DUDGIRpM.js +14 -0
- package/dist/widget/disconnect-DUFST9QQ.js +13 -0
- package/dist/widget/discord-C1cj365Z.js +22 -0
- package/dist/widget/email-BHhmb_lX.js +703 -0
- package/dist/widget/embedded-wallet-CuuC4eah.js +467 -0
- package/dist/widget/ethereum-CfmBVfeB.js +15 -0
- package/dist/widget/etherscan-BSiynDhW.js +11 -0
- package/dist/widget/exclamation-triangle-DEiFNpHw.js +9 -0
- package/dist/widget/extension-mRmfCDxo.js +13 -0
- package/dist/widget/external-link-B4xMIVnW.js +13 -0
- package/dist/widget/facebook-CBAZStBR.js +31 -0
- package/dist/widget/farcaster-LHDEDf5S.js +17 -0
- package/dist/widget/filters-CBijuvFv.js +13 -0
- package/dist/widget/github-C3ILD420.js +23 -0
- package/dist/widget/google-CSj73POX.js +23 -0
- package/dist/widget/help-circle-2hdG5IdB.js +17 -0
- package/dist/widget/hooks/useAmountUsd.d.ts +13 -0
- package/dist/widget/hooks/useAmountUsd.d.ts.map +1 -0
- package/dist/widget/hooks/useAmountUsd.js +35 -0
- package/dist/widget/hooks/useSendForm.d.ts +125 -0
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -0
- package/dist/widget/hooks/useSendForm.js +450 -0
- package/dist/widget/hooks/useTokenList.d.ts +52 -0
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -0
- package/dist/widget/hooks/useTokenList.js +252 -0
- package/dist/widget/id-ByYSrwsd.js +17 -0
- package/dist/widget/if-defined-DRXJEhv7.js +752 -0
- package/dist/widget/image-C90L4Rf6.js +9 -0
- package/dist/widget/index-B3SlQ9v3.js +46 -0
- package/dist/widget/index-B8LPuLXQ.js +78 -0
- package/dist/widget/index-BDbworWA.js +171 -0
- package/dist/widget/index-BTlDgFSK.js +98 -0
- package/dist/widget/index-BUCcjXbd.js +306 -0
- package/dist/widget/index-BZ34edi2.js +1055 -0
- package/dist/widget/index-BiCU29wK.js +147 -0
- package/dist/widget/index-BlmqIKsY.js +266 -0
- package/dist/widget/index-BlviH5nG.js +55 -0
- package/dist/widget/index-Bwd5X3fS.js +8306 -0
- package/dist/widget/index-C5gmknHK.js +78 -0
- package/dist/widget/index-CD6dBcRj.js +76 -0
- package/dist/widget/index-CDlhy529.js +63 -0
- package/dist/widget/index-CHXa5ke-.js +59 -0
- package/dist/widget/index-CK94R-H7.js +22498 -0
- package/dist/widget/index-CQzo3m3x.js +182 -0
- package/dist/widget/index-CRT8cAwG.js +325 -0
- package/dist/widget/index-CY7Lt2Yu.js +310 -0
- package/dist/widget/index-CiKfAu1E.js +79 -0
- package/dist/widget/index-CkCu6rMi.js +258 -0
- package/dist/widget/index-CngLTu_R.js +517 -0
- package/dist/widget/index-CsMV8-em.js +2577 -0
- package/dist/widget/index-Cu2Wva8v.js +200 -0
- package/dist/widget/index-DKBxLTEF.js +240 -0
- package/dist/widget/index-DQEVT3dx.js +511 -0
- package/dist/widget/index-DU2HcCis.js +200 -0
- package/dist/widget/index-DutZGWNW.js +321 -0
- package/dist/widget/index-O0glArmc.js +182 -0
- package/dist/widget/index-O8FmRjKe.js +63719 -0
- package/dist/widget/index-RtKXrB6I.js +576 -0
- package/dist/widget/index-TIYtS0gE.js +88 -0
- package/dist/widget/index-dQNJvWHs.js +66 -0
- package/dist/widget/index-wmEwdsq7.js +909 -0
- package/dist/widget/index.d.ts +3 -0
- package/dist/widget/index.d.ts.map +1 -0
- package/dist/widget/index.js +2 -0
- package/dist/widget/info-DMPChDjV.js +8 -0
- package/dist/widget/info-circle-DAvS_7nY.js +17 -0
- package/dist/widget/lightbulb-DnZ9mNEs.js +8 -0
- package/dist/widget/lit-html-BRjl1r6K.js +243 -0
- package/dist/widget/mail-DpaVSOP8.js +13 -0
- package/dist/widget/mobile-CRvdyu7I.js +14 -0
- package/dist/widget/more-C5VqW9PR.js +16 -0
- package/dist/widget/network-placeholder-CZ0vApma.js +19 -0
- package/dist/widget/nftPlaceholder-7jjIK2bT.js +13 -0
- package/dist/widget/off-4mHjJLLX.js +9 -0
- package/dist/widget/onramp-Bc0ozVsw.js +929 -0
- package/dist/widget/play-store-Uocul8nC.js +37 -0
- package/dist/widget/plus-DrYF7siO.js +18 -0
- package/dist/widget/prepareSend-BQJmzM5B.js +54987 -0
- package/dist/widget/qr-code-DcnGMUB3.js +11 -0
- package/dist/widget/receive-fvIVd7R_.js +184 -0
- package/dist/widget/recycle-horizontal-DrDwXC4D.js +14 -0
- package/dist/widget/ref-CXNmEjML.js +41 -0
- package/dist/widget/refresh-OK9lIPLS.js +13 -0
- package/dist/widget/reown-logo-C-Qn7mS3.js +17 -0
- package/dist/widget/search-DZqv1oKg.js +13 -0
- package/dist/widget/send-CJlmI-xe.js +1039 -0
- package/dist/widget/send-otoEC8uU.js +20 -0
- package/dist/widget/socials-BJciurWF.js +599 -0
- package/dist/widget/solana-Bv5Hs_0T.js +18 -0
- package/dist/widget/swapHorizontal-BzOPGV37.js +13 -0
- package/dist/widget/swapHorizontalBold-axyHnSmj.js +13 -0
- package/dist/widget/swapHorizontalMedium-C6YOPfPz.js +21 -0
- package/dist/widget/swapHorizontalRoundedBold-yVcLbWNT.js +13 -0
- package/dist/widget/swapVertical-BDjxt9pE.js +13 -0
- package/dist/widget/swaps-DEWNj4kd.js +1637 -0
- package/dist/widget/telegram-BQJD7dlP.js +21 -0
- package/dist/widget/three-dots-DW9jmSMG.js +10 -0
- package/dist/widget/transactions-uCseGQQt.js +38 -0
- package/dist/widget/twitch-XugxDfOE.js +23 -0
- package/dist/widget/twitterIcon-DQVObQUL.js +11 -0
- package/dist/widget/types.d.ts +51 -0
- package/dist/widget/types.d.ts.map +1 -0
- package/dist/widget/types.js +1 -0
- package/dist/widget/verify-DpMYHxLf.js +13 -0
- package/dist/widget/verify-filled-KpEL6ZJ_.js +13 -0
- package/dist/widget/w3m-modal-C8e-6Kba.js +1047 -0
- package/dist/widget/wallet-D8ssEB0o.js +13 -0
- package/dist/widget/wallet-placeholder-HtAy21Wc.js +19 -0
- package/dist/widget/walletconnect-Bp_4XfrY.js +37 -0
- package/dist/widget/warning-circle-FgYS7P7n.js +17 -0
- package/dist/widget/widget/index.js +7 -0
- package/dist/widget/widget.d.ts +47 -0
- package/dist/widget/widget.d.ts.map +1 -0
- package/dist/widget/widget.js +932 -0
- package/dist/widget/x-DlZBoP9k.js +17 -0
- package/dist/widget/x-mark-Ba9pt-_h.js +8 -0
- package/package.json +102 -8
- package/src/abi.ts +38 -0
- package/src/apiClient.ts +32 -0
- package/src/buffer.ts +10 -0
- package/src/cctp.ts +579 -0
- package/src/chainSwitch.ts +55 -0
- package/src/chains.ts +124 -0
- package/src/constants.ts +26 -0
- package/src/encoders.ts +20 -0
- package/src/error.ts +15 -0
- package/src/explorer.ts +37 -0
- package/src/gasless.ts +545 -0
- package/src/index.ts +48 -0
- package/src/indexerClient.ts +36 -0
- package/src/intents.ts +537 -0
- package/src/metaTxnMonitor.ts +163 -0
- package/src/metaTxns.ts +21 -0
- package/src/paymasterSend.ts +503 -0
- package/src/preconditions.ts +52 -0
- package/src/prepareSend.ts +1849 -0
- package/src/prices.ts +186 -0
- package/src/queryParams.ts +80 -0
- package/src/relaySdk.ts +481 -0
- package/src/relayer.ts +255 -0
- package/src/sendUserOp.ts +570 -0
- package/src/sequenceWallet.ts +579 -0
- package/src/theme.ts +2 -0
- package/src/toSimpleSmartAccount.ts +567 -0
- package/src/tokenBalances.ts +760 -0
- package/src/tokens.ts +471 -0
- package/src/trails.ts +1591 -0
- package/src/types.d.ts +11 -0
- package/src/umd.tsx +49 -0
- package/src/utils.ts +16 -0
- package/src/vite-env.d.ts +4 -0
- package/src/widget/assets/MetaMask-icon-fox-with-margins.svg +31 -0
- package/src/widget/assets/MetaMask-icon-fox.svg +26 -0
- package/src/widget/assets/MetaMask-logo-black.svg +3 -0
- package/src/widget/assets/MetaMask-logo-white.svg +16 -0
- package/src/widget/assets/Privy_Brandmark_Black.svg +9 -0
- package/src/widget/assets/Privy_Brandmark_White.svg +9 -0
- package/src/widget/assets/Trails-logo-black.svg +11 -0
- package/src/widget/assets/Trails-logo-white.svg +11 -0
- package/src/widget/components/ChainImage.tsx +28 -0
- package/src/widget/components/ConnectWallet.tsx +206 -0
- package/src/widget/components/DebugScreensDropdown.tsx +88 -0
- package/src/widget/components/FeeOptions.tsx +199 -0
- package/src/widget/components/Footer.tsx +51 -0
- package/src/widget/components/GreenCheckAnimation.tsx +119 -0
- package/src/widget/components/Modal.tsx +97 -0
- package/src/widget/components/Receipt.tsx +237 -0
- package/src/widget/components/SendForm.tsx +695 -0
- package/src/widget/components/TokenImage.tsx +37 -0
- package/src/widget/components/TokenList.tsx +287 -0
- package/src/widget/components/TransferPending.tsx +204 -0
- package/src/widget/components/TransferPendingVertical.tsx +412 -0
- package/src/widget/components/WalletConfirmation.tsx +172 -0
- package/src/widget/config.ts +5 -0
- package/src/widget/hooks/useAmountUsd.ts +59 -0
- package/src/widget/hooks/useSendForm.ts +715 -0
- package/src/widget/hooks/useTokenList.ts +397 -0
- package/src/widget/index.css +2 -0
- package/src/widget/index.tsx +8 -0
- package/src/widget/types/svg.d.ts +8 -0
- package/src/widget/types.ts +59 -0
- package/src/widget/widget.tsx +1438 -0
- package/index.js +0 -1
|
@@ -0,0 +1,932 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "@0xsequence/design-system/preset";
|
|
3
|
+
import { SequenceHooksContext, SequenceHooksProvider } from "@0xsequence/hooks";
|
|
4
|
+
import { PrivyProvider, useLogin, usePrivy, useWallets as usePrivyWallets, } from "@privy-io/react-auth";
|
|
5
|
+
import { createConfig as createPrivyWagmiConfig, useSetActiveWallet, WagmiProvider, } from "@privy-io/wagmi";
|
|
6
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
7
|
+
import { AnimatePresence, motion } from "motion/react";
|
|
8
|
+
import React, { forwardRef, StrictMode, useCallback, useContext, useEffect, useImperativeHandle, useRef, useState, } from "react";
|
|
9
|
+
import { createPortal } from "react-dom";
|
|
10
|
+
import { createWalletClient, custom, http } from "viem";
|
|
11
|
+
import { mainnet } from "viem/chains";
|
|
12
|
+
import { createConfig, useAccount, useConnect, useDisconnect, WagmiContext, } from "wagmi";
|
|
13
|
+
import { injected } from "wagmi/connectors";
|
|
14
|
+
import { useAPIClient } from "../apiClient.js";
|
|
15
|
+
import { getChainInfo } from "../chains.js";
|
|
16
|
+
import { useIndexerGatewayClient } from "../indexerClient.js";
|
|
17
|
+
import { ConnectWallet } from "./components/ConnectWallet.js";
|
|
18
|
+
import Footer from "./components/Footer.js";
|
|
19
|
+
import Modal from "./components/Modal.js";
|
|
20
|
+
import Receipt from "./components/Receipt.js";
|
|
21
|
+
import SendForm from "./components/SendForm.js";
|
|
22
|
+
import TokenList from "./components/TokenList.js";
|
|
23
|
+
import TransferPending from "./components/TransferPendingVertical.js";
|
|
24
|
+
import WalletConfirmation from "./components/WalletConfirmation.js";
|
|
25
|
+
import { defaultPrivyAppId, defaultPrivyClientId } from "./config.js";
|
|
26
|
+
import { useAmountUsd } from "./hooks/useAmountUsd.js";
|
|
27
|
+
import css from "./index.css?inline";
|
|
28
|
+
export const defaultWalletOptions = ["injected", "privy"];
|
|
29
|
+
const queryClient = new QueryClient();
|
|
30
|
+
// Function to get system theme preference
|
|
31
|
+
const getSystemTheme = () => {
|
|
32
|
+
if (typeof window === "undefined")
|
|
33
|
+
return "light";
|
|
34
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
35
|
+
? "dark"
|
|
36
|
+
: "light";
|
|
37
|
+
};
|
|
38
|
+
// Function to get initial theme based on mode
|
|
39
|
+
const getInitialTheme = (mode) => {
|
|
40
|
+
if (mode === "auto") {
|
|
41
|
+
return getSystemTheme();
|
|
42
|
+
}
|
|
43
|
+
return mode;
|
|
44
|
+
};
|
|
45
|
+
const WALLET_CONFIGS = {
|
|
46
|
+
injected: {
|
|
47
|
+
id: "injected",
|
|
48
|
+
name: "Injected Web3",
|
|
49
|
+
connector: injected,
|
|
50
|
+
},
|
|
51
|
+
privy: {
|
|
52
|
+
id: "privy",
|
|
53
|
+
name: "Privy",
|
|
54
|
+
connector: () => { },
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
// Create a custom hook for theme management
|
|
58
|
+
const useThemeManager = (initialTheme) => {
|
|
59
|
+
const [theme, setTheme] = useState(getInitialTheme(initialTheme));
|
|
60
|
+
const [themeMode, setThemeMode] = useState(initialTheme);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (themeMode !== "auto")
|
|
63
|
+
return;
|
|
64
|
+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
65
|
+
const handleChange = (e) => {
|
|
66
|
+
setTheme(e.matches ? "dark" : "light");
|
|
67
|
+
};
|
|
68
|
+
setTheme(mediaQuery.matches ? "dark" : "light");
|
|
69
|
+
mediaQuery.addEventListener("change", handleChange);
|
|
70
|
+
return () => mediaQuery.removeEventListener("change", handleChange);
|
|
71
|
+
}, [themeMode]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
setThemeMode(initialTheme);
|
|
74
|
+
setTheme(getInitialTheme(initialTheme));
|
|
75
|
+
}, [initialTheme]);
|
|
76
|
+
return { theme, themeMode };
|
|
77
|
+
};
|
|
78
|
+
// Create a custom hook for wallet management
|
|
79
|
+
const useWalletManager = (address, chainId, connector) => {
|
|
80
|
+
const [walletClient, setWalletClient] = useState(null);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const connect = async () => {
|
|
83
|
+
try {
|
|
84
|
+
if (!connector) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const activeProvider = await connector.getProvider?.();
|
|
88
|
+
if (activeProvider && address && chainId) {
|
|
89
|
+
const chain = getChainInfo(chainId);
|
|
90
|
+
if (!chain) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const client = createWalletClient({
|
|
94
|
+
account: address,
|
|
95
|
+
chain,
|
|
96
|
+
transport: custom(activeProvider),
|
|
97
|
+
});
|
|
98
|
+
setWalletClient(client);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.error("[trails-sdk] Failed to connect wallet", error);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
connect().catch(console.error);
|
|
106
|
+
}, [address, chainId, connector]);
|
|
107
|
+
return walletClient;
|
|
108
|
+
};
|
|
109
|
+
// Create a custom hook for transaction state management
|
|
110
|
+
const useTransactionState = (onOriginConfirmation, onDestinationConfirmation) => {
|
|
111
|
+
const [originTxHash, setOriginTxHash] = useState("");
|
|
112
|
+
const [originChainId, setOriginChainId] = useState(null);
|
|
113
|
+
const [destinationTxHash, setDestinationTxHash] = useState("");
|
|
114
|
+
const [destinationChainId, setDestinationChainId] = useState(null);
|
|
115
|
+
const [transactionStates, setTransactionStates] = useState([]);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (onOriginConfirmation && originTxHash && originChainId) {
|
|
118
|
+
onOriginConfirmation(originTxHash, originChainId);
|
|
119
|
+
}
|
|
120
|
+
}, [originTxHash, onOriginConfirmation, originChainId]);
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (onDestinationConfirmation && destinationTxHash && destinationChainId) {
|
|
123
|
+
onDestinationConfirmation(destinationTxHash, destinationChainId);
|
|
124
|
+
}
|
|
125
|
+
}, [destinationTxHash, onDestinationConfirmation, destinationChainId]);
|
|
126
|
+
return {
|
|
127
|
+
originTxHash,
|
|
128
|
+
setOriginTxHash,
|
|
129
|
+
originChainId,
|
|
130
|
+
setOriginChainId,
|
|
131
|
+
destinationTxHash,
|
|
132
|
+
setDestinationTxHash,
|
|
133
|
+
destinationChainId,
|
|
134
|
+
setDestinationChainId,
|
|
135
|
+
transactionStates,
|
|
136
|
+
setTransactionStates,
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
const WidgetInner = forwardRef(({ appId: sequenceProjectAccessKey, sequenceIndexerUrl, sequenceApiUrl, sequenceEnv, toAddress, toAmount, toChainId, toToken, toCalldata, children, renderInline = true, theme: initialTheme = "auto", walletOptions, onOriginConfirmation, onDestinationConfirmation, useSourceTokenForButtonText, paymasterUrls, gasless, buttonText, }, ref) => {
|
|
140
|
+
const { address, isConnected, chainId, connector } = useAccount();
|
|
141
|
+
const { disconnectAsync } = useDisconnect();
|
|
142
|
+
const { theme } = useThemeManager(initialTheme);
|
|
143
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
144
|
+
const [currentScreen, setCurrentScreen] = useState(isConnected ? "tokens" : "connect");
|
|
145
|
+
const [selectedToken, setSelectedToken] = useState(null);
|
|
146
|
+
const [error, setError] = useState(null);
|
|
147
|
+
const [intentAddress, setIntentAddress] = useState(null);
|
|
148
|
+
const [originTokenInfo, setOriginTokenInfo] = useState(null);
|
|
149
|
+
const [showWalletConfirmRetry, setShowWalletConfirmRetry] = useState(false);
|
|
150
|
+
const [walletConfirmRetryHandler, setWalletConfirmRetryHandler] = useState(null);
|
|
151
|
+
const { connect } = useConnect();
|
|
152
|
+
const { connectWallet: privyConnectWallet, ready: privyReady, logout: privyLogout, } = usePrivy();
|
|
153
|
+
const { login: loginPrivy } = useLogin();
|
|
154
|
+
const { wallets: privyWallets } = usePrivyWallets();
|
|
155
|
+
const { setActiveWallet: setPrivyActiveWallet } = useSetActiveWallet();
|
|
156
|
+
const usePrivyLogin = true; // Set to true to use Privy email login options
|
|
157
|
+
const walletClient = useWalletManager(address, chainId, connector);
|
|
158
|
+
const { setOriginTxHash, setDestinationTxHash, setDestinationChainId, setOriginChainId, transactionStates, setTransactionStates, } = useTransactionState(onOriginConfirmation, onDestinationConfirmation);
|
|
159
|
+
// Update screen based on connection state
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (isConnected) {
|
|
162
|
+
if (currentScreen === "connect") {
|
|
163
|
+
setCurrentScreen("tokens");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
if (currentScreen !== "connect") {
|
|
168
|
+
setTimeout(() => {
|
|
169
|
+
setCurrentScreen("connect");
|
|
170
|
+
}, 0);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}, [isConnected, currentScreen]);
|
|
174
|
+
const indexerGatewayClient = useIndexerGatewayClient({
|
|
175
|
+
indexerGatewayUrl: sequenceIndexerUrl || undefined,
|
|
176
|
+
projectAccessKey: sequenceProjectAccessKey,
|
|
177
|
+
});
|
|
178
|
+
const apiClient = useAPIClient({
|
|
179
|
+
apiUrl: sequenceApiUrl || undefined,
|
|
180
|
+
projectAccessKey: sequenceProjectAccessKey,
|
|
181
|
+
});
|
|
182
|
+
const handleWalletConnect = async (walletId) => {
|
|
183
|
+
try {
|
|
184
|
+
setError(null);
|
|
185
|
+
const config = WALLET_CONFIGS[walletId];
|
|
186
|
+
if (!config) {
|
|
187
|
+
setError(`No configuration found for wallet: ${walletId}`);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (walletId === "injected") {
|
|
191
|
+
await connect({ connector: config.connector() });
|
|
192
|
+
}
|
|
193
|
+
else if (walletId === "privy") {
|
|
194
|
+
console.log("[trails-sdk] Privy ready", privyReady);
|
|
195
|
+
if (!privyReady) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
await disconnectAsync();
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
console.error("[trails-sdk] Failed to disconnect", error);
|
|
203
|
+
}
|
|
204
|
+
if (usePrivyLogin) {
|
|
205
|
+
try {
|
|
206
|
+
await privyLogout();
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
console.error("[trails-sdk] Failed to logout Privy", error);
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
await loginPrivy();
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
console.error("[trails-sdk] Failed to login Privy", error);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
await privyConnectWallet();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
console.log(`[trails-sdk] Connected to ${config.name}`);
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
console.error("[trails-sdk] Failed to connect:", error);
|
|
226
|
+
setError(error instanceof Error ? error.message : "Failed to connect wallet");
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
if (privyWallets?.length === 0 || !walletOptions?.includes("privy")) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const latestWallet = privyWallets?.sort((a, b) => a.connectedAt - b.connectedAt)?.[0];
|
|
234
|
+
if (latestWallet) {
|
|
235
|
+
console.log("[trails-sdk] Setting Privy active wallet", latestWallet);
|
|
236
|
+
setPrivyActiveWallet(latestWallet);
|
|
237
|
+
}
|
|
238
|
+
}, [privyWallets, setPrivyActiveWallet, walletOptions]);
|
|
239
|
+
const handleWalletDisconnect = () => {
|
|
240
|
+
setError(null);
|
|
241
|
+
if (connector?.name?.toLowerCase()?.includes("privy")) {
|
|
242
|
+
Promise.resolve()
|
|
243
|
+
.then(async () => {
|
|
244
|
+
try {
|
|
245
|
+
await disconnectAsync();
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
console.error("[trails-sdk] Failed to disconnect", error);
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
.then(async () => {
|
|
252
|
+
try {
|
|
253
|
+
await privyLogout();
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
console.error("[trails-sdk] Failed to logout Privy", error);
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
.then(async () => {
|
|
260
|
+
setPrivyActiveWallet(null);
|
|
261
|
+
})
|
|
262
|
+
.finally(() => {
|
|
263
|
+
setCurrentScreen("connect");
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
setCurrentScreen("connect");
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const handleContinue = () => {
|
|
271
|
+
setCurrentScreen("tokens");
|
|
272
|
+
};
|
|
273
|
+
const getAvailableWallets = () => {
|
|
274
|
+
const requestedWallets = walletOptions || defaultWalletOptions;
|
|
275
|
+
const availableWallets = requestedWallets
|
|
276
|
+
.filter((id) => WALLET_CONFIGS[id])
|
|
277
|
+
.map((id) => {
|
|
278
|
+
const config = WALLET_CONFIGS[id];
|
|
279
|
+
if (!config)
|
|
280
|
+
return null;
|
|
281
|
+
return {
|
|
282
|
+
id: config.id,
|
|
283
|
+
name: config.name,
|
|
284
|
+
};
|
|
285
|
+
})
|
|
286
|
+
.filter(Boolean);
|
|
287
|
+
return availableWallets;
|
|
288
|
+
};
|
|
289
|
+
const handleTokenSelect = (token) => {
|
|
290
|
+
try {
|
|
291
|
+
setError(null);
|
|
292
|
+
setSelectedToken(token);
|
|
293
|
+
setCurrentScreen("send");
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
setError(err instanceof Error ? err.message : "An unknown error occurred");
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
const handleOnSend = async (amount, recipient) => {
|
|
300
|
+
console.log("[trails-sdk] handleOnSend", amount, recipient);
|
|
301
|
+
};
|
|
302
|
+
const handleSendAnother = () => {
|
|
303
|
+
setCurrentScreen("tokens");
|
|
304
|
+
resetState();
|
|
305
|
+
};
|
|
306
|
+
const resetState = useCallback(() => {
|
|
307
|
+
setCurrentScreen("connect");
|
|
308
|
+
setSelectedToken(null);
|
|
309
|
+
setOriginTxHash("");
|
|
310
|
+
setOriginChainId(null);
|
|
311
|
+
setDestinationTxHash("");
|
|
312
|
+
setDestinationChainId(null);
|
|
313
|
+
setTransactionStates([]);
|
|
314
|
+
setIntentAddress(null);
|
|
315
|
+
setOriginTokenInfo(null);
|
|
316
|
+
}, [
|
|
317
|
+
setDestinationTxHash,
|
|
318
|
+
setDestinationChainId,
|
|
319
|
+
setTransactionStates,
|
|
320
|
+
setOriginTxHash,
|
|
321
|
+
setOriginChainId,
|
|
322
|
+
]);
|
|
323
|
+
// Expose modal control methods via ref
|
|
324
|
+
useImperativeHandle(ref, () => ({
|
|
325
|
+
openModal: () => {
|
|
326
|
+
setIsModalOpen(true);
|
|
327
|
+
},
|
|
328
|
+
closeModal: () => {
|
|
329
|
+
setIsModalOpen(false);
|
|
330
|
+
resetState();
|
|
331
|
+
},
|
|
332
|
+
isModalOpen,
|
|
333
|
+
}), [isModalOpen, resetState]);
|
|
334
|
+
const handleCloseModal = () => {
|
|
335
|
+
setIsModalOpen(false);
|
|
336
|
+
resetState();
|
|
337
|
+
};
|
|
338
|
+
const handleBack = () => {
|
|
339
|
+
setError(null);
|
|
340
|
+
switch (currentScreen) {
|
|
341
|
+
case "tokens":
|
|
342
|
+
setCurrentScreen("connect");
|
|
343
|
+
break;
|
|
344
|
+
case "send":
|
|
345
|
+
setCurrentScreen("tokens");
|
|
346
|
+
setSelectedToken(null);
|
|
347
|
+
break;
|
|
348
|
+
case "wallet-confirmation":
|
|
349
|
+
setCurrentScreen("send");
|
|
350
|
+
break;
|
|
351
|
+
case "receipt":
|
|
352
|
+
setCurrentScreen("tokens");
|
|
353
|
+
setSelectedToken(null);
|
|
354
|
+
setDestinationTxHash("");
|
|
355
|
+
setDestinationChainId(null);
|
|
356
|
+
setOriginTxHash("");
|
|
357
|
+
setOriginChainId(null);
|
|
358
|
+
break;
|
|
359
|
+
default:
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
function handleTransferComplete(data) {
|
|
364
|
+
if (data) {
|
|
365
|
+
if (data.originUserTxReceipt) {
|
|
366
|
+
setOriginTxHash(data.originUserTxReceipt.transactionHash);
|
|
367
|
+
}
|
|
368
|
+
if (data.originChainId) {
|
|
369
|
+
setOriginChainId(data.originChainId);
|
|
370
|
+
}
|
|
371
|
+
if (data.destinationMetaTxnReceipt || data.originUserTxReceipt) {
|
|
372
|
+
setDestinationTxHash(data.destinationMetaTxnReceipt?.txnHash ||
|
|
373
|
+
data.originUserTxReceipt?.transactionHash);
|
|
374
|
+
}
|
|
375
|
+
if (data.destinationChainId) {
|
|
376
|
+
setDestinationChainId(data.destinationChainId);
|
|
377
|
+
}
|
|
378
|
+
setCurrentScreen("receipt");
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
function handleTransactionStateChange(_transactionStates) {
|
|
382
|
+
console.log("[trails-sdk] transactionStates from widget", _transactionStates);
|
|
383
|
+
setTransactionStates([..._transactionStates]);
|
|
384
|
+
}
|
|
385
|
+
const handleDebugScreenSelect = (screen) => {
|
|
386
|
+
// Reset necessary state based on the target screen
|
|
387
|
+
setError(null);
|
|
388
|
+
switch (screen.toLowerCase()) {
|
|
389
|
+
case "connect":
|
|
390
|
+
setCurrentScreen("connect");
|
|
391
|
+
setSelectedToken(null);
|
|
392
|
+
setTransactionStates([]);
|
|
393
|
+
break;
|
|
394
|
+
case "tokens":
|
|
395
|
+
if (isConnected) {
|
|
396
|
+
setCurrentScreen("tokens");
|
|
397
|
+
setSelectedToken(null);
|
|
398
|
+
setTransactionStates([]);
|
|
399
|
+
}
|
|
400
|
+
break;
|
|
401
|
+
case "send":
|
|
402
|
+
// Set dummy USDC token for debug mode
|
|
403
|
+
setSelectedToken({
|
|
404
|
+
id: 1,
|
|
405
|
+
name: "USD Coin",
|
|
406
|
+
symbol: "USDC",
|
|
407
|
+
balance: "1000000000",
|
|
408
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
409
|
+
chainId: 1,
|
|
410
|
+
contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
411
|
+
contractInfo: {
|
|
412
|
+
decimals: 6,
|
|
413
|
+
symbol: "USDC",
|
|
414
|
+
name: "USD Coin",
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
setCurrentScreen("send");
|
|
418
|
+
setTransactionStates([]);
|
|
419
|
+
break;
|
|
420
|
+
case "wallet confirmation":
|
|
421
|
+
// Set dummy USDC token for debug mode
|
|
422
|
+
setSelectedToken({
|
|
423
|
+
id: 1,
|
|
424
|
+
name: "USD Coin",
|
|
425
|
+
symbol: "USDC",
|
|
426
|
+
balance: "1000000000",
|
|
427
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
428
|
+
chainId: 1,
|
|
429
|
+
contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
430
|
+
contractInfo: {
|
|
431
|
+
decimals: 6,
|
|
432
|
+
symbol: "USDC",
|
|
433
|
+
name: "USD Coin",
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
setCurrentScreen("wallet-confirmation");
|
|
437
|
+
setIntentAddress("0x5A0fb747531bC369367CB031472b89ea4D5c6Df7");
|
|
438
|
+
setOriginTokenInfo({
|
|
439
|
+
amount: "1",
|
|
440
|
+
amountUsd: "$0.01",
|
|
441
|
+
tokenSymbol: "USDC",
|
|
442
|
+
tokenName: "USD Coin",
|
|
443
|
+
chainId: 137,
|
|
444
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
445
|
+
});
|
|
446
|
+
setTransactionStates([]);
|
|
447
|
+
break;
|
|
448
|
+
case "pending 1-item-0-confirmed":
|
|
449
|
+
// Set dummy transaction states for debug mode - showing all steps
|
|
450
|
+
setTransactionStates([
|
|
451
|
+
{
|
|
452
|
+
transactionHash: "0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
453
|
+
explorerUrl: "https://polygonscan.com/tx/0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
454
|
+
chainId: 137,
|
|
455
|
+
state: "pending",
|
|
456
|
+
label: "Swap",
|
|
457
|
+
},
|
|
458
|
+
]);
|
|
459
|
+
setOriginTokenInfo({
|
|
460
|
+
amount: "10000",
|
|
461
|
+
amountUsd: "$0.01",
|
|
462
|
+
tokenSymbol: "USDC",
|
|
463
|
+
tokenName: "USD Coin",
|
|
464
|
+
chainId: 137,
|
|
465
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
466
|
+
});
|
|
467
|
+
setCurrentScreen("pending");
|
|
468
|
+
break;
|
|
469
|
+
case "pending 1-item-1-confirmed":
|
|
470
|
+
// Set dummy transaction states for debug mode - showing all steps
|
|
471
|
+
setTransactionStates([
|
|
472
|
+
{
|
|
473
|
+
transactionHash: "0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
474
|
+
explorerUrl: "https://polygonscan.com/tx/0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
475
|
+
chainId: 137,
|
|
476
|
+
state: "confirmed",
|
|
477
|
+
label: "Swap",
|
|
478
|
+
},
|
|
479
|
+
]);
|
|
480
|
+
setOriginTokenInfo({
|
|
481
|
+
amount: "10000",
|
|
482
|
+
amountUsd: "$0.01",
|
|
483
|
+
tokenSymbol: "USDC",
|
|
484
|
+
tokenName: "USD Coin",
|
|
485
|
+
chainId: 137,
|
|
486
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
487
|
+
});
|
|
488
|
+
setCurrentScreen("pending");
|
|
489
|
+
break;
|
|
490
|
+
case "pending 2-item-0-confirmed":
|
|
491
|
+
// Set dummy transaction states for debug mode - showing all steps
|
|
492
|
+
setTransactionStates([
|
|
493
|
+
{
|
|
494
|
+
transactionHash: "0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
495
|
+
explorerUrl: "https://polygonscan.com/tx/0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
496
|
+
chainId: 137,
|
|
497
|
+
state: "pending",
|
|
498
|
+
label: "Transfer",
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
transactionHash: "0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
502
|
+
explorerUrl: "https://polygonscan.com/tx/0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
503
|
+
chainId: 137,
|
|
504
|
+
state: "pending",
|
|
505
|
+
label: "Swap",
|
|
506
|
+
},
|
|
507
|
+
]);
|
|
508
|
+
setOriginTokenInfo({
|
|
509
|
+
amount: "10000",
|
|
510
|
+
amountUsd: "$0.01",
|
|
511
|
+
tokenSymbol: "USDC",
|
|
512
|
+
tokenName: "USD Coin",
|
|
513
|
+
chainId: 137,
|
|
514
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
515
|
+
});
|
|
516
|
+
setCurrentScreen("pending");
|
|
517
|
+
break;
|
|
518
|
+
case "pending 2-item-1-confirmed":
|
|
519
|
+
// Set dummy transaction states for debug mode - showing all steps
|
|
520
|
+
setTransactionStates([
|
|
521
|
+
{
|
|
522
|
+
transactionHash: "0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
523
|
+
explorerUrl: "https://polygonscan.com/tx/0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
524
|
+
chainId: 137,
|
|
525
|
+
state: "confirmed",
|
|
526
|
+
label: "Transfer",
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
transactionHash: "0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
530
|
+
explorerUrl: "https://polygonscan.com/tx/0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
531
|
+
chainId: 137,
|
|
532
|
+
state: "pending",
|
|
533
|
+
label: "Swap",
|
|
534
|
+
},
|
|
535
|
+
]);
|
|
536
|
+
setOriginTokenInfo({
|
|
537
|
+
amount: "10000",
|
|
538
|
+
amountUsd: "$0.01",
|
|
539
|
+
tokenSymbol: "USDC",
|
|
540
|
+
tokenName: "USD Coin",
|
|
541
|
+
chainId: 137,
|
|
542
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
543
|
+
});
|
|
544
|
+
setCurrentScreen("pending");
|
|
545
|
+
break;
|
|
546
|
+
case "pending 2-item-2-confirmed":
|
|
547
|
+
// Set dummy transaction states for debug mode - showing all steps
|
|
548
|
+
setTransactionStates([
|
|
549
|
+
{
|
|
550
|
+
transactionHash: "0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
551
|
+
explorerUrl: "https://polygonscan.com/tx/0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
552
|
+
chainId: 137,
|
|
553
|
+
state: "confirmed",
|
|
554
|
+
label: "Transfer",
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
transactionHash: "0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
558
|
+
explorerUrl: "https://polygonscan.com/tx/0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
559
|
+
chainId: 137,
|
|
560
|
+
state: "confirmed",
|
|
561
|
+
label: "Swap",
|
|
562
|
+
},
|
|
563
|
+
]);
|
|
564
|
+
setOriginTokenInfo({
|
|
565
|
+
amount: "10000",
|
|
566
|
+
amountUsd: "$0.01",
|
|
567
|
+
tokenSymbol: "USDC",
|
|
568
|
+
tokenName: "USD Coin",
|
|
569
|
+
chainId: 137,
|
|
570
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
571
|
+
});
|
|
572
|
+
setCurrentScreen("pending");
|
|
573
|
+
break;
|
|
574
|
+
case "pending 3-item-0-confirmed":
|
|
575
|
+
// Set dummy transaction states for debug mode - showing all steps
|
|
576
|
+
setTransactionStates([
|
|
577
|
+
{
|
|
578
|
+
transactionHash: "0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
579
|
+
explorerUrl: "https://polygonscan.com/tx/0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
580
|
+
chainId: 137,
|
|
581
|
+
state: "pending",
|
|
582
|
+
label: "Transfer",
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
transactionHash: "0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
586
|
+
explorerUrl: "https://polygonscan.com/tx/0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
587
|
+
chainId: 137,
|
|
588
|
+
state: "pending",
|
|
589
|
+
label: "Swap & Bridge",
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
transactionHash: "0xf3b172111d2e64e9d4940d91097f04a0bbd0acc816e2cf49eec664c6f8fcaf76",
|
|
593
|
+
explorerUrl: "https://arbiscan.io/tx/0xf3b172111d2e64e9d4940d91097f04a0bbd0acc816e2cf49eec664c6f8fcaf76",
|
|
594
|
+
chainId: 42161,
|
|
595
|
+
state: "pending",
|
|
596
|
+
label: "Execute",
|
|
597
|
+
},
|
|
598
|
+
]);
|
|
599
|
+
setOriginTokenInfo({
|
|
600
|
+
amount: "10000",
|
|
601
|
+
amountUsd: "$0.01",
|
|
602
|
+
tokenSymbol: "USDC",
|
|
603
|
+
tokenName: "USD Coin",
|
|
604
|
+
chainId: 137,
|
|
605
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
606
|
+
});
|
|
607
|
+
setCurrentScreen("pending");
|
|
608
|
+
break;
|
|
609
|
+
case "pending 3-item-1-confirmed":
|
|
610
|
+
// Set dummy transaction states for debug mode - showing all steps
|
|
611
|
+
setTransactionStates([
|
|
612
|
+
{
|
|
613
|
+
transactionHash: "0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
614
|
+
explorerUrl: "https://polygonscan.com/tx/0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
615
|
+
chainId: 137,
|
|
616
|
+
state: "confirmed",
|
|
617
|
+
label: "Transfer",
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
transactionHash: "0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
621
|
+
explorerUrl: "https://polygonscan.com/tx/0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
622
|
+
chainId: 137,
|
|
623
|
+
state: "pending",
|
|
624
|
+
label: "Swap & Bridge",
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
transactionHash: "0xf3b172111d2e64e9d4940d91097f04a0bbd0acc816e2cf49eec664c6f8fcaf76",
|
|
628
|
+
explorerUrl: "https://arbiscan.io/tx/0xf3b172111d2e64e9d4940d91097f04a0bbd0acc816e2cf49eec664c6f8fcaf76",
|
|
629
|
+
chainId: 42161,
|
|
630
|
+
state: "pending",
|
|
631
|
+
label: "Execute",
|
|
632
|
+
},
|
|
633
|
+
]);
|
|
634
|
+
setOriginTokenInfo({
|
|
635
|
+
amount: "10000",
|
|
636
|
+
amountUsd: "$0.01",
|
|
637
|
+
tokenSymbol: "USDC",
|
|
638
|
+
tokenName: "USD Coin",
|
|
639
|
+
chainId: 137,
|
|
640
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
641
|
+
});
|
|
642
|
+
setCurrentScreen("pending");
|
|
643
|
+
break;
|
|
644
|
+
case "pending 3-item-2-confirmed":
|
|
645
|
+
// Set dummy transaction states for debug mode - showing all steps
|
|
646
|
+
setTransactionStates([
|
|
647
|
+
{
|
|
648
|
+
transactionHash: "0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
649
|
+
explorerUrl: "https://polygonscan.com/tx/0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
650
|
+
chainId: 137,
|
|
651
|
+
state: "confirmed",
|
|
652
|
+
label: "Transfer",
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
transactionHash: "0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
656
|
+
explorerUrl: "https://polygonscan.com/tx/0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
657
|
+
chainId: 137,
|
|
658
|
+
state: "confirmed",
|
|
659
|
+
label: "Swap & Bridge",
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
transactionHash: "0xf3b172111d2e64e9d4940d91097f04a0bbd0acc816e2cf49eec664c6f8fcaf76",
|
|
663
|
+
explorerUrl: "https://arbiscan.io/tx/0xf3b172111d2e64e9d4940d91097f04a0bbd0acc816e2cf49eec664c6f8fcaf76",
|
|
664
|
+
chainId: 42161,
|
|
665
|
+
state: "pending",
|
|
666
|
+
label: "Execute",
|
|
667
|
+
},
|
|
668
|
+
]);
|
|
669
|
+
setOriginTokenInfo({
|
|
670
|
+
amount: "10000",
|
|
671
|
+
amountUsd: "$0.01",
|
|
672
|
+
tokenSymbol: "USDC",
|
|
673
|
+
tokenName: "USD Coin",
|
|
674
|
+
chainId: 137,
|
|
675
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
676
|
+
});
|
|
677
|
+
setCurrentScreen("pending");
|
|
678
|
+
break;
|
|
679
|
+
case "pending 3-item-3-confirmed":
|
|
680
|
+
// Set dummy transaction states for debug mode - showing all steps
|
|
681
|
+
setTransactionStates([
|
|
682
|
+
{
|
|
683
|
+
transactionHash: "0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
684
|
+
explorerUrl: "https://polygonscan.com/tx/0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
685
|
+
chainId: 137,
|
|
686
|
+
state: "confirmed",
|
|
687
|
+
label: "Transfer",
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
transactionHash: "0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
691
|
+
explorerUrl: "https://polygonscan.com/tx/0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
692
|
+
chainId: 137,
|
|
693
|
+
state: "confirmed",
|
|
694
|
+
label: "Swap & Bridge",
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
transactionHash: "0xf3b172111d2e64e9d4940d91097f04a0bbd0acc816e2cf49eec664c6f8fcaf76",
|
|
698
|
+
explorerUrl: "https://arbiscan.io/tx/0xf3b172111d2e64e9d4940d91097f04a0bbd0acc816e2cf49eec664c6f8fcaf76",
|
|
699
|
+
chainId: 42161,
|
|
700
|
+
state: "confirmed",
|
|
701
|
+
label: "Execute",
|
|
702
|
+
},
|
|
703
|
+
]);
|
|
704
|
+
setOriginTokenInfo({
|
|
705
|
+
amount: "10000",
|
|
706
|
+
amountUsd: "$0.01",
|
|
707
|
+
tokenSymbol: "USDC",
|
|
708
|
+
tokenName: "USD Coin",
|
|
709
|
+
chainId: 137,
|
|
710
|
+
imageUrl: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
711
|
+
});
|
|
712
|
+
setCurrentScreen("pending");
|
|
713
|
+
break;
|
|
714
|
+
case "receipt":
|
|
715
|
+
// Set dummy transaction states data for debug mode
|
|
716
|
+
setTransactionStates([
|
|
717
|
+
{
|
|
718
|
+
transactionHash: "0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
719
|
+
explorerUrl: "https://polygonscan.com/tx/0x45bb2259631e73f32841a6058b0a4008c75bca296942bec6326d188978d5353d",
|
|
720
|
+
chainId: 137,
|
|
721
|
+
state: "confirmed",
|
|
722
|
+
label: "Transfer",
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
transactionHash: "0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
726
|
+
explorerUrl: "https://polygonscan.com/tx/0x6ff30196ca0d4998cc6928bca2ec282766eb3c3997535e0a61e0d69c9c9b16b8",
|
|
727
|
+
chainId: 137,
|
|
728
|
+
state: "confirmed",
|
|
729
|
+
label: "Swap & Bridge",
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
transactionHash: "0xf3b172111d2e64e9d4940d91097f04a0bbd0acc816e2cf49eec664c6f8fcaf76",
|
|
733
|
+
explorerUrl: "https://arbiscan.io/tx/0xf3b172111d2e64e9d4940d91097f04a0bbd0acc816e2cf49eec664c6f8fcaf76",
|
|
734
|
+
chainId: 42161,
|
|
735
|
+
state: "confirmed",
|
|
736
|
+
label: "Execute",
|
|
737
|
+
},
|
|
738
|
+
]);
|
|
739
|
+
setCurrentScreen("receipt");
|
|
740
|
+
break;
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
const handleSendError = (error) => {
|
|
744
|
+
if (error) {
|
|
745
|
+
console.error("[trails-sdk] Error sending transaction", error);
|
|
746
|
+
}
|
|
747
|
+
const errorMessage = error instanceof Error ? error.message : error;
|
|
748
|
+
if (errorMessage?.toLowerCase().includes("rejected")) {
|
|
749
|
+
console.log("[trails-sdk] currentScreen", currentScreen);
|
|
750
|
+
setShowWalletConfirmRetry(true);
|
|
751
|
+
}
|
|
752
|
+
else {
|
|
753
|
+
setError(errorMessage);
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
const handleConnectError = (error) => {
|
|
757
|
+
if (error) {
|
|
758
|
+
console.error("[trails-sdk] Error connecting wallet", error);
|
|
759
|
+
}
|
|
760
|
+
setError(error instanceof Error ? error.message : error);
|
|
761
|
+
};
|
|
762
|
+
const handleTokenListError = (error) => {
|
|
763
|
+
if (error) {
|
|
764
|
+
console.error("[trails-sdk] Error selecting token", error);
|
|
765
|
+
}
|
|
766
|
+
setError(error instanceof Error ? error.message : error);
|
|
767
|
+
};
|
|
768
|
+
const handleWaitingForWalletConfirm = (intentAddress, details) => {
|
|
769
|
+
setShowWalletConfirmRetry(false);
|
|
770
|
+
setCurrentScreen("wallet-confirmation");
|
|
771
|
+
setIntentAddress(intentAddress ?? null);
|
|
772
|
+
setOriginTokenInfo(details ?? null);
|
|
773
|
+
};
|
|
774
|
+
async function handleWalletConfirmRetry() {
|
|
775
|
+
if (!walletConfirmRetryHandler) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
try {
|
|
779
|
+
setShowWalletConfirmRetry(false);
|
|
780
|
+
await walletConfirmRetryHandler();
|
|
781
|
+
}
|
|
782
|
+
catch (error) {
|
|
783
|
+
console.error("[trails-sdk] Error retrying wallet confirmation", error);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
const { amountUsd: targetAmountUsd, amountUsdFormatted: targetAmountUsdFormatted, } = useAmountUsd({
|
|
787
|
+
amount: toAmount,
|
|
788
|
+
token: toToken,
|
|
789
|
+
chainId: Number(toChainId),
|
|
790
|
+
apiClient: apiClient,
|
|
791
|
+
});
|
|
792
|
+
const renderScreenContent = () => {
|
|
793
|
+
switch (currentScreen) {
|
|
794
|
+
case "connect":
|
|
795
|
+
return (_jsx(ConnectWallet, { onConnect: handleWalletConnect, onDisconnect: handleWalletDisconnect, onContinue: handleContinue, theme: theme, walletOptions: getAvailableWallets(), onError: handleConnectError }));
|
|
796
|
+
case "tokens":
|
|
797
|
+
return (_jsx(TokenList, { onContinue: handleTokenSelect, onBack: handleBack, indexerGatewayClient: indexerGatewayClient, theme: theme, targetAmountUsd: targetAmountUsd, targetAmountUsdFormatted: targetAmountUsdFormatted, onError: handleTokenListError }));
|
|
798
|
+
case "send":
|
|
799
|
+
return selectedToken && walletClient?.account ? (_jsx(SendForm, { onSend: handleOnSend, onBack: handleBack, onWaitingForWalletConfirm: handleWaitingForWalletConfirm, onConfirm: () => setCurrentScreen("pending"), onComplete: handleTransferComplete, selectedToken: selectedToken, account: walletClient.account, sequenceProjectAccessKey: sequenceProjectAccessKey, apiUrl: sequenceApiUrl || undefined, env: sequenceEnv, toRecipient: toAddress || undefined, toAmount: toAmount || undefined, toChainId: toChainId ? Number(toChainId) : undefined, toToken: toToken || undefined, toCalldata: toCalldata || undefined, walletClient: walletClient, theme: theme, onTransactionStateChange: handleTransactionStateChange, useSourceTokenForButtonText: useSourceTokenForButtonText, onError: handleSendError, paymasterUrls: paymasterUrls, gasless: gasless, setWalletConfirmRetryHandler: setWalletConfirmRetryHandler })) : (_jsx("div", { className: `text-center p-4 rounded-lg ${theme === "dark"
|
|
800
|
+
? "text-gray-300 bg-gray-800"
|
|
801
|
+
: "text-gray-600 bg-gray-50"}`, children: "Please connect wallet" }));
|
|
802
|
+
case "wallet-confirmation":
|
|
803
|
+
return (_jsx(WalletConfirmation, { onBack: handleBack, onComplete: () => setCurrentScreen("pending"), theme: theme, amount: originTokenInfo?.amount ?? undefined, recipient: intentAddress ?? "", tokenSymbol: selectedToken?.symbol, retryEnabled: showWalletConfirmRetry, onRetry: handleWalletConfirmRetry, fromTokenSymbol: originTokenInfo?.tokenSymbol || "", fromChainId: originTokenInfo?.chainId || 0, fromTokenImageUrl: originTokenInfo?.imageUrl || "" }));
|
|
804
|
+
case "pending":
|
|
805
|
+
return (_jsx(TransferPending, { onComplete: handleTransferComplete, theme: theme, transactionStates: transactionStates, fromAmount: originTokenInfo?.amount || "", fromAmountUsd: originTokenInfo?.amountUsd || "", fromTokenSymbol: originTokenInfo?.tokenSymbol || "", fromTokenName: originTokenInfo?.tokenName || "", fromChainId: originTokenInfo?.chainId || 0, fromTokenImageUrl: originTokenInfo?.imageUrl || "" }));
|
|
806
|
+
case "receipt":
|
|
807
|
+
return (_jsx(Receipt, { onSendAnother: handleSendAnother, onClose: handleCloseModal, theme: theme, renderInline: renderInline, transactionStates: transactionStates }));
|
|
808
|
+
default:
|
|
809
|
+
return null;
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
const renderScreen = () => {
|
|
813
|
+
return (_jsxs(motion.div, { initial: { opacity: 0, scale: 0.95 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.95 }, transition: {
|
|
814
|
+
type: "spring",
|
|
815
|
+
stiffness: 200,
|
|
816
|
+
damping: 30,
|
|
817
|
+
mass: 1,
|
|
818
|
+
}, className: `flex flex-col min-h-[400px] rounded-[32px] shadow-xl p-4 sm:p-6 relative w-full sm:w-[400px] mx-auto ${theme === "dark"
|
|
819
|
+
? "bg-gray-900 text-white"
|
|
820
|
+
: "bg-white text-gray-900"}`, layout: true, layoutId: "modal-container", onClick: (e) => e.stopPropagation(), children: [_jsx(AnimatePresence, { mode: "wait", children: _jsxs(motion.div, { initial: { opacity: 0, x: 20 }, animate: { opacity: 1, x: 0 }, exit: { opacity: 0, x: -20 }, transition: {
|
|
821
|
+
type: "spring",
|
|
822
|
+
stiffness: 500,
|
|
823
|
+
damping: 30,
|
|
824
|
+
mass: 0.6,
|
|
825
|
+
}, className: "flex-1 flex flex-col w-full", layout: true, children: [renderScreenContent(), error && (_jsx("div", { className: `border rounded-lg p-4 mt-4 ${theme === "dark"
|
|
826
|
+
? "bg-red-900/20 border-red-800"
|
|
827
|
+
: "bg-red-50 border-red-200"}`, children: _jsx("p", { className: `text-sm break-words ${theme === "dark" ? "text-red-200" : "text-red-600"}`, children: error }) }))] }, currentScreen) }), _jsx(Footer, { theme: theme, onDebugScreenSelect: handleDebugScreenSelect })] }));
|
|
828
|
+
};
|
|
829
|
+
if (renderInline) {
|
|
830
|
+
return renderScreen();
|
|
831
|
+
}
|
|
832
|
+
return (_jsxs("div", { className: "flex flex-col items-center justify-center space-y-8 py-12", children: [!children ? (_jsx(motion.button, { whileHover: { scale: 1.02 }, whileTap: { scale: 0.98 }, onClick: () => setIsModalOpen(true), className: `${theme === "dark"
|
|
833
|
+
? "bg-blue-600 hover:bg-blue-700"
|
|
834
|
+
: "bg-blue-500 hover:bg-blue-600"} text-white cursor-pointer font-semibold py-3 px-6 rounded-[24px] shadow-sm transition-colors`, children: buttonText || "Pay" })) : (_jsx(motion.div, { whileHover: { scale: 1.02 }, whileTap: { scale: 0.98 }, className: "flex flex-col items-center justify-center", onClick: () => setIsModalOpen(true), children: children })), _jsx(AnimatePresence, { children: isModalOpen && (_jsx(Modal, { isOpen: isModalOpen, onClose: handleCloseModal, theme: theme, children: renderScreen() })) })] }));
|
|
835
|
+
});
|
|
836
|
+
export const TrailsWidget = forwardRef((props, ref) => {
|
|
837
|
+
const wagmiContext = useContext(WagmiContext);
|
|
838
|
+
const sequenceHooksContext = useContext(SequenceHooksContext);
|
|
839
|
+
// Check if privy is in walletOptions
|
|
840
|
+
// const walletOptions = props.walletOptions || defaultWalletOptions
|
|
841
|
+
const shouldUsePrivy = true; // walletOptions.includes('privy') // TODO: need to disable all privy hooks if walletOptions.includes('privy') is false
|
|
842
|
+
const wagmiConfig = React.useMemo(() => {
|
|
843
|
+
const chains = [mainnet];
|
|
844
|
+
const baseConfig = {
|
|
845
|
+
chains,
|
|
846
|
+
transports: Object.values(chains).reduce((acc, chain) => ({
|
|
847
|
+
...acc,
|
|
848
|
+
[chain.id]: http(),
|
|
849
|
+
}), {}),
|
|
850
|
+
};
|
|
851
|
+
if (shouldUsePrivy) {
|
|
852
|
+
return createPrivyWagmiConfig(baseConfig);
|
|
853
|
+
}
|
|
854
|
+
else {
|
|
855
|
+
return createConfig({
|
|
856
|
+
...baseConfig,
|
|
857
|
+
connectors: [injected()],
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
}, []);
|
|
861
|
+
// Create content with only the providers that don't exist in parent
|
|
862
|
+
const content = (() => {
|
|
863
|
+
const widgetContent = _jsx(WidgetInner, { ...props, ref: ref });
|
|
864
|
+
const baseContent = (_jsx(QueryClientProvider, { client: queryClient, children: sequenceHooksContext ? (
|
|
865
|
+
// SequenceHooksProvider exists in parent, don't wrap
|
|
866
|
+
wagmiContext ? (
|
|
867
|
+
// Both providers exist in parent, just render widget
|
|
868
|
+
widgetContent) : (
|
|
869
|
+
// Only WagmiProvider missing, wrap with it
|
|
870
|
+
_jsx(WagmiProvider, { config: wagmiConfig, children: widgetContent }))) : (
|
|
871
|
+
// SequenceHooksProvider missing, wrap with it
|
|
872
|
+
_jsx(SequenceHooksProvider, { config: {
|
|
873
|
+
projectAccessKey: props.appId,
|
|
874
|
+
env: {
|
|
875
|
+
indexerUrl: props.sequenceIndexerUrl || undefined,
|
|
876
|
+
indexerGatewayUrl: props.sequenceIndexerUrl || undefined,
|
|
877
|
+
apiUrl: props.sequenceApiUrl || undefined,
|
|
878
|
+
},
|
|
879
|
+
}, children: wagmiContext ? (
|
|
880
|
+
// WagmiProvider exists in parent, don't wrap
|
|
881
|
+
widgetContent) : (
|
|
882
|
+
// WagmiProvider missing, wrap with it
|
|
883
|
+
_jsx(WagmiProvider, { config: wagmiConfig, children: widgetContent })) })) }));
|
|
884
|
+
// Only wrap with PrivyProvider if privy is in walletOptions
|
|
885
|
+
if (shouldUsePrivy) {
|
|
886
|
+
return (_jsx(PrivyProvider, { appId: props.privyAppId || defaultPrivyAppId, clientId: props.privyClientId || defaultPrivyClientId, config: {
|
|
887
|
+
embeddedWallets: {
|
|
888
|
+
createOnLogin: "users-without-wallets",
|
|
889
|
+
requireUserPasswordOnCreate: true,
|
|
890
|
+
showWalletUIs: true,
|
|
891
|
+
},
|
|
892
|
+
loginMethods: ["google", "wallet", "email", "sms"],
|
|
893
|
+
appearance: {
|
|
894
|
+
showWalletLoginFirst: false,
|
|
895
|
+
walletList: [
|
|
896
|
+
"detected_wallets",
|
|
897
|
+
"metamask",
|
|
898
|
+
"coinbase_wallet",
|
|
899
|
+
"rainbow",
|
|
900
|
+
"zerion",
|
|
901
|
+
"uniswap",
|
|
902
|
+
"wallet_connect",
|
|
903
|
+
],
|
|
904
|
+
},
|
|
905
|
+
}, children: baseContent }));
|
|
906
|
+
}
|
|
907
|
+
return baseContent;
|
|
908
|
+
})();
|
|
909
|
+
return (_jsx(ShadowPortal, { children: _jsx(StrictMode, { children: content }) }));
|
|
910
|
+
});
|
|
911
|
+
export function ShadowPortal({ children }) {
|
|
912
|
+
const hostRef = useRef(null);
|
|
913
|
+
const [shadowRoot, setShadowRoot] = useState(null);
|
|
914
|
+
useEffect(() => {
|
|
915
|
+
if (hostRef.current && !hostRef.current.shadowRoot) {
|
|
916
|
+
const shadow = hostRef.current.attachShadow({ mode: "open" });
|
|
917
|
+
setShadowRoot(shadow);
|
|
918
|
+
// Inject <style> tag with your widget's CSS
|
|
919
|
+
const styleTag = document.createElement("style");
|
|
920
|
+
styleTag.textContent = css;
|
|
921
|
+
shadow.appendChild(styleTag);
|
|
922
|
+
}
|
|
923
|
+
}, []);
|
|
924
|
+
return (_jsx("div", { ref: hostRef, children: shadowRoot ? createPortal(children, shadowRoot) : null }));
|
|
925
|
+
}
|
|
926
|
+
// Export standalone functions for modal control
|
|
927
|
+
export const createModalController = (ref) => ({
|
|
928
|
+
openModal: () => ref.current?.openModal?.(),
|
|
929
|
+
closeModal: () => ref.current?.closeModal?.(),
|
|
930
|
+
isModalOpen: ref.current?.isModalOpen ?? false,
|
|
931
|
+
});
|
|
932
|
+
export default TrailsWidget;
|