@rash2x/bridge-widget 0.8.9 → 0.8.10

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.
@@ -5962,6 +5962,39 @@ class EvmChainStrategy {
5962
5962
  ...rpcError
5963
5963
  });
5964
5964
  }
5965
+ isNonceResubmissionError(error) {
5966
+ const rpcError = this.getRpcErrorDetails(error);
5967
+ const combined = [rpcError.message, rpcError.shortMessage, rpcError.details].filter(Boolean).join(" ").toLowerCase();
5968
+ return combined.includes("nonce too low") || combined.includes("replacement transaction underpriced");
5969
+ }
5970
+ async sendTransactionWithNonceRetry(walletClient, params) {
5971
+ try {
5972
+ return await walletClient.sendTransaction(params);
5973
+ } catch (error) {
5974
+ if (!this.isNonceResubmissionError(error)) {
5975
+ throw error;
5976
+ }
5977
+ this.logRpcWarning(
5978
+ "Retrying transaction after nonce-related error",
5979
+ error
5980
+ );
5981
+ return await walletClient.sendTransaction(params);
5982
+ }
5983
+ }
5984
+ async writeContractWithNonceRetry(walletClient, params) {
5985
+ try {
5986
+ return await walletClient.writeContract(params);
5987
+ } catch (error) {
5988
+ if (!this.isNonceResubmissionError(error)) {
5989
+ throw error;
5990
+ }
5991
+ this.logRpcWarning(
5992
+ "Retrying contract write after nonce-related error",
5993
+ error
5994
+ );
5995
+ return await walletClient.writeContract(params);
5996
+ }
5997
+ }
5965
5998
  async getBalances(address, tokens) {
5966
5999
  const chainKey = tokens[0]?.chainKey;
5967
6000
  const client = this.resolvePublicClientForChain(chainKey);
@@ -6026,12 +6059,16 @@ class EvmChainStrategy {
6026
6059
  if (!tx?.to) continue;
6027
6060
  const client = this.resolvePublicClientForChain(step.chainKey);
6028
6061
  if (!client) {
6029
- this.logRpcWarning("Skipped network fee estimation: no public client", "no-client", {
6030
- chainKey: step.chainKey,
6031
- stepType: step.type,
6032
- stepIndex: i3 + 1,
6033
- totalSteps: txSteps.length
6034
- });
6062
+ this.logRpcWarning(
6063
+ "Skipped network fee estimation: no public client",
6064
+ "no-client",
6065
+ {
6066
+ chainKey: step.chainKey,
6067
+ stepType: step.type,
6068
+ stepIndex: i3 + 1,
6069
+ totalSteps: txSteps.length
6070
+ }
6071
+ );
6035
6072
  continue;
6036
6073
  }
6037
6074
  try {
@@ -6059,12 +6096,16 @@ class EvmChainStrategy {
6059
6096
  try {
6060
6097
  feePerGas = await client.getGasPrice();
6061
6098
  } catch (gasPriceError) {
6062
- this.logRpcWarning("Failed to get gas price for network fee estimation", gasPriceError, {
6063
- chainKey: step.chainKey,
6064
- stepType: step.type,
6065
- stepIndex: i3 + 1,
6066
- totalSteps: txSteps.length
6067
- });
6099
+ this.logRpcWarning(
6100
+ "Failed to get gas price for network fee estimation",
6101
+ gasPriceError,
6102
+ {
6103
+ chainKey: step.chainKey,
6104
+ stepType: step.type,
6105
+ stepIndex: i3 + 1,
6106
+ totalSteps: txSteps.length
6107
+ }
6108
+ );
6068
6109
  }
6069
6110
  }
6070
6111
  if (gas && feePerGas) {
@@ -6143,7 +6184,9 @@ class EvmChainStrategy {
6143
6184
  const requiredChainId = this.config.chainKeyToId[firstChainKey.toLowerCase()];
6144
6185
  const currentChainId = this.walletClient.chain?.id;
6145
6186
  if (requiredChainId && currentChainId !== requiredChainId) {
6146
- console.log(`Switching from chain ${currentChainId} to ${requiredChainId}`);
6187
+ console.log(
6188
+ `Switching from chain ${currentChainId} to ${requiredChainId}`
6189
+ );
6147
6190
  await this.switchToChain(requiredChainId);
6148
6191
  } else {
6149
6192
  console.log(`Already on correct chain ${currentChainId}`);
@@ -6172,6 +6215,16 @@ class EvmChainStrategy {
6172
6215
  bridgeTxHash = hash;
6173
6216
  }
6174
6217
  lastTxHash = hash;
6218
+ if (step.type === "approve") {
6219
+ const receiptClient = this.resolvePublicClientForChain(step.chainKey);
6220
+ if (!receiptClient) {
6221
+ throw new WalletNotConnectedError("evm");
6222
+ }
6223
+ await receiptClient.waitForTransactionReceipt({
6224
+ hash,
6225
+ confirmations: 1
6226
+ });
6227
+ }
6175
6228
  onStepComplete?.(hash, step.type, i3, totalSteps);
6176
6229
  }
6177
6230
  const hashForTracking = bridgeTxHash ?? lastTxHash;
@@ -6189,15 +6242,6 @@ class EvmChainStrategy {
6189
6242
  throw toChainStrategyError(error, "evm", "transaction");
6190
6243
  }
6191
6244
  }
6192
- async getNextNonce() {
6193
- if (!this.publicClient || !this.config.evmAddress) {
6194
- throw new WalletNotConnectedError("evm");
6195
- }
6196
- return await this.publicClient.getTransactionCount({
6197
- address: this.config.evmAddress,
6198
- blockTag: "pending"
6199
- });
6200
- }
6201
6245
  async executeTransaction(step) {
6202
6246
  const walletClient = this.walletClient;
6203
6247
  if (!walletClient) {
@@ -6210,14 +6254,12 @@ class EvmChainStrategy {
6210
6254
  );
6211
6255
  }
6212
6256
  const tx = step.transaction;
6213
- const nonce = await this.getNextNonce();
6214
- const hash = await walletClient.sendTransaction({
6257
+ const hash = await this.sendTransactionWithNonceRetry(walletClient, {
6215
6258
  to: tx.to,
6216
6259
  data: tx.data,
6217
6260
  account: tx.from || this.config.evmAddress,
6218
6261
  value: tx.value ? BigInt(tx.value) : void 0,
6219
- chain: walletClient.chain,
6220
- nonce
6262
+ chain: walletClient.chain
6221
6263
  });
6222
6264
  return hash;
6223
6265
  }
@@ -6259,16 +6301,17 @@ class EvmChainStrategy {
6259
6301
  });
6260
6302
  if (currentAllowance > 0n) {
6261
6303
  try {
6262
- const resetNonce = await this.getNextNonce();
6263
- const resetHash = await walletClient.writeContract({
6264
- address: tokenAddress,
6265
- abi: ERC20_ABI,
6266
- functionName: "approve",
6267
- args: [spenderAddress, 0n],
6268
- account: this.config.evmAddress,
6269
- chain: walletClient.chain,
6270
- nonce: resetNonce
6271
- });
6304
+ const resetHash = await this.writeContractWithNonceRetry(
6305
+ walletClient,
6306
+ {
6307
+ address: tokenAddress,
6308
+ abi: ERC20_ABI,
6309
+ functionName: "approve",
6310
+ args: [spenderAddress, 0n],
6311
+ account: this.config.evmAddress,
6312
+ chain: walletClient.chain
6313
+ }
6314
+ );
6272
6315
  await publicClient.waitForTransactionReceipt({
6273
6316
  hash: resetHash
6274
6317
  });
@@ -6284,16 +6327,17 @@ class EvmChainStrategy {
6284
6327
  console.log("USDT allowance is 0, no reset needed");
6285
6328
  }
6286
6329
  try {
6287
- const approveNonce = await this.getNextNonce();
6288
- const approveHash = await walletClient.writeContract({
6289
- address: tokenAddress,
6290
- abi: ERC20_ABI,
6291
- functionName: "approve",
6292
- args: [spenderAddress, amount],
6293
- account: this.config.evmAddress,
6294
- chain: walletClient.chain,
6295
- nonce: approveNonce
6296
- });
6330
+ const approveHash = await this.writeContractWithNonceRetry(
6331
+ walletClient,
6332
+ {
6333
+ address: tokenAddress,
6334
+ abi: ERC20_ABI,
6335
+ functionName: "approve",
6336
+ args: [spenderAddress, amount],
6337
+ account: this.config.evmAddress,
6338
+ chain: walletClient.chain
6339
+ }
6340
+ );
6297
6341
  return approveHash;
6298
6342
  } catch (approveError) {
6299
6343
  throw new TransactionFailedError(
@@ -26748,7 +26792,7 @@ class WalletConnectModal {
26748
26792
  }
26749
26793
  async initUi() {
26750
26794
  if (typeof window !== "undefined") {
26751
- await import("./index-Bl4_W_Mc.js");
26795
+ await import("./index-CPSV-tFm.js");
26752
26796
  const modal = document.createElement("wcm-modal");
26753
26797
  document.body.insertAdjacentElement("beforeend", modal);
26754
26798
  OptionsCtrl.setIsUiLoaded(true);
@@ -27672,4 +27716,4 @@ export {
27672
27716
  calculateMinReceived as y,
27673
27717
  getQuoteDetails as z
27674
27718
  };
27675
- //# sourceMappingURL=index-IZ7t2PGj.js.map
27719
+ //# sourceMappingURL=index-DLlaTmxx.js.map