@silentswap/react 0.0.74 → 0.0.75
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.
|
@@ -206,6 +206,18 @@ export function useAuth({ client, address, walletClient, domain = typeof window
|
|
|
206
206
|
const isAuthenticated = useCallback(() => {
|
|
207
207
|
return auth !== null && auth.authExpires > Date.now();
|
|
208
208
|
}, [auth]);
|
|
209
|
+
// Clear auth when address changes (e.g. user switched from MetaMask to Phantom)
|
|
210
|
+
const prevAddressRef = useRef(normalizedAddress);
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
if (prevAddressRef.current && normalizedAddress && prevAddressRef.current !== normalizedAddress) {
|
|
213
|
+
setAuth(null);
|
|
214
|
+
setNonce(null);
|
|
215
|
+
setError(null);
|
|
216
|
+
setIsAutoAuthenticating(false);
|
|
217
|
+
hasAutoAuthenticatedRef.current = false;
|
|
218
|
+
}
|
|
219
|
+
prevAddressRef.current = normalizedAddress;
|
|
220
|
+
}, [normalizedAddress]);
|
|
209
221
|
// Load cached auth on mount
|
|
210
222
|
useEffect(() => {
|
|
211
223
|
if (normalizedAddress && !auth && !isLoading) {
|
|
@@ -167,6 +167,25 @@ export function useSilentQuote({ client, address, evmAddress, solAddress, wallet
|
|
|
167
167
|
throw new Error('Wallet is being generated. Please wait for wallet generation to complete before executing swap.');
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
+
// Wallet generation hasn't started yet (e.g. auto-trigger effect hasn't fired) - trigger it now
|
|
171
|
+
if (!walletRef.current && !walletLoadingRef.current && !walletErrorRef.current && generateWalletRef.current) {
|
|
172
|
+
setCurrentStep('Generating wallet...');
|
|
173
|
+
onStatus?.('Generating wallet...');
|
|
174
|
+
try {
|
|
175
|
+
await generateWalletRef.current();
|
|
176
|
+
// Wait for wallet ref to update after generation
|
|
177
|
+
const maxWaitTime = 30000;
|
|
178
|
+
const checkInterval = 100;
|
|
179
|
+
const startTime = Date.now();
|
|
180
|
+
while (!walletRef.current && Date.now() - startTime < maxWaitTime) {
|
|
181
|
+
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
const error = err instanceof Error ? err : new Error('Failed to generate wallet');
|
|
186
|
+
throw new Error(`Wallet generation failed: ${error.message}. Please try again or ensure wallet is connected and authenticated.`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
170
189
|
// Final check: wallet must exist for swap execution
|
|
171
190
|
if (!walletRef.current) {
|
|
172
191
|
throw new Error('Wallet is required for swap execution. Please ensure wallet is connected and authenticated.');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useState, useEffect } from 'react';
|
|
1
|
+
import { useCallback, useState, useEffect, useRef } from 'react';
|
|
2
2
|
import { createHdFacilitatorGroupFromEntropy, createEip712DocForWalletGeneration, queryDepositCount, loadWalletData, saveWalletData, clearWalletData, XT_TTL_SESSION_CACHE, ensureChain, base93ToBytes, bytesToBase93, } from '@silentswap/sdk';
|
|
3
3
|
import { getAddress, hexToBytes } from 'viem';
|
|
4
4
|
/**
|
|
@@ -182,6 +182,15 @@ export function useWallet({ client, address, auth, walletClient, connector, allD
|
|
|
182
182
|
clearWallet();
|
|
183
183
|
await generateWallet();
|
|
184
184
|
}, [clearWallet, generateWallet]);
|
|
185
|
+
// Clear wallet when address changes (e.g. user switched from MetaMask to Phantom)
|
|
186
|
+
const prevAddressRef = useRef(normalizedAddress);
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
if (prevAddressRef.current && normalizedAddress && prevAddressRef.current !== normalizedAddress) {
|
|
189
|
+
setWallet(null);
|
|
190
|
+
setError(null);
|
|
191
|
+
}
|
|
192
|
+
prevAddressRef.current = normalizedAddress;
|
|
193
|
+
}, [normalizedAddress]);
|
|
185
194
|
// Auto-load cached wallet on mount
|
|
186
195
|
useEffect(() => {
|
|
187
196
|
if (normalizedAddress && !wallet && !isLoading) {
|
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.75",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@bigmi/core": "^0.6.5",
|
|
26
26
|
"@ensdomains/ensjs": "^4.2.0",
|
|
27
|
-
"@silentswap/sdk": "0.0.
|
|
28
|
-
"@silentswap/ui-kit": "0.0.
|
|
27
|
+
"@silentswap/sdk": "0.0.75",
|
|
28
|
+
"@silentswap/ui-kit": "0.0.75",
|
|
29
29
|
"@solana/codecs-strings": "^5.1.0",
|
|
30
30
|
"@solana/kit": "^5.1.0",
|
|
31
31
|
"@solana/rpc": "^5.1.0",
|