@rash2x/bridge-widget 0.8.8 → 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.
@@ -4626,7 +4626,7 @@ function useBridgeTransaction() {
4626
4626
  const txStore = useTransactionStore();
4627
4627
  const gas = useGasEstimate();
4628
4628
  const srcToken = useMemo(
4629
- () => resolveTokenOnChainFromMatrix$1(
4629
+ () => resolveBridgeSourceTokenOnChainFromMatrix(
4630
4630
  assetMatrix,
4631
4631
  selectedAssetSymbol,
4632
4632
  quote?.srcChainKey
@@ -4634,7 +4634,7 @@ function useBridgeTransaction() {
4634
4634
  [assetMatrix, selectedAssetSymbol, quote?.srcChainKey]
4635
4635
  );
4636
4636
  const dstToken = useMemo(
4637
- () => resolveTokenOnChainFromMatrix$1(
4637
+ () => resolveBridgeDestinationTokenOnChainFromMatrix(
4638
4638
  assetMatrix,
4639
4639
  selectedAssetSymbol,
4640
4640
  quote?.dstChainKey
@@ -5589,6 +5589,14 @@ const SuccessStep = ({
5589
5589
  const { t: t2 } = useBridgeTranslation();
5590
5590
  const metadata = current?.metadata;
5591
5591
  const srcTxHash = current?.tonTransactionHash || current?.srcTxHash;
5592
+ const srcAmount = metadata?.srcAmountHuman;
5593
+ const hasSrcAmount = Number.isFinite(srcAmount);
5594
+ const srcTokenSymbol = metadata?.srcTokenSymbol ?? "default";
5595
+ const formatSrcAmount = (value) => {
5596
+ if (value <= 0) return "0";
5597
+ if (value >= 1) return formatBalance(value, 2);
5598
+ return value.toFixed(6).replace(/\.?0+$/, "");
5599
+ };
5592
5600
  return /* @__PURE__ */ jsxs(
5593
5601
  DialogContent,
5594
5602
  {
@@ -5599,17 +5607,17 @@ const SuccessStep = ({
5599
5607
  icon,
5600
5608
  /* @__PURE__ */ jsx(DialogHeader, { className: "z-10 relative p-0", children: /* @__PURE__ */ jsx(DialogTitle, { className: "text-[28px] text-center", children: t2("transaction.success") }) }),
5601
5609
  /* @__PURE__ */ jsxs("div", { className: "w-full space-y-2 mt-5 relative z-10 pb-14", children: [
5602
- metadata?.srcAmountHuman && /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center", children: [
5610
+ hasSrcAmount && /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center", children: [
5603
5611
  /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: t2("transaction.bridged") }),
5604
5612
  /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1 font-medium", children: [
5605
- formatBalance(metadata.srcAmountHuman, 2),
5613
+ formatSrcAmount(srcAmount ?? 0),
5606
5614
  " ",
5607
- metadata?.srcTokenSymbol,
5615
+ srcTokenSymbol,
5608
5616
  /* @__PURE__ */ jsx(
5609
5617
  TokenSymbol,
5610
5618
  {
5611
5619
  className: "w-[18px] h-[18px]",
5612
- symbol: metadata?.srcTokenSymbol
5620
+ symbol: srcTokenSymbol
5613
5621
  }
5614
5622
  )
5615
5623
  ] })
@@ -5954,6 +5962,39 @@ class EvmChainStrategy {
5954
5962
  ...rpcError
5955
5963
  });
5956
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
+ }
5957
5998
  async getBalances(address, tokens) {
5958
5999
  const chainKey = tokens[0]?.chainKey;
5959
6000
  const client = this.resolvePublicClientForChain(chainKey);
@@ -6018,12 +6059,16 @@ class EvmChainStrategy {
6018
6059
  if (!tx?.to) continue;
6019
6060
  const client = this.resolvePublicClientForChain(step.chainKey);
6020
6061
  if (!client) {
6021
- this.logRpcWarning("Skipped network fee estimation: no public client", "no-client", {
6022
- chainKey: step.chainKey,
6023
- stepType: step.type,
6024
- stepIndex: i3 + 1,
6025
- totalSteps: txSteps.length
6026
- });
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
+ );
6027
6072
  continue;
6028
6073
  }
6029
6074
  try {
@@ -6051,12 +6096,16 @@ class EvmChainStrategy {
6051
6096
  try {
6052
6097
  feePerGas = await client.getGasPrice();
6053
6098
  } catch (gasPriceError) {
6054
- this.logRpcWarning("Failed to get gas price for network fee estimation", gasPriceError, {
6055
- chainKey: step.chainKey,
6056
- stepType: step.type,
6057
- stepIndex: i3 + 1,
6058
- totalSteps: txSteps.length
6059
- });
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
+ );
6060
6109
  }
6061
6110
  }
6062
6111
  if (gas && feePerGas) {
@@ -6135,7 +6184,9 @@ class EvmChainStrategy {
6135
6184
  const requiredChainId = this.config.chainKeyToId[firstChainKey.toLowerCase()];
6136
6185
  const currentChainId = this.walletClient.chain?.id;
6137
6186
  if (requiredChainId && currentChainId !== requiredChainId) {
6138
- console.log(`Switching from chain ${currentChainId} to ${requiredChainId}`);
6187
+ console.log(
6188
+ `Switching from chain ${currentChainId} to ${requiredChainId}`
6189
+ );
6139
6190
  await this.switchToChain(requiredChainId);
6140
6191
  } else {
6141
6192
  console.log(`Already on correct chain ${currentChainId}`);
@@ -6164,6 +6215,16 @@ class EvmChainStrategy {
6164
6215
  bridgeTxHash = hash;
6165
6216
  }
6166
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
+ }
6167
6228
  onStepComplete?.(hash, step.type, i3, totalSteps);
6168
6229
  }
6169
6230
  const hashForTracking = bridgeTxHash ?? lastTxHash;
@@ -6181,15 +6242,6 @@ class EvmChainStrategy {
6181
6242
  throw toChainStrategyError(error, "evm", "transaction");
6182
6243
  }
6183
6244
  }
6184
- async getNextNonce() {
6185
- if (!this.publicClient || !this.config.evmAddress) {
6186
- throw new WalletNotConnectedError("evm");
6187
- }
6188
- return await this.publicClient.getTransactionCount({
6189
- address: this.config.evmAddress,
6190
- blockTag: "pending"
6191
- });
6192
- }
6193
6245
  async executeTransaction(step) {
6194
6246
  const walletClient = this.walletClient;
6195
6247
  if (!walletClient) {
@@ -6202,14 +6254,12 @@ class EvmChainStrategy {
6202
6254
  );
6203
6255
  }
6204
6256
  const tx = step.transaction;
6205
- const nonce = await this.getNextNonce();
6206
- const hash = await walletClient.sendTransaction({
6257
+ const hash = await this.sendTransactionWithNonceRetry(walletClient, {
6207
6258
  to: tx.to,
6208
6259
  data: tx.data,
6209
6260
  account: tx.from || this.config.evmAddress,
6210
6261
  value: tx.value ? BigInt(tx.value) : void 0,
6211
- chain: walletClient.chain,
6212
- nonce
6262
+ chain: walletClient.chain
6213
6263
  });
6214
6264
  return hash;
6215
6265
  }
@@ -6251,16 +6301,17 @@ class EvmChainStrategy {
6251
6301
  });
6252
6302
  if (currentAllowance > 0n) {
6253
6303
  try {
6254
- const resetNonce = await this.getNextNonce();
6255
- const resetHash = await walletClient.writeContract({
6256
- address: tokenAddress,
6257
- abi: ERC20_ABI,
6258
- functionName: "approve",
6259
- args: [spenderAddress, 0n],
6260
- account: this.config.evmAddress,
6261
- chain: walletClient.chain,
6262
- nonce: resetNonce
6263
- });
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
+ );
6264
6315
  await publicClient.waitForTransactionReceipt({
6265
6316
  hash: resetHash
6266
6317
  });
@@ -6276,16 +6327,17 @@ class EvmChainStrategy {
6276
6327
  console.log("USDT allowance is 0, no reset needed");
6277
6328
  }
6278
6329
  try {
6279
- const approveNonce = await this.getNextNonce();
6280
- const approveHash = await walletClient.writeContract({
6281
- address: tokenAddress,
6282
- abi: ERC20_ABI,
6283
- functionName: "approve",
6284
- args: [spenderAddress, amount],
6285
- account: this.config.evmAddress,
6286
- chain: walletClient.chain,
6287
- nonce: approveNonce
6288
- });
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
+ );
6289
6341
  return approveHash;
6290
6342
  } catch (approveError) {
6291
6343
  throw new TransactionFailedError(
@@ -26740,7 +26792,7 @@ class WalletConnectModal {
26740
26792
  }
26741
26793
  async initUi() {
26742
26794
  if (typeof window !== "undefined") {
26743
- await import("./index-CZGfdIKB.js");
26795
+ await import("./index-CPSV-tFm.js");
26744
26796
  const modal = document.createElement("wcm-modal");
26745
26797
  document.body.insertAdjacentElement("beforeend", modal);
26746
26798
  OptionsCtrl.setIsUiLoaded(true);
@@ -27664,4 +27716,4 @@ export {
27664
27716
  calculateMinReceived as y,
27665
27717
  getQuoteDetails as z
27666
27718
  };
27667
- //# sourceMappingURL=index-JmSrX7Hz.js.map
27719
+ //# sourceMappingURL=index-DLlaTmxx.js.map