@b3dotfun/sdk 0.0.82-alpha.3 → 0.0.83-test.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/anyspend/react/components/AnySpend.js +3 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +3 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +177 -47
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +3 -0
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +73 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +57 -12
- package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/index.js +3 -1
- package/dist/cjs/global-account/react/hooks/useAuth.d.ts +76 -0
- package/dist/cjs/global-account/react/hooks/useAuth.js +338 -0
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +72 -63
- package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +3 -0
- package/dist/cjs/global-account/react/hooks/useTWAuth.js +8 -0
- package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +54 -24
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +3 -0
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +175 -45
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +3 -0
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +70 -0
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +57 -12
- package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/index.js +1 -0
- package/dist/esm/global-account/react/hooks/useAuth.d.ts +76 -0
- package/dist/esm/global-account/react/hooks/useAuth.js +332 -0
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +72 -63
- package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +3 -0
- package/dist/esm/global-account/react/hooks/useTWAuth.js +8 -0
- package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +54 -24
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
- package/dist/types/global-account/react/hooks/index.d.ts +1 -0
- package/dist/types/global-account/react/hooks/useAuth.d.ts +76 -0
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/types/global-account/react/hooks/useTWAuth.d.ts +3 -0
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +4 -0
- package/src/anyspend/react/components/AnySpendCustom.tsx +4 -0
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +253 -22
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +4 -0
- package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +80 -0
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +77 -22
- package/src/global-account/react/hooks/index.ts +1 -0
- package/src/global-account/react/hooks/useAuth.ts +380 -0
- package/src/global-account/react/hooks/useAuthentication.ts +88 -85
- package/src/global-account/react/hooks/useTWAuth.tsx +10 -0
- package/src/global-account/react/hooks/useTurnkeyAuth.ts +59 -26
|
@@ -22,6 +22,7 @@ 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");
|
|
25
26
|
const useConnectedWalletDisplay_1 = require("../hooks/useConnectedWalletDisplay");
|
|
26
27
|
const useCryptoPaymentMethodState_1 = require("../hooks/useCryptoPaymentMethodState");
|
|
27
28
|
const useRecipientAddressState_1 = require("../hooks/useRecipientAddressState");
|
|
@@ -319,6 +320,8 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
319
320
|
// );
|
|
320
321
|
const { address: globalAddress, wallet: globalWallet, connectedEOAWallet } = (0, react_2.useAccountWallet)();
|
|
321
322
|
const globalWalletImage = (0, useAccountWallet_1.useAccountWalletImage)();
|
|
323
|
+
// Auto-set active wallet from wagmi
|
|
324
|
+
(0, useAutoSetActiveWalletFromWagmi_1.useAutoSetActiveWalletFromWagmi)();
|
|
322
325
|
// Get wallet address based on selected payment method
|
|
323
326
|
const { walletAddress } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(effectiveCryptoPaymentMethod);
|
|
324
327
|
// Recipient address state with dual-state system (auto + explicit user selection)
|
|
@@ -52,6 +52,7 @@ 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");
|
|
55
56
|
const useCryptoPaymentMethodState_1 = require("../hooks/useCryptoPaymentMethodState");
|
|
56
57
|
const useRecipientAddressState_1 = require("../hooks/useRecipientAddressState");
|
|
57
58
|
const AnySpendFingerprintWrapper_1 = require("./AnySpendFingerprintWrapper");
|
|
@@ -149,6 +150,8 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
149
150
|
const hasMounted = (0, react_2.useHasMounted)();
|
|
150
151
|
const searchParams = (0, react_2.useSearchParamsSSR)();
|
|
151
152
|
const router = (0, react_2.useRouter)();
|
|
153
|
+
// Auto-set active wallet from wagmi
|
|
154
|
+
(0, useAutoSetActiveWalletFromWagmi_1.useAutoSetActiveWalletFromWagmi)();
|
|
152
155
|
const [activePanel, setActivePanel] = (0, react_5.useState)(loadOrder ? PanelView.ORDER_DETAILS : PanelView.CONFIRM_ORDER);
|
|
153
156
|
const [activeTab, setActiveTab] = (0, react_5.useState)(activeTabProps);
|
|
154
157
|
// Payment method state with dual-state system (auto + explicit user selection)
|
|
@@ -8,8 +8,13 @@ const react_1 = require("../../../../global-account/react");
|
|
|
8
8
|
const cn_1 = require("../../../../shared/utils/cn");
|
|
9
9
|
const formatAddress_1 = require("../../../../shared/utils/formatAddress");
|
|
10
10
|
const thirdweb_1 = require("../../../../shared/utils/thirdweb");
|
|
11
|
+
const react_2 = require("@web3icons/react");
|
|
11
12
|
const lucide_react_1 = require("lucide-react");
|
|
12
|
-
const
|
|
13
|
+
const react_3 = require("react");
|
|
14
|
+
const react_dom_1 = require("react-dom");
|
|
15
|
+
const react_4 = require("thirdweb/react");
|
|
16
|
+
const wallets_1 = require("thirdweb/wallets");
|
|
17
|
+
const wagmi_1 = require("wagmi");
|
|
13
18
|
const useConnectedWalletDisplay_1 = require("../../hooks/useConnectedWalletDisplay");
|
|
14
19
|
var CryptoPaymentMethodType;
|
|
15
20
|
(function (CryptoPaymentMethodType) {
|
|
@@ -19,70 +24,195 @@ var CryptoPaymentMethodType;
|
|
|
19
24
|
CryptoPaymentMethodType["TRANSFER_CRYPTO"] = "transfer_crypto";
|
|
20
25
|
})(CryptoPaymentMethodType || (exports.CryptoPaymentMethodType = CryptoPaymentMethodType = {}));
|
|
21
26
|
function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod, isCreatingOrder, onBack, onSelectPaymentMethod, }) {
|
|
22
|
-
const { connectedEOAWallet, connectedSmartWallet } = (0, react_1.useAccountWallet)();
|
|
23
|
-
const {
|
|
24
|
-
const { connect
|
|
25
|
-
const {
|
|
27
|
+
const { connectedEOAWallet: connectedEOAWallet, connectedSmartWallet: connectedSmartWallet } = (0, react_1.useAccountWallet)();
|
|
28
|
+
const { connector, address } = (0, wagmi_1.useAccount)();
|
|
29
|
+
const { connect, connectors, isPending } = (0, wagmi_1.useConnect)();
|
|
30
|
+
const { disconnect } = (0, wagmi_1.useDisconnect)();
|
|
31
|
+
const { data: walletClient } = (0, wagmi_1.useWalletClient)();
|
|
32
|
+
const [showWalletModal, setShowWalletModal] = (0, react_3.useState)(false);
|
|
33
|
+
const setActiveWallet = (0, react_4.useSetActiveWallet)();
|
|
34
|
+
const { data: eoaWalletInfo } = (0, react_4.useWalletInfo)(connectedEOAWallet?.id);
|
|
35
|
+
const isConnected = !!connectedEOAWallet;
|
|
26
36
|
const globalAddress = connectedSmartWallet?.getAccount()?.address;
|
|
27
37
|
// Use custom hook to determine wallet display logic
|
|
28
|
-
const { shouldShowConnectedEOA } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(selectedPaymentMethod);
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
const { shouldShowConnectedEOA, shouldShowWagmiWallet } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(selectedPaymentMethod);
|
|
39
|
+
console.log("shouldShowWagmiWallet :", shouldShowWagmiWallet);
|
|
40
|
+
// Map wagmi connector names to thirdweb wallet IDs
|
|
41
|
+
const getThirdwebWalletId = (connectorName) => {
|
|
42
|
+
const walletMap = {
|
|
43
|
+
MetaMask: "io.metamask",
|
|
44
|
+
"Coinbase Wallet": "com.coinbase.wallet",
|
|
45
|
+
Rainbow: "me.rainbow",
|
|
46
|
+
WalletConnect: "walletConnect",
|
|
47
|
+
Phantom: "app.phantom",
|
|
48
|
+
};
|
|
49
|
+
return walletMap[connectorName] || null;
|
|
50
|
+
};
|
|
51
|
+
// Create thirdweb wallet from wagmi connector
|
|
52
|
+
const createThirdwebWalletFromConnector = async (connectorName) => {
|
|
53
|
+
const walletId = getThirdwebWalletId(connectorName);
|
|
54
|
+
if (!walletId) {
|
|
55
|
+
console.warn(`No thirdweb wallet ID found for connector: ${connectorName}`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const thirdwebWallet = (0, wallets_1.createWallet)(walletId);
|
|
60
|
+
// Connect the wallet to sync with the existing wagmi connection
|
|
61
|
+
await thirdwebWallet.connect({ client: thirdweb_1.client });
|
|
62
|
+
return thirdwebWallet;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(`Failed to create thirdweb wallet for ${connectorName}:`, error);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
// Define available wallet connectors
|
|
70
|
+
const availableConnectors = connectors.filter(connector => ["MetaMask", "WalletConnect", "Coinbase Wallet", "Rainbow", "Phantom"].includes(connector.name));
|
|
71
|
+
// Define wallet options with icons and info
|
|
72
|
+
const walletOptions = [
|
|
73
|
+
{
|
|
74
|
+
id: "metamask",
|
|
75
|
+
name: "MetaMask",
|
|
76
|
+
icon: (0, jsx_runtime_1.jsx)(react_2.WalletMetamask, { size: 48 }),
|
|
77
|
+
description: "Connect using MetaMask browser extension",
|
|
78
|
+
connector: availableConnectors.find(c => c.name === "MetaMask"),
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "coinbase",
|
|
82
|
+
name: "Coinbase Wallet",
|
|
83
|
+
icon: (0, jsx_runtime_1.jsx)(react_2.WalletCoinbase, { size: 48 }),
|
|
84
|
+
description: "Connect using Coinbase Wallet",
|
|
85
|
+
connector: availableConnectors.find(c => c.name === "Coinbase Wallet"),
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "rainbow",
|
|
89
|
+
name: "Rainbow",
|
|
90
|
+
icon: (0, jsx_runtime_1.jsx)(react_2.WalletRainbow, { size: 48 }),
|
|
91
|
+
description: "Connect using Rainbow wallet",
|
|
92
|
+
connector: availableConnectors.find(c => c.name === "Rainbow"),
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: "walletconnect",
|
|
96
|
+
name: "WalletConnect",
|
|
97
|
+
icon: (0, jsx_runtime_1.jsx)(react_2.WalletWalletConnect, { size: 48 }),
|
|
98
|
+
description: "Connect using WalletConnect protocol",
|
|
99
|
+
connector: availableConnectors.find(c => c.name === "WalletConnect"),
|
|
100
|
+
},
|
|
101
|
+
].filter(wallet => wallet.connector); // Only show wallets that have available connectors
|
|
102
|
+
// Reset modal state when closing
|
|
103
|
+
const handleCloseModal = () => {
|
|
104
|
+
setShowWalletModal(false);
|
|
105
|
+
};
|
|
106
|
+
// Function to request wallet permissions for specific wallet
|
|
107
|
+
const requestWalletPermissions = async (walletConnector) => {
|
|
31
108
|
try {
|
|
32
|
-
//
|
|
33
|
-
if (
|
|
34
|
-
|
|
109
|
+
// If a specific wallet connector is provided and it's different from current
|
|
110
|
+
if (walletConnector && connector?.name !== walletConnector.name) {
|
|
111
|
+
// Disconnect current and connect to the selected wallet
|
|
112
|
+
// if (isConnected) {
|
|
113
|
+
// disconnect();
|
|
114
|
+
// // Small delay to ensure disconnection
|
|
115
|
+
// await new Promise(resolve => setTimeout(resolve, 100));
|
|
116
|
+
// }
|
|
117
|
+
await connect({ connector: walletConnector });
|
|
118
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
119
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
120
|
+
react_1.toast.success(`Connected to ${walletConnector.name}`);
|
|
121
|
+
return;
|
|
35
122
|
}
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
123
|
+
// If same wallet or no specific wallet, request permissions for account switching
|
|
124
|
+
if (walletClient && "request" in walletClient) {
|
|
125
|
+
await walletClient.request({
|
|
126
|
+
method: "wallet_requestPermissions",
|
|
127
|
+
params: [{ eth_accounts: {} }],
|
|
128
|
+
});
|
|
129
|
+
react_1.toast.success("Account selection completed");
|
|
39
130
|
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
40
131
|
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
41
|
-
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// Fallback: show modal for manual wallet selection
|
|
135
|
+
setShowWalletModal(true);
|
|
42
136
|
}
|
|
43
137
|
}
|
|
44
138
|
catch (error) {
|
|
45
|
-
console.error("Failed to
|
|
139
|
+
console.error("Failed to request wallet permissions:", error);
|
|
46
140
|
if (error && typeof error === "object" && "message" in error) {
|
|
47
141
|
const errorMessage = error.message.toLowerCase();
|
|
48
142
|
if (errorMessage.includes("rejected") ||
|
|
49
143
|
errorMessage.includes("denied") ||
|
|
50
144
|
errorMessage.includes("cancelled")) {
|
|
51
|
-
|
|
145
|
+
react_1.toast.error("Account selection cancelled");
|
|
52
146
|
}
|
|
53
147
|
else {
|
|
54
|
-
react_1.toast.error("Failed to
|
|
148
|
+
react_1.toast.error("Failed to open account selection");
|
|
55
149
|
}
|
|
56
150
|
}
|
|
151
|
+
else {
|
|
152
|
+
react_1.toast.error("Failed to open account selection");
|
|
153
|
+
}
|
|
57
154
|
}
|
|
58
155
|
};
|
|
59
|
-
return ((0, jsx_runtime_1.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
156
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "crypto-payment-method mx-auto h-fit w-[460px] max-w-full px-5 pb-5 pt-5 sm:px-0 sm:pt-5", children: [(0, jsx_runtime_1.jsxs)("div", { className: (0, cn_1.cn)("relative flex flex-col gap-10"), children: [(0, jsx_runtime_1.jsx)("button", { onClick: onBack, className: "text-as-quaternary hover:text-as-primary absolute flex h-8 w-8 items-center justify-center rounded-lg transition-colors", children: (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronLeft, { className: "h-6 w-6" }) }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-around gap-4", children: (0, jsx_runtime_1.jsx)("div", { className: "flex-1 text-center", children: (0, jsx_runtime_1.jsx)("h2", { className: "text-as-primary text-lg font-semibold", children: "Select a payment method" }) }) }), process.env.NODE_ENV === "development" && ((0, jsx_runtime_1.jsxs)("div", { className: "rounded-lg border border-yellow-500/50 bg-yellow-50 p-3 dark:bg-yellow-950/20", children: [(0, jsx_runtime_1.jsx)("p", { className: "mb-2 text-xs font-semibold text-yellow-800 dark:text-yellow-300", children: "\uD83E\uDDEA Toast Test (Dev Only)" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-wrap gap-2", children: [(0, jsx_runtime_1.jsx)("button", { onClick: () => react_1.toast.success("Success! Transaction completed"), className: "rounded bg-green-600 px-2 py-1 text-xs font-medium text-white hover:bg-green-700", children: "Success" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => react_1.toast.error("Error! Transaction failed"), className: "rounded bg-red-600 px-2 py-1 text-xs font-medium text-white hover:bg-red-700", children: "Error" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => react_1.toast.info("Info: Processing your request..."), className: "rounded bg-blue-600 px-2 py-1 text-xs font-medium text-white hover:bg-blue-700", children: "Info" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => react_1.toast.warning("Warning: Low balance detected"), className: "rounded bg-yellow-600 px-2 py-1 text-xs font-medium text-white hover:bg-yellow-700", children: "Warning" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => {
|
|
157
|
+
react_1.toast.success("Multiple test 1");
|
|
158
|
+
setTimeout(() => react_1.toast.info("Multiple test 2"), 200);
|
|
159
|
+
setTimeout(() => react_1.toast.warning("Multiple test 3"), 400);
|
|
160
|
+
}, 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 || shouldShowWagmiWallet || 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: () => {
|
|
161
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
162
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
163
|
+
if (connectedEOAWallet) {
|
|
164
|
+
setActiveWallet(connectedEOAWallet);
|
|
165
|
+
}
|
|
166
|
+
react_1.toast.success(`Selected ${eoaWalletInfo?.name || connector?.name || "wallet"}`);
|
|
167
|
+
}, 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
|
|
168
|
+
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
169
|
+
: "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 || connector?.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 => {
|
|
170
|
+
e.stopPropagation();
|
|
171
|
+
disconnect();
|
|
172
|
+
react_1.toast.success("Wallet disconnected");
|
|
173
|
+
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
174
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
175
|
+
}
|
|
176
|
+
}, 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: async () => {
|
|
177
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
178
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
179
|
+
// Create thirdweb wallet from wagmi connector
|
|
180
|
+
if (connector?.name) {
|
|
181
|
+
const thirdwebWallet = await createThirdwebWalletFromConnector(connector.name);
|
|
182
|
+
if (thirdwebWallet) {
|
|
183
|
+
setActiveWallet(thirdwebWallet);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
react_1.toast.success(`Selected ${connector?.name || "wallet"}`);
|
|
187
|
+
}, 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
|
|
188
|
+
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
189
|
+
: "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 => {
|
|
190
|
+
e.stopPropagation();
|
|
191
|
+
disconnect();
|
|
192
|
+
react_1.toast.success("Wallet disconnected");
|
|
193
|
+
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
194
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
195
|
+
}
|
|
196
|
+
}, 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" }) })] })] }) })), globalAddress && ((0, jsx_runtime_1.jsx)("button", { onClick: () => {
|
|
197
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.GLOBAL_WALLET);
|
|
198
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.GLOBAL_WALLET);
|
|
199
|
+
react_1.toast.success("Selected B3 Account");
|
|
200
|
+
}, className: (0, cn_1.cn)("crypto-payment-method-global-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET
|
|
201
|
+
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
202
|
+
: "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)(react_1.WalletImage, { fallback: (0, jsx_runtime_1.jsx)("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-purple-100", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Wallet, { className: "h-5 w-5 text-purple-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: "Global Account" }), (0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/60 text-sm", children: (0, formatAddress_1.shortenAddress)(globalAddress || "") })] })] }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: selectedPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET && ((0, jsx_runtime_1.jsx)("div", { className: "h-2 w-2 rounded-full bg-green-500" })) })] }) }))] })] })), (0, jsx_runtime_1.jsxs)("div", { className: "other-payment-methods", children: [(0, jsx_runtime_1.jsx)("h3", { className: "text-as-primary/80 mb-3 text-sm font-medium", children: "Payment methods" }), (0, jsx_runtime_1.jsxs)("div", { className: "space-y-3", children: [(0, jsx_runtime_1.jsxs)("button", { onClick: () => {
|
|
203
|
+
// Always show wallet selection modal first
|
|
204
|
+
setShowWalletModal(true);
|
|
205
|
+
}, className: "crypto-payment-method-connect-wallet bg-as-surface-primary border-as-border-secondary hover:border-as-secondary/80 group flex w-full items-center justify-between gap-4 rounded-xl border px-4 py-3.5 transition-all duration-200 hover:shadow-md", 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-8 w-8 items-center justify-center rounded-full bg-blue-100", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Wallet, { className: "h-4 w-4 text-blue-600" }) }), (0, jsx_runtime_1.jsx)("div", { className: "flex flex-col items-start text-left", children: (0, jsx_runtime_1.jsx)("h4", { className: "text-as-primary font-semibold", children: "Connect wallet" }) })] }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRightCircle, { className: "text-as-primary/40 group-hover:text-as-primary/60 h-5 w-5 transition-colors" })] }), (0, jsx_runtime_1.jsxs)("button", { onClick: () => {
|
|
206
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
|
|
207
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
|
|
208
|
+
}, disabled: isCreatingOrder, className: "crypto-payment-method-transfer bg-as-surface-primary border-as-border-secondary hover:border-as-secondary/80 group flex w-full items-center justify-between gap-4 rounded-xl border px-4 py-3.5 transition-all duration-200 hover:shadow-md", 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-8 w-8 items-center justify-center rounded-full bg-orange-100", children: (0, jsx_runtime_1.jsx)(lucide_react_1.ZapIcon, { className: "h-4 w-4" }) }), (0, jsx_runtime_1.jsx)("div", { className: "flex flex-col items-start text-left", children: (0, jsx_runtime_1.jsx)("h4", { className: "text-as-primary font-semibold", children: "Transfer crypto" }) })] }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRightCircle, { className: "text-as-primary/40 group-hover:text-as-primary/60 h-5 w-5 transition-colors" })] })] })] })] })] }), showWalletModal &&
|
|
209
|
+
(0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)("div", { className: "wallet-connection-modal pointer-events-auto fixed inset-0 z-[9999] flex items-center justify-center bg-black/50", children: (0, jsx_runtime_1.jsxs)("div", { className: "max-h-[80vh] w-[400px] max-w-[90vw] overflow-auto rounded-xl bg-white p-6 dark:bg-gray-900", children: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-4 flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white", children: isConnected ? "Switch wallet or account" : "Choose wallet to connect" }), (0, jsx_runtime_1.jsx)("button", { onClick: handleCloseModal, className: "text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200", children: (0, jsx_runtime_1.jsx)(lucide_react_1.X, { className: "h-5 w-5" }) })] }), (0, jsx_runtime_1.jsx)("div", { className: "space-y-4", children: (0, jsx_runtime_1.jsx)("div", { className: "space-y-3", children: walletOptions.map(walletOption => {
|
|
210
|
+
const isCurrentWallet = isConnected && connector?.name === walletOption.connector?.name;
|
|
211
|
+
return ((0, jsx_runtime_1.jsx)("button", { onClick: async () => {
|
|
212
|
+
handleCloseModal();
|
|
213
|
+
await requestWalletPermissions(walletOption.connector);
|
|
214
|
+
}, disabled: isPending, className: `wallet-option w-full rounded-xl border p-4 text-left transition-all hover:shadow-md disabled:opacity-50 ${isCurrentWallet
|
|
215
|
+
? "wallet-option--active border-blue-500 bg-blue-50 dark:bg-blue-900/20"
|
|
216
|
+
: "border-gray-200 bg-white hover:border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:hover:border-gray-500"}`, 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: [walletOption.icon, (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("div", { className: "wallet-option-name flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: walletOption.name }), isCurrentWallet && ((0, jsx_runtime_1.jsx)("span", { className: "rounded-full bg-blue-100 px-2 py-0.5 text-xs font-medium text-blue-700 dark:bg-blue-800 dark:text-blue-200", children: "Connected" }))] }), (0, jsx_runtime_1.jsx)("div", { className: "text-xs text-gray-500 dark:text-gray-400", children: isCurrentWallet ? "Switch account or reconnect" : walletOption.description })] })] }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRightCircle, { className: "h-5 w-5 text-gray-400" })] }) }, walletOption.id));
|
|
217
|
+
}) }) })] }) }), typeof window !== "undefined" ? document.getElementById("b3-root") || document.body : document.body)] }));
|
|
88
218
|
}
|
|
@@ -13,6 +13,7 @@ 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");
|
|
16
17
|
const useConnectedWalletDisplay_1 = require("./useConnectedWalletDisplay");
|
|
17
18
|
const useCryptoPaymentMethodState_1 = require("./useCryptoPaymentMethodState");
|
|
18
19
|
const useRecipientAddressState_1 = require("./useRecipientAddressState");
|
|
@@ -52,6 +53,8 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
52
53
|
// Recipient state with dual-state system (auto + explicit user selection)
|
|
53
54
|
const { address: globalAddress } = (0, react_2.useAccountWallet)();
|
|
54
55
|
const { walletAddress } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(effectiveCryptoPaymentMethod);
|
|
56
|
+
// Auto-set active wallet from wagmi
|
|
57
|
+
(0, useAutoSetActiveWalletFromWagmi_1.useAutoSetActiveWalletFromWagmi)();
|
|
55
58
|
// Recipient address state - hook automatically manages priority: props > user selection > wallet/global
|
|
56
59
|
const { setSelectedRecipientAddress, effectiveRecipientAddress } = (0, useRecipientAddressState_1.useRecipientAddressState)({
|
|
57
60
|
recipientAddressFromProps: recipientAddress,
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
}
|
|
@@ -6,6 +6,7 @@ const react_1 = require("../../../../global-account/react");
|
|
|
6
6
|
const debug_1 = require("../../../../shared/utils/debug");
|
|
7
7
|
const react_2 = require("react");
|
|
8
8
|
const react_3 = require("thirdweb/react");
|
|
9
|
+
const TurnkeyAuthModal_1 = require("../TurnkeyAuthModal");
|
|
9
10
|
const SignInWithB3Privy_1 = require("./SignInWithB3Privy");
|
|
10
11
|
const LoginStep_1 = require("./steps/LoginStep");
|
|
11
12
|
const LoginStepCustom_1 = require("./steps/LoginStepCustom");
|
|
@@ -23,7 +24,9 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
23
24
|
const account = (0, react_3.useActiveAccount)();
|
|
24
25
|
const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
|
|
25
26
|
const isAuthenticated = (0, react_1.useAuthStore)(state => state.isAuthenticated);
|
|
27
|
+
const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
|
|
26
28
|
const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
|
|
29
|
+
const setIsConnected = (0, react_1.useAuthStore)(state => state.setIsConnected);
|
|
27
30
|
const setJustCompletedLogin = (0, react_1.useAuthStore)(state => state.setJustCompletedLogin);
|
|
28
31
|
const [refetchCount, setRefetchCount] = (0, react_2.useState)(0);
|
|
29
32
|
const [refetchError, setRefetchError] = (0, react_2.useState)(null);
|
|
@@ -125,6 +128,10 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
125
128
|
debug("Refetching user after Turnkey success...");
|
|
126
129
|
await refetchUser();
|
|
127
130
|
debug("User refetched successfully");
|
|
131
|
+
// Set authentication and connection state so UI updates properly
|
|
132
|
+
setIsAuthenticated(true);
|
|
133
|
+
setIsConnected(true);
|
|
134
|
+
setJustCompletedLogin(true);
|
|
128
135
|
// After user data is refreshed, close Turnkey modal and go back to sign-in flow
|
|
129
136
|
debug("Switching back to signInWithB3 modal");
|
|
130
137
|
setB3ModalContentType({
|
|
@@ -154,6 +161,9 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
154
161
|
closeAfterLogin,
|
|
155
162
|
source,
|
|
156
163
|
signersEnabled,
|
|
164
|
+
setIsAuthenticated,
|
|
165
|
+
setIsConnected,
|
|
166
|
+
setJustCompletedLogin,
|
|
157
167
|
]);
|
|
158
168
|
// Handle post-login flow after signers are loaded
|
|
159
169
|
(0, react_2.useEffect)(() => {
|
|
@@ -289,21 +299,56 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
289
299
|
if (refetchError) {
|
|
290
300
|
content = ((0, jsx_runtime_1.jsx)(LoginStep_1.LoginStepContainer, { partnerId: partnerId, children: (0, jsx_runtime_1.jsx)("div", { className: "p-4 text-center text-red-500", children: refetchError }) }));
|
|
291
301
|
}
|
|
292
|
-
else if (isAuthenticating || (isFetchingSigners && step === "login") || source === "requestPermissions") {
|
|
293
|
-
content = ((0, jsx_runtime_1.jsx)(LoginStep_1.LoginStepContainer, { partnerId: partnerId, children: (0, jsx_runtime_1.jsx)("div", { className: "my-8 flex min-h-[350px] items-center justify-center", children: (0, jsx_runtime_1.jsx)(react_1.Loading, { variant: "white", size: "lg" }) }) }));
|
|
294
|
-
}
|
|
295
302
|
else if (step === "login") {
|
|
296
|
-
//
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
//
|
|
302
|
-
|
|
303
|
+
// PRIORITY: If Turnkey is enabled, show Turnkey modal FIRST as the primary authentication option
|
|
304
|
+
// Show Turnkey when enabled and not already completed in this session
|
|
305
|
+
const shouldShowTurnkeyFirst = enableTurnkey && !turnkeyAuthCompleted;
|
|
306
|
+
if (shouldShowTurnkeyFirst) {
|
|
307
|
+
// Don't show loading spinner for Turnkey - let the modal handle its own loading state
|
|
308
|
+
// This prevents the infinite loop where isAuthenticating causes the modal to be replaced
|
|
309
|
+
debug("Showing Turnkey as primary authentication option", {
|
|
310
|
+
enableTurnkey,
|
|
311
|
+
turnkeyAuthCompleted,
|
|
312
|
+
isAuthenticated,
|
|
313
|
+
});
|
|
314
|
+
// Show Turnkey authentication as primary option
|
|
315
|
+
content = ((0, jsx_runtime_1.jsx)(LoginStep_1.LoginStepContainer, { partnerId: partnerId, children: (0, jsx_runtime_1.jsx)(TurnkeyAuthModal_1.TurnkeyAuthModal, { onSuccess: async (authenticatedUser) => {
|
|
316
|
+
debug("Turnkey authentication successful in primary flow", { authenticatedUser });
|
|
317
|
+
setTurnkeyAuthCompleted(true);
|
|
318
|
+
// After Turnkey auth, refetch user to get the full user object
|
|
319
|
+
await refetchUser();
|
|
320
|
+
// User is now authenticated via Turnkey
|
|
321
|
+
// Set both isAuthenticated and isConnected to true so UI updates properly
|
|
322
|
+
// Wallet connection is optional and can happen later for signing transactions
|
|
323
|
+
setIsAuthenticated(true);
|
|
324
|
+
setIsConnected(true);
|
|
325
|
+
setJustCompletedLogin(true);
|
|
326
|
+
// Call the login success callback
|
|
327
|
+
onLoginSuccess?.({});
|
|
328
|
+
}, onClose: () => {
|
|
329
|
+
// If user closes Turnkey modal, they can still use wallet connection as fallback
|
|
330
|
+
setTurnkeyAuthCompleted(true);
|
|
331
|
+
}, initialEmail: "", skipToOtp: false }) }));
|
|
303
332
|
}
|
|
304
333
|
else {
|
|
305
|
-
//
|
|
306
|
-
|
|
334
|
+
// Show loading spinner only if not in Turnkey flow
|
|
335
|
+
if (isAuthenticating || (isFetchingSigners && step === "login") || source === "requestPermissions") {
|
|
336
|
+
content = ((0, jsx_runtime_1.jsx)(LoginStep_1.LoginStepContainer, { partnerId: partnerId, children: (0, jsx_runtime_1.jsx)("div", { className: "my-8 flex min-h-[350px] items-center justify-center", children: (0, jsx_runtime_1.jsx)(react_1.Loading, { variant: "white", size: "lg" }) }) }));
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
// Custom strategy
|
|
340
|
+
if (strategies?.[0] === "privy") {
|
|
341
|
+
content = (0, jsx_runtime_1.jsx)(SignInWithB3Privy_1.SignInWithB3Privy, { onSuccess: handleLoginSuccess, chain: chain });
|
|
342
|
+
}
|
|
343
|
+
else if (strategies) {
|
|
344
|
+
// Strategies are explicitly provided
|
|
345
|
+
content = ((0, jsx_runtime_1.jsx)(LoginStepCustom_1.LoginStepCustom, { strategies: strategies, chain: chain, onSuccess: handleLoginSuccess, onError: onError, automaticallySetFirstEoa: !!automaticallySetFirstEoa }));
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
// Default to handle all strategies we support
|
|
349
|
+
content = (0, jsx_runtime_1.jsx)(LoginStep_1.LoginStep, { chain: chain, onSuccess: handleLoginSuccess, onError: onError });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
307
352
|
}
|
|
308
353
|
}
|
|
309
354
|
return content;
|
|
@@ -3,6 +3,7 @@ export { useAccountAssets } from "./useAccountAssets";
|
|
|
3
3
|
export { useAccountWallet } from "./useAccountWallet";
|
|
4
4
|
export { useAddTWSessionKey } from "./useAddTWSessionKey";
|
|
5
5
|
export { useAnalytics } from "./useAnalytics";
|
|
6
|
+
export { useAuth } from "./useAuth";
|
|
6
7
|
export { useAuthentication } from "./useAuthentication";
|
|
7
8
|
export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses";
|
|
8
9
|
export { useB3EnsName } from "./useB3EnsName";
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.useURLParams = exports.useUnifiedChainSwitchAndExecute = exports.useTurnkeyAuth = exports.useTokensFromAddress = exports.useTokenPriceWithFallback = exports.useTokenPrice = exports.useTokenFromUrl = exports.useTokenData = exports.useTokenBalancesByChain = exports.useTokenBalanceDirect = exports.useTokenBalance = exports.useSiwe = exports.useSimSvmBalance = exports.useSimBalance = exports.useSearchParamsSSR = exports.useRouter = exports.useRemoveSessionKey = exports.useQueryBSMNT = exports.useQueryB3 = exports.useProfileSettings = exports.useProfilePreference = exports.useProfile = exports.useDisplayName = exports.useOneBalance = exports.useNotifications = exports.useNativeBalanceFromRPC = exports.useNativeBalance = exports.useMediaQuery = exports.useIsomorphicLayoutEffect = exports.useIsMobile = exports.useHasMounted = exports.useHandleConnectWithPrivy = exports.useGlobalAccount = exports.useGetGeo = exports.useGetAllTWSigners = exports.useFirstEOA = exports.useExchangeRate = exports.useConnect = exports.useClient = exports.useChainSwitchWithAction = exports.useBestTransactionPath = exports.useB3EnsName = exports.useB3BalanceFromAddresses = exports.useAuthentication = exports.useAnalytics = exports.useAddTWSessionKey = exports.useAccountWallet = exports.useAccountAssets = exports.createWagmiConfig = void 0;
|
|
17
|
+
exports.useURLParams = exports.useUnifiedChainSwitchAndExecute = exports.useTurnkeyAuth = exports.useTokensFromAddress = exports.useTokenPriceWithFallback = exports.useTokenPrice = exports.useTokenFromUrl = exports.useTokenData = exports.useTokenBalancesByChain = exports.useTokenBalanceDirect = exports.useTokenBalance = exports.useSiwe = exports.useSimSvmBalance = exports.useSimBalance = exports.useSearchParamsSSR = exports.useRouter = exports.useRemoveSessionKey = exports.useQueryBSMNT = exports.useQueryB3 = exports.useProfileSettings = exports.useProfilePreference = exports.useProfile = exports.useDisplayName = exports.useOneBalance = exports.useNotifications = exports.useNativeBalanceFromRPC = exports.useNativeBalance = exports.useMediaQuery = exports.useIsomorphicLayoutEffect = exports.useIsMobile = exports.useHasMounted = exports.useHandleConnectWithPrivy = exports.useGlobalAccount = exports.useGetGeo = exports.useGetAllTWSigners = exports.useFirstEOA = exports.useExchangeRate = exports.useConnect = exports.useClient = exports.useChainSwitchWithAction = exports.useBestTransactionPath = exports.useB3EnsName = exports.useB3BalanceFromAddresses = exports.useAuthentication = exports.useAuth = exports.useAnalytics = exports.useAddTWSessionKey = exports.useAccountWallet = exports.useAccountAssets = exports.createWagmiConfig = void 0;
|
|
18
18
|
var createWagmiConfig_1 = require("../utils/createWagmiConfig");
|
|
19
19
|
Object.defineProperty(exports, "createWagmiConfig", { enumerable: true, get: function () { return createWagmiConfig_1.createWagmiConfig; } });
|
|
20
20
|
var useAccountAssets_1 = require("./useAccountAssets");
|
|
@@ -25,6 +25,8 @@ var useAddTWSessionKey_1 = require("./useAddTWSessionKey");
|
|
|
25
25
|
Object.defineProperty(exports, "useAddTWSessionKey", { enumerable: true, get: function () { return useAddTWSessionKey_1.useAddTWSessionKey; } });
|
|
26
26
|
var useAnalytics_1 = require("./useAnalytics");
|
|
27
27
|
Object.defineProperty(exports, "useAnalytics", { enumerable: true, get: function () { return useAnalytics_1.useAnalytics; } });
|
|
28
|
+
var useAuth_1 = require("./useAuth");
|
|
29
|
+
Object.defineProperty(exports, "useAuth", { enumerable: true, get: function () { return useAuth_1.useAuth; } });
|
|
28
30
|
var useAuthentication_1 = require("./useAuthentication");
|
|
29
31
|
Object.defineProperty(exports, "useAuthentication", { enumerable: true, get: function () { return useAuthentication_1.useAuthentication; } });
|
|
30
32
|
var useB3BalanceFromAddresses_1 = require("./useB3BalanceFromAddresses");
|