signer-test-sdk-react 0.0.18 → 0.0.20
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/src/AbstraxnProvider.d.ts +2 -2
- package/dist/src/AbstraxnProvider.js +603 -534
- package/dist/src/AbstraxnProvider.js.map +1 -1
- package/dist/src/ConnectButton.css +1 -1
- package/dist/src/ExternalWalletButtons.css +1 -1
- package/dist/src/WalletModal.css +193 -373
- package/dist/src/WalletModal.d.ts +1 -1
- package/dist/src/WalletModal.js +108 -45
- package/dist/src/WalletModal.js.map +1 -1
- package/dist/src/chains.d.ts +4 -3
- package/dist/src/chains.js +154 -84
- package/dist/src/chains.js.map +1 -1
- package/dist/src/components/OnboardingUI/OnboardingUI.css +6 -5
- package/dist/src/components/OnboardingUI/OnboardingUIWeb.js +6 -0
- package/dist/src/components/OnboardingUI/OnboardingUIWeb.js.map +1 -1
- package/dist/src/components/WalletModal/components/ChainSelector.css +249 -102
- package/dist/src/components/WalletModal/components/ChainSelector.d.ts +7 -6
- package/dist/src/components/WalletModal/components/ChainSelector.js +68 -27
- package/dist/src/components/WalletModal/components/ChainSelector.js.map +1 -1
- package/dist/src/components/WalletModal/components/ExportKeyModal.css +89 -88
- package/dist/src/components/WalletModal/components/ExportKeyModal.d.ts +6 -1
- package/dist/src/components/WalletModal/components/ExportKeyModal.js +6 -11
- package/dist/src/components/WalletModal/components/ExportKeyModal.js.map +1 -1
- package/dist/src/components/WalletModal/components/ExportWarningModal.css +107 -2
- package/dist/src/components/WalletModal/components/ExportWarningModal.d.ts +7 -1
- package/dist/src/components/WalletModal/components/ExportWarningModal.js +5 -3
- package/dist/src/components/WalletModal/components/ExportWarningModal.js.map +1 -1
- package/dist/src/components/WalletModal/components/ManageWalletModal.css +90 -4
- package/dist/src/components/WalletModal/components/ManageWalletModal.d.ts +3 -3
- package/dist/src/components/WalletModal/components/ManageWalletModal.js +28 -13
- package/dist/src/components/WalletModal/components/ManageWalletModal.js.map +1 -1
- package/dist/src/components/WalletModal/components/PreviewTransactionModal.css +3 -4
- package/dist/src/components/WalletModal/components/ReceiveModal.css +93 -58
- package/dist/src/components/WalletModal/components/ReceiveModal.js +1 -1
- package/dist/src/components/WalletModal/components/ReceiveModal.js.map +1 -1
- package/dist/src/components/WalletModal/components/SendModal.css +170 -127
- package/dist/src/components/WalletModal/components/SendModal.d.ts +4 -6
- package/dist/src/components/WalletModal/components/SendModal.js +131 -39
- package/dist/src/components/WalletModal/components/SendModal.js.map +1 -1
- package/dist/src/components/WalletModal/components/SuccessModal.css +7 -8
- package/dist/src/components/WalletModal/components/TokenSelectorModal.css +240 -0
- package/dist/src/components/WalletModal/components/TokenSelectorModal.d.ts +21 -0
- package/dist/src/components/WalletModal/components/TokenSelectorModal.js +44 -0
- package/dist/src/components/WalletModal/components/TokenSelectorModal.js.map +1 -0
- package/dist/src/components/WalletModal/components/index.d.ts +2 -0
- package/dist/src/components/WalletModal/components/index.js +1 -0
- package/dist/src/components/WalletModal/components/index.js.map +1 -1
- package/dist/src/hooks.js +5 -39
- package/dist/src/hooks.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/types.d.ts +18 -0
- package/dist/src/wagmiConfig.d.ts +1 -1
- package/dist/src/wagmiConfig.js +9 -8
- package/dist/src/wagmiConfig.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -3,15 +3,15 @@ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
|
3
3
|
* Abstraxn Wallet Provider - React Context Provider
|
|
4
4
|
* Wrap your app with this provider to use Abstraxn Wallet SDK
|
|
5
5
|
*/
|
|
6
|
-
import React, { createContext, useContext, useEffect, useState, useRef, useCallback, useMemo } from
|
|
7
|
-
import { AbstraxnWallet, AuthenticationError } from
|
|
8
|
-
import { OnboardingUIWeb } from
|
|
9
|
-
import { WagmiProvider, useAccount, useConnect, useDisconnect, useSignMessage, useSendTransaction, useSwitchChain, useBalance, useChainId } from
|
|
10
|
-
import { QueryClient, QueryClientProvider } from
|
|
11
|
-
import { createWagmiConfig } from
|
|
12
|
-
import { parseEther, createPublicClient, http } from
|
|
13
|
-
import { ExternalWalletButtons } from
|
|
14
|
-
import { EVM_CHAINS, SOLANA_CHAINS, getChainById, toCoreChain } from
|
|
6
|
+
import React, { createContext, useContext, useEffect, useState, useRef, useCallback, useMemo, } from "react";
|
|
7
|
+
import { AbstraxnWallet, AuthenticationError, } from "signer-test-sdk-core";
|
|
8
|
+
import { OnboardingUIWeb } from "./components/OnboardingUI";
|
|
9
|
+
import { WagmiProvider, useAccount, useConnect, useDisconnect, useSignMessage, useSendTransaction, useSwitchChain, useBalance, useChainId, } from "wagmi";
|
|
10
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
11
|
+
import { createWagmiConfig } from "./wagmiConfig";
|
|
12
|
+
import { parseEther, createPublicClient, http } from "viem";
|
|
13
|
+
import { ExternalWalletButtons } from "./ExternalWalletButtons";
|
|
14
|
+
import { EVM_CHAINS, SOLANA_CHAINS, getChainById, toCoreChain, } from "./chains";
|
|
15
15
|
export const AbstraxnContext = createContext(null);
|
|
16
16
|
// QueryClient will be created inside the component to ensure React context is available
|
|
17
17
|
// Base provider logic (shared between with and without wagmi)
|
|
@@ -32,20 +32,34 @@ function useAbstraxnProviderBase(_config) {
|
|
|
32
32
|
const twitterCallbackHandledRef = useRef(false);
|
|
33
33
|
const discordCallbackHandledRef = useRef(false);
|
|
34
34
|
return {
|
|
35
|
-
isInitialized,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
isInitialized,
|
|
36
|
+
setIsInitialized,
|
|
37
|
+
isConnected,
|
|
38
|
+
setIsConnected,
|
|
39
|
+
address,
|
|
40
|
+
setAddress,
|
|
41
|
+
user,
|
|
42
|
+
setUser,
|
|
43
|
+
whoami,
|
|
44
|
+
setWhoami,
|
|
45
|
+
chainId,
|
|
46
|
+
setChainId,
|
|
47
|
+
error,
|
|
48
|
+
setError,
|
|
49
|
+
loading,
|
|
50
|
+
setLoading,
|
|
51
|
+
walletBalance,
|
|
52
|
+
setWalletBalance,
|
|
53
|
+
onboardingRef,
|
|
54
|
+
otpIdRef,
|
|
55
|
+
walletRef,
|
|
56
|
+
googleCallbackHandledRef,
|
|
57
|
+
twitterCallbackHandledRef,
|
|
58
|
+
discordCallbackHandledRef,
|
|
45
59
|
};
|
|
46
60
|
}
|
|
47
61
|
// Internal component WITH wagmi hooks (used when external wallets are enabled)
|
|
48
|
-
function AbstraxnProviderWithWagmi({ config, children }) {
|
|
62
|
+
function AbstraxnProviderWithWagmi({ config, children, }) {
|
|
49
63
|
const base = useAbstraxnProviderBase(config);
|
|
50
64
|
const externalWalletsEnabled = config.externalWallets?.enabled ?? false;
|
|
51
65
|
// Keep a ref so callbacks remain stable when config toggles
|
|
@@ -70,14 +84,23 @@ function AbstraxnProviderWithWagmi({ config, children }) {
|
|
|
70
84
|
refetchInterval: false,
|
|
71
85
|
},
|
|
72
86
|
});
|
|
73
|
-
return _jsx(AbstraxnProviderInner, { config: config, children: children, base: base, wagmi: {
|
|
87
|
+
return (_jsx(AbstraxnProviderInner, { config: config, children: children, base: base, wagmi: {
|
|
88
|
+
wagmiAccount,
|
|
89
|
+
wagmiConnect,
|
|
90
|
+
wagmiDisconnect,
|
|
91
|
+
wagmiSignMessage,
|
|
92
|
+
wagmiSendTransaction,
|
|
93
|
+
wagmiSwitchChain,
|
|
94
|
+
wagmiBalance,
|
|
95
|
+
wagmiChainIdHook,
|
|
96
|
+
} }));
|
|
74
97
|
}
|
|
75
98
|
// Internal component WITHOUT wagmi hooks (used when external wallets are disabled)
|
|
76
|
-
function AbstraxnProviderWithoutWagmi({ config, children }) {
|
|
99
|
+
function AbstraxnProviderWithoutWagmi({ config, children, }) {
|
|
77
100
|
const base = useAbstraxnProviderBase(config);
|
|
78
|
-
return _jsx(AbstraxnProviderInner, { config: config, children: children, base: base, wagmi: null });
|
|
101
|
+
return (_jsx(AbstraxnProviderInner, { config: config, children: children, base: base, wagmi: null }));
|
|
79
102
|
}
|
|
80
|
-
function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
103
|
+
function AbstraxnProviderInner({ config, children, base, wagmi, }) {
|
|
81
104
|
const { isInitialized, setIsInitialized, isConnected, setIsConnected, address, setAddress, user, setUser, whoami, setWhoami, chainId, setChainId, error, setError, loading, setLoading, walletBalance, setWalletBalance, onboardingRef, otpIdRef, walletRef, googleCallbackHandledRef, twitterCallbackHandledRef, discordCallbackHandledRef, } = base;
|
|
82
105
|
const externalWalletsEnabled = config.externalWallets?.enabled ?? false;
|
|
83
106
|
// Keep a ref to avoid re-creating callbacks when toggling config (prevents flicker)
|
|
@@ -119,24 +142,27 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
119
142
|
if (externalWalletsEnabled) {
|
|
120
143
|
// Show external wallet container when enabled
|
|
121
144
|
if (onboardingAny.externalWalletContainer) {
|
|
122
|
-
onboardingAny.externalWalletContainer.style.display =
|
|
145
|
+
onboardingAny.externalWalletContainer.style.display = "";
|
|
123
146
|
}
|
|
124
147
|
// Show divider if email/Google are also visible
|
|
125
|
-
const authMethods = onboardingAny.config?.authMethods || [
|
|
126
|
-
|
|
127
|
-
|
|
148
|
+
const authMethods = onboardingAny.config?.authMethods || [
|
|
149
|
+
"otp",
|
|
150
|
+
"google",
|
|
151
|
+
];
|
|
152
|
+
const showEmail = authMethods.includes("otp");
|
|
153
|
+
const showGoogle = authMethods.includes("google");
|
|
128
154
|
const hasEmailOrGoogle = showEmail || showGoogle;
|
|
129
155
|
if (onboardingAny.externalWalletDivider && hasEmailOrGoogle) {
|
|
130
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
156
|
+
onboardingAny.externalWalletDivider.style.display = "";
|
|
131
157
|
}
|
|
132
158
|
}
|
|
133
159
|
else {
|
|
134
160
|
// Hide external wallet container when disabled
|
|
135
161
|
if (onboardingAny.externalWalletContainer) {
|
|
136
|
-
onboardingAny.externalWalletContainer.style.display =
|
|
162
|
+
onboardingAny.externalWalletContainer.style.display = "none";
|
|
137
163
|
}
|
|
138
164
|
if (onboardingAny.externalWalletDivider) {
|
|
139
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
165
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
140
166
|
}
|
|
141
167
|
}
|
|
142
168
|
});
|
|
@@ -150,7 +176,9 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
150
176
|
// Check if wagmi has already restored a connection from localStorage
|
|
151
177
|
// This happens automatically with wagmi's persistence when storage is configured
|
|
152
178
|
const checkAndRestore = () => {
|
|
153
|
-
if (wagmiAccount.isConnected &&
|
|
179
|
+
if (wagmiAccount.isConnected &&
|
|
180
|
+
wagmiAccount.address &&
|
|
181
|
+
!isExternalWalletConnected) {
|
|
154
182
|
const walletAddress = wagmiAccount.address.toLowerCase();
|
|
155
183
|
const currentChainId = wagmiChainIdHook || wagmiAccount.chainId || null;
|
|
156
184
|
// Set explicitConnectionRef FIRST to prevent auto-disconnect from interfering
|
|
@@ -223,7 +251,13 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
223
251
|
clearTimeout(timeout2);
|
|
224
252
|
}
|
|
225
253
|
};
|
|
226
|
-
}, [
|
|
254
|
+
}, [
|
|
255
|
+
externalWalletsEnabled,
|
|
256
|
+
wagmiAccount?.isConnected,
|
|
257
|
+
wagmiAccount?.address,
|
|
258
|
+
wagmiChainIdHook,
|
|
259
|
+
isExternalWalletConnected,
|
|
260
|
+
]); // Re-run if wagmi state changes
|
|
227
261
|
// Initialize wallet
|
|
228
262
|
useEffect(() => {
|
|
229
263
|
// If wallet already exists (from previous mount), reuse it to prevent flicker
|
|
@@ -245,10 +279,12 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
245
279
|
// Priority 1: Check if chains is an array of viem chain objects (direct format)
|
|
246
280
|
if (Array.isArray(chainConfig) && chainConfig?.length > 0) {
|
|
247
281
|
const firstItem = chainConfig[0];
|
|
248
|
-
if (firstItem &&
|
|
282
|
+
if (firstItem &&
|
|
283
|
+
typeof firstItem.id === "number" &&
|
|
284
|
+
firstItem.nativeCurrency) {
|
|
249
285
|
// Convert viem chain objects to core chain format
|
|
250
286
|
chainConfig.forEach((viemChain) => {
|
|
251
|
-
let rpcUrl =
|
|
287
|
+
let rpcUrl = "";
|
|
252
288
|
if (viemChain.rpcUrls?.default?.http) {
|
|
253
289
|
rpcUrl = Array.isArray(viemChain.rpcUrls.default.http)
|
|
254
290
|
? viemChain.rpcUrls.default.http[0]
|
|
@@ -262,17 +298,19 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
262
298
|
chains.push({
|
|
263
299
|
id: viemChain.id,
|
|
264
300
|
name: viemChain.name,
|
|
265
|
-
rpcUrl: rpcUrl ||
|
|
301
|
+
rpcUrl: rpcUrl ||
|
|
302
|
+
`https://rpc.ankr.com/${viemChain.name.toLowerCase()}`,
|
|
266
303
|
nativeCurrency: viemChain.nativeCurrency,
|
|
267
304
|
});
|
|
268
305
|
});
|
|
269
306
|
}
|
|
270
307
|
}
|
|
271
308
|
// Priority 2: Check new chains config format
|
|
272
|
-
else if (chainConfig?.supportedEvmChains &&
|
|
309
|
+
else if (chainConfig?.supportedEvmChains &&
|
|
310
|
+
chainConfig.supportedEvmChains.length > 0) {
|
|
273
311
|
chainConfig.supportedEvmChains.forEach((chainName) => {
|
|
274
312
|
const chainData = EVM_CHAINS[chainName];
|
|
275
|
-
if (chainData && chainData.type ===
|
|
313
|
+
if (chainData && chainData.type === "evm") {
|
|
276
314
|
chains.push(toCoreChain(chainData));
|
|
277
315
|
}
|
|
278
316
|
});
|
|
@@ -285,11 +323,14 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
285
323
|
chains.push(toCoreChain(EVM_CHAINS.polygon));
|
|
286
324
|
chains.push(toCoreChain(EVM_CHAINS.base));
|
|
287
325
|
}
|
|
288
|
-
computedSupportedChains =
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
326
|
+
computedSupportedChains =
|
|
327
|
+
chains.length > 0
|
|
328
|
+
? chains
|
|
329
|
+
: [
|
|
330
|
+
toCoreChain(EVM_CHAINS.ethereum),
|
|
331
|
+
toCoreChain(EVM_CHAINS.polygon),
|
|
332
|
+
toCoreChain(EVM_CHAINS.base),
|
|
333
|
+
];
|
|
293
334
|
}
|
|
294
335
|
const walletInstance = new AbstraxnWallet({
|
|
295
336
|
apiKey: config.apiKey,
|
|
@@ -302,7 +343,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
302
343
|
});
|
|
303
344
|
walletRef.current = walletInstance;
|
|
304
345
|
// Set up event listeners
|
|
305
|
-
walletInstance.on(
|
|
346
|
+
walletInstance.on("connect", async () => {
|
|
306
347
|
try {
|
|
307
348
|
// Verify whoami exists before setting connected
|
|
308
349
|
const whoamiInfo = await walletInstance.getWhoami();
|
|
@@ -320,7 +361,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
320
361
|
setAddress(addr);
|
|
321
362
|
}
|
|
322
363
|
catch (addrErr) {
|
|
323
|
-
console.warn(
|
|
364
|
+
console.warn("Address not available on connect:", addrErr);
|
|
324
365
|
}
|
|
325
366
|
const cid = await walletInstance.getChainId();
|
|
326
367
|
setChainId(cid);
|
|
@@ -338,7 +379,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
338
379
|
}
|
|
339
380
|
}
|
|
340
381
|
catch (err) {
|
|
341
|
-
console.error(
|
|
382
|
+
console.error("Error getting wallet info on connect:", err);
|
|
342
383
|
}
|
|
343
384
|
// Ensure loading modal is closed when connected (whoami received)
|
|
344
385
|
if (onboardingRef.current) {
|
|
@@ -347,19 +388,20 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
347
388
|
onboardingAny.hideLoadingModal();
|
|
348
389
|
}
|
|
349
390
|
// Also ensure the overlay is hidden if it was opened
|
|
350
|
-
if (onboardingAny.modalOverlay &&
|
|
351
|
-
onboardingAny.modalOverlay.classList.
|
|
352
|
-
onboardingAny.modalOverlay.classList.
|
|
391
|
+
if (onboardingAny.modalOverlay &&
|
|
392
|
+
onboardingAny.modalOverlay.classList.contains("onboarding-modal-open")) {
|
|
393
|
+
onboardingAny.modalOverlay.classList.remove("onboarding-modal-open");
|
|
394
|
+
onboardingAny.modalOverlay.classList.add("onboarding-modal-closing");
|
|
353
395
|
setTimeout(() => {
|
|
354
396
|
if (onboardingAny.modalOverlay) {
|
|
355
|
-
onboardingAny.modalOverlay.style.display =
|
|
397
|
+
onboardingAny.modalOverlay.style.display = "none";
|
|
356
398
|
}
|
|
357
399
|
}, 200);
|
|
358
|
-
document.body.style.overflow =
|
|
400
|
+
document.body.style.overflow = "";
|
|
359
401
|
}
|
|
360
402
|
}
|
|
361
403
|
});
|
|
362
|
-
walletInstance.on(
|
|
404
|
+
walletInstance.on("disconnect", () => {
|
|
363
405
|
setIsConnected(false);
|
|
364
406
|
setAddress(null);
|
|
365
407
|
setUser(null);
|
|
@@ -374,10 +416,10 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
374
416
|
// Ignore localStorage errors
|
|
375
417
|
}
|
|
376
418
|
});
|
|
377
|
-
walletInstance.on(
|
|
419
|
+
walletInstance.on("accountChanged", (newAddress) => {
|
|
378
420
|
setAddress(newAddress);
|
|
379
421
|
});
|
|
380
|
-
walletInstance.on(
|
|
422
|
+
walletInstance.on("chainChanged", (newChainId) => {
|
|
381
423
|
setChainId(newChainId);
|
|
382
424
|
});
|
|
383
425
|
// Initialize OnboardingUI only if not already created (prevents flicker on config change)
|
|
@@ -387,9 +429,9 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
387
429
|
const uiConfig = config.ui || {};
|
|
388
430
|
const onboarding = new OnboardingUIWeb({
|
|
389
431
|
logo: uiConfig.logo,
|
|
390
|
-
theme: uiConfig.theme ||
|
|
432
|
+
theme: uiConfig.theme || "light",
|
|
391
433
|
showFooter: uiConfig.showFooter !== false,
|
|
392
|
-
onboardTitle: uiConfig.onboardTitle ||
|
|
434
|
+
onboardTitle: uiConfig.onboardTitle || "Sign In",
|
|
393
435
|
modal: uiConfig.modal !== false,
|
|
394
436
|
closeOnBackdropClick: uiConfig.closeOnBackdropClick !== false,
|
|
395
437
|
className: uiConfig.className,
|
|
@@ -401,12 +443,12 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
401
443
|
onEmailOtpInitiate: async (email) => {
|
|
402
444
|
try {
|
|
403
445
|
if (!walletInstance)
|
|
404
|
-
throw new Error(
|
|
446
|
+
throw new Error("Wallet not initialized");
|
|
405
447
|
const authManager = walletInstance.getAuthManager();
|
|
406
|
-
const connectionTypeValue =
|
|
448
|
+
const connectionTypeValue = "email";
|
|
407
449
|
setConnectionType(connectionTypeValue);
|
|
408
450
|
try {
|
|
409
|
-
localStorage.setItem(
|
|
451
|
+
localStorage.setItem("abstraxn_connection_type", connectionTypeValue);
|
|
410
452
|
}
|
|
411
453
|
catch (e) {
|
|
412
454
|
// Ignore localStorage errors
|
|
@@ -415,21 +457,21 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
415
457
|
otpIdRef.current = result.otpId;
|
|
416
458
|
}
|
|
417
459
|
catch (err) {
|
|
418
|
-
console.error(
|
|
460
|
+
console.error("OTP Init Error:", err);
|
|
419
461
|
throw err;
|
|
420
462
|
}
|
|
421
463
|
},
|
|
422
464
|
onEmailOtpVerify: async (_email, otp) => {
|
|
423
465
|
try {
|
|
424
466
|
if (!walletInstance)
|
|
425
|
-
throw new Error(
|
|
467
|
+
throw new Error("Wallet not initialized");
|
|
426
468
|
if (!otpIdRef.current)
|
|
427
|
-
throw new Error(
|
|
469
|
+
throw new Error("OTP ID not found");
|
|
428
470
|
// Set connection type for email OTP before verification
|
|
429
|
-
const connectionTypeValue =
|
|
471
|
+
const connectionTypeValue = "email";
|
|
430
472
|
setConnectionType(connectionTypeValue);
|
|
431
473
|
try {
|
|
432
|
-
localStorage.setItem(
|
|
474
|
+
localStorage.setItem("abstraxn_connection_type", connectionTypeValue);
|
|
433
475
|
}
|
|
434
476
|
catch (e) {
|
|
435
477
|
// Ignore localStorage errors
|
|
@@ -444,214 +486,82 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
444
486
|
return { success: true, user };
|
|
445
487
|
}
|
|
446
488
|
catch (err) {
|
|
447
|
-
console.error(
|
|
489
|
+
console.error("OTP Verify Error:", err);
|
|
448
490
|
// Return the actual error message from the API
|
|
449
|
-
const errorMessage = err instanceof Error ? err.message :
|
|
491
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to verify OTP";
|
|
450
492
|
return { success: false, error: errorMessage };
|
|
451
493
|
}
|
|
452
494
|
},
|
|
453
495
|
onGoogleLogin: async () => {
|
|
454
496
|
if (!walletInstance)
|
|
455
|
-
throw new Error(
|
|
456
|
-
const connectionTypeValue =
|
|
497
|
+
throw new Error("Wallet not initialized");
|
|
498
|
+
const connectionTypeValue = "google";
|
|
457
499
|
setConnectionType(connectionTypeValue);
|
|
458
500
|
// Store in localStorage for restoration
|
|
459
501
|
try {
|
|
460
|
-
localStorage.setItem(
|
|
461
|
-
}
|
|
462
|
-
catch (e) {
|
|
463
|
-
// Ignore localStorage errors
|
|
464
|
-
}
|
|
465
|
-
const authManager = walletInstance.getAuthManager();
|
|
466
|
-
await authManager.loginWithGoogle();
|
|
467
|
-
},
|
|
468
|
-
onTwitterLogin: async () => {
|
|
469
|
-
if (!walletInstance)
|
|
470
|
-
throw new Error('Wallet not initialized');
|
|
471
|
-
const connectionTypeValue = 'x';
|
|
472
|
-
setConnectionType(connectionTypeValue);
|
|
473
|
-
try {
|
|
474
|
-
localStorage.setItem('abstraxn_connection_type', connectionTypeValue);
|
|
475
|
-
}
|
|
476
|
-
catch (e) {
|
|
477
|
-
// Ignore localStorage errors
|
|
478
|
-
}
|
|
479
|
-
const authManager = walletInstance.getAuthManager();
|
|
480
|
-
await authManager.loginWithTwitter();
|
|
481
|
-
},
|
|
482
|
-
onDiscordLogin: async () => {
|
|
483
|
-
if (!walletInstance)
|
|
484
|
-
throw new Error('Wallet not initialized');
|
|
485
|
-
const connectionTypeValue = 'discord';
|
|
486
|
-
setConnectionType(connectionTypeValue);
|
|
487
|
-
try {
|
|
488
|
-
localStorage.setItem('abstraxn_connection_type', connectionTypeValue);
|
|
489
|
-
}
|
|
490
|
-
catch (e) {
|
|
491
|
-
// Ignore localStorage errors
|
|
492
|
-
}
|
|
493
|
-
const authManager = walletInstance.getAuthManager();
|
|
494
|
-
await authManager.loginWithDiscord();
|
|
495
|
-
},
|
|
496
|
-
onPasskeyLogin: async () => {
|
|
497
|
-
if (!walletInstance)
|
|
498
|
-
throw new Error('Wallet not initialized');
|
|
499
|
-
const connectionTypeValue = 'passkey';
|
|
500
|
-
setConnectionType(connectionTypeValue);
|
|
501
|
-
try {
|
|
502
|
-
localStorage.setItem('abstraxn_connection_type', connectionTypeValue);
|
|
503
|
-
}
|
|
504
|
-
catch (e) {
|
|
505
|
-
// Ignore localStorage errors
|
|
506
|
-
}
|
|
507
|
-
const authManager = walletInstance.getAuthManager();
|
|
508
|
-
const user = await authManager.loginWithPasskey();
|
|
509
|
-
// Set user immediately so onLoginSuccess can access it
|
|
510
|
-
setUser(user);
|
|
511
|
-
// Connect wallet after successful authentication
|
|
512
|
-
await walletInstance.connect();
|
|
513
|
-
},
|
|
514
|
-
onPasskeySignup: async () => {
|
|
515
|
-
if (!walletInstance)
|
|
516
|
-
throw new Error('Wallet not initialized');
|
|
517
|
-
const connectionTypeValue = 'passkey';
|
|
518
|
-
setConnectionType(connectionTypeValue);
|
|
519
|
-
try {
|
|
520
|
-
localStorage.setItem('abstraxn_connection_type', connectionTypeValue);
|
|
521
|
-
}
|
|
522
|
-
catch (e) {
|
|
523
|
-
// Ignore localStorage errors
|
|
524
|
-
}
|
|
525
|
-
const authManager = walletInstance.getAuthManager();
|
|
526
|
-
const user = await authManager.signupWithPasskey();
|
|
527
|
-
// Set user immediately so onLoginSuccess can access it
|
|
528
|
-
setUser(user);
|
|
529
|
-
// Connect wallet after successful authentication
|
|
530
|
-
await walletInstance.connect();
|
|
531
|
-
},
|
|
532
|
-
onLoginSuccess: async (data) => {
|
|
533
|
-
// Clear any previous errors on successful login
|
|
534
|
-
setError(null);
|
|
535
|
-
// Restore connection type from localStorage for OAuth logins (Google, X, Discord)
|
|
536
|
-
// This ensures connectionType is set after OAuth redirects
|
|
537
|
-
try {
|
|
538
|
-
const storedType = localStorage.getItem('abstraxn_connection_type');
|
|
539
|
-
if (storedType && (storedType === 'google' || storedType === 'x' || storedType === 'discord' || storedType === 'email' || storedType === 'passkey')) {
|
|
540
|
-
setConnectionType(storedType);
|
|
541
|
-
}
|
|
502
|
+
localStorage.setItem("abstraxn_connection_type", connectionTypeValue);
|
|
542
503
|
}
|
|
543
504
|
catch (e) {
|
|
544
505
|
// Ignore localStorage errors
|
|
545
506
|
}
|
|
546
|
-
|
|
547
|
-
if (data.user) {
|
|
548
|
-
setUser(data.user);
|
|
549
|
-
}
|
|
550
|
-
// Load whoami after successful login
|
|
551
|
-
if (walletInstance) {
|
|
552
|
-
try {
|
|
553
|
-
const whoamiInfo = await walletInstance.getWhoami();
|
|
554
|
-
setWhoami(whoamiInfo);
|
|
555
|
-
const addr = await walletInstance.getAddress();
|
|
556
|
-
setAddress(addr);
|
|
557
|
-
const cid = await walletInstance.getChainId();
|
|
558
|
-
setChainId(cid);
|
|
559
|
-
// Only hide onboarding UI and set connected if whoami succeeds
|
|
560
|
-
if (onboardingRef.current) {
|
|
561
|
-
const onboardingAny = onboardingRef.current;
|
|
562
|
-
if (onboardingAny.hideLoadingModal) {
|
|
563
|
-
onboardingAny.hideLoadingModal();
|
|
564
|
-
}
|
|
565
|
-
if (onboardingAny.modalOverlay) {
|
|
566
|
-
onboardingAny.modalOverlay.classList.remove('onboarding-modal-open');
|
|
567
|
-
onboardingAny.modalOverlay.classList.add('onboarding-modal-closing');
|
|
568
|
-
setTimeout(() => {
|
|
569
|
-
if (onboardingAny.modalOverlay) {
|
|
570
|
-
onboardingAny.modalOverlay.style.display = 'none';
|
|
571
|
-
}
|
|
572
|
-
}, 200);
|
|
573
|
-
}
|
|
574
|
-
document.body.style.overflow = '';
|
|
575
|
-
}
|
|
576
|
-
// Set connected state only after whoami succeeds
|
|
577
|
-
setIsConnected(true);
|
|
578
|
-
}
|
|
579
|
-
catch (err) {
|
|
580
|
-
console.error('Error loading whoami after login:', err);
|
|
581
|
-
// Hide loading modal on whoami error
|
|
582
|
-
if (onboardingRef.current) {
|
|
583
|
-
const onboardingAny = onboardingRef.current;
|
|
584
|
-
if (onboardingAny.hideLoadingModal) {
|
|
585
|
-
onboardingAny.hideLoadingModal();
|
|
586
|
-
}
|
|
587
|
-
// Show error modal/screen
|
|
588
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to load user information';
|
|
589
|
-
if (onboardingAny.showError) {
|
|
590
|
-
onboardingAny.showError(errorMessage);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
// Set error state
|
|
594
|
-
const error = err instanceof Error ? err : new Error('Failed to load user information after login');
|
|
595
|
-
setError(error);
|
|
596
|
-
// Don't set connected if whoami fails
|
|
597
|
-
setIsConnected(false);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
},
|
|
601
|
-
onLoginError: (err) => {
|
|
602
|
-
setError(err);
|
|
603
|
-
},
|
|
507
|
+
}
|
|
604
508
|
}, externalWalletsEnabled); // Pass externalWalletsEnabled as second parameter
|
|
605
509
|
// Inject custom CSS if provided
|
|
606
510
|
if (uiConfig.customCSS) {
|
|
607
|
-
const styleId =
|
|
511
|
+
const styleId = "abstraxn-custom-css";
|
|
608
512
|
if (!document.getElementById(styleId)) {
|
|
609
|
-
const style = document.createElement(
|
|
513
|
+
const style = document.createElement("style");
|
|
610
514
|
style.id = styleId;
|
|
611
515
|
style.textContent = uiConfig.customCSS;
|
|
612
516
|
document.head.appendChild(style);
|
|
613
517
|
}
|
|
614
518
|
}
|
|
615
|
-
const hasAuthParams = (params) => params.get(
|
|
616
|
-
params.get(
|
|
617
|
-
params.get(
|
|
618
|
-
params.get(
|
|
519
|
+
const hasAuthParams = (params) => params.get("success") === "true" ||
|
|
520
|
+
params.get("error") ||
|
|
521
|
+
params.get("code") ||
|
|
522
|
+
params.get("accessToken");
|
|
619
523
|
const getAuthProviderFromToken = (token) => {
|
|
620
524
|
try {
|
|
621
|
-
const base64Url = token.split(
|
|
622
|
-
const base64 = base64Url.replace(/-/g,
|
|
623
|
-
const jsonPayload = decodeURIComponent(window
|
|
624
|
-
|
|
625
|
-
|
|
525
|
+
const base64Url = token.split(".")[1];
|
|
526
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
527
|
+
const jsonPayload = decodeURIComponent(window
|
|
528
|
+
.atob(base64)
|
|
529
|
+
.split("")
|
|
530
|
+
.map(function (c) {
|
|
531
|
+
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
|
532
|
+
})
|
|
533
|
+
.join(""));
|
|
626
534
|
const payload = JSON.parse(jsonPayload);
|
|
627
|
-
return (payload.authProvider || payload.provider ||
|
|
535
|
+
return (payload.authProvider || payload.provider || "").toLowerCase();
|
|
628
536
|
}
|
|
629
537
|
catch (e) {
|
|
630
538
|
return null;
|
|
631
539
|
}
|
|
632
540
|
};
|
|
633
541
|
const matchesProvider = (provider, params) => {
|
|
634
|
-
const providerParam = (params.get(
|
|
542
|
+
const providerParam = (params.get("provider") ||
|
|
543
|
+
params.get("authProvider") ||
|
|
544
|
+
"").toLowerCase();
|
|
635
545
|
const path = window.location.pathname.toLowerCase();
|
|
636
546
|
if (providerParam) {
|
|
637
|
-
if (provider ===
|
|
638
|
-
return providerParam ===
|
|
547
|
+
if (provider === "twitter") {
|
|
548
|
+
return providerParam === "twitter" || providerParam === "x";
|
|
639
549
|
}
|
|
640
550
|
return providerParam === provider;
|
|
641
551
|
}
|
|
642
552
|
// Check accessToken for provider
|
|
643
|
-
const accessToken = params.get(
|
|
553
|
+
const accessToken = params.get("accessToken");
|
|
644
554
|
if (accessToken) {
|
|
645
555
|
const tokenProvider = getAuthProviderFromToken(accessToken);
|
|
646
556
|
if (tokenProvider) {
|
|
647
|
-
if (provider ===
|
|
648
|
-
return tokenProvider ===
|
|
557
|
+
if (provider === "twitter") {
|
|
558
|
+
return tokenProvider === "twitter" || tokenProvider === "x";
|
|
649
559
|
}
|
|
650
560
|
return tokenProvider === provider;
|
|
651
561
|
}
|
|
652
562
|
}
|
|
653
|
-
if (provider ===
|
|
654
|
-
return path.includes(
|
|
563
|
+
if (provider === "twitter") {
|
|
564
|
+
return path.includes("/twitter") || path.includes("/x");
|
|
655
565
|
}
|
|
656
566
|
return path.includes(`/${provider}`);
|
|
657
567
|
};
|
|
@@ -659,15 +569,15 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
659
569
|
// Check if we should keep it open (if handling a callback)
|
|
660
570
|
const urlParams = new URLSearchParams(window.location.search);
|
|
661
571
|
const shouldKeepOpen = hasAuthParams(urlParams);
|
|
662
|
-
const hasSuccess = urlParams.get(
|
|
572
|
+
const hasSuccess = urlParams.get("success") === "true";
|
|
663
573
|
// Hide immediately - use synchronous approach to prevent flicker
|
|
664
574
|
// Only hide if NOT handling a callback
|
|
665
575
|
const onboardingAny = onboarding;
|
|
666
576
|
if (!shouldKeepOpen && onboardingAny.modalOverlay) {
|
|
667
577
|
// Hide immediately without delay to prevent flicker
|
|
668
|
-
onboardingAny.modalOverlay.classList.remove(
|
|
669
|
-
onboardingAny.modalOverlay.style.display =
|
|
670
|
-
document.body.style.overflow =
|
|
578
|
+
onboardingAny.modalOverlay.classList.remove("onboarding-modal-open");
|
|
579
|
+
onboardingAny.modalOverlay.style.display = "none";
|
|
580
|
+
document.body.style.overflow = "";
|
|
671
581
|
}
|
|
672
582
|
else if (hasSuccess) {
|
|
673
583
|
// If success=true is in URL, show loading modal
|
|
@@ -686,11 +596,13 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
686
596
|
if (googleCallbackHandledRef.current)
|
|
687
597
|
return;
|
|
688
598
|
const urlParams = new URLSearchParams(window.location.search);
|
|
689
|
-
if (!hasAuthParams(urlParams) ||
|
|
599
|
+
if (!hasAuthParams(urlParams) ||
|
|
600
|
+
matchesProvider("twitter", urlParams) ||
|
|
601
|
+
matchesProvider("discord", urlParams)) {
|
|
690
602
|
return;
|
|
691
603
|
}
|
|
692
604
|
// Show loading modal if success=true is in URL
|
|
693
|
-
const hasSuccess = urlParams.get(
|
|
605
|
+
const hasSuccess = urlParams.get("success") === "true";
|
|
694
606
|
if (hasSuccess && onboardingRef.current) {
|
|
695
607
|
const onboardingAny = onboardingRef.current;
|
|
696
608
|
if (onboardingAny.showLoadingScreen) {
|
|
@@ -717,7 +629,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
717
629
|
}
|
|
718
630
|
}
|
|
719
631
|
catch (err) {
|
|
720
|
-
console.error(
|
|
632
|
+
console.error("Google callback error:", err);
|
|
721
633
|
// Hide loading modal on error (including whoami API failures)
|
|
722
634
|
if (onboardingRef.current) {
|
|
723
635
|
const onboardingAny = onboardingRef.current;
|
|
@@ -727,29 +639,29 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
727
639
|
}
|
|
728
640
|
// Also hide any main modal overlay
|
|
729
641
|
if (onboardingAny.modalOverlay) {
|
|
730
|
-
onboardingAny.modalOverlay.style.display =
|
|
642
|
+
onboardingAny.modalOverlay.style.display = "none";
|
|
731
643
|
}
|
|
732
644
|
// Show error modal/screen
|
|
733
|
-
const errorMessage = err instanceof Error ? err.message :
|
|
645
|
+
const errorMessage = err instanceof Error ? err.message : "Google authentication failed";
|
|
734
646
|
if (onboardingAny.showError) {
|
|
735
647
|
onboardingAny.showError(errorMessage);
|
|
736
648
|
}
|
|
737
649
|
}
|
|
738
|
-
setError(err instanceof Error ? err : new Error(
|
|
650
|
+
setError(err instanceof Error ? err : new Error("Google callback failed"));
|
|
739
651
|
googleCallbackHandledRef.current = false;
|
|
740
652
|
// Ensure body scroll is restored
|
|
741
|
-
document.body.style.overflow =
|
|
653
|
+
document.body.style.overflow = "";
|
|
742
654
|
}
|
|
743
655
|
};
|
|
744
656
|
const handleDiscordCallback = async () => {
|
|
745
657
|
if (discordCallbackHandledRef.current)
|
|
746
658
|
return;
|
|
747
659
|
const urlParams = new URLSearchParams(window.location.search);
|
|
748
|
-
if (!hasAuthParams(urlParams) || !matchesProvider(
|
|
660
|
+
if (!hasAuthParams(urlParams) || !matchesProvider("discord", urlParams)) {
|
|
749
661
|
return;
|
|
750
662
|
}
|
|
751
663
|
// Show loading modal if success=true is in URL
|
|
752
|
-
const hasSuccess = urlParams.get(
|
|
664
|
+
const hasSuccess = urlParams.get("success") === "true";
|
|
753
665
|
if (hasSuccess && onboardingRef.current) {
|
|
754
666
|
const onboardingAny = onboardingRef.current;
|
|
755
667
|
if (onboardingAny.showLoadingScreen) {
|
|
@@ -776,7 +688,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
776
688
|
}
|
|
777
689
|
}
|
|
778
690
|
catch (err) {
|
|
779
|
-
console.error(
|
|
691
|
+
console.error("Discord callback error:", err);
|
|
780
692
|
// Hide loading modal on error (including whoami API failures)
|
|
781
693
|
if (onboardingRef.current) {
|
|
782
694
|
const onboardingAny = onboardingRef.current;
|
|
@@ -786,29 +698,31 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
786
698
|
}
|
|
787
699
|
// Also hide any main modal overlay
|
|
788
700
|
if (onboardingAny.modalOverlay) {
|
|
789
|
-
onboardingAny.modalOverlay.style.display =
|
|
701
|
+
onboardingAny.modalOverlay.style.display = "none";
|
|
790
702
|
}
|
|
791
703
|
// Show error modal/screen
|
|
792
|
-
const errorMessage = err instanceof Error
|
|
704
|
+
const errorMessage = err instanceof Error
|
|
705
|
+
? err.message
|
|
706
|
+
: "Discord authentication failed";
|
|
793
707
|
if (onboardingAny.showError) {
|
|
794
708
|
onboardingAny.showError(errorMessage);
|
|
795
709
|
}
|
|
796
710
|
}
|
|
797
|
-
setError(err instanceof Error ? err : new Error(
|
|
711
|
+
setError(err instanceof Error ? err : new Error("Discord callback failed"));
|
|
798
712
|
discordCallbackHandledRef.current = false;
|
|
799
713
|
// Ensure body scroll is restored
|
|
800
|
-
document.body.style.overflow =
|
|
714
|
+
document.body.style.overflow = "";
|
|
801
715
|
}
|
|
802
716
|
};
|
|
803
717
|
const handleTwitterCallback = async () => {
|
|
804
718
|
if (twitterCallbackHandledRef.current)
|
|
805
719
|
return;
|
|
806
720
|
const urlParams = new URLSearchParams(window.location.search);
|
|
807
|
-
if (!hasAuthParams(urlParams) || !matchesProvider(
|
|
721
|
+
if (!hasAuthParams(urlParams) || !matchesProvider("twitter", urlParams)) {
|
|
808
722
|
return;
|
|
809
723
|
}
|
|
810
724
|
// Show loading modal if success=true is in URL
|
|
811
|
-
const hasSuccess = urlParams.get(
|
|
725
|
+
const hasSuccess = urlParams.get("success") === "true";
|
|
812
726
|
if (hasSuccess && onboardingRef.current) {
|
|
813
727
|
const onboardingAny = onboardingRef.current;
|
|
814
728
|
if (onboardingAny.showLoadingScreen) {
|
|
@@ -835,7 +749,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
835
749
|
}
|
|
836
750
|
}
|
|
837
751
|
catch (err) {
|
|
838
|
-
console.error(
|
|
752
|
+
console.error("Twitter callback error:", err);
|
|
839
753
|
// Hide loading modal on error (including whoami API failures)
|
|
840
754
|
if (onboardingRef.current) {
|
|
841
755
|
const onboardingAny = onboardingRef.current;
|
|
@@ -845,18 +759,20 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
845
759
|
}
|
|
846
760
|
// Also hide any main modal overlay
|
|
847
761
|
if (onboardingAny.modalOverlay) {
|
|
848
|
-
onboardingAny.modalOverlay.style.display =
|
|
762
|
+
onboardingAny.modalOverlay.style.display = "none";
|
|
849
763
|
}
|
|
850
764
|
// Show error modal/screen
|
|
851
|
-
const errorMessage = err instanceof Error
|
|
765
|
+
const errorMessage = err instanceof Error
|
|
766
|
+
? err.message
|
|
767
|
+
: "Twitter authentication failed";
|
|
852
768
|
if (onboardingAny.showError) {
|
|
853
769
|
onboardingAny.showError(errorMessage);
|
|
854
770
|
}
|
|
855
771
|
}
|
|
856
|
-
setError(err instanceof Error ? err : new Error(
|
|
772
|
+
setError(err instanceof Error ? err : new Error("Twitter callback failed"));
|
|
857
773
|
twitterCallbackHandledRef.current = false;
|
|
858
774
|
// Ensure body scroll is restored
|
|
859
|
-
document.body.style.overflow =
|
|
775
|
+
document.body.style.overflow = "";
|
|
860
776
|
}
|
|
861
777
|
};
|
|
862
778
|
handleGoogleCallback();
|
|
@@ -881,13 +797,13 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
881
797
|
setAddress(addr);
|
|
882
798
|
}
|
|
883
799
|
catch (addrErr) {
|
|
884
|
-
console.warn(
|
|
800
|
+
console.warn("Address not available during restore:", addrErr);
|
|
885
801
|
}
|
|
886
802
|
const cid = await wallet.getChainId();
|
|
887
803
|
setChainId(cid);
|
|
888
804
|
}
|
|
889
805
|
catch (err) {
|
|
890
|
-
console.error(
|
|
806
|
+
console.error("Error restoring connection state:", err);
|
|
891
807
|
// If restore fails, mark as disconnected
|
|
892
808
|
setIsConnected(false);
|
|
893
809
|
}
|
|
@@ -920,19 +836,21 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
920
836
|
if (onboardingRef.current) {
|
|
921
837
|
const onboarding = onboardingRef.current;
|
|
922
838
|
// Re-initialize if destroyed
|
|
923
|
-
if (!onboarding.modalOverlay ||
|
|
839
|
+
if (!onboarding.modalOverlay ||
|
|
840
|
+
!document.body.contains(onboarding.modalOverlay)) {
|
|
924
841
|
onboarding.init();
|
|
925
842
|
// Wait for init to complete
|
|
926
843
|
setTimeout(() => {
|
|
927
844
|
if (onboarding.modalOverlay) {
|
|
928
845
|
// Use requestAnimationFrame to prevent blinking
|
|
929
846
|
requestAnimationFrame(() => {
|
|
930
|
-
onboarding.modalOverlay.classList.remove(
|
|
931
|
-
onboarding.modalOverlay.classList.add(
|
|
932
|
-
onboarding.modalOverlay.style.display =
|
|
933
|
-
document.body.style.overflow =
|
|
847
|
+
onboarding.modalOverlay.classList.remove("onboarding-modal-closing");
|
|
848
|
+
onboarding.modalOverlay.classList.add("onboarding-modal-open");
|
|
849
|
+
onboarding.modalOverlay.style.display = "flex";
|
|
850
|
+
document.body.style.overflow = "hidden";
|
|
934
851
|
// Ensure external wallet container is visible when modal opens
|
|
935
|
-
if (externalWalletsEnabledRef.current &&
|
|
852
|
+
if (externalWalletsEnabledRef.current &&
|
|
853
|
+
onboarding.externalWalletContainer) {
|
|
936
854
|
// Check if we're on OTP screen - if so, don't show external wallets
|
|
937
855
|
// Check if OTP screen exists AND is actually visible in the DOM
|
|
938
856
|
const isOtpScreen = onboarding.otpVerificationScreen &&
|
|
@@ -940,24 +858,27 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
940
858
|
onboarding.otpVerificationScreen.offsetParent !== null;
|
|
941
859
|
if (!isOtpScreen) {
|
|
942
860
|
// Only show external wallets if not on OTP screen
|
|
943
|
-
onboarding.externalWalletContainer.style.display =
|
|
861
|
+
onboarding.externalWalletContainer.style.display = "";
|
|
944
862
|
// Show divider only if both email/Google AND external wallets are visible
|
|
945
|
-
const authMethods = onboarding.config?.authMethods || [
|
|
946
|
-
|
|
947
|
-
|
|
863
|
+
const authMethods = onboarding.config?.authMethods || [
|
|
864
|
+
"otp",
|
|
865
|
+
"google",
|
|
866
|
+
];
|
|
867
|
+
const showEmail = authMethods.includes("otp");
|
|
868
|
+
const showGoogle = authMethods.includes("google");
|
|
948
869
|
const hasEmailOrGoogle = showEmail || showGoogle;
|
|
949
870
|
if (onboarding.externalWalletDivider && hasEmailOrGoogle) {
|
|
950
|
-
onboarding.externalWalletDivider.style.display =
|
|
871
|
+
onboarding.externalWalletDivider.style.display = "";
|
|
951
872
|
}
|
|
952
873
|
else if (onboarding.externalWalletDivider) {
|
|
953
|
-
onboarding.externalWalletDivider.style.display =
|
|
874
|
+
onboarding.externalWalletDivider.style.display = "none";
|
|
954
875
|
}
|
|
955
876
|
}
|
|
956
877
|
else {
|
|
957
878
|
// On OTP screen - hide external wallets
|
|
958
|
-
onboarding.externalWalletContainer.style.display =
|
|
879
|
+
onboarding.externalWalletContainer.style.display = "none";
|
|
959
880
|
if (onboarding.externalWalletDivider) {
|
|
960
|
-
onboarding.externalWalletDivider.style.display =
|
|
881
|
+
onboarding.externalWalletDivider.style.display = "none";
|
|
961
882
|
}
|
|
962
883
|
}
|
|
963
884
|
// Always re-render external wallets when modal opens immediately
|
|
@@ -982,66 +903,71 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
982
903
|
const isOtpScreen = onboarding.otpVerificationScreen &&
|
|
983
904
|
onboarding.otpVerificationScreen.parentElement &&
|
|
984
905
|
onboarding.otpVerificationScreen.offsetParent !== null;
|
|
985
|
-
onboarding.modalOverlay.classList.remove(
|
|
986
|
-
onboarding.modalOverlay.classList.add(
|
|
987
|
-
onboarding.modalOverlay.style.display =
|
|
906
|
+
onboarding.modalOverlay.classList.remove("onboarding-modal-closing");
|
|
907
|
+
onboarding.modalOverlay.classList.add("onboarding-modal-open");
|
|
908
|
+
onboarding.modalOverlay.style.display = "flex";
|
|
988
909
|
if (onboarding.rootElement) {
|
|
989
|
-
onboarding.rootElement.style.display =
|
|
910
|
+
onboarding.rootElement.style.display = "";
|
|
990
911
|
}
|
|
991
|
-
document.body.style.overflow =
|
|
912
|
+
document.body.style.overflow = "hidden";
|
|
992
913
|
// If on OTP screen, ensure all login elements (social buttons, etc.) are hidden
|
|
993
914
|
if (isOtpScreen) {
|
|
994
915
|
// On OTP screen - ensure all login elements are hidden
|
|
995
|
-
if (onboarding.hideLoginElements &&
|
|
916
|
+
if (onboarding.hideLoginElements &&
|
|
917
|
+
typeof onboarding.hideLoginElements === "function") {
|
|
996
918
|
onboarding.hideLoginElements();
|
|
997
919
|
}
|
|
998
920
|
else {
|
|
999
921
|
// Fallback: manually hide elements
|
|
1000
922
|
if (onboarding.googleButton)
|
|
1001
|
-
onboarding.googleButton.style.display =
|
|
923
|
+
onboarding.googleButton.style.display = "none";
|
|
1002
924
|
if (onboarding.twitterButton)
|
|
1003
|
-
onboarding.twitterButton.style.display =
|
|
925
|
+
onboarding.twitterButton.style.display = "none";
|
|
1004
926
|
if (onboarding.discordButton)
|
|
1005
|
-
onboarding.discordButton.style.display =
|
|
927
|
+
onboarding.discordButton.style.display = "none";
|
|
1006
928
|
if (onboarding.socialGrid)
|
|
1007
|
-
onboarding.socialGrid.style.display =
|
|
929
|
+
onboarding.socialGrid.style.display = "none";
|
|
1008
930
|
if (onboarding.divider)
|
|
1009
|
-
onboarding.divider.style.display =
|
|
931
|
+
onboarding.divider.style.display = "none";
|
|
1010
932
|
if (onboarding.passkeyLoginButton)
|
|
1011
|
-
onboarding.passkeyLoginButton.style.display =
|
|
933
|
+
onboarding.passkeyLoginButton.style.display = "none";
|
|
1012
934
|
if (onboarding.passkeySignupLink)
|
|
1013
|
-
onboarding.passkeySignupLink.style.display =
|
|
935
|
+
onboarding.passkeySignupLink.style.display = "none";
|
|
1014
936
|
if (onboarding.passkeyDivider)
|
|
1015
|
-
onboarding.passkeyDivider.style.display =
|
|
937
|
+
onboarding.passkeyDivider.style.display = "none";
|
|
1016
938
|
if (onboarding.externalWalletContainer)
|
|
1017
|
-
onboarding.externalWalletContainer.style.display =
|
|
939
|
+
onboarding.externalWalletContainer.style.display = "none";
|
|
1018
940
|
if (onboarding.externalWalletDivider)
|
|
1019
|
-
onboarding.externalWalletDivider.style.display =
|
|
941
|
+
onboarding.externalWalletDivider.style.display = "none";
|
|
1020
942
|
}
|
|
1021
943
|
}
|
|
1022
944
|
// CRITICAL: Always ensure external wallets are mounted when modal reopens
|
|
1023
|
-
if (externalWalletsEnabledRef.current &&
|
|
945
|
+
if (externalWalletsEnabledRef.current &&
|
|
946
|
+
onboarding.externalWalletContainer) {
|
|
1024
947
|
// Check if we're on OTP screen - if so, don't show external wallets
|
|
1025
948
|
if (!isOtpScreen) {
|
|
1026
949
|
// Only show external wallets if not on OTP screen
|
|
1027
|
-
onboarding.externalWalletContainer.style.display =
|
|
950
|
+
onboarding.externalWalletContainer.style.display = "";
|
|
1028
951
|
// Show divider only if both email/Google AND external wallets are visible
|
|
1029
|
-
const authMethods = onboarding.config?.authMethods || [
|
|
1030
|
-
|
|
1031
|
-
|
|
952
|
+
const authMethods = onboarding.config?.authMethods || [
|
|
953
|
+
"otp",
|
|
954
|
+
"google",
|
|
955
|
+
];
|
|
956
|
+
const showEmail = authMethods.includes("otp");
|
|
957
|
+
const showGoogle = authMethods.includes("google");
|
|
1032
958
|
const hasEmailOrGoogle = showEmail || showGoogle;
|
|
1033
959
|
if (onboarding.externalWalletDivider && hasEmailOrGoogle) {
|
|
1034
|
-
onboarding.externalWalletDivider.style.display =
|
|
960
|
+
onboarding.externalWalletDivider.style.display = "";
|
|
1035
961
|
}
|
|
1036
962
|
else if (onboarding.externalWalletDivider) {
|
|
1037
|
-
onboarding.externalWalletDivider.style.display =
|
|
963
|
+
onboarding.externalWalletDivider.style.display = "none";
|
|
1038
964
|
}
|
|
1039
965
|
}
|
|
1040
966
|
else {
|
|
1041
967
|
// On OTP screen - hide external wallets
|
|
1042
|
-
onboarding.externalWalletContainer.style.display =
|
|
968
|
+
onboarding.externalWalletContainer.style.display = "none";
|
|
1043
969
|
if (onboarding.externalWalletDivider) {
|
|
1044
|
-
onboarding.externalWalletDivider.style.display =
|
|
970
|
+
onboarding.externalWalletDivider.style.display = "none";
|
|
1045
971
|
}
|
|
1046
972
|
}
|
|
1047
973
|
// Always re-render external wallets when modal opens (even if already mounted)
|
|
@@ -1052,7 +978,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1052
978
|
return;
|
|
1053
979
|
}
|
|
1054
980
|
// Use the reusable mount function (will be defined later, but accessible via closure)
|
|
1055
|
-
if (typeof mountExternalWalletsToContainer ===
|
|
981
|
+
if (typeof mountExternalWalletsToContainer === "function") {
|
|
1056
982
|
mountExternalWalletsToContainer(container, onboarding);
|
|
1057
983
|
}
|
|
1058
984
|
}, 50); // Reduced delay for faster initial render
|
|
@@ -1123,7 +1049,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1123
1049
|
setAddress(addr);
|
|
1124
1050
|
}
|
|
1125
1051
|
catch (addrErr) {
|
|
1126
|
-
console.warn(
|
|
1052
|
+
console.warn("Address not available during restore:", addrErr);
|
|
1127
1053
|
}
|
|
1128
1054
|
const cid = await walletRef.current.getChainId();
|
|
1129
1055
|
setChainId(cid);
|
|
@@ -1139,16 +1065,16 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1139
1065
|
}
|
|
1140
1066
|
}
|
|
1141
1067
|
catch (restoreErr) {
|
|
1142
|
-
console.error(
|
|
1068
|
+
console.error("Error restoring connection state:", restoreErr);
|
|
1143
1069
|
setIsConnected(false);
|
|
1144
1070
|
}
|
|
1145
1071
|
}
|
|
1146
1072
|
}
|
|
1147
1073
|
}
|
|
1148
1074
|
catch (err) {
|
|
1149
|
-
const error = err instanceof Error ? err : new Error(
|
|
1075
|
+
const error = err instanceof Error ? err : new Error("Failed to initialize");
|
|
1150
1076
|
setError(error);
|
|
1151
|
-
console.error(
|
|
1077
|
+
console.error("Init error:", err);
|
|
1152
1078
|
}
|
|
1153
1079
|
finally {
|
|
1154
1080
|
setLoading(false);
|
|
@@ -1171,7 +1097,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1171
1097
|
setAddress(addr);
|
|
1172
1098
|
}
|
|
1173
1099
|
catch (err) {
|
|
1174
|
-
console.error(
|
|
1100
|
+
console.error("Error loading whoami after connect:", err);
|
|
1175
1101
|
}
|
|
1176
1102
|
}
|
|
1177
1103
|
catch (err) {
|
|
@@ -1181,7 +1107,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1181
1107
|
setError(err);
|
|
1182
1108
|
}
|
|
1183
1109
|
else {
|
|
1184
|
-
setError(err instanceof Error ? err : new Error(
|
|
1110
|
+
setError(err instanceof Error ? err : new Error("Failed to connect"));
|
|
1185
1111
|
}
|
|
1186
1112
|
}
|
|
1187
1113
|
finally {
|
|
@@ -1197,11 +1123,13 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1197
1123
|
const wasExternalWalletConnected = isExternalWalletConnected;
|
|
1198
1124
|
const wasAbstraxnWalletConnected = walletRef.current?.isConnected ?? false;
|
|
1199
1125
|
// If external wallet is connected, disconnect it first
|
|
1200
|
-
if (wasExternalWalletConnected &&
|
|
1126
|
+
if (wasExternalWalletConnected &&
|
|
1127
|
+
externalWalletsEnabled &&
|
|
1128
|
+
wagmiDisconnect) {
|
|
1201
1129
|
try {
|
|
1202
1130
|
await wagmiDisconnect.disconnect();
|
|
1203
1131
|
// Wait a bit to ensure wagmi state updates
|
|
1204
|
-
await new Promise(resolve => setTimeout(resolve, 150));
|
|
1132
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
1205
1133
|
// Reset external wallet state immediately
|
|
1206
1134
|
setIsExternalWalletConnected(false);
|
|
1207
1135
|
setExternalWalletAddress(null);
|
|
@@ -1248,7 +1176,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1248
1176
|
// console.log('✅ Abstraxn wallet disconnected, main state reset');
|
|
1249
1177
|
}
|
|
1250
1178
|
catch (err) {
|
|
1251
|
-
console.error(
|
|
1179
|
+
console.error("Error disconnecting Abstraxn wallet:", err);
|
|
1252
1180
|
// Continue even if Abstraxn wallet disconnect fails, but still reset state
|
|
1253
1181
|
setIsConnected(false);
|
|
1254
1182
|
setAddress(null);
|
|
@@ -1286,16 +1214,17 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1286
1214
|
const onboarding = onboardingRef.current;
|
|
1287
1215
|
onboarding.resetToLoginForm();
|
|
1288
1216
|
// If modal is visible (showing OTP screen), ensure it shows the login form
|
|
1289
|
-
if (onboarding.modalOverlay &&
|
|
1217
|
+
if (onboarding.modalOverlay &&
|
|
1218
|
+
onboarding.modalOverlay.style.display !== "none") {
|
|
1290
1219
|
// Modal is visible, just reset the form (already done above)
|
|
1291
1220
|
// Ensure modal is in open state
|
|
1292
|
-
onboarding.modalOverlay.classList.remove(
|
|
1293
|
-
onboarding.modalOverlay.classList.add(
|
|
1221
|
+
onboarding.modalOverlay.classList.remove("onboarding-modal-closing");
|
|
1222
|
+
onboarding.modalOverlay.classList.add("onboarding-modal-open");
|
|
1294
1223
|
}
|
|
1295
1224
|
}
|
|
1296
1225
|
}
|
|
1297
1226
|
catch (err) {
|
|
1298
|
-
setError(err instanceof Error ? err : new Error(
|
|
1227
|
+
setError(err instanceof Error ? err : new Error("Failed to disconnect"));
|
|
1299
1228
|
throw err;
|
|
1300
1229
|
}
|
|
1301
1230
|
finally {
|
|
@@ -1312,15 +1241,15 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1312
1241
|
if (onboardingRef.current) {
|
|
1313
1242
|
const onboarding = onboardingRef.current;
|
|
1314
1243
|
if (onboarding.modalOverlay) {
|
|
1315
|
-
onboarding.modalOverlay.classList.remove(
|
|
1316
|
-
onboarding.modalOverlay.classList.add(
|
|
1244
|
+
onboarding.modalOverlay.classList.remove("onboarding-modal-open");
|
|
1245
|
+
onboarding.modalOverlay.classList.add("onboarding-modal-closing");
|
|
1317
1246
|
setTimeout(() => {
|
|
1318
1247
|
if (onboarding.modalOverlay) {
|
|
1319
|
-
onboarding.modalOverlay.style.display =
|
|
1248
|
+
onboarding.modalOverlay.style.display = "none";
|
|
1320
1249
|
}
|
|
1321
1250
|
}, 200);
|
|
1322
1251
|
}
|
|
1323
|
-
document.body.style.overflow =
|
|
1252
|
+
document.body.style.overflow = "";
|
|
1324
1253
|
}
|
|
1325
1254
|
}, []);
|
|
1326
1255
|
// Get address - works for both Abstraxn wallet and external wallets
|
|
@@ -1332,7 +1261,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1332
1261
|
}
|
|
1333
1262
|
// Otherwise use Abstraxn wallet
|
|
1334
1263
|
if (!walletRef.current)
|
|
1335
|
-
throw new Error(
|
|
1264
|
+
throw new Error("Wallet not initialized");
|
|
1336
1265
|
return await walletRef.current.getAddress();
|
|
1337
1266
|
}, [isExternalWalletConnected, externalWalletAddress]);
|
|
1338
1267
|
// Get chain ID - works for both Abstraxn wallet and external wallets
|
|
@@ -1344,7 +1273,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1344
1273
|
}
|
|
1345
1274
|
// Otherwise use Abstraxn wallet
|
|
1346
1275
|
if (!walletRef.current)
|
|
1347
|
-
throw new Error(
|
|
1276
|
+
throw new Error("Wallet not initialized");
|
|
1348
1277
|
return await walletRef.current.getChainId();
|
|
1349
1278
|
}, [isExternalWalletConnected, externalWalletChainId]);
|
|
1350
1279
|
// Switch chain - works for both Abstraxn wallet and external wallets
|
|
@@ -1357,7 +1286,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1357
1286
|
await wagmiSwitchChain.switchChainAsync({ chainId: newChainId });
|
|
1358
1287
|
}
|
|
1359
1288
|
catch (err) {
|
|
1360
|
-
const error = err instanceof Error ? err : new Error(
|
|
1289
|
+
const error = err instanceof Error ? err : new Error("Failed to switch chain");
|
|
1361
1290
|
setError(error);
|
|
1362
1291
|
throw error;
|
|
1363
1292
|
}
|
|
@@ -1368,12 +1297,12 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1368
1297
|
else {
|
|
1369
1298
|
// Otherwise use Abstraxn wallet
|
|
1370
1299
|
if (!walletRef.current)
|
|
1371
|
-
throw new Error(
|
|
1300
|
+
throw new Error("Wallet not initialized");
|
|
1372
1301
|
try {
|
|
1373
1302
|
await walletRef.current.switchChain(newChainId);
|
|
1374
1303
|
}
|
|
1375
1304
|
catch (err) {
|
|
1376
|
-
setError(err instanceof Error ? err : new Error(
|
|
1305
|
+
setError(err instanceof Error ? err : new Error("Failed to switch chain"));
|
|
1377
1306
|
throw err;
|
|
1378
1307
|
}
|
|
1379
1308
|
}
|
|
@@ -1382,14 +1311,18 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1382
1311
|
const signMessage = useCallback(async (message) => {
|
|
1383
1312
|
setError(null);
|
|
1384
1313
|
// If external wallet is connected, use wagmi
|
|
1385
|
-
if (isExternalWalletConnected &&
|
|
1314
|
+
if (isExternalWalletConnected &&
|
|
1315
|
+
externalWalletAddress &&
|
|
1316
|
+
wagmiSignMessage) {
|
|
1386
1317
|
try {
|
|
1387
1318
|
setLoading(true);
|
|
1388
|
-
const signature = await wagmiSignMessage.signMessageAsync({
|
|
1319
|
+
const signature = await wagmiSignMessage.signMessageAsync({
|
|
1320
|
+
message,
|
|
1321
|
+
});
|
|
1389
1322
|
return signature;
|
|
1390
1323
|
}
|
|
1391
1324
|
catch (err) {
|
|
1392
|
-
const error = err instanceof Error ? err : new Error(
|
|
1325
|
+
const error = err instanceof Error ? err : new Error("Failed to sign message");
|
|
1393
1326
|
setError(error);
|
|
1394
1327
|
throw error;
|
|
1395
1328
|
}
|
|
@@ -1399,12 +1332,12 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1399
1332
|
}
|
|
1400
1333
|
// Otherwise use Abstraxn wallet
|
|
1401
1334
|
if (!walletRef.current)
|
|
1402
|
-
throw new Error(
|
|
1335
|
+
throw new Error("Wallet not initialized");
|
|
1403
1336
|
try {
|
|
1404
1337
|
return await walletRef.current.signMessage(message);
|
|
1405
1338
|
}
|
|
1406
1339
|
catch (err) {
|
|
1407
|
-
setError(err instanceof Error ? err : new Error(
|
|
1340
|
+
setError(err instanceof Error ? err : new Error("Failed to sign message"));
|
|
1408
1341
|
throw err;
|
|
1409
1342
|
}
|
|
1410
1343
|
}, [isExternalWalletConnected, externalWalletAddress, wagmiSignMessage]);
|
|
@@ -1412,12 +1345,12 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1412
1345
|
const signTransaction = useCallback(async (tx) => {
|
|
1413
1346
|
setError(null); // Clear any previous errors
|
|
1414
1347
|
if (!walletRef.current)
|
|
1415
|
-
throw new Error(
|
|
1348
|
+
throw new Error("Wallet not initialized");
|
|
1416
1349
|
try {
|
|
1417
1350
|
return await walletRef.current.signTransaction(tx);
|
|
1418
1351
|
}
|
|
1419
1352
|
catch (err) {
|
|
1420
|
-
setError(err instanceof Error ? err : new Error(
|
|
1353
|
+
setError(err instanceof Error ? err : new Error("Failed to sign transaction"));
|
|
1421
1354
|
throw err;
|
|
1422
1355
|
}
|
|
1423
1356
|
}, []);
|
|
@@ -1425,7 +1358,9 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1425
1358
|
const sendTransaction = useCallback(async (tx) => {
|
|
1426
1359
|
setError(null);
|
|
1427
1360
|
// If external wallet is connected, use wagmi
|
|
1428
|
-
if (isExternalWalletConnected &&
|
|
1361
|
+
if (isExternalWalletConnected &&
|
|
1362
|
+
externalWalletAddress &&
|
|
1363
|
+
wagmiSendTransaction) {
|
|
1429
1364
|
try {
|
|
1430
1365
|
setLoading(true);
|
|
1431
1366
|
// Convert TransactionRequest to wagmi format
|
|
@@ -1433,7 +1368,10 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1433
1368
|
to: tx.to,
|
|
1434
1369
|
};
|
|
1435
1370
|
if (tx.value) {
|
|
1436
|
-
wagmiTx.value =
|
|
1371
|
+
wagmiTx.value =
|
|
1372
|
+
typeof tx.value === "string"
|
|
1373
|
+
? parseEther(tx.value)
|
|
1374
|
+
: BigInt(tx.value);
|
|
1437
1375
|
}
|
|
1438
1376
|
if (tx.data) {
|
|
1439
1377
|
wagmiTx.data = tx.data;
|
|
@@ -1456,7 +1394,9 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1456
1394
|
};
|
|
1457
1395
|
}
|
|
1458
1396
|
catch (err) {
|
|
1459
|
-
const error = err instanceof Error
|
|
1397
|
+
const error = err instanceof Error
|
|
1398
|
+
? err
|
|
1399
|
+
: new Error("Failed to send transaction");
|
|
1460
1400
|
setError(error);
|
|
1461
1401
|
throw error;
|
|
1462
1402
|
}
|
|
@@ -1466,26 +1406,26 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1466
1406
|
}
|
|
1467
1407
|
// Otherwise use Abstraxn wallet
|
|
1468
1408
|
if (!walletRef.current)
|
|
1469
|
-
throw new Error(
|
|
1409
|
+
throw new Error("Wallet not initialized");
|
|
1470
1410
|
try {
|
|
1471
1411
|
return await walletRef.current.sendTransaction(tx);
|
|
1472
1412
|
}
|
|
1473
1413
|
catch (err) {
|
|
1474
|
-
setError(err instanceof Error ? err : new Error(
|
|
1414
|
+
setError(err instanceof Error ? err : new Error("Failed to send transaction"));
|
|
1475
1415
|
throw err;
|
|
1476
1416
|
}
|
|
1477
1417
|
}, [isExternalWalletConnected, externalWalletAddress, wagmiSendTransaction]);
|
|
1478
1418
|
// Sign transaction via API (returns signed transaction)
|
|
1479
1419
|
const signTransactionViaAPI = useCallback(async (unsignedTransaction, fromAddress) => {
|
|
1480
1420
|
if (!walletRef.current)
|
|
1481
|
-
throw new Error(
|
|
1421
|
+
throw new Error("Wallet not initialized");
|
|
1482
1422
|
setLoading(true);
|
|
1483
1423
|
setError(null);
|
|
1484
1424
|
try {
|
|
1485
1425
|
return await walletRef.current.signTransactionViaAPI(unsignedTransaction, fromAddress);
|
|
1486
1426
|
}
|
|
1487
1427
|
catch (err) {
|
|
1488
|
-
const error = err instanceof Error ? err : new Error(
|
|
1428
|
+
const error = err instanceof Error ? err : new Error("Failed to sign transaction");
|
|
1489
1429
|
setError(error);
|
|
1490
1430
|
throw error;
|
|
1491
1431
|
}
|
|
@@ -1496,14 +1436,16 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1496
1436
|
// Sign and send transaction using backend API
|
|
1497
1437
|
const signAndSendTransaction = useCallback(async (unsignedTransaction, fromAddress, rpcUrl) => {
|
|
1498
1438
|
if (!walletRef.current)
|
|
1499
|
-
throw new Error(
|
|
1439
|
+
throw new Error("Wallet not initialized");
|
|
1500
1440
|
setLoading(true);
|
|
1501
1441
|
setError(null);
|
|
1502
1442
|
try {
|
|
1503
1443
|
return await walletRef.current.signAndSendTransaction(unsignedTransaction, fromAddress, rpcUrl);
|
|
1504
1444
|
}
|
|
1505
1445
|
catch (err) {
|
|
1506
|
-
const error = err instanceof Error
|
|
1446
|
+
const error = err instanceof Error
|
|
1447
|
+
? err
|
|
1448
|
+
: new Error("Failed to sign and send transaction");
|
|
1507
1449
|
setError(error);
|
|
1508
1450
|
throw error;
|
|
1509
1451
|
}
|
|
@@ -1514,7 +1456,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1514
1456
|
// Login with email OTP (initiate OTP)
|
|
1515
1457
|
const loginWithOTP = useCallback(async (email) => {
|
|
1516
1458
|
if (!walletRef.current)
|
|
1517
|
-
throw new Error(
|
|
1459
|
+
throw new Error("Wallet not initialized");
|
|
1518
1460
|
setLoading(true);
|
|
1519
1461
|
setError(null);
|
|
1520
1462
|
try {
|
|
@@ -1530,7 +1472,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1530
1472
|
return result;
|
|
1531
1473
|
}
|
|
1532
1474
|
catch (err) {
|
|
1533
|
-
const error = err instanceof Error ? err : new Error(
|
|
1475
|
+
const error = err instanceof Error ? err : new Error("Failed to initiate OTP");
|
|
1534
1476
|
setError(error);
|
|
1535
1477
|
throw error;
|
|
1536
1478
|
}
|
|
@@ -1541,7 +1483,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1541
1483
|
// Verify OTP
|
|
1542
1484
|
const verifyOTP = useCallback(async (otpId, otpCode) => {
|
|
1543
1485
|
if (!walletRef.current)
|
|
1544
|
-
throw new Error(
|
|
1486
|
+
throw new Error("Wallet not initialized");
|
|
1545
1487
|
setLoading(true);
|
|
1546
1488
|
setError(null);
|
|
1547
1489
|
try {
|
|
@@ -1575,11 +1517,11 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1575
1517
|
setChainId(cid);
|
|
1576
1518
|
}
|
|
1577
1519
|
catch (err) {
|
|
1578
|
-
console.error(
|
|
1520
|
+
console.error("Error loading whoami after OTP verification:", err);
|
|
1579
1521
|
}
|
|
1580
1522
|
}
|
|
1581
1523
|
catch (err) {
|
|
1582
|
-
const error = err instanceof Error ? err : new Error(
|
|
1524
|
+
const error = err instanceof Error ? err : new Error("Failed to verify OTP");
|
|
1583
1525
|
setError(error);
|
|
1584
1526
|
throw error;
|
|
1585
1527
|
}
|
|
@@ -1590,7 +1532,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1590
1532
|
// Login with Google
|
|
1591
1533
|
const loginWithGoogle = useCallback(async () => {
|
|
1592
1534
|
if (!walletRef.current)
|
|
1593
|
-
throw new Error(
|
|
1535
|
+
throw new Error("Wallet not initialized");
|
|
1594
1536
|
setLoading(true);
|
|
1595
1537
|
setError(null);
|
|
1596
1538
|
try {
|
|
@@ -1606,7 +1548,9 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1606
1548
|
// Note: This will redirect, so loading state will be reset on callback
|
|
1607
1549
|
}
|
|
1608
1550
|
catch (err) {
|
|
1609
|
-
const error = err instanceof Error
|
|
1551
|
+
const error = err instanceof Error
|
|
1552
|
+
? err
|
|
1553
|
+
: new Error("Failed to initiate Google login");
|
|
1610
1554
|
setError(error);
|
|
1611
1555
|
setLoading(false);
|
|
1612
1556
|
throw error;
|
|
@@ -1640,7 +1584,9 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1640
1584
|
}
|
|
1641
1585
|
}
|
|
1642
1586
|
catch (err) {
|
|
1643
|
-
const error = err instanceof Error
|
|
1587
|
+
const error = err instanceof Error
|
|
1588
|
+
? err
|
|
1589
|
+
: new Error("Failed to handle Google callback");
|
|
1644
1590
|
setError(error);
|
|
1645
1591
|
throw error;
|
|
1646
1592
|
}
|
|
@@ -1676,7 +1622,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1676
1622
|
return whoamiInfo;
|
|
1677
1623
|
}
|
|
1678
1624
|
catch (err) {
|
|
1679
|
-
const error = err instanceof Error ? err : new Error(
|
|
1625
|
+
const error = err instanceof Error ? err : new Error("Failed to refresh whoami");
|
|
1680
1626
|
setError(error);
|
|
1681
1627
|
throw error;
|
|
1682
1628
|
}
|
|
@@ -1700,7 +1646,10 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1700
1646
|
// 2. We don't have explicitConnectionRef set (meaning user didn't explicitly connect)
|
|
1701
1647
|
// 3. We haven't already handled auto-disconnect
|
|
1702
1648
|
// 4. We don't have a stored address (meaning this isn't a restoration from persistence)
|
|
1703
|
-
if (wagmiAccount.isConnected &&
|
|
1649
|
+
if (wagmiAccount.isConnected &&
|
|
1650
|
+
!explicitConnectionRef.current &&
|
|
1651
|
+
!autoDisconnectHandledRef.current &&
|
|
1652
|
+
lastAddressRef.current === null) {
|
|
1704
1653
|
autoDisconnectHandledRef.current = true;
|
|
1705
1654
|
if (wagmiDisconnect) {
|
|
1706
1655
|
setTimeout(() => {
|
|
@@ -1747,7 +1696,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1747
1696
|
if (wagmiAccount.isConnected && wagmiAccount.address) {
|
|
1748
1697
|
const walletAddress = wagmiAccount.address;
|
|
1749
1698
|
// Ensure address is properly formatted (should be 0x...)
|
|
1750
|
-
const formattedAddress = walletAddress && typeof walletAddress ===
|
|
1699
|
+
const formattedAddress = walletAddress && typeof walletAddress === "string"
|
|
1751
1700
|
? walletAddress.toLowerCase()
|
|
1752
1701
|
: walletAddress;
|
|
1753
1702
|
// Use wagmiChainIdHook first (more reliable), then fallback to wagmiAccount.chainId
|
|
@@ -1757,7 +1706,9 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1757
1706
|
const chainIdChanged = lastChainIdRef.current !== currentChainId;
|
|
1758
1707
|
// Also check if we need to reconnect (lastAddressRef is null but wagmiAccount is connected)
|
|
1759
1708
|
// This handles the case where user disconnects and then reconnects, OR page reload
|
|
1760
|
-
const needsReconnect = lastAddressRef.current === null &&
|
|
1709
|
+
const needsReconnect = lastAddressRef.current === null &&
|
|
1710
|
+
wagmiAccount.isConnected &&
|
|
1711
|
+
formattedAddress;
|
|
1761
1712
|
// Only update if something actually changed OR if we need to reconnect
|
|
1762
1713
|
if (addressChanged || chainIdChanged || needsReconnect) {
|
|
1763
1714
|
isUpdatingRef.current = true;
|
|
@@ -1776,7 +1727,8 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1776
1727
|
lastConnectionTimeRef.current = Date.now();
|
|
1777
1728
|
}
|
|
1778
1729
|
// Update chainId if it changed or if we need to reconnect
|
|
1779
|
-
if ((chainIdChanged && currentChainId) ||
|
|
1730
|
+
if ((chainIdChanged && currentChainId) ||
|
|
1731
|
+
(needsReconnect && currentChainId)) {
|
|
1780
1732
|
setExternalWalletChainId(currentChainId);
|
|
1781
1733
|
setChainId(currentChainId);
|
|
1782
1734
|
lastChainIdRef.current = currentChainId;
|
|
@@ -1788,14 +1740,14 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1788
1740
|
if (onboardingAny.modalOverlay) {
|
|
1789
1741
|
setTimeout(() => {
|
|
1790
1742
|
if (onboardingAny.modalOverlay) {
|
|
1791
|
-
onboardingAny.modalOverlay.classList.remove(
|
|
1792
|
-
onboardingAny.modalOverlay.classList.add(
|
|
1743
|
+
onboardingAny.modalOverlay.classList.remove("onboarding-modal-open");
|
|
1744
|
+
onboardingAny.modalOverlay.classList.add("onboarding-modal-closing");
|
|
1793
1745
|
setTimeout(() => {
|
|
1794
1746
|
if (onboardingAny.modalOverlay) {
|
|
1795
|
-
onboardingAny.modalOverlay.style.display =
|
|
1747
|
+
onboardingAny.modalOverlay.style.display = "none";
|
|
1796
1748
|
}
|
|
1797
1749
|
}, 200);
|
|
1798
|
-
document.body.style.overflow =
|
|
1750
|
+
document.body.style.overflow = "";
|
|
1799
1751
|
}
|
|
1800
1752
|
}, 100);
|
|
1801
1753
|
}
|
|
@@ -1835,7 +1787,14 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1835
1787
|
clearTimeout(checkAddressTimeout);
|
|
1836
1788
|
}
|
|
1837
1789
|
};
|
|
1838
|
-
}, [
|
|
1790
|
+
}, [
|
|
1791
|
+
wagmiAccount?.isConnected,
|
|
1792
|
+
wagmiAccount?.address,
|
|
1793
|
+
wagmiAccount?.chainId,
|
|
1794
|
+
wagmiChainIdHook,
|
|
1795
|
+
externalWalletsEnabled,
|
|
1796
|
+
wagmiDisconnect,
|
|
1797
|
+
]);
|
|
1839
1798
|
// Connect external wallet
|
|
1840
1799
|
const connectExternalWallet = useCallback(async (connectorId) => {
|
|
1841
1800
|
if (!externalWalletsEnabled || !wagmiConnect || !wagmiDisconnect) {
|
|
@@ -2041,7 +2000,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2041
2000
|
// Await the disconnect to ensure it completes
|
|
2042
2001
|
await wagmiDisconnect.disconnect();
|
|
2043
2002
|
// Wait a bit to ensure wagmi state updates
|
|
2044
|
-
await new Promise(resolve => setTimeout(resolve, 150));
|
|
2003
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
2045
2004
|
// Reset external wallet state immediately
|
|
2046
2005
|
setIsExternalWalletConnected(false);
|
|
2047
2006
|
setExternalWalletAddress(null);
|
|
@@ -2068,8 +2027,10 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2068
2027
|
setConnectionType(null);
|
|
2069
2028
|
}
|
|
2070
2029
|
catch (err) {
|
|
2071
|
-
const error = err instanceof Error
|
|
2072
|
-
|
|
2030
|
+
const error = err instanceof Error
|
|
2031
|
+
? err
|
|
2032
|
+
: new Error("Failed to disconnect external wallet");
|
|
2033
|
+
console.error("Error disconnecting external wallet:", error);
|
|
2073
2034
|
setError(error);
|
|
2074
2035
|
throw error;
|
|
2075
2036
|
}
|
|
@@ -2084,27 +2045,27 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2084
2045
|
// Helper function to get network name from chain ID
|
|
2085
2046
|
const getNetworkName = useCallback((chainId) => {
|
|
2086
2047
|
const chainNames = {
|
|
2087
|
-
1:
|
|
2088
|
-
5:
|
|
2089
|
-
11155111:
|
|
2090
|
-
137:
|
|
2091
|
-
80001:
|
|
2092
|
-
80002:
|
|
2093
|
-
8453:
|
|
2094
|
-
84531:
|
|
2095
|
-
42161:
|
|
2096
|
-
421613:
|
|
2097
|
-
10:
|
|
2098
|
-
420:
|
|
2099
|
-
56:
|
|
2100
|
-
97:
|
|
2048
|
+
1: "Ethereum Mainnet",
|
|
2049
|
+
5: "Goerli",
|
|
2050
|
+
11155111: "Sepolia",
|
|
2051
|
+
137: "Polygon",
|
|
2052
|
+
80001: "Mumbai",
|
|
2053
|
+
80002: "Polygon Amoy",
|
|
2054
|
+
8453: "Base",
|
|
2055
|
+
84531: "Base Goerli",
|
|
2056
|
+
42161: "Arbitrum One",
|
|
2057
|
+
421613: "Arbitrum Goerli",
|
|
2058
|
+
10: "Optimism",
|
|
2059
|
+
420: "Optimism Goerli",
|
|
2060
|
+
56: "BNB Smart Chain",
|
|
2061
|
+
97: "BNB Smart Chain Testnet",
|
|
2101
2062
|
};
|
|
2102
2063
|
return chainNames[chainId] || `Chain ${chainId}`;
|
|
2103
2064
|
}, []);
|
|
2104
2065
|
// Switch external wallet chain (dedicated function for external wallets)
|
|
2105
2066
|
const switchExternalWalletChain = useCallback(async (chainId) => {
|
|
2106
2067
|
if (!externalWalletsEnabled || !wagmiSwitchChain) {
|
|
2107
|
-
const error = new Error(
|
|
2068
|
+
const error = new Error("External wallets are not enabled or chain switching is not available");
|
|
2108
2069
|
setError(error);
|
|
2109
2070
|
throw error;
|
|
2110
2071
|
}
|
|
@@ -2118,7 +2079,9 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2118
2079
|
setExternalWalletChainId(chainId);
|
|
2119
2080
|
}
|
|
2120
2081
|
catch (err) {
|
|
2121
|
-
const error = err instanceof Error
|
|
2082
|
+
const error = err instanceof Error
|
|
2083
|
+
? err
|
|
2084
|
+
: new Error(`Failed to switch chain: ${err instanceof Error ? err.message : String(err)}`);
|
|
2122
2085
|
setError(error);
|
|
2123
2086
|
throw error;
|
|
2124
2087
|
}
|
|
@@ -2133,8 +2096,8 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2133
2096
|
? wagmiConnect.connectors
|
|
2134
2097
|
.filter((connector) => {
|
|
2135
2098
|
// If io.metamask exists, exclude generic 'injected' connector
|
|
2136
|
-
const hasIoMetaMask = wagmiConnect.connectors.some((c) => c.id ===
|
|
2137
|
-
if (hasIoMetaMask && connector.id ===
|
|
2099
|
+
const hasIoMetaMask = wagmiConnect.connectors.some((c) => c.id === "io.metamask");
|
|
2100
|
+
if (hasIoMetaMask && connector.id === "injected") {
|
|
2138
2101
|
return false; // Exclude generic injected when io.metamask is available
|
|
2139
2102
|
}
|
|
2140
2103
|
return true;
|
|
@@ -2162,7 +2125,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2162
2125
|
const fetchBalance = async () => {
|
|
2163
2126
|
try {
|
|
2164
2127
|
const currentChain = getChainById(currentChainId);
|
|
2165
|
-
if (!currentChain || currentChain.type !==
|
|
2128
|
+
if (!currentChain || currentChain.type !== "evm") {
|
|
2166
2129
|
setWalletBalance(null);
|
|
2167
2130
|
return;
|
|
2168
2131
|
}
|
|
@@ -2185,7 +2148,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2185
2148
|
setWalletBalance(balance);
|
|
2186
2149
|
}
|
|
2187
2150
|
catch (error) {
|
|
2188
|
-
console.error(
|
|
2151
|
+
console.error("Failed to fetch balance:", error);
|
|
2189
2152
|
setWalletBalance(null);
|
|
2190
2153
|
}
|
|
2191
2154
|
};
|
|
@@ -2199,9 +2162,10 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2199
2162
|
const chains = [];
|
|
2200
2163
|
const chainConfig = config.chains;
|
|
2201
2164
|
// Priority 1: Check new chains config format
|
|
2202
|
-
if (chainConfig?.supportedEvmChains &&
|
|
2165
|
+
if (chainConfig?.supportedEvmChains &&
|
|
2166
|
+
chainConfig.supportedEvmChains.length > 0) {
|
|
2203
2167
|
// Use configured chains from new format
|
|
2204
|
-
chainConfig.supportedEvmChains.forEach(chainName => {
|
|
2168
|
+
chainConfig.supportedEvmChains.forEach((chainName) => {
|
|
2205
2169
|
const chain = EVM_CHAINS[chainName];
|
|
2206
2170
|
if (chain) {
|
|
2207
2171
|
chains.push(chain);
|
|
@@ -2211,7 +2175,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2211
2175
|
// Priority 2: Check legacy supportedChains format
|
|
2212
2176
|
else if (config.supportedChains && config.supportedChains.length > 0) {
|
|
2213
2177
|
// Convert legacy Chain format to ChainData
|
|
2214
|
-
config.supportedChains.forEach(legacyChain => {
|
|
2178
|
+
config.supportedChains.forEach((legacyChain) => {
|
|
2215
2179
|
// Try to find matching chain by ID
|
|
2216
2180
|
const chainData = getChainById(legacyChain.id);
|
|
2217
2181
|
if (chainData) {
|
|
@@ -2221,13 +2185,15 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2221
2185
|
// If not found, create ChainData from legacy chain
|
|
2222
2186
|
const newChain = {
|
|
2223
2187
|
id: legacyChain.id,
|
|
2224
|
-
name: legacyChain.name.toLowerCase().replace(/\s+/g,
|
|
2188
|
+
name: legacyChain.name.toLowerCase().replace(/\s+/g, "-"),
|
|
2225
2189
|
displayName: legacyChain.name,
|
|
2226
2190
|
rpcUrl: legacyChain.rpcUrl,
|
|
2227
2191
|
explorerUrl: `https://etherscan.io`, // Default explorer
|
|
2228
2192
|
nativeCurrency: legacyChain.nativeCurrency,
|
|
2229
|
-
type:
|
|
2230
|
-
isTestnet: legacyChain.id !== 1 &&
|
|
2193
|
+
type: "evm", // Assume EVM for legacy chains
|
|
2194
|
+
isTestnet: legacyChain.id !== 1 &&
|
|
2195
|
+
legacyChain.id !== 137 &&
|
|
2196
|
+
legacyChain.id !== 8453, // Common mainnets
|
|
2231
2197
|
};
|
|
2232
2198
|
chains.push(newChain);
|
|
2233
2199
|
}
|
|
@@ -2243,13 +2209,13 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2243
2209
|
chains.push(SOLANA_CHAINS.solana);
|
|
2244
2210
|
}
|
|
2245
2211
|
// Remove duplicates by chain ID
|
|
2246
|
-
const uniqueChains = chains.filter((chain, index, self) => index === self.findIndex(c => c.id === chain.id));
|
|
2212
|
+
const uniqueChains = chains.filter((chain, index, self) => index === self.findIndex((c) => c.id === chain.id));
|
|
2247
2213
|
// Only return defaults if absolutely nothing was configured
|
|
2248
2214
|
return uniqueChains.length > 0
|
|
2249
2215
|
? uniqueChains
|
|
2250
|
-
:
|
|
2216
|
+
: !chainConfig && !config.supportedChains
|
|
2251
2217
|
? [EVM_CHAINS.ethereum, EVM_CHAINS.polygon, EVM_CHAINS.base]
|
|
2252
|
-
: []
|
|
2218
|
+
: [];
|
|
2253
2219
|
}, [config.chains, config.supportedChains]);
|
|
2254
2220
|
// Get current chain data
|
|
2255
2221
|
const currentChain = useMemo(() => {
|
|
@@ -2260,10 +2226,10 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2260
2226
|
// Enhanced switchChain that works for both EVM and Solana
|
|
2261
2227
|
const switchChainEnhanced = useCallback(async (targetChainId) => {
|
|
2262
2228
|
if (!walletRef.current) {
|
|
2263
|
-
throw new Error(
|
|
2229
|
+
throw new Error("Wallet not initialized");
|
|
2264
2230
|
}
|
|
2265
2231
|
// Check if chain is in availableChains (user-configured chains)
|
|
2266
|
-
const targetChainInAvailable = availableChains?.find(c => c.id === targetChainId);
|
|
2232
|
+
const targetChainInAvailable = availableChains?.find((c) => c.id === targetChainId);
|
|
2267
2233
|
if (!targetChainInAvailable) {
|
|
2268
2234
|
throw new Error(`Chain with ID ${targetChainId} is not available. Please configure it in your SDK setup.`);
|
|
2269
2235
|
}
|
|
@@ -2274,7 +2240,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2274
2240
|
setLoading(true);
|
|
2275
2241
|
setError(null);
|
|
2276
2242
|
try {
|
|
2277
|
-
if (targetChain.type ===
|
|
2243
|
+
if (targetChain.type === "evm") {
|
|
2278
2244
|
// For EVM chains, use the existing switchChain
|
|
2279
2245
|
if (isExternalWalletConnected && wagmiSwitchChain) {
|
|
2280
2246
|
// External wallet - use wagmi switchChain
|
|
@@ -2290,12 +2256,14 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2290
2256
|
catch (switchErr) {
|
|
2291
2257
|
// If the wallet doesn't support this chain, but it's in availableChains,
|
|
2292
2258
|
// we can still update the state to allow UI to work
|
|
2293
|
-
if (switchErr?.message?.includes(
|
|
2259
|
+
if (switchErr?.message?.includes("not supported") &&
|
|
2260
|
+
targetChainInAvailable) {
|
|
2294
2261
|
// Update chainId state directly for chains in availableChains
|
|
2295
2262
|
setChainId(targetChainId);
|
|
2296
2263
|
// Emit chainChanged event if wallet supports it
|
|
2297
|
-
if (walletRef.current &&
|
|
2298
|
-
walletRef.current.emit
|
|
2264
|
+
if (walletRef.current &&
|
|
2265
|
+
typeof walletRef.current.emit === "function") {
|
|
2266
|
+
walletRef.current.emit("chainChanged", targetChainId);
|
|
2299
2267
|
}
|
|
2300
2268
|
}
|
|
2301
2269
|
else {
|
|
@@ -2304,7 +2272,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2304
2272
|
}
|
|
2305
2273
|
}
|
|
2306
2274
|
}
|
|
2307
|
-
else if (targetChain.type ===
|
|
2275
|
+
else if (targetChain.type === "solana") {
|
|
2308
2276
|
// For Solana, we might need different handling
|
|
2309
2277
|
// For now, just update the chainId state
|
|
2310
2278
|
// TODO: Implement actual Solana chain switching when wallet supports it
|
|
@@ -2316,7 +2284,9 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2316
2284
|
}
|
|
2317
2285
|
}
|
|
2318
2286
|
catch (err) {
|
|
2319
|
-
const error = err instanceof Error
|
|
2287
|
+
const error = err instanceof Error
|
|
2288
|
+
? err
|
|
2289
|
+
: new Error(`Failed to switch to chain ${targetChainId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
2320
2290
|
setError(error);
|
|
2321
2291
|
throw error;
|
|
2322
2292
|
}
|
|
@@ -2354,15 +2324,37 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2354
2324
|
refreshWhoami,
|
|
2355
2325
|
uiConfig: config.ui,
|
|
2356
2326
|
// External wallet methods
|
|
2357
|
-
connectExternalWallet: externalWalletsEnabled
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2327
|
+
connectExternalWallet: externalWalletsEnabled
|
|
2328
|
+
? connectExternalWallet
|
|
2329
|
+
: undefined,
|
|
2330
|
+
disconnectExternalWallet: externalWalletsEnabled
|
|
2331
|
+
? disconnectExternalWallet
|
|
2332
|
+
: undefined,
|
|
2333
|
+
isExternalWalletConnected: externalWalletsEnabled
|
|
2334
|
+
? isExternalWalletConnected
|
|
2335
|
+
: undefined,
|
|
2336
|
+
externalWalletAddress: externalWalletsEnabled
|
|
2337
|
+
? externalWalletAddress
|
|
2338
|
+
: undefined,
|
|
2339
|
+
externalWalletChainId: externalWalletsEnabled
|
|
2340
|
+
? externalWalletChainId
|
|
2341
|
+
: undefined,
|
|
2342
|
+
externalWalletBalance: externalWalletsEnabled &&
|
|
2343
|
+
wagmiBalance?.data &&
|
|
2344
|
+
typeof wagmiBalance.data === "object" &&
|
|
2345
|
+
wagmiBalance.data !== null &&
|
|
2346
|
+
"value" in wagmiBalance.data
|
|
2347
|
+
? wagmiBalance.data.value
|
|
2348
|
+
: undefined,
|
|
2349
|
+
externalWalletNetwork: externalWalletsEnabled && wagmiChainIdHook
|
|
2350
|
+
? getNetworkName(wagmiChainIdHook)
|
|
2351
|
+
: undefined,
|
|
2352
|
+
availableConnectors: externalWalletsEnabled
|
|
2353
|
+
? availableConnectors
|
|
2354
|
+
: undefined,
|
|
2355
|
+
switchExternalWalletChain: externalWalletsEnabled
|
|
2356
|
+
? switchExternalWalletChain
|
|
2357
|
+
: undefined,
|
|
2366
2358
|
// Chain management
|
|
2367
2359
|
switchChainEnhanced,
|
|
2368
2360
|
currentChain,
|
|
@@ -2397,24 +2389,27 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2397
2389
|
onboardingAny.otpVerificationScreen.offsetParent !== null;
|
|
2398
2390
|
if (!isOtpScreen) {
|
|
2399
2391
|
// Only show external wallets if not on OTP screen
|
|
2400
|
-
container.style.display =
|
|
2392
|
+
container.style.display = "";
|
|
2401
2393
|
// Show divider only if both email/Google AND external wallets are visible
|
|
2402
|
-
const authMethods = onboardingAny.config?.authMethods || [
|
|
2403
|
-
|
|
2404
|
-
|
|
2394
|
+
const authMethods = onboardingAny.config?.authMethods || [
|
|
2395
|
+
"otp",
|
|
2396
|
+
"google",
|
|
2397
|
+
];
|
|
2398
|
+
const showEmail = authMethods.includes("otp");
|
|
2399
|
+
const showGoogle = authMethods.includes("google");
|
|
2405
2400
|
const hasEmailOrGoogle = showEmail || showGoogle;
|
|
2406
2401
|
if (onboardingAny.externalWalletDivider && hasEmailOrGoogle) {
|
|
2407
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2402
|
+
onboardingAny.externalWalletDivider.style.display = "";
|
|
2408
2403
|
}
|
|
2409
2404
|
else if (onboardingAny.externalWalletDivider) {
|
|
2410
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2405
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
2411
2406
|
}
|
|
2412
2407
|
}
|
|
2413
2408
|
else {
|
|
2414
2409
|
// On OTP screen - hide external wallets
|
|
2415
|
-
container.style.display =
|
|
2410
|
+
container.style.display = "none";
|
|
2416
2411
|
if (onboardingAny.externalWalletDivider) {
|
|
2417
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2412
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
2418
2413
|
}
|
|
2419
2414
|
return;
|
|
2420
2415
|
}
|
|
@@ -2423,69 +2418,79 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2423
2418
|
// Check if the container is the same as the one we created the root for
|
|
2424
2419
|
const isSameContainer = externalWalletContainerRef.current === container;
|
|
2425
2420
|
const rootStillValid = externalWalletRootRef.current && containerInDOM && isSameContainer;
|
|
2426
|
-
const renderExternalWalletButtons = () => (_jsx(AbstraxnContext.Provider, { value: valueRef.current, children: _jsx(ExternalWalletButtons, { onConnect: async () => {
|
|
2427
|
-
}, onShowMoreWallets: () => {
|
|
2421
|
+
const renderExternalWalletButtons = () => (_jsx(AbstraxnContext.Provider, { value: valueRef.current, children: _jsx(ExternalWalletButtons, { onConnect: async () => { }, onShowMoreWallets: () => {
|
|
2428
2422
|
const onboardingAny = onboardingRef.current;
|
|
2429
2423
|
if (onboardingAny?.emailForm) {
|
|
2430
|
-
onboardingAny.emailForm.style.display =
|
|
2424
|
+
onboardingAny.emailForm.style.display = "none";
|
|
2431
2425
|
}
|
|
2432
2426
|
if (onboardingAny?.googleButton) {
|
|
2433
|
-
onboardingAny.googleButton.style.display =
|
|
2427
|
+
onboardingAny.googleButton.style.display = "none";
|
|
2434
2428
|
}
|
|
2435
2429
|
// Hide all passkey elements when wallet selection screen is shown
|
|
2436
2430
|
if (onboardingAny?.passkeyLoginButton) {
|
|
2437
|
-
onboardingAny.passkeyLoginButton.style.display =
|
|
2431
|
+
onboardingAny.passkeyLoginButton.style.display = "none";
|
|
2438
2432
|
}
|
|
2439
2433
|
if (onboardingAny?.passkeySignupLink) {
|
|
2440
|
-
onboardingAny.passkeySignupLink.style.display =
|
|
2434
|
+
onboardingAny.passkeySignupLink.style.display = "none";
|
|
2441
2435
|
}
|
|
2442
2436
|
if (onboardingAny?.passkeyErrorElement) {
|
|
2443
|
-
onboardingAny.passkeyErrorElement.style.display =
|
|
2437
|
+
onboardingAny.passkeyErrorElement.style.display = "none";
|
|
2444
2438
|
}
|
|
2445
2439
|
if (onboardingAny?.passkeyDivider) {
|
|
2446
|
-
onboardingAny.passkeyDivider.style.display =
|
|
2440
|
+
onboardingAny.passkeyDivider.style.display = "none";
|
|
2447
2441
|
}
|
|
2448
2442
|
if (onboardingAny?.externalWalletDivider) {
|
|
2449
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2443
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
2450
2444
|
}
|
|
2451
2445
|
if (onboardingAny?.divider) {
|
|
2452
|
-
onboardingAny.divider.style.display =
|
|
2446
|
+
onboardingAny.divider.style.display = "none";
|
|
2453
2447
|
}
|
|
2454
2448
|
}, onHideMoreWallets: () => {
|
|
2455
2449
|
const onboardingAny = onboardingRef.current;
|
|
2456
|
-
const authMethods = onboardingAny?.config?.authMethods || [
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2450
|
+
const authMethods = onboardingAny?.config?.authMethods || [
|
|
2451
|
+
"otp",
|
|
2452
|
+
"google",
|
|
2453
|
+
];
|
|
2454
|
+
const showEmail = authMethods.includes("otp");
|
|
2455
|
+
const showGoogle = authMethods.includes("google");
|
|
2456
|
+
const showPasskey = authMethods.includes("passkey");
|
|
2460
2457
|
if (onboardingAny?.emailForm) {
|
|
2461
|
-
onboardingAny.emailForm.style.display = showEmail ?
|
|
2458
|
+
onboardingAny.emailForm.style.display = showEmail ? "" : "none";
|
|
2462
2459
|
}
|
|
2463
2460
|
if (onboardingAny?.googleButton) {
|
|
2464
|
-
onboardingAny.googleButton.style.display = showGoogle
|
|
2461
|
+
onboardingAny.googleButton.style.display = showGoogle
|
|
2462
|
+
? ""
|
|
2463
|
+
: "none";
|
|
2465
2464
|
}
|
|
2466
2465
|
// Show passkey controls if enabled
|
|
2467
2466
|
if (onboardingAny?.passkeyLoginButton) {
|
|
2468
|
-
onboardingAny.passkeyLoginButton.style.display = showPasskey
|
|
2467
|
+
onboardingAny.passkeyLoginButton.style.display = showPasskey
|
|
2468
|
+
? ""
|
|
2469
|
+
: "none";
|
|
2469
2470
|
}
|
|
2470
2471
|
if (onboardingAny?.passkeySignupLink) {
|
|
2471
|
-
onboardingAny.passkeySignupLink.style.display = showPasskey
|
|
2472
|
+
onboardingAny.passkeySignupLink.style.display = showPasskey
|
|
2473
|
+
? ""
|
|
2474
|
+
: "none";
|
|
2472
2475
|
}
|
|
2473
2476
|
if (onboardingAny?.passkeyErrorElement) {
|
|
2474
|
-
onboardingAny.passkeyErrorElement.style.display =
|
|
2477
|
+
onboardingAny.passkeyErrorElement.style.display = "none";
|
|
2475
2478
|
}
|
|
2476
2479
|
// Show passkey divider if passkey is enabled and there are other auth methods
|
|
2477
2480
|
if (onboardingAny?.passkeyDivider) {
|
|
2478
|
-
onboardingAny.passkeyDivider.style.display =
|
|
2481
|
+
onboardingAny.passkeyDivider.style.display =
|
|
2482
|
+
showPasskey && (showEmail || showGoogle) ? "" : "none";
|
|
2479
2483
|
}
|
|
2480
2484
|
if (onboardingAny?.divider) {
|
|
2481
|
-
onboardingAny.divider.style.display =
|
|
2485
|
+
onboardingAny.divider.style.display =
|
|
2486
|
+
showEmail && showGoogle ? "" : "none";
|
|
2482
2487
|
}
|
|
2483
2488
|
const hasEmailOrGoogle = showEmail || showGoogle;
|
|
2484
2489
|
if (onboardingAny?.externalWalletDivider && hasEmailOrGoogle) {
|
|
2485
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2490
|
+
onboardingAny.externalWalletDivider.style.display = "";
|
|
2486
2491
|
}
|
|
2487
2492
|
else if (onboardingAny?.externalWalletDivider) {
|
|
2488
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2493
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
2489
2494
|
}
|
|
2490
2495
|
} }) }));
|
|
2491
2496
|
if (rootStillValid) {
|
|
@@ -2506,7 +2511,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2506
2511
|
}
|
|
2507
2512
|
externalWalletRootRef.current = null;
|
|
2508
2513
|
}
|
|
2509
|
-
const reactDomClient = await import(
|
|
2514
|
+
const reactDomClient = await import("react-dom/client");
|
|
2510
2515
|
const rootInstance = reactDomClient.createRoot(container);
|
|
2511
2516
|
externalWalletRootRef.current = rootInstance;
|
|
2512
2517
|
externalWalletContainerRef.current = container; // Track the container
|
|
@@ -2524,23 +2529,23 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2524
2529
|
// When disabled, ensure container is hidden
|
|
2525
2530
|
const onboardingAny = onboardingRef.current;
|
|
2526
2531
|
if (onboardingAny?.externalWalletContainer) {
|
|
2527
|
-
onboardingAny.externalWalletContainer.style.display =
|
|
2532
|
+
onboardingAny.externalWalletContainer.style.display = "none";
|
|
2528
2533
|
}
|
|
2529
2534
|
if (onboardingAny?.externalWalletDivider) {
|
|
2530
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2535
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
2531
2536
|
}
|
|
2532
2537
|
return;
|
|
2533
2538
|
}
|
|
2534
2539
|
if (!onboardingRef.current) {
|
|
2535
|
-
console.log(
|
|
2540
|
+
console.log("OnboardingUI not initialized yet");
|
|
2536
2541
|
return;
|
|
2537
2542
|
}
|
|
2538
2543
|
if (!wagmiConnect) {
|
|
2539
|
-
console.log(
|
|
2544
|
+
console.log("Wagmi connect not available");
|
|
2540
2545
|
return;
|
|
2541
2546
|
}
|
|
2542
2547
|
if (!wagmiConnect.connectors || wagmiConnect.connectors.length === 0) {
|
|
2543
|
-
console.log(
|
|
2548
|
+
console.log("Wagmi connectors not ready yet");
|
|
2544
2549
|
return;
|
|
2545
2550
|
}
|
|
2546
2551
|
if (availableConnectors.length === 0) {
|
|
@@ -2563,7 +2568,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2563
2568
|
try {
|
|
2564
2569
|
const container = onboardingAny.externalWalletContainer;
|
|
2565
2570
|
if (!container) {
|
|
2566
|
-
console.warn(
|
|
2571
|
+
console.warn("External wallet container is null");
|
|
2567
2572
|
return;
|
|
2568
2573
|
}
|
|
2569
2574
|
// Check if we're on OTP screen - if so, don't show external wallets
|
|
@@ -2574,24 +2579,27 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2574
2579
|
if (!isOtpScreen) {
|
|
2575
2580
|
// Only show external wallets if not on OTP screen
|
|
2576
2581
|
// Force container to be visible when external wallets are enabled
|
|
2577
|
-
container.style.display =
|
|
2582
|
+
container.style.display = "";
|
|
2578
2583
|
// Show divider only if both email/Google AND external wallets are visible
|
|
2579
|
-
const authMethods = onboardingAny.config?.authMethods || [
|
|
2580
|
-
|
|
2581
|
-
|
|
2584
|
+
const authMethods = onboardingAny.config?.authMethods || [
|
|
2585
|
+
"otp",
|
|
2586
|
+
"google",
|
|
2587
|
+
];
|
|
2588
|
+
const showEmail = authMethods.includes("otp");
|
|
2589
|
+
const showGoogle = authMethods.includes("google");
|
|
2582
2590
|
const hasEmailOrGoogle = showEmail || showGoogle;
|
|
2583
2591
|
if (onboardingAny.externalWalletDivider && hasEmailOrGoogle) {
|
|
2584
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2592
|
+
onboardingAny.externalWalletDivider.style.display = "";
|
|
2585
2593
|
}
|
|
2586
2594
|
else if (onboardingAny.externalWalletDivider) {
|
|
2587
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2595
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
2588
2596
|
}
|
|
2589
2597
|
}
|
|
2590
2598
|
else {
|
|
2591
2599
|
// On OTP screen - hide external wallets
|
|
2592
|
-
container.style.display =
|
|
2600
|
+
container.style.display = "none";
|
|
2593
2601
|
if (onboardingAny.externalWalletDivider) {
|
|
2594
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2602
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
2595
2603
|
}
|
|
2596
2604
|
}
|
|
2597
2605
|
// Always unmount and create fresh mount when config changes
|
|
@@ -2607,7 +2615,7 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2607
2615
|
externalWalletContainerRef.current = null;
|
|
2608
2616
|
}
|
|
2609
2617
|
// Create fresh mount - this ensures buttons appear when config changes
|
|
2610
|
-
const reactDomClient = await import(
|
|
2618
|
+
const reactDomClient = await import("react-dom/client");
|
|
2611
2619
|
const rootInstance = reactDomClient.createRoot(container);
|
|
2612
2620
|
externalWalletRootRef.current = rootInstance;
|
|
2613
2621
|
externalWalletContainerRef.current = container; // Track the container
|
|
@@ -2619,77 +2627,90 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2619
2627
|
// Hide email and Google sections when "More wallets" is clicked
|
|
2620
2628
|
const onboardingAny = onboardingRef.current;
|
|
2621
2629
|
if (onboardingAny?.emailForm) {
|
|
2622
|
-
onboardingAny.emailForm.style.display =
|
|
2630
|
+
onboardingAny.emailForm.style.display = "none";
|
|
2623
2631
|
}
|
|
2624
2632
|
if (onboardingAny?.googleButton) {
|
|
2625
|
-
onboardingAny.googleButton.style.display =
|
|
2633
|
+
onboardingAny.googleButton.style.display = "none";
|
|
2626
2634
|
}
|
|
2627
2635
|
// Hide all passkey elements when wallet selection screen is shown
|
|
2628
2636
|
if (onboardingAny?.passkeyLoginButton) {
|
|
2629
|
-
onboardingAny.passkeyLoginButton.style.display =
|
|
2637
|
+
onboardingAny.passkeyLoginButton.style.display = "none";
|
|
2630
2638
|
}
|
|
2631
2639
|
if (onboardingAny?.passkeySignupLink) {
|
|
2632
|
-
onboardingAny.passkeySignupLink.style.display =
|
|
2640
|
+
onboardingAny.passkeySignupLink.style.display = "none";
|
|
2633
2641
|
}
|
|
2634
2642
|
if (onboardingAny?.passkeyErrorElement) {
|
|
2635
|
-
onboardingAny.passkeyErrorElement.style.display =
|
|
2643
|
+
onboardingAny.passkeyErrorElement.style.display = "none";
|
|
2636
2644
|
}
|
|
2637
2645
|
if (onboardingAny?.passkeyDivider) {
|
|
2638
|
-
onboardingAny.passkeyDivider.style.display =
|
|
2646
|
+
onboardingAny.passkeyDivider.style.display = "none";
|
|
2639
2647
|
}
|
|
2640
2648
|
if (onboardingAny?.externalWalletDivider) {
|
|
2641
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2649
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
2642
2650
|
}
|
|
2643
2651
|
// Also hide the divider between email and Google if it exists
|
|
2644
2652
|
if (onboardingAny?.divider) {
|
|
2645
|
-
onboardingAny.divider.style.display =
|
|
2653
|
+
onboardingAny.divider.style.display = "none";
|
|
2646
2654
|
}
|
|
2647
2655
|
}, onHideMoreWallets: () => {
|
|
2648
2656
|
// Show email and Google sections when back is clicked (restore initial screen)
|
|
2649
2657
|
const onboardingAny = onboardingRef.current;
|
|
2650
|
-
const authMethods = onboardingAny?.config?.authMethods || [
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2658
|
+
const authMethods = onboardingAny?.config?.authMethods || [
|
|
2659
|
+
"otp",
|
|
2660
|
+
"google",
|
|
2661
|
+
];
|
|
2662
|
+
const showEmail = authMethods.includes("otp");
|
|
2663
|
+
const showGoogle = authMethods.includes("google");
|
|
2664
|
+
const showPasskey = authMethods.includes("passkey");
|
|
2654
2665
|
// Show email form if enabled
|
|
2655
2666
|
if (onboardingAny?.emailForm) {
|
|
2656
|
-
onboardingAny.emailForm.style.display = showEmail
|
|
2667
|
+
onboardingAny.emailForm.style.display = showEmail
|
|
2668
|
+
? ""
|
|
2669
|
+
: "none";
|
|
2657
2670
|
}
|
|
2658
2671
|
// Show Google button if enabled
|
|
2659
2672
|
if (onboardingAny?.googleButton) {
|
|
2660
|
-
onboardingAny.googleButton.style.display = showGoogle
|
|
2673
|
+
onboardingAny.googleButton.style.display = showGoogle
|
|
2674
|
+
? ""
|
|
2675
|
+
: "none";
|
|
2661
2676
|
}
|
|
2662
2677
|
// Show passkey controls if enabled
|
|
2663
2678
|
if (onboardingAny?.passkeyLoginButton) {
|
|
2664
|
-
onboardingAny.passkeyLoginButton.style.display = showPasskey
|
|
2679
|
+
onboardingAny.passkeyLoginButton.style.display = showPasskey
|
|
2680
|
+
? ""
|
|
2681
|
+
: "none";
|
|
2665
2682
|
}
|
|
2666
2683
|
if (onboardingAny?.passkeySignupLink) {
|
|
2667
|
-
onboardingAny.passkeySignupLink.style.display = showPasskey
|
|
2684
|
+
onboardingAny.passkeySignupLink.style.display = showPasskey
|
|
2685
|
+
? ""
|
|
2686
|
+
: "none";
|
|
2668
2687
|
}
|
|
2669
2688
|
if (onboardingAny?.passkeyErrorElement) {
|
|
2670
|
-
onboardingAny.passkeyErrorElement.style.display =
|
|
2689
|
+
onboardingAny.passkeyErrorElement.style.display = "none";
|
|
2671
2690
|
}
|
|
2672
2691
|
// Show passkey divider if passkey is enabled and there are other auth methods
|
|
2673
2692
|
if (onboardingAny?.passkeyDivider) {
|
|
2674
|
-
onboardingAny.passkeyDivider.style.display =
|
|
2693
|
+
onboardingAny.passkeyDivider.style.display =
|
|
2694
|
+
showPasskey && (showEmail || showGoogle) ? "" : "none";
|
|
2675
2695
|
}
|
|
2676
2696
|
// Show divider between email and Google if both are enabled
|
|
2677
2697
|
if (onboardingAny?.divider) {
|
|
2678
|
-
onboardingAny.divider.style.display =
|
|
2698
|
+
onboardingAny.divider.style.display =
|
|
2699
|
+
showEmail && showGoogle ? "" : "none";
|
|
2679
2700
|
}
|
|
2680
2701
|
// Show the "or" divider before external wallets only if email/Google are visible
|
|
2681
2702
|
const hasEmailOrGoogle = showEmail || showGoogle;
|
|
2682
2703
|
if (onboardingAny?.externalWalletDivider && hasEmailOrGoogle) {
|
|
2683
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2704
|
+
onboardingAny.externalWalletDivider.style.display = "";
|
|
2684
2705
|
}
|
|
2685
2706
|
else if (onboardingAny?.externalWalletDivider) {
|
|
2686
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2707
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
2687
2708
|
}
|
|
2688
2709
|
} }) }));
|
|
2689
2710
|
externalWalletMountedRef.current = true;
|
|
2690
2711
|
}
|
|
2691
2712
|
catch (error) {
|
|
2692
|
-
console.error(
|
|
2713
|
+
console.error("Failed to mount ExternalWalletButtons:", error);
|
|
2693
2714
|
externalWalletMountedRef.current = false;
|
|
2694
2715
|
}
|
|
2695
2716
|
};
|
|
@@ -2714,7 +2735,12 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2714
2735
|
return () => {
|
|
2715
2736
|
// Cleanup if needed
|
|
2716
2737
|
};
|
|
2717
|
-
}, [
|
|
2738
|
+
}, [
|
|
2739
|
+
externalWalletsEnabled,
|
|
2740
|
+
wagmiConnect,
|
|
2741
|
+
wagmiConnect?.connectors,
|
|
2742
|
+
availableConnectors.length,
|
|
2743
|
+
]);
|
|
2718
2744
|
// Update the rendered component when value changes (but don't re-mount)
|
|
2719
2745
|
useEffect(() => {
|
|
2720
2746
|
if (!externalWalletsEnabled)
|
|
@@ -2729,112 +2755,134 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2729
2755
|
// Hide email and Google sections when "More wallets" is clicked
|
|
2730
2756
|
const onboardingAny = onboardingRef.current;
|
|
2731
2757
|
if (onboardingAny?.emailForm) {
|
|
2732
|
-
onboardingAny.emailForm.style.display =
|
|
2758
|
+
onboardingAny.emailForm.style.display = "none";
|
|
2733
2759
|
}
|
|
2734
2760
|
if (onboardingAny?.googleButton) {
|
|
2735
|
-
onboardingAny.googleButton.style.display =
|
|
2761
|
+
onboardingAny.googleButton.style.display = "none";
|
|
2736
2762
|
}
|
|
2737
2763
|
// Hide Discord and X (Twitter) buttons when wallet selection screen is shown
|
|
2738
2764
|
if (onboardingAny?.discordButton) {
|
|
2739
|
-
onboardingAny.discordButton.style.display =
|
|
2765
|
+
onboardingAny.discordButton.style.display = "none";
|
|
2740
2766
|
}
|
|
2741
2767
|
if (onboardingAny?.twitterButton) {
|
|
2742
|
-
onboardingAny.twitterButton.style.display =
|
|
2768
|
+
onboardingAny.twitterButton.style.display = "none";
|
|
2743
2769
|
}
|
|
2744
2770
|
// Hide social grid if it exists
|
|
2745
2771
|
if (onboardingAny?.socialGrid) {
|
|
2746
|
-
onboardingAny.socialGrid.style.display =
|
|
2772
|
+
onboardingAny.socialGrid.style.display = "none";
|
|
2747
2773
|
}
|
|
2748
2774
|
// Extra guard: hide any social icon buttons by class
|
|
2749
2775
|
if (onboardingAny?.rootElement) {
|
|
2750
2776
|
onboardingAny.rootElement
|
|
2751
|
-
.querySelectorAll(
|
|
2777
|
+
.querySelectorAll(".onboarding-button-social-icon, .onboarding-button-social")
|
|
2752
2778
|
.forEach((el) => {
|
|
2753
|
-
el.style.display =
|
|
2779
|
+
el.style.display = "none";
|
|
2754
2780
|
});
|
|
2755
2781
|
}
|
|
2756
2782
|
// Hide all passkey elements when wallet selection screen is shown
|
|
2757
2783
|
if (onboardingAny?.passkeyLoginButton) {
|
|
2758
|
-
onboardingAny.passkeyLoginButton.style.display =
|
|
2784
|
+
onboardingAny.passkeyLoginButton.style.display = "none";
|
|
2759
2785
|
}
|
|
2760
2786
|
if (onboardingAny?.passkeySignupLink) {
|
|
2761
|
-
onboardingAny.passkeySignupLink.style.display =
|
|
2787
|
+
onboardingAny.passkeySignupLink.style.display = "none";
|
|
2762
2788
|
}
|
|
2763
2789
|
if (onboardingAny?.passkeyErrorElement) {
|
|
2764
|
-
onboardingAny.passkeyErrorElement.style.display =
|
|
2790
|
+
onboardingAny.passkeyErrorElement.style.display = "none";
|
|
2765
2791
|
}
|
|
2766
2792
|
if (onboardingAny?.passkeyDivider) {
|
|
2767
|
-
onboardingAny.passkeyDivider.style.display =
|
|
2793
|
+
onboardingAny.passkeyDivider.style.display = "none";
|
|
2768
2794
|
}
|
|
2769
2795
|
if (onboardingAny?.externalWalletDivider) {
|
|
2770
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2796
|
+
onboardingAny.externalWalletDivider.style.display = "none";
|
|
2771
2797
|
}
|
|
2772
2798
|
// Also hide the divider between email and Google if it exists
|
|
2773
2799
|
if (onboardingAny?.divider) {
|
|
2774
|
-
onboardingAny.divider.style.display =
|
|
2800
|
+
onboardingAny.divider.style.display = "none";
|
|
2775
2801
|
}
|
|
2776
2802
|
}, onHideMoreWallets: () => {
|
|
2777
2803
|
// Show email and Google sections when back is clicked
|
|
2778
2804
|
const onboardingAny = onboardingRef.current;
|
|
2779
|
-
const authMethods = onboardingAny?.config?.authMethods || [
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
const
|
|
2784
|
-
const
|
|
2805
|
+
const authMethods = onboardingAny?.config?.authMethods || [
|
|
2806
|
+
"otp",
|
|
2807
|
+
"google",
|
|
2808
|
+
];
|
|
2809
|
+
const showEmail = authMethods.includes("otp");
|
|
2810
|
+
const showGoogle = authMethods.includes("google");
|
|
2811
|
+
const showTwitter = authMethods.includes("twitter");
|
|
2812
|
+
const showDiscord = authMethods.includes("discord");
|
|
2813
|
+
const showPasskey = authMethods.includes("passkey");
|
|
2785
2814
|
if (onboardingAny?.emailForm) {
|
|
2786
|
-
onboardingAny.emailForm.style.display = showEmail ?
|
|
2815
|
+
onboardingAny.emailForm.style.display = showEmail ? "" : "none";
|
|
2787
2816
|
}
|
|
2788
2817
|
if (onboardingAny?.googleButton) {
|
|
2789
|
-
onboardingAny.googleButton.style.display = showGoogle
|
|
2818
|
+
onboardingAny.googleButton.style.display = showGoogle
|
|
2819
|
+
? ""
|
|
2820
|
+
: "none";
|
|
2790
2821
|
}
|
|
2791
2822
|
// Show Discord and X (Twitter) buttons if enabled
|
|
2792
2823
|
if (onboardingAny?.discordButton) {
|
|
2793
|
-
onboardingAny.discordButton.style.display = showDiscord
|
|
2824
|
+
onboardingAny.discordButton.style.display = showDiscord
|
|
2825
|
+
? ""
|
|
2826
|
+
: "none";
|
|
2794
2827
|
}
|
|
2795
2828
|
if (onboardingAny?.twitterButton) {
|
|
2796
|
-
onboardingAny.twitterButton.style.display = showTwitter
|
|
2829
|
+
onboardingAny.twitterButton.style.display = showTwitter
|
|
2830
|
+
? ""
|
|
2831
|
+
: "none";
|
|
2797
2832
|
}
|
|
2798
2833
|
// Show social grid if it exists and social methods are enabled
|
|
2799
2834
|
if (onboardingAny?.socialGrid) {
|
|
2800
2835
|
const hasSocialMethods = showGoogle || showTwitter || showDiscord;
|
|
2801
|
-
onboardingAny.socialGrid.style.display = hasSocialMethods
|
|
2836
|
+
onboardingAny.socialGrid.style.display = hasSocialMethods
|
|
2837
|
+
? ""
|
|
2838
|
+
: "none";
|
|
2802
2839
|
}
|
|
2803
2840
|
// Extra guard: restore social icon buttons by class based on flags
|
|
2804
2841
|
if (onboardingAny?.rootElement) {
|
|
2805
2842
|
const hasSocialMethods = showGoogle || showTwitter || showDiscord;
|
|
2806
2843
|
onboardingAny.rootElement
|
|
2807
|
-
.querySelectorAll(
|
|
2844
|
+
.querySelectorAll(".onboarding-button-social-icon, .onboarding-button-social")
|
|
2808
2845
|
.forEach((el) => {
|
|
2809
|
-
el.style.display = hasSocialMethods
|
|
2846
|
+
el.style.display = hasSocialMethods
|
|
2847
|
+
? ""
|
|
2848
|
+
: "none";
|
|
2810
2849
|
});
|
|
2811
2850
|
}
|
|
2812
2851
|
// Show passkey controls if enabled
|
|
2813
2852
|
if (onboardingAny?.passkeyLoginButton) {
|
|
2814
|
-
onboardingAny.passkeyLoginButton.style.display = showPasskey
|
|
2853
|
+
onboardingAny.passkeyLoginButton.style.display = showPasskey
|
|
2854
|
+
? ""
|
|
2855
|
+
: "none";
|
|
2815
2856
|
}
|
|
2816
2857
|
if (onboardingAny?.passkeySignupLink) {
|
|
2817
|
-
onboardingAny.passkeySignupLink.style.display = showPasskey
|
|
2858
|
+
onboardingAny.passkeySignupLink.style.display = showPasskey
|
|
2859
|
+
? ""
|
|
2860
|
+
: "none";
|
|
2818
2861
|
}
|
|
2819
2862
|
if (onboardingAny?.passkeyErrorElement) {
|
|
2820
|
-
onboardingAny.passkeyErrorElement.style.display =
|
|
2863
|
+
onboardingAny.passkeyErrorElement.style.display = "none";
|
|
2821
2864
|
}
|
|
2822
2865
|
// Show passkey divider if passkey is enabled and there are other auth methods
|
|
2823
2866
|
if (onboardingAny?.passkeyDivider) {
|
|
2824
|
-
onboardingAny.passkeyDivider.style.display =
|
|
2867
|
+
onboardingAny.passkeyDivider.style.display =
|
|
2868
|
+
showPasskey &&
|
|
2869
|
+
(showEmail || showGoogle || showTwitter || showDiscord)
|
|
2870
|
+
? ""
|
|
2871
|
+
: "none";
|
|
2825
2872
|
}
|
|
2826
2873
|
// Show divider between email and social methods if both are enabled
|
|
2827
2874
|
if (onboardingAny?.divider) {
|
|
2828
2875
|
const hasSocialMethods = showGoogle || showTwitter || showDiscord;
|
|
2829
|
-
onboardingAny.divider.style.display =
|
|
2876
|
+
onboardingAny.divider.style.display =
|
|
2877
|
+
showEmail && hasSocialMethods ? "" : "none";
|
|
2830
2878
|
}
|
|
2831
2879
|
if (onboardingAny?.externalWalletDivider) {
|
|
2832
|
-
onboardingAny.externalWalletDivider.style.display =
|
|
2880
|
+
onboardingAny.externalWalletDivider.style.display = "";
|
|
2833
2881
|
}
|
|
2834
2882
|
} }) }));
|
|
2835
2883
|
}
|
|
2836
2884
|
catch (error) {
|
|
2837
|
-
console.warn(
|
|
2885
|
+
console.warn("Failed to update ExternalWalletButtons:", error);
|
|
2838
2886
|
}
|
|
2839
2887
|
}, [value, externalWalletsEnabled]);
|
|
2840
2888
|
return (_jsx(AbstraxnContext.Provider, { value: value, children: children }));
|
|
@@ -2847,18 +2895,19 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2847
2895
|
function canUseReactQuery() {
|
|
2848
2896
|
try {
|
|
2849
2897
|
// Check if React is available
|
|
2850
|
-
if (typeof React ===
|
|
2851
|
-
return { canUse: false, reason:
|
|
2898
|
+
if (typeof React === "undefined" || React === null) {
|
|
2899
|
+
return { canUse: false, reason: "React is not available" };
|
|
2852
2900
|
}
|
|
2853
2901
|
// Check if React has the version property (indicates it's a valid React object)
|
|
2854
2902
|
if (!React.version) {
|
|
2855
|
-
return { canUse: false, reason:
|
|
2903
|
+
return { canUse: false, reason: "React version is not available" };
|
|
2856
2904
|
}
|
|
2857
2905
|
// Check if QueryClientProvider is available
|
|
2858
|
-
if (typeof QueryClientProvider ===
|
|
2906
|
+
if (typeof QueryClientProvider === "undefined" ||
|
|
2907
|
+
QueryClientProvider === null) {
|
|
2859
2908
|
return {
|
|
2860
2909
|
canUse: false,
|
|
2861
|
-
reason:
|
|
2910
|
+
reason: "@tanstack/react-query is not installed. Please install it: npm install @tanstack/react-query@^5.90.16",
|
|
2862
2911
|
};
|
|
2863
2912
|
}
|
|
2864
2913
|
return { canUse: true };
|
|
@@ -2871,21 +2920,21 @@ function canUseReactQuery() {
|
|
|
2871
2920
|
* Wrapper component that conditionally uses QueryClientProvider
|
|
2872
2921
|
* Falls back to rendering children directly if React Query is not available
|
|
2873
2922
|
*/
|
|
2874
|
-
function QueryClientWrapper({ children, queryClient }) {
|
|
2923
|
+
function QueryClientWrapper({ children, queryClient, }) {
|
|
2875
2924
|
// Check if we can safely use QueryClientProvider
|
|
2876
2925
|
const queryCheck = canUseReactQuery();
|
|
2877
2926
|
if (!queryCheck.canUse) {
|
|
2878
|
-
console.error(
|
|
2879
|
-
`Reason: ${queryCheck.reason ||
|
|
2880
|
-
|
|
2927
|
+
console.error("❌ React Query is not available. External wallets are disabled.\n" +
|
|
2928
|
+
`Reason: ${queryCheck.reason || "Unknown"}\n` +
|
|
2929
|
+
"Please install @tanstack/react-query@^5.90.16 and ensure there is only one React instance.");
|
|
2881
2930
|
// Return children without QueryClientProvider - external wallets won't work but app won't crash
|
|
2882
2931
|
return _jsx(_Fragment, { children: children });
|
|
2883
2932
|
}
|
|
2884
2933
|
try {
|
|
2885
|
-
return _jsx(QueryClientProvider, { client: queryClient, children: children });
|
|
2934
|
+
return (_jsx(QueryClientProvider, { client: queryClient, children: children }));
|
|
2886
2935
|
}
|
|
2887
2936
|
catch (error) {
|
|
2888
|
-
console.error(
|
|
2937
|
+
console.error("Failed to render QueryClientProvider:", error);
|
|
2889
2938
|
// Fallback: render children without QueryClientProvider
|
|
2890
2939
|
return _jsx(_Fragment, { children: children });
|
|
2891
2940
|
}
|
|
@@ -2934,14 +2983,16 @@ export function AbstraxnProvider({ config, children }) {
|
|
|
2934
2983
|
if (Array.isArray(chainConfig) && chainConfig.length > 0) {
|
|
2935
2984
|
// Check if first item looks like a viem chain object (has id, name, nativeCurrency)
|
|
2936
2985
|
const firstItem = chainConfig[0];
|
|
2937
|
-
if (firstItem &&
|
|
2986
|
+
if (firstItem &&
|
|
2987
|
+
typeof firstItem.id === "number" &&
|
|
2988
|
+
firstItem.nativeCurrency) {
|
|
2938
2989
|
hasViemChains = true;
|
|
2939
2990
|
// Store viem chains directly for wagmi
|
|
2940
2991
|
viemChainsForWagmi.push(...chainConfig);
|
|
2941
2992
|
// Also convert to core chain format for wallet instance
|
|
2942
2993
|
chainConfig.forEach((viemChain) => {
|
|
2943
2994
|
// Extract RPC URL from viem chain format
|
|
2944
|
-
let rpcUrl =
|
|
2995
|
+
let rpcUrl = "";
|
|
2945
2996
|
if (viemChain.rpcUrls?.default?.http) {
|
|
2946
2997
|
rpcUrl = Array.isArray(viemChain.rpcUrls.default.http)
|
|
2947
2998
|
? viemChain.rpcUrls.default.http[0]
|
|
@@ -2962,16 +3013,23 @@ export function AbstraxnProvider({ config, children }) {
|
|
|
2962
3013
|
}
|
|
2963
3014
|
}
|
|
2964
3015
|
// Priority 2: Check new chains config format (object with supportedEvmChains)
|
|
2965
|
-
if (!hasViemChains &&
|
|
3016
|
+
if (!hasViemChains &&
|
|
3017
|
+
chainConfig &&
|
|
3018
|
+
typeof chainConfig === "object" &&
|
|
3019
|
+
!Array.isArray(chainConfig) &&
|
|
3020
|
+
chainConfig.supportedEvmChains &&
|
|
3021
|
+
chainConfig.supportedEvmChains.length > 0) {
|
|
2966
3022
|
chainConfig.supportedEvmChains.forEach((chainName) => {
|
|
2967
3023
|
const chainData = EVM_CHAINS[chainName];
|
|
2968
|
-
if (chainData && chainData.type ===
|
|
3024
|
+
if (chainData && chainData.type === "evm") {
|
|
2969
3025
|
chains.push(toCoreChain(chainData));
|
|
2970
3026
|
}
|
|
2971
3027
|
});
|
|
2972
3028
|
}
|
|
2973
3029
|
// Priority 3: Check legacy supportedChains format
|
|
2974
|
-
else if (!hasViemChains &&
|
|
3030
|
+
else if (!hasViemChains &&
|
|
3031
|
+
config.supportedChains &&
|
|
3032
|
+
config.supportedChains.length > 0) {
|
|
2975
3033
|
chains.push(...config.supportedChains);
|
|
2976
3034
|
}
|
|
2977
3035
|
// Priority 4: Default chains
|
|
@@ -2987,44 +3045,55 @@ export function AbstraxnProvider({ config, children }) {
|
|
|
2987
3045
|
const { wagmiConfig, configError } = useMemo(() => {
|
|
2988
3046
|
if (!externalWalletsEnabled)
|
|
2989
3047
|
return { wagmiConfig: null, configError: null };
|
|
3048
|
+
// Use provided config if available
|
|
3049
|
+
if (config.wagmiConfig) {
|
|
3050
|
+
return { wagmiConfig: config.wagmiConfig, configError: null };
|
|
3051
|
+
}
|
|
2990
3052
|
try {
|
|
2991
|
-
const configResult = createWagmiConfig(wagmiChains, config.externalWallets?.walletConnectProjectId, config.externalWallets?.connectors, config.ui?.theme ||
|
|
3053
|
+
const configResult = createWagmiConfig(wagmiChains, config.externalWallets?.walletConnectProjectId, config.externalWallets?.connectors, config.ui?.theme || "dark");
|
|
2992
3054
|
return { wagmiConfig: configResult, configError: null };
|
|
2993
3055
|
}
|
|
2994
3056
|
catch (error) {
|
|
2995
|
-
console.error(
|
|
3057
|
+
console.error("Failed to create wagmi config:", error);
|
|
2996
3058
|
return {
|
|
2997
3059
|
wagmiConfig: null,
|
|
2998
|
-
configError: error instanceof Error
|
|
3060
|
+
configError: error instanceof Error
|
|
3061
|
+
? error
|
|
3062
|
+
: new Error("Failed to create wagmi config"),
|
|
2999
3063
|
};
|
|
3000
3064
|
}
|
|
3001
|
-
}, [
|
|
3065
|
+
}, [
|
|
3066
|
+
externalWalletsEnabled,
|
|
3067
|
+
wagmiChains,
|
|
3068
|
+
config.externalWallets?.walletConnectProjectId,
|
|
3069
|
+
config.externalWallets?.connectors,
|
|
3070
|
+
]);
|
|
3002
3071
|
// If external wallets are enabled, wrap with QueryClientProvider and WagmiProvider
|
|
3003
3072
|
if (externalWalletsEnabled) {
|
|
3004
3073
|
// Check if React Query is available BEFORE doing anything else
|
|
3005
3074
|
// This prevents errors from happening in the first place
|
|
3006
3075
|
const queryCheck = canUseReactQuery();
|
|
3007
3076
|
if (!queryCheck.canUse) {
|
|
3008
|
-
console.error(
|
|
3009
|
-
`Reason: ${queryCheck.reason ||
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
return _jsx(AbstraxnProviderWithoutWagmi, { config: config, children: children });
|
|
3077
|
+
console.error("❌ External wallets are disabled because React Query is not available.\n" +
|
|
3078
|
+
`Reason: ${queryCheck.reason || "Unknown"}\n` +
|
|
3079
|
+
"Please install @tanstack/react-query@^5.90.16 and ensure there is only one React instance.\n" +
|
|
3080
|
+
"Falling back to Abstraxn wallet only.");
|
|
3081
|
+
return (_jsx(AbstraxnProviderWithoutWagmi, { config: config, children: children }));
|
|
3013
3082
|
}
|
|
3014
3083
|
if (configError) {
|
|
3015
|
-
console.error(
|
|
3084
|
+
console.error("Failed to create wagmi config:", configError);
|
|
3016
3085
|
// Fallback to provider without wagmi if config creation fails
|
|
3017
|
-
return _jsx(AbstraxnProviderWithoutWagmi, { config: config, children: children });
|
|
3086
|
+
return (_jsx(AbstraxnProviderWithoutWagmi, { config: config, children: children }));
|
|
3018
3087
|
}
|
|
3019
3088
|
if (!wagmiConfig) {
|
|
3020
3089
|
// Show loading state while config is being created
|
|
3021
3090
|
// Don't render AbstraxnProviderInner until wagmiConfig is ready
|
|
3022
|
-
return (_jsx(QueryClientWrapper, { queryClient: queryClient, children: _jsx("div", { style: { display:
|
|
3091
|
+
return (_jsx(QueryClientWrapper, { queryClient: queryClient, children: _jsx("div", { style: { display: "none" }, children: "Loading wallet connectors..." }) }));
|
|
3023
3092
|
}
|
|
3024
|
-
return (_jsx(QueryClientWrapper, { queryClient: queryClient, children: _jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(AbstraxnProviderWithWagmi, { config: config, children: children }) }) }));
|
|
3093
|
+
return (_jsx(QueryClientWrapper, { queryClient: queryClient, children: _jsx(WagmiProvider, { config: wagmiConfig, initialState: config.initialState, children: _jsx(AbstraxnProviderWithWagmi, { config: config, children: children }) }) }));
|
|
3025
3094
|
}
|
|
3026
3095
|
// If external wallets are disabled, use the provider without wagmi
|
|
3027
|
-
return _jsx(AbstraxnProviderWithoutWagmi, { config: config, children: children });
|
|
3096
|
+
return (_jsx(AbstraxnProviderWithoutWagmi, { config: config, children: children }));
|
|
3028
3097
|
}
|
|
3029
3098
|
/**
|
|
3030
3099
|
* Hook to access Abstraxn Wallet context
|
|
@@ -3032,7 +3101,7 @@ export function AbstraxnProvider({ config, children }) {
|
|
|
3032
3101
|
export function useAbstraxnWallet() {
|
|
3033
3102
|
const context = useContext(AbstraxnContext);
|
|
3034
3103
|
if (!context) {
|
|
3035
|
-
throw new Error(
|
|
3104
|
+
throw new Error("useAbstraxnWallet must be used within AbstraxnProvider");
|
|
3036
3105
|
}
|
|
3037
3106
|
return context;
|
|
3038
3107
|
}
|