signer-test-sdk-react 0.0.12 → 0.0.14
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 -5
- package/dist/src/AbstraxnProvider.js +266 -31
- package/dist/src/AbstraxnProvider.js.map +1 -1
- package/dist/src/ExternalWalletButtons.js +37 -10
- package/dist/src/ExternalWalletButtons.js.map +1 -1
- package/dist/src/WalletModal.css +547 -21
- package/dist/src/WalletModal.js +98 -164
- package/dist/src/WalletModal.js.map +1 -1
- package/dist/src/components/OnboardingUI/OnboardingUIWeb.d.ts +7 -0
- package/dist/src/components/OnboardingUI/OnboardingUIWeb.js +169 -20
- package/dist/src/components/OnboardingUI/OnboardingUIWeb.js.map +1 -1
- package/dist/src/components/WalletModal/components/ChainSelector.css +180 -0
- package/dist/src/components/WalletModal/components/ChainSelector.d.ts +10 -0
- package/dist/src/components/WalletModal/components/ChainSelector.js +34 -0
- package/dist/src/components/WalletModal/components/ChainSelector.js.map +1 -0
- package/dist/src/components/WalletModal/components/ExportKeyModal.css +133 -0
- package/dist/src/components/WalletModal/components/ExportKeyModal.d.ts +9 -0
- package/dist/src/components/WalletModal/components/ExportKeyModal.js +31 -0
- package/dist/src/components/WalletModal/components/ExportKeyModal.js.map +1 -0
- package/dist/src/components/WalletModal/components/ExportWarningModal.css +2 -0
- package/dist/src/components/WalletModal/components/ExportWarningModal.d.ts +11 -0
- package/dist/src/components/WalletModal/components/ExportWarningModal.js +18 -0
- package/dist/src/components/WalletModal/components/ExportWarningModal.js.map +1 -0
- package/dist/src/components/WalletModal/components/ManageWalletModal.css +160 -0
- package/dist/src/components/WalletModal/components/ManageWalletModal.d.ts +12 -0
- package/dist/src/components/WalletModal/components/ManageWalletModal.js +21 -0
- package/dist/src/components/WalletModal/components/ManageWalletModal.js.map +1 -0
- package/dist/src/components/WalletModal/components/PreviewTransactionModal.css +128 -0
- package/dist/src/components/WalletModal/components/PreviewTransactionModal.d.ts +17 -0
- package/dist/src/components/WalletModal/components/PreviewTransactionModal.js +10 -0
- package/dist/src/components/WalletModal/components/PreviewTransactionModal.js.map +1 -0
- package/dist/src/components/WalletModal/components/ReceiveModal.css +101 -0
- package/dist/src/components/WalletModal/components/ReceiveModal.d.ts +8 -0
- package/dist/src/components/WalletModal/components/ReceiveModal.js +22 -0
- package/dist/src/components/WalletModal/components/ReceiveModal.js.map +1 -0
- package/dist/src/components/WalletModal/components/SendModal.css +234 -0
- package/dist/src/components/WalletModal/components/SendModal.d.ts +18 -0
- package/dist/src/components/WalletModal/components/SendModal.js +127 -0
- package/dist/src/components/WalletModal/components/SendModal.js.map +1 -0
- package/dist/src/components/WalletModal/components/SuccessModal.css +86 -0
- package/dist/src/components/WalletModal/components/SuccessModal.d.ts +13 -0
- package/dist/src/components/WalletModal/components/SuccessModal.js +8 -0
- package/dist/src/components/WalletModal/components/SuccessModal.js.map +1 -0
- package/dist/src/components/WalletModal/components/UserAvatar.d.ts +9 -0
- package/dist/src/components/WalletModal/components/UserAvatar.js +31 -0
- package/dist/src/components/WalletModal/components/UserAvatar.js.map +1 -0
- package/dist/src/components/WalletModal/components/index.d.ts +21 -0
- package/dist/src/components/WalletModal/components/index.js +13 -0
- package/dist/src/components/WalletModal/components/index.js.map +1 -0
- package/dist/src/components/WalletModal/hooks/index.d.ts +6 -0
- package/dist/src/components/WalletModal/hooks/index.js +7 -0
- package/dist/src/components/WalletModal/hooks/index.js.map +1 -0
- package/dist/src/components/WalletModal/hooks/useAddressValidation.d.ts +4 -0
- package/dist/src/components/WalletModal/hooks/useAddressValidation.js +17 -0
- package/dist/src/components/WalletModal/hooks/useAddressValidation.js.map +1 -0
- package/dist/src/components/WalletModal/hooks/useAmountValidation.d.ts +4 -0
- package/dist/src/components/WalletModal/hooks/useAmountValidation.js +29 -0
- package/dist/src/components/WalletModal/hooks/useAmountValidation.js.map +1 -0
- package/dist/src/components/WalletModal/hooks/useSendTransaction.d.ts +20 -0
- package/dist/src/components/WalletModal/hooks/useSendTransaction.js +55 -0
- package/dist/src/components/WalletModal/hooks/useSendTransaction.js.map +1 -0
- package/dist/src/components/WalletModal/index.d.ts +5 -0
- package/dist/src/components/WalletModal/index.js +7 -0
- package/dist/src/components/WalletModal/index.js.map +1 -0
- package/dist/src/components/WalletModal/utils/addressUtils.d.ts +19 -0
- package/dist/src/components/WalletModal/utils/addressUtils.js +62 -0
- package/dist/src/components/WalletModal/utils/addressUtils.js.map +1 -0
- package/dist/src/components/WalletModal/utils/formatUtils.d.ts +20 -0
- package/dist/src/components/WalletModal/utils/formatUtils.js +47 -0
- package/dist/src/components/WalletModal/utils/formatUtils.js.map +1 -0
- package/dist/src/components/WalletModal/utils/index.d.ts +5 -0
- package/dist/src/components/WalletModal/utils/index.js +6 -0
- package/dist/src/components/WalletModal/utils/index.js.map +1 -0
- package/dist/src/hooks.d.ts +8937 -0
- package/dist/src/hooks.js +776 -1
- package/dist/src/hooks.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/wagmiConfig.d.ts +2 -1
- package/dist/src/wagmiConfig.js +11 -3
- package/dist/src/wagmiConfig.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
* Abstraxn Wallet Provider - React Context Provider
|
|
3
3
|
* Wrap your app with this provider to use Abstraxn Wallet SDK
|
|
4
4
|
*/
|
|
5
|
-
import { type ReactNode } from 'react';
|
|
5
|
+
import React, { type ReactNode } from 'react';
|
|
6
6
|
import type { AbstraxnProviderConfig, AbstraxnContextValue } from './types';
|
|
7
|
-
export declare const AbstraxnContext:
|
|
7
|
+
export declare const AbstraxnContext: React.Context<AbstraxnContextValue | null>;
|
|
8
8
|
interface AbstraxnProviderProps {
|
|
9
9
|
config: AbstraxnProviderConfig;
|
|
10
10
|
children: ReactNode;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
* Main AbstraxnProvider component with optional WagmiProvider wrapper
|
|
14
|
-
*/
|
|
15
12
|
export declare function AbstraxnProvider({ config, children }: AbstraxnProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
16
13
|
/**
|
|
17
14
|
* Hook to access Abstraxn Wallet context
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/**
|
|
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 { createContext, useContext, useEffect, useState, useRef, useCallback, useMemo } from 'react';
|
|
6
|
+
import React, { createContext, useContext, useEffect, useState, useRef, useCallback, useMemo } from 'react';
|
|
7
7
|
import { AbstraxnWallet, AuthenticationError } from 'signer-test-sdk-core';
|
|
8
8
|
import { OnboardingUIWeb } from './components/OnboardingUI';
|
|
9
9
|
import { WagmiProvider, useAccount, useConnect, useDisconnect, useSignMessage, useSendTransaction, useSwitchChain, useBalance, useChainId } from 'wagmi';
|
|
@@ -13,15 +13,7 @@ import { parseEther, createPublicClient, http } from 'viem';
|
|
|
13
13
|
import { ExternalWalletButtons } from './ExternalWalletButtons';
|
|
14
14
|
import { EVM_CHAINS, SOLANA_CHAINS, getChainById, toCoreChain } from './chains';
|
|
15
15
|
export const AbstraxnContext = createContext(null);
|
|
16
|
-
//
|
|
17
|
-
const defaultQueryClient = new QueryClient({
|
|
18
|
-
defaultOptions: {
|
|
19
|
-
queries: {
|
|
20
|
-
refetchOnWindowFocus: false,
|
|
21
|
-
retry: false,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
});
|
|
16
|
+
// QueryClient will be created inside the component to ensure React context is available
|
|
25
17
|
// Base provider logic (shared between with and without wagmi)
|
|
26
18
|
function useAbstraxnProviderBase(_config) {
|
|
27
19
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
@@ -147,6 +139,58 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
147
139
|
}
|
|
148
140
|
});
|
|
149
141
|
}, [externalWalletsEnabled]);
|
|
142
|
+
// Restore external wallet connection on mount if wagmi has already restored it
|
|
143
|
+
// This runs after wagmi has had time to restore from localStorage
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (!externalWalletsEnabled || !wagmiAccount) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
// Check if wagmi has already restored a connection from localStorage
|
|
149
|
+
// This happens automatically with wagmi's persistence when storage is configured
|
|
150
|
+
const checkAndRestore = () => {
|
|
151
|
+
if (wagmiAccount.isConnected && wagmiAccount.address && !isExternalWalletConnected) {
|
|
152
|
+
const walletAddress = wagmiAccount.address.toLowerCase();
|
|
153
|
+
const currentChainId = wagmiChainIdHook || wagmiAccount.chainId || null;
|
|
154
|
+
// Set explicitConnectionRef FIRST to prevent auto-disconnect from interfering
|
|
155
|
+
explicitConnectionRef.current = true;
|
|
156
|
+
autoDisconnectHandledRef.current = false;
|
|
157
|
+
// Restore external wallet state
|
|
158
|
+
setIsExternalWalletConnected(true);
|
|
159
|
+
setExternalWalletAddress(walletAddress);
|
|
160
|
+
setAddress(walletAddress);
|
|
161
|
+
setIsConnected(true);
|
|
162
|
+
setExternalWalletChainId(currentChainId);
|
|
163
|
+
setChainId(currentChainId);
|
|
164
|
+
// Update refs to track the restored connection
|
|
165
|
+
lastAddressRef.current = walletAddress;
|
|
166
|
+
lastChainIdRef.current = currentChainId;
|
|
167
|
+
lastConnectionTimeRef.current = Date.now();
|
|
168
|
+
return true; // Indicate restoration happened
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
};
|
|
172
|
+
// Check immediately
|
|
173
|
+
if (checkAndRestore()) {
|
|
174
|
+
return; // Already restored
|
|
175
|
+
}
|
|
176
|
+
// Also check after delays to catch wagmi's async restoration
|
|
177
|
+
// Wagmi might restore the connection asynchronously after the component mounts
|
|
178
|
+
let timeout2 = null;
|
|
179
|
+
const timeout1 = setTimeout(() => {
|
|
180
|
+
if (!checkAndRestore()) {
|
|
181
|
+
// Check one more time after a longer delay
|
|
182
|
+
timeout2 = setTimeout(() => {
|
|
183
|
+
checkAndRestore();
|
|
184
|
+
}, 300);
|
|
185
|
+
}
|
|
186
|
+
}, 150);
|
|
187
|
+
return () => {
|
|
188
|
+
clearTimeout(timeout1);
|
|
189
|
+
if (timeout2) {
|
|
190
|
+
clearTimeout(timeout2);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}, [externalWalletsEnabled, wagmiAccount?.isConnected, wagmiAccount?.address, wagmiChainIdHook, isExternalWalletConnected]); // Re-run if wagmi state changes
|
|
150
194
|
// Initialize wallet
|
|
151
195
|
useEffect(() => {
|
|
152
196
|
// If wallet already exists (from previous mount), reuse it to prevent flicker
|
|
@@ -165,16 +209,42 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
165
209
|
// Compute from chains config - use same logic as availableChains
|
|
166
210
|
const chainConfig = config.chains;
|
|
167
211
|
const chains = [];
|
|
168
|
-
// Priority 1: Check
|
|
169
|
-
if (chainConfig
|
|
170
|
-
|
|
212
|
+
// Priority 1: Check if chains is an array of viem chain objects (direct format)
|
|
213
|
+
if (Array.isArray(chainConfig) && chainConfig?.length > 0) {
|
|
214
|
+
const firstItem = chainConfig[0];
|
|
215
|
+
if (firstItem && typeof firstItem.id === 'number' && firstItem.nativeCurrency) {
|
|
216
|
+
// Convert viem chain objects to core chain format
|
|
217
|
+
chainConfig.forEach((viemChain) => {
|
|
218
|
+
let rpcUrl = '';
|
|
219
|
+
if (viemChain.rpcUrls?.default?.http) {
|
|
220
|
+
rpcUrl = Array.isArray(viemChain.rpcUrls.default.http)
|
|
221
|
+
? viemChain.rpcUrls.default.http[0]
|
|
222
|
+
: viemChain.rpcUrls.default.http;
|
|
223
|
+
}
|
|
224
|
+
else if (viemChain.rpcUrls?.public?.http) {
|
|
225
|
+
rpcUrl = Array.isArray(viemChain.rpcUrls.public.http)
|
|
226
|
+
? viemChain.rpcUrls.public.http[0]
|
|
227
|
+
: viemChain.rpcUrls.public.http;
|
|
228
|
+
}
|
|
229
|
+
chains.push({
|
|
230
|
+
id: viemChain.id,
|
|
231
|
+
name: viemChain.name,
|
|
232
|
+
rpcUrl: rpcUrl || `https://rpc.ankr.com/${viemChain.name.toLowerCase()}`,
|
|
233
|
+
nativeCurrency: viemChain.nativeCurrency,
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// Priority 2: Check new chains config format
|
|
239
|
+
else if (chainConfig?.supportedEvmChains && chainConfig.supportedEvmChains.length > 0) {
|
|
240
|
+
chainConfig.supportedEvmChains.forEach((chainName) => {
|
|
171
241
|
const chainData = EVM_CHAINS[chainName];
|
|
172
242
|
if (chainData && chainData.type === 'evm') {
|
|
173
243
|
chains.push(toCoreChain(chainData));
|
|
174
244
|
}
|
|
175
245
|
});
|
|
176
246
|
}
|
|
177
|
-
// Priority
|
|
247
|
+
// Priority 3: If no specific config, include default chains that might be shown
|
|
178
248
|
// This ensures Base and other common chains are available even if not explicitly configured
|
|
179
249
|
if (chains.length === 0) {
|
|
180
250
|
// Include common chains that are likely to be in availableChains
|
|
@@ -787,6 +857,10 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
787
857
|
// Modal already exists, just show it
|
|
788
858
|
// Use requestAnimationFrame to prevent blinking
|
|
789
859
|
requestAnimationFrame(() => {
|
|
860
|
+
// Check if we're on OTP screen - if so, ensure social buttons stay hidden
|
|
861
|
+
const isOtpScreen = onboarding.otpVerificationScreen &&
|
|
862
|
+
onboarding.otpVerificationScreen.parentElement &&
|
|
863
|
+
onboarding.otpVerificationScreen.offsetParent !== null;
|
|
790
864
|
onboarding.modalOverlay.classList.remove('onboarding-modal-closing');
|
|
791
865
|
onboarding.modalOverlay.classList.add('onboarding-modal-open');
|
|
792
866
|
onboarding.modalOverlay.style.display = 'flex';
|
|
@@ -794,11 +868,39 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
794
868
|
onboarding.rootElement.style.display = '';
|
|
795
869
|
}
|
|
796
870
|
document.body.style.overflow = 'hidden';
|
|
871
|
+
// If on OTP screen, ensure all login elements (social buttons, etc.) are hidden
|
|
872
|
+
if (isOtpScreen) {
|
|
873
|
+
// On OTP screen - ensure all login elements are hidden
|
|
874
|
+
if (onboarding.hideLoginElements && typeof onboarding.hideLoginElements === 'function') {
|
|
875
|
+
onboarding.hideLoginElements();
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
878
|
+
// Fallback: manually hide elements
|
|
879
|
+
if (onboarding.googleButton)
|
|
880
|
+
onboarding.googleButton.style.display = 'none';
|
|
881
|
+
if (onboarding.twitterButton)
|
|
882
|
+
onboarding.twitterButton.style.display = 'none';
|
|
883
|
+
if (onboarding.discordButton)
|
|
884
|
+
onboarding.discordButton.style.display = 'none';
|
|
885
|
+
if (onboarding.socialGrid)
|
|
886
|
+
onboarding.socialGrid.style.display = 'none';
|
|
887
|
+
if (onboarding.divider)
|
|
888
|
+
onboarding.divider.style.display = 'none';
|
|
889
|
+
if (onboarding.passkeyLoginButton)
|
|
890
|
+
onboarding.passkeyLoginButton.style.display = 'none';
|
|
891
|
+
if (onboarding.passkeySignupLink)
|
|
892
|
+
onboarding.passkeySignupLink.style.display = 'none';
|
|
893
|
+
if (onboarding.passkeyDivider)
|
|
894
|
+
onboarding.passkeyDivider.style.display = 'none';
|
|
895
|
+
if (onboarding.externalWalletContainer)
|
|
896
|
+
onboarding.externalWalletContainer.style.display = 'none';
|
|
897
|
+
if (onboarding.externalWalletDivider)
|
|
898
|
+
onboarding.externalWalletDivider.style.display = 'none';
|
|
899
|
+
}
|
|
900
|
+
}
|
|
797
901
|
// CRITICAL: Always ensure external wallets are mounted when modal reopens
|
|
798
902
|
if (externalWalletsEnabledRef.current && onboarding.externalWalletContainer) {
|
|
799
903
|
// Check if we're on OTP screen - if so, don't show external wallets
|
|
800
|
-
const isOtpScreen = onboarding.otpVerificationScreen &&
|
|
801
|
-
onboarding.otpVerificationScreen.parentElement;
|
|
802
904
|
if (!isOtpScreen) {
|
|
803
905
|
// Only show external wallets if not on OTP screen
|
|
804
906
|
onboarding.externalWalletContainer.style.display = '';
|
|
@@ -1376,8 +1478,13 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1376
1478
|
if (!externalWalletsEnabled || !wagmiAccount) {
|
|
1377
1479
|
return;
|
|
1378
1480
|
}
|
|
1379
|
-
// Prevent auto-connect
|
|
1380
|
-
|
|
1481
|
+
// Prevent auto-connect (but allow restoration from persistence)
|
|
1482
|
+
// Only auto-disconnect if:
|
|
1483
|
+
// 1. wagmiAccount is connected
|
|
1484
|
+
// 2. We don't have explicitConnectionRef set (meaning user didn't explicitly connect)
|
|
1485
|
+
// 3. We haven't already handled auto-disconnect
|
|
1486
|
+
// 4. We don't have a stored address (meaning this isn't a restoration from persistence)
|
|
1487
|
+
if (wagmiAccount.isConnected && !explicitConnectionRef.current && !autoDisconnectHandledRef.current && lastAddressRef.current === null) {
|
|
1381
1488
|
autoDisconnectHandledRef.current = true;
|
|
1382
1489
|
if (wagmiDisconnect) {
|
|
1383
1490
|
setTimeout(() => {
|
|
@@ -1433,11 +1540,16 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
1433
1540
|
const addressChanged = lastAddressRef.current !== formattedAddress;
|
|
1434
1541
|
const chainIdChanged = lastChainIdRef.current !== currentChainId;
|
|
1435
1542
|
// Also check if we need to reconnect (lastAddressRef is null but wagmiAccount is connected)
|
|
1436
|
-
// This handles the case where user disconnects and then reconnects
|
|
1543
|
+
// This handles the case where user disconnects and then reconnects, OR page reload
|
|
1437
1544
|
const needsReconnect = lastAddressRef.current === null && wagmiAccount.isConnected && formattedAddress;
|
|
1438
1545
|
// Only update if something actually changed OR if we need to reconnect
|
|
1439
1546
|
if (addressChanged || chainIdChanged || needsReconnect) {
|
|
1440
1547
|
isUpdatingRef.current = true;
|
|
1548
|
+
// If this is a restoration (needsReconnect), set explicitConnectionRef to prevent auto-disconnect
|
|
1549
|
+
if (needsReconnect) {
|
|
1550
|
+
explicitConnectionRef.current = true;
|
|
1551
|
+
autoDisconnectHandledRef.current = false;
|
|
1552
|
+
}
|
|
1441
1553
|
// Update address if it changed or if we need to reconnect
|
|
1442
1554
|
if (addressChanged || needsReconnect) {
|
|
1443
1555
|
setIsExternalWalletConnected(true);
|
|
@@ -2465,37 +2577,150 @@ function AbstraxnProviderInner({ config, children, base, wagmi }) {
|
|
|
2465
2577
|
}, [value, externalWalletsEnabled]);
|
|
2466
2578
|
return (_jsx(AbstraxnContext.Provider, { value: value, children: children }));
|
|
2467
2579
|
}
|
|
2580
|
+
/**
|
|
2581
|
+
* Check if React Query is available and can be used safely
|
|
2582
|
+
* This is a simple check - we can't fully verify React is properly set up
|
|
2583
|
+
* without trying to use it, but we can check if the dependencies exist
|
|
2584
|
+
*/
|
|
2585
|
+
function canUseReactQuery() {
|
|
2586
|
+
try {
|
|
2587
|
+
// Check if React is available
|
|
2588
|
+
if (typeof React === 'undefined' || React === null) {
|
|
2589
|
+
return { canUse: false, reason: 'React is not available' };
|
|
2590
|
+
}
|
|
2591
|
+
// Check if React has the version property (indicates it's a valid React object)
|
|
2592
|
+
if (!React.version) {
|
|
2593
|
+
return { canUse: false, reason: 'React version is not available' };
|
|
2594
|
+
}
|
|
2595
|
+
// Check if QueryClientProvider is available
|
|
2596
|
+
if (typeof QueryClientProvider === 'undefined' || QueryClientProvider === null) {
|
|
2597
|
+
return {
|
|
2598
|
+
canUse: false,
|
|
2599
|
+
reason: '@tanstack/react-query is not installed. Please install it: npm install @tanstack/react-query@^5.90.16'
|
|
2600
|
+
};
|
|
2601
|
+
}
|
|
2602
|
+
return { canUse: true };
|
|
2603
|
+
}
|
|
2604
|
+
catch (error) {
|
|
2605
|
+
return { canUse: false, reason: `Error checking React Query: ${error}` };
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
/**
|
|
2609
|
+
* Wrapper component that conditionally uses QueryClientProvider
|
|
2610
|
+
* Falls back to rendering children directly if React Query is not available
|
|
2611
|
+
*/
|
|
2612
|
+
function QueryClientWrapper({ children, queryClient }) {
|
|
2613
|
+
// Check if we can safely use QueryClientProvider
|
|
2614
|
+
const queryCheck = canUseReactQuery();
|
|
2615
|
+
if (!queryCheck.canUse) {
|
|
2616
|
+
console.error('❌ React Query is not available. External wallets are disabled.\n' +
|
|
2617
|
+
`Reason: ${queryCheck.reason || 'Unknown'}\n` +
|
|
2618
|
+
'Please install @tanstack/react-query@^5.90.16 and ensure there is only one React instance.');
|
|
2619
|
+
// Return children without QueryClientProvider - external wallets won't work but app won't crash
|
|
2620
|
+
return _jsx(_Fragment, { children: children });
|
|
2621
|
+
}
|
|
2622
|
+
try {
|
|
2623
|
+
return _jsx(QueryClientProvider, { client: queryClient, children: children });
|
|
2624
|
+
}
|
|
2625
|
+
catch (error) {
|
|
2626
|
+
console.error('Failed to render QueryClientProvider:', error);
|
|
2627
|
+
// Fallback: render children without QueryClientProvider
|
|
2628
|
+
return _jsx(_Fragment, { children: children });
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2468
2631
|
/**
|
|
2469
2632
|
* Main AbstraxnProvider component with optional WagmiProvider wrapper
|
|
2470
2633
|
*/
|
|
2634
|
+
/**
|
|
2635
|
+
* Hook to create QueryClient
|
|
2636
|
+
* Creates a QueryClient instance that's only created once per component instance
|
|
2637
|
+
* Since @tanstack/react-query is now only in peerDependencies, the app's instance will be used
|
|
2638
|
+
* This prevents multiple instances of the package from being bundled
|
|
2639
|
+
*/
|
|
2640
|
+
function useQueryClientSafe() {
|
|
2641
|
+
// Create QueryClient using useState to ensure it's only created once
|
|
2642
|
+
// Since @tanstack/react-query is in peerDependencies, this will use the app's instance
|
|
2643
|
+
const [queryClient] = useState(() => {
|
|
2644
|
+
return new QueryClient({
|
|
2645
|
+
defaultOptions: {
|
|
2646
|
+
queries: {
|
|
2647
|
+
refetchOnWindowFocus: false,
|
|
2648
|
+
retry: false,
|
|
2649
|
+
},
|
|
2650
|
+
},
|
|
2651
|
+
});
|
|
2652
|
+
});
|
|
2653
|
+
return queryClient;
|
|
2654
|
+
}
|
|
2471
2655
|
export function AbstraxnProvider({ config, children }) {
|
|
2472
2656
|
const externalWalletsEnabled = config.externalWallets?.enabled ?? false;
|
|
2657
|
+
// Get or create QueryClient - tries to use existing one from context first
|
|
2658
|
+
// This ensures we use the app's QueryClient instance if it exists, preventing multiple instances
|
|
2659
|
+
const queryClient = useQueryClientSafe();
|
|
2473
2660
|
// Create wagmi config if external wallets are enabled
|
|
2474
2661
|
// Use useMemo to ensure config is created synchronously during render
|
|
2475
2662
|
// This prevents the "Loading wallet connectors..." state from flashing or blocking initial render
|
|
2476
2663
|
// Compute chains for wagmi config (needs to be done before useMemo)
|
|
2477
|
-
|
|
2664
|
+
// Store both core chains (for wallet) and viem chains (for wagmi) if viem chains are passed directly
|
|
2665
|
+
const { wagmiChains, coreChains } = useMemo(() => {
|
|
2478
2666
|
// Use the same logic as availableChains but convert to Core Chain format
|
|
2479
2667
|
const chains = [];
|
|
2668
|
+
const viemChainsForWagmi = [];
|
|
2480
2669
|
const chainConfig = config.chains;
|
|
2481
|
-
|
|
2482
|
-
if
|
|
2483
|
-
|
|
2670
|
+
let hasViemChains = false;
|
|
2671
|
+
// Priority 1: Check if chains is an array of viem chain objects (direct format)
|
|
2672
|
+
if (Array.isArray(chainConfig) && chainConfig.length > 0) {
|
|
2673
|
+
// Check if first item looks like a viem chain object (has id, name, nativeCurrency)
|
|
2674
|
+
const firstItem = chainConfig[0];
|
|
2675
|
+
if (firstItem && typeof firstItem.id === 'number' && firstItem.nativeCurrency) {
|
|
2676
|
+
hasViemChains = true;
|
|
2677
|
+
// Store viem chains directly for wagmi
|
|
2678
|
+
viemChainsForWagmi.push(...chainConfig);
|
|
2679
|
+
// Also convert to core chain format for wallet instance
|
|
2680
|
+
chainConfig.forEach((viemChain) => {
|
|
2681
|
+
// Extract RPC URL from viem chain format
|
|
2682
|
+
let rpcUrl = '';
|
|
2683
|
+
if (viemChain.rpcUrls?.default?.http) {
|
|
2684
|
+
rpcUrl = Array.isArray(viemChain.rpcUrls.default.http)
|
|
2685
|
+
? viemChain.rpcUrls.default.http[0]
|
|
2686
|
+
: viemChain.rpcUrls.default.http;
|
|
2687
|
+
}
|
|
2688
|
+
else if (viemChain.rpcUrls?.public?.http) {
|
|
2689
|
+
rpcUrl = Array.isArray(viemChain.rpcUrls.public.http)
|
|
2690
|
+
? viemChain.rpcUrls.public.http[0]
|
|
2691
|
+
: viemChain.rpcUrls.public.http;
|
|
2692
|
+
}
|
|
2693
|
+
chains.push({
|
|
2694
|
+
id: viemChain.id,
|
|
2695
|
+
name: viemChain.name,
|
|
2696
|
+
rpcUrl: rpcUrl || `https://rpc.ankr.com/${viemChain.name.toLowerCase()}`,
|
|
2697
|
+
nativeCurrency: viemChain.nativeCurrency,
|
|
2698
|
+
});
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
// Priority 2: Check new chains config format (object with supportedEvmChains)
|
|
2703
|
+
if (!hasViemChains && chainConfig && typeof chainConfig === 'object' && !Array.isArray(chainConfig) && chainConfig.supportedEvmChains && chainConfig.supportedEvmChains.length > 0) {
|
|
2704
|
+
chainConfig.supportedEvmChains.forEach((chainName) => {
|
|
2484
2705
|
const chainData = EVM_CHAINS[chainName];
|
|
2485
2706
|
if (chainData && chainData.type === 'evm') {
|
|
2486
2707
|
chains.push(toCoreChain(chainData));
|
|
2487
2708
|
}
|
|
2488
2709
|
});
|
|
2489
2710
|
}
|
|
2490
|
-
// Priority
|
|
2491
|
-
else if (config.supportedChains && config.supportedChains.length > 0) {
|
|
2711
|
+
// Priority 3: Check legacy supportedChains format
|
|
2712
|
+
else if (!hasViemChains && config.supportedChains && config.supportedChains.length > 0) {
|
|
2492
2713
|
chains.push(...config.supportedChains);
|
|
2493
2714
|
}
|
|
2494
|
-
// Priority
|
|
2495
|
-
else {
|
|
2715
|
+
// Priority 4: Default chains
|
|
2716
|
+
else if (!hasViemChains) {
|
|
2496
2717
|
chains.push(toCoreChain(EVM_CHAINS.ethereum));
|
|
2497
2718
|
}
|
|
2498
|
-
|
|
2719
|
+
const finalChains = chains.length > 0 ? chains : [toCoreChain(EVM_CHAINS.ethereum)];
|
|
2720
|
+
return {
|
|
2721
|
+
wagmiChains: hasViemChains ? viemChainsForWagmi : finalChains,
|
|
2722
|
+
coreChains: finalChains,
|
|
2723
|
+
};
|
|
2499
2724
|
}, [config.chains, config.supportedChains]);
|
|
2500
2725
|
const { wagmiConfig, configError } = useMemo(() => {
|
|
2501
2726
|
if (!externalWalletsEnabled)
|
|
@@ -2514,6 +2739,16 @@ export function AbstraxnProvider({ config, children }) {
|
|
|
2514
2739
|
}, [externalWalletsEnabled, wagmiChains, config.externalWallets?.walletConnectProjectId, config.externalWallets?.connectors]);
|
|
2515
2740
|
// If external wallets are enabled, wrap with QueryClientProvider and WagmiProvider
|
|
2516
2741
|
if (externalWalletsEnabled) {
|
|
2742
|
+
// Check if React Query is available BEFORE doing anything else
|
|
2743
|
+
// This prevents errors from happening in the first place
|
|
2744
|
+
const queryCheck = canUseReactQuery();
|
|
2745
|
+
if (!queryCheck.canUse) {
|
|
2746
|
+
console.error('❌ External wallets are disabled because React Query is not available.\n' +
|
|
2747
|
+
`Reason: ${queryCheck.reason || 'Unknown'}\n` +
|
|
2748
|
+
'Please install @tanstack/react-query@^5.90.16 and ensure there is only one React instance.\n' +
|
|
2749
|
+
'Falling back to Abstraxn wallet only.');
|
|
2750
|
+
return _jsx(AbstraxnProviderWithoutWagmi, { config: config, children: children });
|
|
2751
|
+
}
|
|
2517
2752
|
if (configError) {
|
|
2518
2753
|
console.error('Failed to create wagmi config:', configError);
|
|
2519
2754
|
// Fallback to provider without wagmi if config creation fails
|
|
@@ -2522,9 +2757,9 @@ export function AbstraxnProvider({ config, children }) {
|
|
|
2522
2757
|
if (!wagmiConfig) {
|
|
2523
2758
|
// Show loading state while config is being created
|
|
2524
2759
|
// Don't render AbstraxnProviderInner until wagmiConfig is ready
|
|
2525
|
-
return (_jsx(
|
|
2760
|
+
return (_jsx(QueryClientWrapper, { queryClient: queryClient, children: _jsx("div", { style: { display: 'none' }, children: "Loading wallet connectors..." }) }));
|
|
2526
2761
|
}
|
|
2527
|
-
return (_jsx(
|
|
2762
|
+
return (_jsx(QueryClientWrapper, { queryClient: queryClient, children: _jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(AbstraxnProviderWithWagmi, { config: config, children: children }) }) }));
|
|
2528
2763
|
}
|
|
2529
2764
|
// If external wallets are disabled, use the provider without wagmi
|
|
2530
2765
|
return _jsx(AbstraxnProviderWithoutWagmi, { config: config, children: children });
|