@b3dotfun/sdk 0.0.82-alpha.1 → 0.0.82-alpha.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/dist/cjs/anyspend/react/components/AnySpend.js +0 -3
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +0 -3
- 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/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/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)
|
|
@@ -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)
|
|
@@ -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
|
);
|
|
@@ -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
|
-
}
|