@b3dotfun/sdk 0.0.82-alpha.1 → 0.0.82-alpha.3
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/cjs/anyspend/react/components/AnySpend.js +0 -3
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +0 -3
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +12 -25
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +0 -3
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +0 -3
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +0 -3
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +12 -25
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +0 -3
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +0 -4
- package/src/anyspend/react/components/AnySpendCustom.tsx +0 -4
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +12 -58
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +0 -4
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +0 -73
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +0 -70
- package/dist/types/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +0 -80
|
@@ -22,7 +22,6 @@ const react_4 = require("react");
|
|
|
22
22
|
const viem_1 = require("viem");
|
|
23
23
|
const chains_1 = require("viem/chains");
|
|
24
24
|
const useAutoSelectCryptoPaymentMethod_1 = require("../hooks/useAutoSelectCryptoPaymentMethod");
|
|
25
|
-
const useAutoSetActiveWalletFromWagmi_1 = require("../hooks/useAutoSetActiveWalletFromWagmi");
|
|
26
25
|
const useConnectedWalletDisplay_1 = require("../hooks/useConnectedWalletDisplay");
|
|
27
26
|
const useCryptoPaymentMethodState_1 = require("../hooks/useCryptoPaymentMethodState");
|
|
28
27
|
const useRecipientAddressState_1 = require("../hooks/useRecipientAddressState");
|
|
@@ -320,8 +319,6 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
320
319
|
// );
|
|
321
320
|
const { address: globalAddress, wallet: globalWallet, connectedEOAWallet } = (0, react_2.useAccountWallet)();
|
|
322
321
|
const globalWalletImage = (0, useAccountWallet_1.useAccountWalletImage)();
|
|
323
|
-
// Auto-set active wallet from wagmi
|
|
324
|
-
(0, useAutoSetActiveWalletFromWagmi_1.useAutoSetActiveWalletFromWagmi)();
|
|
325
322
|
// Get wallet address based on selected payment method
|
|
326
323
|
const { walletAddress } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(effectiveCryptoPaymentMethod);
|
|
327
324
|
// Recipient address state with dual-state system (auto + explicit user selection)
|
|
@@ -52,7 +52,6 @@ const lucide_react_1 = require("lucide-react");
|
|
|
52
52
|
const react_4 = require("motion/react");
|
|
53
53
|
const react_5 = __importStar(require("react"));
|
|
54
54
|
const chains_1 = require("viem/chains");
|
|
55
|
-
const useAutoSetActiveWalletFromWagmi_1 = require("../hooks/useAutoSetActiveWalletFromWagmi");
|
|
56
55
|
const useCryptoPaymentMethodState_1 = require("../hooks/useCryptoPaymentMethodState");
|
|
57
56
|
const useRecipientAddressState_1 = require("../hooks/useRecipientAddressState");
|
|
58
57
|
const AnySpendFingerprintWrapper_1 = require("./AnySpendFingerprintWrapper");
|
|
@@ -150,8 +149,6 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
150
149
|
const hasMounted = (0, react_2.useHasMounted)();
|
|
151
150
|
const searchParams = (0, react_2.useSearchParamsSSR)();
|
|
152
151
|
const router = (0, react_2.useRouter)();
|
|
153
|
-
// Auto-set active wallet from wagmi
|
|
154
|
-
(0, useAutoSetActiveWalletFromWagmi_1.useAutoSetActiveWalletFromWagmi)();
|
|
155
152
|
const [activePanel, setActivePanel] = (0, react_5.useState)(loadOrder ? PanelView.ORDER_DETAILS : PanelView.CONFIRM_ORDER);
|
|
156
153
|
const [activeTab, setActiveTab] = (0, react_5.useState)(activeTabProps);
|
|
157
154
|
// Payment method state with dual-state system (auto + explicit user selection)
|
|
@@ -10,7 +10,6 @@ const formatAddress_1 = require("../../../../shared/utils/formatAddress");
|
|
|
10
10
|
const thirdweb_1 = require("../../../../shared/utils/thirdweb");
|
|
11
11
|
const lucide_react_1 = require("lucide-react");
|
|
12
12
|
const react_2 = require("thirdweb/react");
|
|
13
|
-
const wagmi_1 = require("wagmi");
|
|
14
13
|
const useConnectedWalletDisplay_1 = require("../../hooks/useConnectedWalletDisplay");
|
|
15
14
|
var CryptoPaymentMethodType;
|
|
16
15
|
(function (CryptoPaymentMethodType) {
|
|
@@ -20,18 +19,20 @@ var CryptoPaymentMethodType;
|
|
|
20
19
|
CryptoPaymentMethodType["TRANSFER_CRYPTO"] = "transfer_crypto";
|
|
21
20
|
})(CryptoPaymentMethodType || (exports.CryptoPaymentMethodType = CryptoPaymentMethodType = {}));
|
|
22
21
|
function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod, isCreatingOrder, onBack, onSelectPaymentMethod, }) {
|
|
23
|
-
const { connectedEOAWallet
|
|
24
|
-
const {
|
|
25
|
-
const { disconnect } = (0, wagmi_1.useDisconnect)();
|
|
22
|
+
const { connectedEOAWallet, connectedSmartWallet } = (0, react_1.useAccountWallet)();
|
|
23
|
+
const { disconnect } = (0, react_2.useDisconnect)();
|
|
26
24
|
const { connect: openConnectModal } = (0, react_2.useConnectModal)();
|
|
27
|
-
const setActiveWallet = (0, react_2.useSetActiveWallet)();
|
|
28
25
|
const { data: eoaWalletInfo } = (0, react_2.useWalletInfo)(connectedEOAWallet?.id);
|
|
29
26
|
const globalAddress = connectedSmartWallet?.getAccount()?.address;
|
|
30
27
|
// Use custom hook to determine wallet display logic
|
|
31
|
-
const { shouldShowConnectedEOA
|
|
28
|
+
const { shouldShowConnectedEOA } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(selectedPaymentMethod);
|
|
32
29
|
// Handle wallet connection using thirdweb modal
|
|
33
30
|
const handleConnectWallet = async () => {
|
|
34
31
|
try {
|
|
32
|
+
// Disconnect current wallet before connecting a new one
|
|
33
|
+
if (connectedEOAWallet) {
|
|
34
|
+
await disconnect(connectedEOAWallet);
|
|
35
|
+
}
|
|
35
36
|
const wallet = await openConnectModal({ client: thirdweb_1.client, setActive: false });
|
|
36
37
|
if (wallet) {
|
|
37
38
|
// setActiveWallet(wallet);
|
|
@@ -59,31 +60,17 @@ function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod,
|
|
|
59
60
|
react_1.toast.success("Multiple test 1");
|
|
60
61
|
setTimeout(() => react_1.toast.info("Multiple test 2"), 200);
|
|
61
62
|
setTimeout(() => react_1.toast.warning("Multiple test 3"), 400);
|
|
62
|
-
}, className: "rounded bg-purple-600 px-2 py-1 text-xs font-medium text-white hover:bg-purple-700", children: "Multiple" })] })] })), (0, jsx_runtime_1.jsxs)("div", { className: "crypto-payment-methods flex flex-col gap-4", children: [(shouldShowConnectedEOA ||
|
|
63
|
+
}, className: "rounded bg-purple-600 px-2 py-1 text-xs font-medium text-white hover:bg-purple-700", children: "Multiple" })] })] })), (0, jsx_runtime_1.jsxs)("div", { className: "crypto-payment-methods flex flex-col gap-4", children: [(shouldShowConnectedEOA || globalAddress) && ((0, jsx_runtime_1.jsxs)("div", { className: "installed-wallets", children: [(0, jsx_runtime_1.jsx)("h3", { className: "text-as-primary/80 mb-3 text-sm font-medium", children: "Connected wallets" }), (0, jsx_runtime_1.jsxs)("div", { className: "space-y-2", children: [shouldShowConnectedEOA && ((0, jsx_runtime_1.jsx)("button", { onClick: () => {
|
|
63
64
|
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
64
65
|
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
65
|
-
|
|
66
|
-
setActiveWallet(connectedEOAWallet);
|
|
67
|
-
}
|
|
68
|
-
react_1.toast.success(`Selected ${eoaWalletInfo?.name || connector?.name || "wallet"}`);
|
|
66
|
+
react_1.toast.success(`Selected ${eoaWalletInfo?.name || "wallet"}`);
|
|
69
67
|
}, className: (0, cn_1.cn)("crypto-payment-method-connect-wallet eoa-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
70
68
|
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
71
|
-
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Wallet, { className: "h-5 w-5 text-blue-600" }) }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary font-semibold", children: eoaWalletInfo?.name ||
|
|
69
|
+
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Wallet, { className: "h-5 w-5 text-blue-600" }) }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary font-semibold", children: eoaWalletInfo?.name || "Connected Wallet" }), (0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/60 text-sm", children: (0, formatAddress_1.shortenAddress)(connectedEOAWallet?.getAccount()?.address || "") })] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && ((0, jsx_runtime_1.jsx)("div", { className: "h-2 w-2 rounded-full bg-green-500" })), (0, jsx_runtime_1.jsx)("button", { onClick: e => {
|
|
72
70
|
e.stopPropagation();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
76
|
-
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
71
|
+
if (connectedEOAWallet) {
|
|
72
|
+
disconnect(connectedEOAWallet);
|
|
77
73
|
}
|
|
78
|
-
}, className: "text-as-primary/60 hover:text-as-primary/80 rounded-lg p-1.5 transition-colors", children: (0, jsx_runtime_1.jsx)(lucide_react_1.X, { className: "h-4 w-4" }) })] })] }) })), shouldShowWagmiWallet && ((0, jsx_runtime_1.jsx)("button", { onClick: () => {
|
|
79
|
-
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
80
|
-
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
81
|
-
react_1.toast.success(`Selected ${connector?.name || "wallet"}`);
|
|
82
|
-
}, className: (0, cn_1.cn)("crypto-payment-method-connect-wallet wagmi-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
83
|
-
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
84
|
-
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Wallet, { className: "h-5 w-5 text-blue-600" }) }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary font-semibold", children: connector?.name || "Connected Wallet" }), (0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/60 text-sm", children: (0, formatAddress_1.shortenAddress)(address || "") })] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && ((0, jsx_runtime_1.jsx)("div", { className: "h-2 w-2 rounded-full bg-green-500" })), (0, jsx_runtime_1.jsx)("button", { onClick: e => {
|
|
85
|
-
e.stopPropagation();
|
|
86
|
-
disconnect();
|
|
87
74
|
react_1.toast.success("Wallet disconnected");
|
|
88
75
|
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
89
76
|
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
@@ -13,7 +13,6 @@ const chains_1 = require("viem/chains");
|
|
|
13
13
|
const CryptoPaymentMethod_1 = require("../components/common/CryptoPaymentMethod");
|
|
14
14
|
const FiatPaymentMethod_1 = require("../components/common/FiatPaymentMethod");
|
|
15
15
|
const useAutoSelectCryptoPaymentMethod_1 = require("./useAutoSelectCryptoPaymentMethod");
|
|
16
|
-
const useAutoSetActiveWalletFromWagmi_1 = require("./useAutoSetActiveWalletFromWagmi");
|
|
17
16
|
const useConnectedWalletDisplay_1 = require("./useConnectedWalletDisplay");
|
|
18
17
|
const useCryptoPaymentMethodState_1 = require("./useCryptoPaymentMethodState");
|
|
19
18
|
const useRecipientAddressState_1 = require("./useRecipientAddressState");
|
|
@@ -53,8 +52,6 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
53
52
|
// Recipient state with dual-state system (auto + explicit user selection)
|
|
54
53
|
const { address: globalAddress } = (0, react_2.useAccountWallet)();
|
|
55
54
|
const { walletAddress } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(effectiveCryptoPaymentMethod);
|
|
56
|
-
// Auto-set active wallet from wagmi
|
|
57
|
-
(0, useAutoSetActiveWalletFromWagmi_1.useAutoSetActiveWalletFromWagmi)();
|
|
58
55
|
// Recipient address state - hook automatically manages priority: props > user selection > wallet/global
|
|
59
56
|
const { setSelectedRecipientAddress, effectiveRecipientAddress } = (0, useRecipientAddressState_1.useRecipientAddressState)({
|
|
60
57
|
recipientAddressFromProps: recipientAddress,
|
|
@@ -41,8 +41,8 @@ export declare function useAuthentication(partnerId: string): {
|
|
|
41
41
|
name?: string | undefined;
|
|
42
42
|
address?: string | undefined;
|
|
43
43
|
email?: string | undefined;
|
|
44
|
-
phone?: string | undefined;
|
|
45
44
|
username?: string | undefined;
|
|
45
|
+
phone?: string | undefined;
|
|
46
46
|
fid?: string | undefined;
|
|
47
47
|
};
|
|
48
48
|
}[] | undefined;
|
|
@@ -36,8 +36,8 @@ export declare function useUserQuery(): {
|
|
|
36
36
|
name?: string | undefined;
|
|
37
37
|
address?: string | undefined;
|
|
38
38
|
email?: string | undefined;
|
|
39
|
-
phone?: string | undefined;
|
|
40
39
|
username?: string | undefined;
|
|
40
|
+
phone?: string | undefined;
|
|
41
41
|
fid?: string | undefined;
|
|
42
42
|
};
|
|
43
43
|
}[] | undefined;
|
|
@@ -15,7 +15,6 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
|
15
15
|
import { parseUnits } from "viem";
|
|
16
16
|
import { base, mainnet } from "viem/chains";
|
|
17
17
|
import { useAutoSelectCryptoPaymentMethod } from "../hooks/useAutoSelectCryptoPaymentMethod.js";
|
|
18
|
-
import { useAutoSetActiveWalletFromWagmi } from "../hooks/useAutoSetActiveWalletFromWagmi.js";
|
|
19
18
|
import { useConnectedWalletDisplay } from "../hooks/useConnectedWalletDisplay.js";
|
|
20
19
|
import { useCryptoPaymentMethodState } from "../hooks/useCryptoPaymentMethodState.js";
|
|
21
20
|
import { useRecipientAddressState } from "../hooks/useRecipientAddressState.js";
|
|
@@ -313,8 +312,6 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
313
312
|
// );
|
|
314
313
|
const { address: globalAddress, wallet: globalWallet, connectedEOAWallet } = useAccountWallet();
|
|
315
314
|
const globalWalletImage = useAccountWalletImage();
|
|
316
|
-
// Auto-set active wallet from wagmi
|
|
317
|
-
useAutoSetActiveWalletFromWagmi();
|
|
318
315
|
// Get wallet address based on selected payment method
|
|
319
316
|
const { walletAddress } = useConnectedWalletDisplay(effectiveCryptoPaymentMethod);
|
|
320
317
|
// Recipient address state with dual-state system (auto + explicit user selection)
|
|
@@ -13,7 +13,6 @@ import { ChevronRight, ChevronRightCircle, Info, Loader2 } from "lucide-react";
|
|
|
13
13
|
import { motion } from "motion/react";
|
|
14
14
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
15
15
|
import { base } from "viem/chains";
|
|
16
|
-
import { useAutoSetActiveWalletFromWagmi } from "../hooks/useAutoSetActiveWalletFromWagmi.js";
|
|
17
16
|
import { useCryptoPaymentMethodState } from "../hooks/useCryptoPaymentMethodState.js";
|
|
18
17
|
import { useRecipientAddressState } from "../hooks/useRecipientAddressState.js";
|
|
19
18
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
|
|
@@ -111,8 +110,6 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
111
110
|
const hasMounted = useHasMounted();
|
|
112
111
|
const searchParams = useSearchParamsSSR();
|
|
113
112
|
const router = useRouter();
|
|
114
|
-
// Auto-set active wallet from wagmi
|
|
115
|
-
useAutoSetActiveWalletFromWagmi();
|
|
116
113
|
const [activePanel, setActivePanel] = useState(loadOrder ? PanelView.ORDER_DETAILS : PanelView.CONFIRM_ORDER);
|
|
117
114
|
const [activeTab, setActiveTab] = useState(activeTabProps);
|
|
118
115
|
// Payment method state with dual-state system (auto + explicit user selection)
|
|
@@ -5,8 +5,7 @@ import { cn } from "../../../../shared/utils/cn.js";
|
|
|
5
5
|
import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
|
|
6
6
|
import { client } from "../../../../shared/utils/thirdweb.js";
|
|
7
7
|
import { ChevronLeft, ChevronRightCircle, Wallet, X, ZapIcon } from "lucide-react";
|
|
8
|
-
import { useConnectModal,
|
|
9
|
-
import { useAccount, useDisconnect } from "wagmi";
|
|
8
|
+
import { useConnectModal, useDisconnect, useWalletInfo } from "thirdweb/react";
|
|
10
9
|
import { useConnectedWalletDisplay } from "../../hooks/useConnectedWalletDisplay.js";
|
|
11
10
|
export var CryptoPaymentMethodType;
|
|
12
11
|
(function (CryptoPaymentMethodType) {
|
|
@@ -16,18 +15,20 @@ export var CryptoPaymentMethodType;
|
|
|
16
15
|
CryptoPaymentMethodType["TRANSFER_CRYPTO"] = "transfer_crypto";
|
|
17
16
|
})(CryptoPaymentMethodType || (CryptoPaymentMethodType = {}));
|
|
18
17
|
export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod, isCreatingOrder, onBack, onSelectPaymentMethod, }) {
|
|
19
|
-
const { connectedEOAWallet
|
|
20
|
-
const { connector, address } = useAccount();
|
|
18
|
+
const { connectedEOAWallet, connectedSmartWallet } = useAccountWallet();
|
|
21
19
|
const { disconnect } = useDisconnect();
|
|
22
20
|
const { connect: openConnectModal } = useConnectModal();
|
|
23
|
-
const setActiveWallet = useSetActiveWallet();
|
|
24
21
|
const { data: eoaWalletInfo } = useWalletInfo(connectedEOAWallet?.id);
|
|
25
22
|
const globalAddress = connectedSmartWallet?.getAccount()?.address;
|
|
26
23
|
// Use custom hook to determine wallet display logic
|
|
27
|
-
const { shouldShowConnectedEOA
|
|
24
|
+
const { shouldShowConnectedEOA } = useConnectedWalletDisplay(selectedPaymentMethod);
|
|
28
25
|
// Handle wallet connection using thirdweb modal
|
|
29
26
|
const handleConnectWallet = async () => {
|
|
30
27
|
try {
|
|
28
|
+
// Disconnect current wallet before connecting a new one
|
|
29
|
+
if (connectedEOAWallet) {
|
|
30
|
+
await disconnect(connectedEOAWallet);
|
|
31
|
+
}
|
|
31
32
|
const wallet = await openConnectModal({ client, setActive: false });
|
|
32
33
|
if (wallet) {
|
|
33
34
|
// setActiveWallet(wallet);
|
|
@@ -55,31 +56,17 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
|
|
|
55
56
|
toast.success("Multiple test 1");
|
|
56
57
|
setTimeout(() => toast.info("Multiple test 2"), 200);
|
|
57
58
|
setTimeout(() => toast.warning("Multiple test 3"), 400);
|
|
58
|
-
}, className: "rounded bg-purple-600 px-2 py-1 text-xs font-medium text-white hover:bg-purple-700", children: "Multiple" })] })] })), _jsxs("div", { className: "crypto-payment-methods flex flex-col gap-4", children: [(shouldShowConnectedEOA ||
|
|
59
|
+
}, className: "rounded bg-purple-600 px-2 py-1 text-xs font-medium text-white hover:bg-purple-700", children: "Multiple" })] })] })), _jsxs("div", { className: "crypto-payment-methods flex flex-col gap-4", children: [(shouldShowConnectedEOA || globalAddress) && (_jsxs("div", { className: "installed-wallets", children: [_jsx("h3", { className: "text-as-primary/80 mb-3 text-sm font-medium", children: "Connected wallets" }), _jsxs("div", { className: "space-y-2", children: [shouldShowConnectedEOA && (_jsx("button", { onClick: () => {
|
|
59
60
|
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
60
61
|
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
61
|
-
|
|
62
|
-
setActiveWallet(connectedEOAWallet);
|
|
63
|
-
}
|
|
64
|
-
toast.success(`Selected ${eoaWalletInfo?.name || connector?.name || "wallet"}`);
|
|
62
|
+
toast.success(`Selected ${eoaWalletInfo?.name || "wallet"}`);
|
|
65
63
|
}, className: cn("crypto-payment-method-connect-wallet eoa-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
66
64
|
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
67
|
-
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: _jsx(Wallet, { className: "h-5 w-5 text-blue-600" }) }), _jsxs("div", { className: "flex flex-col", children: [_jsx("span", { className: "text-as-primary font-semibold", children: eoaWalletInfo?.name ||
|
|
65
|
+
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: _jsx(Wallet, { className: "h-5 w-5 text-blue-600" }) }), _jsxs("div", { className: "flex flex-col", children: [_jsx("span", { className: "text-as-primary font-semibold", children: eoaWalletInfo?.name || "Connected Wallet" }), _jsx("span", { className: "text-as-primary/60 text-sm", children: shortenAddress(connectedEOAWallet?.getAccount()?.address || "") })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && (_jsx("div", { className: "h-2 w-2 rounded-full bg-green-500" })), _jsx("button", { onClick: e => {
|
|
68
66
|
e.stopPropagation();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
72
|
-
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
67
|
+
if (connectedEOAWallet) {
|
|
68
|
+
disconnect(connectedEOAWallet);
|
|
73
69
|
}
|
|
74
|
-
}, className: "text-as-primary/60 hover:text-as-primary/80 rounded-lg p-1.5 transition-colors", children: _jsx(X, { className: "h-4 w-4" }) })] })] }) })), shouldShowWagmiWallet && (_jsx("button", { onClick: () => {
|
|
75
|
-
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
76
|
-
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
77
|
-
toast.success(`Selected ${connector?.name || "wallet"}`);
|
|
78
|
-
}, className: cn("crypto-payment-method-connect-wallet wagmi-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
79
|
-
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
80
|
-
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: _jsx(Wallet, { className: "h-5 w-5 text-blue-600" }) }), _jsxs("div", { className: "flex flex-col", children: [_jsx("span", { className: "text-as-primary font-semibold", children: connector?.name || "Connected Wallet" }), _jsx("span", { className: "text-as-primary/60 text-sm", children: shortenAddress(address || "") })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && (_jsx("div", { className: "h-2 w-2 rounded-full bg-green-500" })), _jsx("button", { onClick: e => {
|
|
81
|
-
e.stopPropagation();
|
|
82
|
-
disconnect();
|
|
83
70
|
toast.success("Wallet disconnected");
|
|
84
71
|
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
85
72
|
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
@@ -9,7 +9,6 @@ import { base, mainnet } from "viem/chains";
|
|
|
9
9
|
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod.js";
|
|
10
10
|
import { FiatPaymentMethod } from "../components/common/FiatPaymentMethod.js";
|
|
11
11
|
import { useAutoSelectCryptoPaymentMethod } from "./useAutoSelectCryptoPaymentMethod.js";
|
|
12
|
-
import { useAutoSetActiveWalletFromWagmi } from "./useAutoSetActiveWalletFromWagmi.js";
|
|
13
12
|
import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay.js";
|
|
14
13
|
import { useCryptoPaymentMethodState } from "./useCryptoPaymentMethodState.js";
|
|
15
14
|
import { useRecipientAddressState } from "./useRecipientAddressState.js";
|
|
@@ -49,8 +48,6 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
49
48
|
// Recipient state with dual-state system (auto + explicit user selection)
|
|
50
49
|
const { address: globalAddress } = useAccountWallet();
|
|
51
50
|
const { walletAddress } = useConnectedWalletDisplay(effectiveCryptoPaymentMethod);
|
|
52
|
-
// Auto-set active wallet from wagmi
|
|
53
|
-
useAutoSetActiveWalletFromWagmi();
|
|
54
51
|
// Recipient address state - hook automatically manages priority: props > user selection > wallet/global
|
|
55
52
|
const { setSelectedRecipientAddress, effectiveRecipientAddress } = useRecipientAddressState({
|
|
56
53
|
recipientAddressFromProps: recipientAddress,
|
|
@@ -41,8 +41,8 @@ export declare function useAuthentication(partnerId: string): {
|
|
|
41
41
|
name?: string | undefined;
|
|
42
42
|
address?: string | undefined;
|
|
43
43
|
email?: string | undefined;
|
|
44
|
-
phone?: string | undefined;
|
|
45
44
|
username?: string | undefined;
|
|
45
|
+
phone?: string | undefined;
|
|
46
46
|
fid?: string | undefined;
|
|
47
47
|
};
|
|
48
48
|
}[] | undefined;
|
|
@@ -36,8 +36,8 @@ export declare function useUserQuery(): {
|
|
|
36
36
|
name?: string | undefined;
|
|
37
37
|
address?: string | undefined;
|
|
38
38
|
email?: string | undefined;
|
|
39
|
-
phone?: string | undefined;
|
|
40
39
|
username?: string | undefined;
|
|
40
|
+
phone?: string | undefined;
|
|
41
41
|
fid?: string | undefined;
|
|
42
42
|
};
|
|
43
43
|
}[] | undefined;
|
|
@@ -41,8 +41,8 @@ export declare function useAuthentication(partnerId: string): {
|
|
|
41
41
|
name?: string | undefined;
|
|
42
42
|
address?: string | undefined;
|
|
43
43
|
email?: string | undefined;
|
|
44
|
-
phone?: string | undefined;
|
|
45
44
|
username?: string | undefined;
|
|
45
|
+
phone?: string | undefined;
|
|
46
46
|
fid?: string | undefined;
|
|
47
47
|
};
|
|
48
48
|
}[] | undefined;
|
|
@@ -36,8 +36,8 @@ export declare function useUserQuery(): {
|
|
|
36
36
|
name?: string | undefined;
|
|
37
37
|
address?: string | undefined;
|
|
38
38
|
email?: string | undefined;
|
|
39
|
-
phone?: string | undefined;
|
|
40
39
|
username?: string | undefined;
|
|
40
|
+
phone?: string | undefined;
|
|
41
41
|
fid?: string | undefined;
|
|
42
42
|
};
|
|
43
43
|
}[] | undefined;
|
package/package.json
CHANGED
|
@@ -38,7 +38,6 @@ import { parseUnits } from "viem";
|
|
|
38
38
|
import { base, mainnet } from "viem/chains";
|
|
39
39
|
import { components } from "../../types/api";
|
|
40
40
|
import { useAutoSelectCryptoPaymentMethod } from "../hooks/useAutoSelectCryptoPaymentMethod";
|
|
41
|
-
import { useAutoSetActiveWalletFromWagmi } from "../hooks/useAutoSetActiveWalletFromWagmi";
|
|
42
41
|
import { useConnectedWalletDisplay } from "../hooks/useConnectedWalletDisplay";
|
|
43
42
|
import { useCryptoPaymentMethodState } from "../hooks/useCryptoPaymentMethodState";
|
|
44
43
|
import { useRecipientAddressState } from "../hooks/useRecipientAddressState";
|
|
@@ -461,9 +460,6 @@ function AnySpendInner({
|
|
|
461
460
|
|
|
462
461
|
const globalWalletImage = useAccountWalletImage();
|
|
463
462
|
|
|
464
|
-
// Auto-set active wallet from wagmi
|
|
465
|
-
useAutoSetActiveWalletFromWagmi();
|
|
466
|
-
|
|
467
463
|
// Get wallet address based on selected payment method
|
|
468
464
|
const { walletAddress } = useConnectedWalletDisplay(effectiveCryptoPaymentMethod);
|
|
469
465
|
|
|
@@ -44,7 +44,6 @@ import { motion } from "motion/react";
|
|
|
44
44
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
45
45
|
|
|
46
46
|
import { base } from "viem/chains";
|
|
47
|
-
import { useAutoSetActiveWalletFromWagmi } from "../hooks/useAutoSetActiveWalletFromWagmi";
|
|
48
47
|
import { useCryptoPaymentMethodState } from "../hooks/useCryptoPaymentMethodState";
|
|
49
48
|
import { useRecipientAddressState } from "../hooks/useRecipientAddressState";
|
|
50
49
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper";
|
|
@@ -247,9 +246,6 @@ function AnySpendCustomInner({
|
|
|
247
246
|
const searchParams = useSearchParamsSSR();
|
|
248
247
|
const router = useRouter();
|
|
249
248
|
|
|
250
|
-
// Auto-set active wallet from wagmi
|
|
251
|
-
useAutoSetActiveWalletFromWagmi();
|
|
252
|
-
|
|
253
249
|
const [activePanel, setActivePanel] = useState<PanelView>(
|
|
254
250
|
loadOrder ? PanelView.ORDER_DETAILS : PanelView.CONFIRM_ORDER,
|
|
255
251
|
);
|
|
@@ -5,8 +5,7 @@ import { cn } from "@b3dotfun/sdk/shared/utils/cn";
|
|
|
5
5
|
import { shortenAddress } from "@b3dotfun/sdk/shared/utils/formatAddress";
|
|
6
6
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
7
7
|
import { ChevronLeft, ChevronRightCircle, Wallet, X, ZapIcon } from "lucide-react";
|
|
8
|
-
import { useConnectModal,
|
|
9
|
-
import { useAccount, useDisconnect } from "wagmi";
|
|
8
|
+
import { useConnectModal, useDisconnect, useWalletInfo } from "thirdweb/react";
|
|
10
9
|
import { useConnectedWalletDisplay } from "../../hooks/useConnectedWalletDisplay";
|
|
11
10
|
|
|
12
11
|
export enum CryptoPaymentMethodType {
|
|
@@ -31,21 +30,23 @@ export function CryptoPaymentMethod({
|
|
|
31
30
|
onBack,
|
|
32
31
|
onSelectPaymentMethod,
|
|
33
32
|
}: CryptoPaymentMethodProps) {
|
|
34
|
-
const { connectedEOAWallet
|
|
35
|
-
const { connector, address } = useAccount();
|
|
33
|
+
const { connectedEOAWallet, connectedSmartWallet } = useAccountWallet();
|
|
36
34
|
const { disconnect } = useDisconnect();
|
|
37
35
|
const { connect: openConnectModal } = useConnectModal();
|
|
38
|
-
const setActiveWallet = useSetActiveWallet();
|
|
39
36
|
const { data: eoaWalletInfo } = useWalletInfo(connectedEOAWallet?.id);
|
|
40
37
|
|
|
41
38
|
const globalAddress = connectedSmartWallet?.getAccount()?.address;
|
|
42
39
|
|
|
43
40
|
// Use custom hook to determine wallet display logic
|
|
44
|
-
const { shouldShowConnectedEOA
|
|
41
|
+
const { shouldShowConnectedEOA } = useConnectedWalletDisplay(selectedPaymentMethod);
|
|
45
42
|
|
|
46
43
|
// Handle wallet connection using thirdweb modal
|
|
47
44
|
const handleConnectWallet = async () => {
|
|
48
45
|
try {
|
|
46
|
+
// Disconnect current wallet before connecting a new one
|
|
47
|
+
if (connectedEOAWallet) {
|
|
48
|
+
await disconnect(connectedEOAWallet);
|
|
49
|
+
}
|
|
49
50
|
const wallet = await openConnectModal({ client, setActive: false });
|
|
50
51
|
if (wallet) {
|
|
51
52
|
// setActiveWallet(wallet);
|
|
@@ -132,7 +133,7 @@ export function CryptoPaymentMethod({
|
|
|
132
133
|
{/* Payment Methods */}
|
|
133
134
|
<div className="crypto-payment-methods flex flex-col gap-4">
|
|
134
135
|
{/* Installed Wallets Section */}
|
|
135
|
-
{(shouldShowConnectedEOA ||
|
|
136
|
+
{(shouldShowConnectedEOA || globalAddress) && (
|
|
136
137
|
<div className="installed-wallets">
|
|
137
138
|
<h3 className="text-as-primary/80 mb-3 text-sm font-medium">Connected wallets</h3>
|
|
138
139
|
<div className="space-y-2">
|
|
@@ -143,10 +144,7 @@ export function CryptoPaymentMethod({
|
|
|
143
144
|
onClick={() => {
|
|
144
145
|
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
145
146
|
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
146
|
-
|
|
147
|
-
setActiveWallet(connectedEOAWallet);
|
|
148
|
-
}
|
|
149
|
-
toast.success(`Selected ${eoaWalletInfo?.name || connector?.name || "wallet"}`);
|
|
147
|
+
toast.success(`Selected ${eoaWalletInfo?.name || "wallet"}`);
|
|
150
148
|
}}
|
|
151
149
|
className={cn(
|
|
152
150
|
"crypto-payment-method-connect-wallet eoa-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md",
|
|
@@ -162,7 +160,7 @@ export function CryptoPaymentMethod({
|
|
|
162
160
|
</div>
|
|
163
161
|
<div className="flex flex-col">
|
|
164
162
|
<span className="text-as-primary font-semibold">
|
|
165
|
-
{eoaWalletInfo?.name ||
|
|
163
|
+
{eoaWalletInfo?.name || "Connected Wallet"}
|
|
166
164
|
</span>
|
|
167
165
|
<span className="text-as-primary/60 text-sm">
|
|
168
166
|
{shortenAddress(connectedEOAWallet?.getAccount()?.address || "")}
|
|
@@ -176,53 +174,9 @@ export function CryptoPaymentMethod({
|
|
|
176
174
|
<button
|
|
177
175
|
onClick={e => {
|
|
178
176
|
e.stopPropagation();
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
182
|
-
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
177
|
+
if (connectedEOAWallet) {
|
|
178
|
+
disconnect(connectedEOAWallet);
|
|
183
179
|
}
|
|
184
|
-
}}
|
|
185
|
-
className="text-as-primary/60 hover:text-as-primary/80 rounded-lg p-1.5 transition-colors"
|
|
186
|
-
>
|
|
187
|
-
<X className="h-4 w-4" />
|
|
188
|
-
</button>
|
|
189
|
-
</div>
|
|
190
|
-
</div>
|
|
191
|
-
</button>
|
|
192
|
-
)}
|
|
193
|
-
|
|
194
|
-
{shouldShowWagmiWallet && (
|
|
195
|
-
<button
|
|
196
|
-
onClick={() => {
|
|
197
|
-
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
198
|
-
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
199
|
-
toast.success(`Selected ${connector?.name || "wallet"}`);
|
|
200
|
-
}}
|
|
201
|
-
className={cn(
|
|
202
|
-
"crypto-payment-method-connect-wallet wagmi-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md",
|
|
203
|
-
selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
204
|
-
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
205
|
-
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80",
|
|
206
|
-
)}
|
|
207
|
-
>
|
|
208
|
-
<div className="flex items-center justify-between">
|
|
209
|
-
<div className="flex items-center gap-3">
|
|
210
|
-
<div className="wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100">
|
|
211
|
-
<Wallet className="h-5 w-5 text-blue-600" />
|
|
212
|
-
</div>
|
|
213
|
-
<div className="flex flex-col">
|
|
214
|
-
<span className="text-as-primary font-semibold">{connector?.name || "Connected Wallet"}</span>
|
|
215
|
-
<span className="text-as-primary/60 text-sm">{shortenAddress(address || "")}</span>
|
|
216
|
-
</div>
|
|
217
|
-
</div>
|
|
218
|
-
<div className="flex items-center gap-2">
|
|
219
|
-
{selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && (
|
|
220
|
-
<div className="h-2 w-2 rounded-full bg-green-500"></div>
|
|
221
|
-
)}
|
|
222
|
-
<button
|
|
223
|
-
onClick={e => {
|
|
224
|
-
e.stopPropagation();
|
|
225
|
-
disconnect();
|
|
226
180
|
toast.success("Wallet disconnected");
|
|
227
181
|
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
228
182
|
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
@@ -24,7 +24,6 @@ import { components } from "../../types/api";
|
|
|
24
24
|
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
25
25
|
import { FiatPaymentMethod } from "../components/common/FiatPaymentMethod";
|
|
26
26
|
import { useAutoSelectCryptoPaymentMethod } from "./useAutoSelectCryptoPaymentMethod";
|
|
27
|
-
import { useAutoSetActiveWalletFromWagmi } from "./useAutoSetActiveWalletFromWagmi";
|
|
28
27
|
import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay";
|
|
29
28
|
import { useCryptoPaymentMethodState } from "./useCryptoPaymentMethodState";
|
|
30
29
|
import { useRecipientAddressState } from "./useRecipientAddressState";
|
|
@@ -111,9 +110,6 @@ export function useAnyspendFlow({
|
|
|
111
110
|
const { address: globalAddress } = useAccountWallet();
|
|
112
111
|
const { walletAddress } = useConnectedWalletDisplay(effectiveCryptoPaymentMethod);
|
|
113
112
|
|
|
114
|
-
// Auto-set active wallet from wagmi
|
|
115
|
-
useAutoSetActiveWalletFromWagmi();
|
|
116
|
-
|
|
117
113
|
// Recipient address state - hook automatically manages priority: props > user selection > wallet/global
|
|
118
114
|
const { setSelectedRecipientAddress, effectiveRecipientAddress } = useRecipientAddressState({
|
|
119
115
|
recipientAddressFromProps: recipientAddress,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
|
|
3
|
-
*
|
|
4
|
-
* This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
|
|
5
|
-
* ensuring that when users connect via wagmi, the active wallet is properly set.
|
|
6
|
-
*
|
|
7
|
-
* Place this hook in components that stay mounted throughout the user flow
|
|
8
|
-
* (not in components that unmount during navigation).
|
|
9
|
-
*/
|
|
10
|
-
export declare function useAutoSetActiveWalletFromWagmi(): void;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useAutoSetActiveWalletFromWagmi = useAutoSetActiveWalletFromWagmi;
|
|
4
|
-
const thirdweb_1 = require("../../../shared/utils/thirdweb");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const react_2 = require("thirdweb/react");
|
|
7
|
-
const wallets_1 = require("thirdweb/wallets");
|
|
8
|
-
const wagmi_1 = require("wagmi");
|
|
9
|
-
/**
|
|
10
|
-
* Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
|
|
11
|
-
*
|
|
12
|
-
* This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
|
|
13
|
-
* ensuring that when users connect via wagmi, the active wallet is properly set.
|
|
14
|
-
*
|
|
15
|
-
* Place this hook in components that stay mounted throughout the user flow
|
|
16
|
-
* (not in components that unmount during navigation).
|
|
17
|
-
*/
|
|
18
|
-
function useAutoSetActiveWalletFromWagmi() {
|
|
19
|
-
const { address: wagmiAddress, connector: wagmiConnector } = (0, wagmi_1.useAccount)();
|
|
20
|
-
const setActiveWallet = (0, react_2.useSetActiveWallet)();
|
|
21
|
-
const prevWagmiAddress = (0, react_1.useRef)(undefined);
|
|
22
|
-
// Map wagmi connector names to thirdweb wallet IDs
|
|
23
|
-
const getThirdwebWalletId = (0, react_1.useCallback)((connectorName) => {
|
|
24
|
-
const walletMap = {
|
|
25
|
-
MetaMask: "io.metamask",
|
|
26
|
-
"Coinbase Wallet": "com.coinbase.wallet",
|
|
27
|
-
Rainbow: "me.rainbow",
|
|
28
|
-
WalletConnect: "walletConnect",
|
|
29
|
-
Phantom: "app.phantom",
|
|
30
|
-
};
|
|
31
|
-
return walletMap[connectorName] || null;
|
|
32
|
-
}, []);
|
|
33
|
-
// Create thirdweb wallet from wagmi connector
|
|
34
|
-
const createThirdwebWalletFromConnector = (0, react_1.useCallback)(async (connectorName) => {
|
|
35
|
-
const walletId = getThirdwebWalletId(connectorName);
|
|
36
|
-
if (!walletId) {
|
|
37
|
-
console.warn(`No thirdweb wallet ID found for connector: ${connectorName}`);
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const thirdwebWallet = (0, wallets_1.createWallet)(walletId);
|
|
42
|
-
await thirdwebWallet.connect({ client: thirdweb_1.client });
|
|
43
|
-
return thirdwebWallet;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.error(`Failed to create thirdweb wallet for ${connectorName}:`, error);
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
}, [getThirdwebWalletId]);
|
|
50
|
-
// Listen for wagmi wallet connections and automatically set active wallet
|
|
51
|
-
(0, react_1.useEffect)(() => {
|
|
52
|
-
const isNewConnection = wagmiAddress && wagmiAddress !== prevWagmiAddress.current;
|
|
53
|
-
if (isNewConnection && wagmiConnector?.name) {
|
|
54
|
-
prevWagmiAddress.current = wagmiAddress;
|
|
55
|
-
const setupThirdwebWallet = async () => {
|
|
56
|
-
try {
|
|
57
|
-
const thirdwebWallet = await createThirdwebWalletFromConnector(wagmiConnector.name);
|
|
58
|
-
if (thirdwebWallet) {
|
|
59
|
-
setActiveWallet(thirdwebWallet);
|
|
60
|
-
console.log(`Auto-set active wallet for ${wagmiConnector.name}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
console.error("Failed to auto-set active wallet:", error);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
setupThirdwebWallet();
|
|
68
|
-
}
|
|
69
|
-
if (!wagmiAddress) {
|
|
70
|
-
prevWagmiAddress.current = undefined;
|
|
71
|
-
}
|
|
72
|
-
}, [wagmiAddress, wagmiConnector?.name, setActiveWallet, createThirdwebWalletFromConnector]);
|
|
73
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
|
|
3
|
-
*
|
|
4
|
-
* This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
|
|
5
|
-
* ensuring that when users connect via wagmi, the active wallet is properly set.
|
|
6
|
-
*
|
|
7
|
-
* Place this hook in components that stay mounted throughout the user flow
|
|
8
|
-
* (not in components that unmount during navigation).
|
|
9
|
-
*/
|
|
10
|
-
export declare function useAutoSetActiveWalletFromWagmi(): void;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { client } from "../../../shared/utils/thirdweb.js";
|
|
2
|
-
import { useCallback, useEffect, useRef } from "react";
|
|
3
|
-
import { useSetActiveWallet } from "thirdweb/react";
|
|
4
|
-
import { createWallet } from "thirdweb/wallets";
|
|
5
|
-
import { useAccount } from "wagmi";
|
|
6
|
-
/**
|
|
7
|
-
* Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
|
|
8
|
-
*
|
|
9
|
-
* This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
|
|
10
|
-
* ensuring that when users connect via wagmi, the active wallet is properly set.
|
|
11
|
-
*
|
|
12
|
-
* Place this hook in components that stay mounted throughout the user flow
|
|
13
|
-
* (not in components that unmount during navigation).
|
|
14
|
-
*/
|
|
15
|
-
export function useAutoSetActiveWalletFromWagmi() {
|
|
16
|
-
const { address: wagmiAddress, connector: wagmiConnector } = useAccount();
|
|
17
|
-
const setActiveWallet = useSetActiveWallet();
|
|
18
|
-
const prevWagmiAddress = useRef(undefined);
|
|
19
|
-
// Map wagmi connector names to thirdweb wallet IDs
|
|
20
|
-
const getThirdwebWalletId = useCallback((connectorName) => {
|
|
21
|
-
const walletMap = {
|
|
22
|
-
MetaMask: "io.metamask",
|
|
23
|
-
"Coinbase Wallet": "com.coinbase.wallet",
|
|
24
|
-
Rainbow: "me.rainbow",
|
|
25
|
-
WalletConnect: "walletConnect",
|
|
26
|
-
Phantom: "app.phantom",
|
|
27
|
-
};
|
|
28
|
-
return walletMap[connectorName] || null;
|
|
29
|
-
}, []);
|
|
30
|
-
// Create thirdweb wallet from wagmi connector
|
|
31
|
-
const createThirdwebWalletFromConnector = useCallback(async (connectorName) => {
|
|
32
|
-
const walletId = getThirdwebWalletId(connectorName);
|
|
33
|
-
if (!walletId) {
|
|
34
|
-
console.warn(`No thirdweb wallet ID found for connector: ${connectorName}`);
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
const thirdwebWallet = createWallet(walletId);
|
|
39
|
-
await thirdwebWallet.connect({ client });
|
|
40
|
-
return thirdwebWallet;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
console.error(`Failed to create thirdweb wallet for ${connectorName}:`, error);
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
}, [getThirdwebWalletId]);
|
|
47
|
-
// Listen for wagmi wallet connections and automatically set active wallet
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
const isNewConnection = wagmiAddress && wagmiAddress !== prevWagmiAddress.current;
|
|
50
|
-
if (isNewConnection && wagmiConnector?.name) {
|
|
51
|
-
prevWagmiAddress.current = wagmiAddress;
|
|
52
|
-
const setupThirdwebWallet = async () => {
|
|
53
|
-
try {
|
|
54
|
-
const thirdwebWallet = await createThirdwebWalletFromConnector(wagmiConnector.name);
|
|
55
|
-
if (thirdwebWallet) {
|
|
56
|
-
setActiveWallet(thirdwebWallet);
|
|
57
|
-
console.log(`Auto-set active wallet for ${wagmiConnector.name}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
console.error("Failed to auto-set active wallet:", error);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
setupThirdwebWallet();
|
|
65
|
-
}
|
|
66
|
-
if (!wagmiAddress) {
|
|
67
|
-
prevWagmiAddress.current = undefined;
|
|
68
|
-
}
|
|
69
|
-
}, [wagmiAddress, wagmiConnector?.name, setActiveWallet, createThirdwebWalletFromConnector]);
|
|
70
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
|
|
3
|
-
*
|
|
4
|
-
* This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
|
|
5
|
-
* ensuring that when users connect via wagmi, the active wallet is properly set.
|
|
6
|
-
*
|
|
7
|
-
* Place this hook in components that stay mounted throughout the user flow
|
|
8
|
-
* (not in components that unmount during navigation).
|
|
9
|
-
*/
|
|
10
|
-
export declare function useAutoSetActiveWalletFromWagmi(): void;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
2
|
-
import { useCallback, useEffect, useRef } from "react";
|
|
3
|
-
import { useSetActiveWallet } from "thirdweb/react";
|
|
4
|
-
import { WalletId, createWallet } from "thirdweb/wallets";
|
|
5
|
-
import { useAccount } from "wagmi";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
|
|
9
|
-
*
|
|
10
|
-
* This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
|
|
11
|
-
* ensuring that when users connect via wagmi, the active wallet is properly set.
|
|
12
|
-
*
|
|
13
|
-
* Place this hook in components that stay mounted throughout the user flow
|
|
14
|
-
* (not in components that unmount during navigation).
|
|
15
|
-
*/
|
|
16
|
-
export function useAutoSetActiveWalletFromWagmi() {
|
|
17
|
-
const { address: wagmiAddress, connector: wagmiConnector } = useAccount();
|
|
18
|
-
const setActiveWallet = useSetActiveWallet();
|
|
19
|
-
const prevWagmiAddress = useRef<string | undefined>(undefined);
|
|
20
|
-
|
|
21
|
-
// Map wagmi connector names to thirdweb wallet IDs
|
|
22
|
-
const getThirdwebWalletId = useCallback((connectorName: string): WalletId | null => {
|
|
23
|
-
const walletMap: Record<string, WalletId> = {
|
|
24
|
-
MetaMask: "io.metamask",
|
|
25
|
-
"Coinbase Wallet": "com.coinbase.wallet",
|
|
26
|
-
Rainbow: "me.rainbow",
|
|
27
|
-
WalletConnect: "walletConnect",
|
|
28
|
-
Phantom: "app.phantom",
|
|
29
|
-
};
|
|
30
|
-
return walletMap[connectorName] || null;
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
// Create thirdweb wallet from wagmi connector
|
|
34
|
-
const createThirdwebWalletFromConnector = useCallback(
|
|
35
|
-
async (connectorName: string) => {
|
|
36
|
-
const walletId = getThirdwebWalletId(connectorName);
|
|
37
|
-
if (!walletId) {
|
|
38
|
-
console.warn(`No thirdweb wallet ID found for connector: ${connectorName}`);
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const thirdwebWallet = createWallet(walletId);
|
|
44
|
-
await thirdwebWallet.connect({ client });
|
|
45
|
-
return thirdwebWallet;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.error(`Failed to create thirdweb wallet for ${connectorName}:`, error);
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
[getThirdwebWalletId],
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
// Listen for wagmi wallet connections and automatically set active wallet
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
const isNewConnection = wagmiAddress && wagmiAddress !== prevWagmiAddress.current;
|
|
57
|
-
|
|
58
|
-
if (isNewConnection && wagmiConnector?.name) {
|
|
59
|
-
prevWagmiAddress.current = wagmiAddress;
|
|
60
|
-
|
|
61
|
-
const setupThirdwebWallet = async () => {
|
|
62
|
-
try {
|
|
63
|
-
const thirdwebWallet = await createThirdwebWalletFromConnector(wagmiConnector.name);
|
|
64
|
-
if (thirdwebWallet) {
|
|
65
|
-
setActiveWallet(thirdwebWallet);
|
|
66
|
-
console.log(`Auto-set active wallet for ${wagmiConnector.name}`);
|
|
67
|
-
}
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error("Failed to auto-set active wallet:", error);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
setupThirdwebWallet();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!wagmiAddress) {
|
|
77
|
-
prevWagmiAddress.current = undefined;
|
|
78
|
-
}
|
|
79
|
-
}, [wagmiAddress, wagmiConnector?.name, setActiveWallet, createThirdwebWalletFromConnector]);
|
|
80
|
-
}
|