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