@silentswap/react 0.0.52 → 0.0.53
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.
|
@@ -72,7 +72,7 @@ function SilentSwapInnerProvider({ children, client, evmAddress, solAddress, sol
|
|
|
72
72
|
autoAuthenticate: true,
|
|
73
73
|
});
|
|
74
74
|
// Wallet management hook
|
|
75
|
-
const { wallet, generateWallet, refreshWallet, isLoading: walletLoading, } = useWallet({
|
|
75
|
+
const { wallet, generateWallet, refreshWallet, isLoading: walletLoading, error: walletError, } = useWallet({
|
|
76
76
|
client,
|
|
77
77
|
address: evmAddress,
|
|
78
78
|
auth: auth || undefined,
|
|
@@ -121,6 +121,8 @@ function SilentSwapInnerProvider({ children, client, evmAddress, solAddress, sol
|
|
|
121
121
|
setDestinations,
|
|
122
122
|
wallet,
|
|
123
123
|
walletLoading,
|
|
124
|
+
walletError,
|
|
125
|
+
generateWallet,
|
|
124
126
|
walletClient,
|
|
125
127
|
connector,
|
|
126
128
|
solanaConnector,
|
|
@@ -40,6 +40,10 @@ export interface useSilentQuoteOptions {
|
|
|
40
40
|
wallet: SilentSwapWallet | null;
|
|
41
41
|
/** Whether wallet is currently being generated (to prevent swap execution before wallet is ready) */
|
|
42
42
|
walletLoading?: boolean;
|
|
43
|
+
/** Wallet generation error (if previous generation failed) */
|
|
44
|
+
walletError?: Error | null;
|
|
45
|
+
/** Function to generate wallet (for retry on swap execution) */
|
|
46
|
+
generateWallet?: () => Promise<void>;
|
|
43
47
|
/** Facilitator group for the swap, or a function that resolves it */
|
|
44
48
|
/** Status update callback */
|
|
45
49
|
onStatus?: (status: string) => void;
|
|
@@ -87,4 +91,4 @@ export interface ExecuteSwapParams {
|
|
|
87
91
|
/** Optional integrator ID for tracking */
|
|
88
92
|
integratorId?: string;
|
|
89
93
|
}
|
|
90
|
-
export declare function useSilentQuote({ client, address, evmAddress, solAddress, walletClient, connector, wallet, walletLoading, onStatus, solanaConnector, solanaConnection, solanaRpcUrl, getPrice, setDestinations, }: useSilentQuoteOptions): useSilentQuoteReturn;
|
|
94
|
+
export declare function useSilentQuote({ client, address, evmAddress, solAddress, walletClient, connector, wallet, walletLoading, walletError, generateWallet, onStatus, solanaConnector, solanaConnection, solanaRpcUrl, getPrice, setDestinations, }: useSilentQuoteOptions): useSilentQuoteReturn;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
1
|
+
import { useCallback, useMemo, useState, useRef, useEffect } from 'react';
|
|
2
2
|
import { hexToBase58, isSolanaAsset, parseEvmCaip19, S_CAIP19_USDC_AVALANCHE, NI_CHAIN_ID_AVALANCHE, getAssetByCaip19, } from '@silentswap/sdk';
|
|
3
3
|
import { getAddress } from 'viem';
|
|
4
4
|
import { BigNumber } from 'bignumber.js';
|
|
@@ -7,7 +7,7 @@ import { useOrderSigning } from './useOrderSigning.js';
|
|
|
7
7
|
import { useBridgeExecution } from './useBridgeExecution.js';
|
|
8
8
|
import { useTransaction } from '../useTransaction.js';
|
|
9
9
|
import { useQuoteCalculation } from './useQuoteCalculation.js';
|
|
10
|
-
export function useSilentQuote({ client, address, evmAddress, solAddress, walletClient, connector, wallet, walletLoading = false, onStatus, solanaConnector, solanaConnection, solanaRpcUrl, getPrice, setDestinations, }) {
|
|
10
|
+
export function useSilentQuote({ client, address, evmAddress, solAddress, walletClient, connector, wallet, walletLoading = false, walletError = null, generateWallet, onStatus, solanaConnector, solanaConnection, solanaRpcUrl, getPrice, setDestinations, }) {
|
|
11
11
|
const [isLoading, setIsLoading] = useState(false);
|
|
12
12
|
const [currentStep, setCurrentStep] = useState('');
|
|
13
13
|
const [quote, setQuote] = useState(null);
|
|
@@ -15,6 +15,18 @@ export function useSilentQuote({ client, address, evmAddress, solAddress, wallet
|
|
|
15
15
|
const [orderId, setOrderId] = useState(null);
|
|
16
16
|
const [viewingAuth, setViewingAuth] = useState(null);
|
|
17
17
|
const [isSwapping, setIsSwapping] = useState(false);
|
|
18
|
+
// Use refs to track current wallet state (to avoid stale closure values)
|
|
19
|
+
const walletRef = useRef(wallet);
|
|
20
|
+
const walletLoadingRef = useRef(walletLoading);
|
|
21
|
+
const walletErrorRef = useRef(walletError);
|
|
22
|
+
const generateWalletRef = useRef(generateWallet);
|
|
23
|
+
// Update refs when wallet state changes
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
walletRef.current = wallet;
|
|
26
|
+
walletLoadingRef.current = walletLoading;
|
|
27
|
+
walletErrorRef.current = walletError;
|
|
28
|
+
generateWalletRef.current = generateWallet;
|
|
29
|
+
}, [wallet, walletLoading, walletError, generateWallet]);
|
|
18
30
|
// Normalize address - only normalize EVM addresses
|
|
19
31
|
// Note: For Solana swaps, we still need an EVM address for facilitator operations
|
|
20
32
|
// The address parameter should be EVM for facilitator operations, but can be Solana for quote requests
|
|
@@ -93,9 +105,49 @@ export function useSilentQuote({ client, address, evmAddress, solAddress, wallet
|
|
|
93
105
|
if (!walletClient) {
|
|
94
106
|
throw new Error('Wallet client required for swap execution');
|
|
95
107
|
}
|
|
96
|
-
// Check if wallet
|
|
97
|
-
if (
|
|
98
|
-
|
|
108
|
+
// Check if wallet generation previously failed - retry if so
|
|
109
|
+
if (!walletRef.current && walletErrorRef.current && generateWalletRef.current && !walletLoadingRef.current) {
|
|
110
|
+
setCurrentStep('Retrying wallet generation...');
|
|
111
|
+
onStatus?.('Retrying wallet generation...');
|
|
112
|
+
try {
|
|
113
|
+
await generateWalletRef.current();
|
|
114
|
+
// Wait for wallet to be ready after retry (with timeout)
|
|
115
|
+
const maxWaitTime = 30000; // 30 seconds
|
|
116
|
+
const checkInterval = 100; // Check every 100ms
|
|
117
|
+
const startTime = Date.now();
|
|
118
|
+
while (!walletRef.current && Date.now() - startTime < maxWaitTime) {
|
|
119
|
+
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
120
|
+
}
|
|
121
|
+
// If wallet is still not ready after retry, throw error
|
|
122
|
+
if (!walletRef.current) {
|
|
123
|
+
throw new Error('Wallet generation retry completed but wallet is still not available. Please try again.');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
const error = err instanceof Error ? err : new Error('Failed to generate wallet');
|
|
128
|
+
throw new Error(`Wallet generation failed: ${error.message}. Please try again or ensure wallet is connected and authenticated.`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Wait for wallet to be ready if it's being generated
|
|
132
|
+
// Use refs to check current state (avoid stale closure values)
|
|
133
|
+
if (!walletRef.current && walletLoadingRef.current) {
|
|
134
|
+
setCurrentStep('Waiting for wallet generation...');
|
|
135
|
+
onStatus?.('Waiting for wallet generation...');
|
|
136
|
+
// Wait for wallet generation to complete (with timeout)
|
|
137
|
+
const maxWaitTime = 30000; // 30 seconds
|
|
138
|
+
const checkInterval = 100; // Check every 100ms
|
|
139
|
+
const startTime = Date.now();
|
|
140
|
+
while (!walletRef.current && walletLoadingRef.current && Date.now() - startTime < maxWaitTime) {
|
|
141
|
+
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
142
|
+
}
|
|
143
|
+
// If wallet is still not ready after waiting, throw error
|
|
144
|
+
if (!walletRef.current) {
|
|
145
|
+
throw new Error('Wallet is being generated. Please wait for wallet generation to complete before executing swap.');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Final check: wallet must exist for swap execution
|
|
149
|
+
if (!walletRef.current) {
|
|
150
|
+
throw new Error('Wallet is required for swap execution. Please ensure wallet is connected and authenticated.');
|
|
99
151
|
}
|
|
100
152
|
setIsLoading(true);
|
|
101
153
|
setError(null);
|
|
@@ -233,6 +285,8 @@ export function useSilentQuote({ client, address, evmAddress, solAddress, wallet
|
|
|
233
285
|
evmAddress,
|
|
234
286
|
walletClient,
|
|
235
287
|
walletLoading,
|
|
288
|
+
walletError,
|
|
289
|
+
generateWallet,
|
|
236
290
|
solanaConnector,
|
|
237
291
|
signAuthorizations,
|
|
238
292
|
createOrder,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silentswap/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.53",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@ensdomains/ensjs": "^4.2.0",
|
|
26
|
-
"@silentswap/sdk": "0.0.
|
|
27
|
-
"@silentswap/ui-kit": "0.0.
|
|
26
|
+
"@silentswap/sdk": "0.0.53",
|
|
27
|
+
"@silentswap/ui-kit": "0.0.53",
|
|
28
28
|
"@solana/codecs-strings": "^5.1.0",
|
|
29
29
|
"@solana/kit": "^5.1.0",
|
|
30
30
|
"@solana/rpc": "^5.1.0",
|