@silentswap/react 0.1.2 → 0.1.3

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.
@@ -35,9 +35,11 @@ export function useOrderSigning(walletClient, connector, client, setCurrentStep,
35
35
  if (!connector) {
36
36
  throw new Error('Connector required for chain switching');
37
37
  }
38
- if (isDepositingDirectly) {
39
- await ensureChain(NI_CHAIN_ID_AVALANCHE, walletClient, connector);
40
- }
38
+ // ensureChain returns a fresh walletClient bound to the target chain —
39
+ // critical for WalletConnect where the old client's chain scope gets silently dropped.
40
+ const signingClient = isDepositingDirectly
41
+ ? await ensureChain(NI_CHAIN_ID_AVALANCHE, walletClient, connector, { required: false })
42
+ : walletClient;
41
43
  return Promise.all(authorizations.map(async (auth) => ({
42
44
  ...auth,
43
45
  signature: await (async () => {
@@ -45,7 +47,7 @@ export function useOrderSigning(walletClient, connector, client, setCurrentStep,
45
47
  if (auth.type === 'eip3009_deposit') {
46
48
  if (isDepositingDirectly) {
47
49
  // Sign EIP-712 typed data for direct deposit
48
- return await walletClient.signTypedData(auth.eip712);
50
+ return await signingClient.signTypedData(auth.eip712);
49
51
  }
50
52
  else {
51
53
  // Will be deposited through proxy, no signature needed
@@ -83,18 +85,20 @@ export function useOrderSigning(walletClient, connector, client, setCurrentStep,
83
85
  throw new Error('Facilitator group required for order creation');
84
86
  }
85
87
  // Switch to Ethereum for order signing (orders are signed on Ethereum mainnet)
88
+ // ensureChain returns a fresh walletClient bound to the target chain —
89
+ // critical for WalletConnect where the old client's chain scope gets silently dropped.
86
90
  setCurrentStep('Preparing order signature');
87
91
  onStatus?.('Preparing order signature');
88
- await ensureChain(1, walletClient, connector); // Ethereum mainnet
92
+ const signingClient = await ensureChain(1, walletClient, connector, { required: false });
89
93
  // Create EIP-712 document for order
90
94
  const orderDoc = quoteResponseToEip712Document(quoteResponse);
91
95
  // Sign the order's EIP-712 document
92
96
  // Note: viem's signTypedData may normalize the domain.chainId to match the wallet client's
93
97
  // chain configuration, which can result in chainId being a BigInt instead of a number.
94
98
  // This happens because viem uses the wallet's chain configuration internally.
95
- const orderSignature = await walletClient.signTypedData({
99
+ const orderSignature = await signingClient.signTypedData({
96
100
  ...orderDoc,
97
- account: walletClient.account,
101
+ account: signingClient.account,
98
102
  });
99
103
  // Approve proxy authorizations from facilitators
100
104
  const facilitatorReplies = await effectiveGroup.approveProxyAuthorizations(quoteResponse.facilitators, {
@@ -94,7 +94,10 @@ export function useWallet({ client, address, auth, walletClient, connector, allD
94
94
  throw new Error('Connector required for chain switching');
95
95
  }
96
96
  // Ensure we're on Ethereum mainnet for entropy generation (asked core devs about this in tg)
97
- await ensureChain(1, walletClient, connector);
97
+ // ensureChain returns a fresh walletClient bound to the target chain after switching.
98
+ // Critical for WalletConnect: the old walletClient's chain scope doesn't match after
99
+ // a switch, so signing requests get silently dropped by the mobile wallet.
100
+ const signingClient = await ensureChain(1, walletClient, connector, { required: false });
98
101
  // Create EIP-712 document for wallet generation
99
102
  const eip712Doc = createEip712DocForWalletGeneration(`eip155:43114:${address}`, // Gateway contract scope (Avalanche)
100
103
  auth.secretToken);
@@ -102,10 +105,11 @@ export function useWallet({ client, address, auth, walletClient, connector, allD
102
105
  if (eip712Doc.domain && typeof eip712Doc.domain.chainId === 'number') {
103
106
  eip712Doc.domain.chainId = BigInt(eip712Doc.domain.chainId);
104
107
  }
105
- // Sign the document to generate entropy
106
- const signature = await walletClient.signTypedData({
108
+ // Sign the document to generate entropy — use the fresh signingClient, not
109
+ // the closure's walletClient which may be scoped to the pre-switch chain.
110
+ const signature = await signingClient.signTypedData({
107
111
  ...eip712Doc,
108
- account: walletClient.account,
112
+ account: signingClient.account,
109
113
  });
110
114
  return hexToBytes(signature);
111
115
  }, [auth, walletClient, connector, address]);
@@ -176,7 +180,7 @@ export function useWallet({ client, address, auth, walletClient, connector, allD
176
180
  isGeneratingRef.current = false;
177
181
  setIsLoading(false);
178
182
  }
179
- }, [normalizedAddress, getCachedWallet, queryDepositCount, generateEntropy, allDeposits, connector, client.s0xGatewayAddress]);
183
+ }, [normalizedAddress, getCachedWallet, generateEntropy, allDeposits, client.s0xGatewayAddress]);
180
184
  /**
181
185
  * Clear cached wallet
182
186
  */
@@ -194,6 +198,13 @@ export function useWallet({ client, address, auth, walletClient, connector, allD
194
198
  isGeneratingRef.current = false;
195
199
  await generateWallet();
196
200
  }, [clearWallet, generateWallet]);
201
+ // When walletClient or connector changes (e.g. WalletConnect chain switch causes
202
+ // wagmi to recreate the walletClient), reset the generation guard. Any in-flight
203
+ // generation using stale WalletConnect references will hang on signTypedData,
204
+ // permanently blocking future calls.
205
+ useEffect(() => {
206
+ isGeneratingRef.current = false;
207
+ }, [walletClient, connector]);
197
208
  // Clear wallet when address changes (e.g. user switched from MetaMask to Phantom)
198
209
  const prevAddressRef = useRef(normalizedAddress);
199
210
  useEffect(() => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silentswap/react",
3
3
  "type": "module",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
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.1.2",
28
- "@silentswap/ui-kit": "0.1.2",
27
+ "@silentswap/sdk": "0.1.3",
28
+ "@silentswap/ui-kit": "0.1.3",
29
29
  "@solana/codecs-strings": "^5.1.0",
30
30
  "@solana/kit": "^5.1.0",
31
31
  "@solana/rpc": "^5.1.0",