@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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-CCiUu9QP.cjs");
3
+ const index = require("./index-CEYZ1mEJ.cjs");
4
4
  exports.DEFAULT_SLIPPAGE_BPS = index.DEFAULT_SLIPPAGE_BPS;
5
5
  exports.EvaaBridge = index.EvaaBridge;
6
6
  exports.RoutePriority = index.RoutePriority;
@@ -1,4 +1,4 @@
1
- import { P, d, f, e, D, U, H, y, B, W, w, s, v, r, p, q, G, $, a8, a1, a5, x, z, a2, A, a0, a6, a7, Z, _, V, a3, S, I, X, a4, Y, a9, aa, N, L, J, K, F, Q, t, o, i, u, l, m, j, n, h, k } from "./index-JmSrX7Hz.js";
1
+ import { P, d, f, e, D, U, H, y, B, W, w, s, v, r, p, q, G, $, a8, a1, a5, x, z, a2, A, a0, a6, a7, Z, _, V, a3, S, I, X, a4, Y, a9, aa, N, L, J, K, F, Q, t, o, i, u, l, m, j, n, h, k } from "./index-DLlaTmxx.js";
2
2
  export {
3
3
  P as DEFAULT_SLIPPAGE_BPS,
4
4
  d as EvaaBridge,
@@ -4643,7 +4643,7 @@ function useBridgeTransaction() {
4643
4643
  const txStore = useTransactionStore();
4644
4644
  const gas = useGasEstimate();
4645
4645
  const srcToken = React.useMemo(
4646
- () => resolveTokenOnChainFromMatrix$1(
4646
+ () => resolveBridgeSourceTokenOnChainFromMatrix(
4647
4647
  assetMatrix,
4648
4648
  selectedAssetSymbol,
4649
4649
  quote?.srcChainKey
@@ -4651,7 +4651,7 @@ function useBridgeTransaction() {
4651
4651
  [assetMatrix, selectedAssetSymbol, quote?.srcChainKey]
4652
4652
  );
4653
4653
  const dstToken = React.useMemo(
4654
- () => resolveTokenOnChainFromMatrix$1(
4654
+ () => resolveBridgeDestinationTokenOnChainFromMatrix(
4655
4655
  assetMatrix,
4656
4656
  selectedAssetSymbol,
4657
4657
  quote?.dstChainKey
@@ -5606,6 +5606,14 @@ const SuccessStep = ({
5606
5606
  const { t: t2 } = useBridgeTranslation();
5607
5607
  const metadata = current?.metadata;
5608
5608
  const srcTxHash = current?.tonTransactionHash || current?.srcTxHash;
5609
+ const srcAmount = metadata?.srcAmountHuman;
5610
+ const hasSrcAmount = Number.isFinite(srcAmount);
5611
+ const srcTokenSymbol = metadata?.srcTokenSymbol ?? "default";
5612
+ const formatSrcAmount = (value) => {
5613
+ if (value <= 0) return "0";
5614
+ if (value >= 1) return formatBalance(value, 2);
5615
+ return value.toFixed(6).replace(/\.?0+$/, "");
5616
+ };
5609
5617
  return /* @__PURE__ */ jsxRuntime.jsxs(
5610
5618
  dialog.DialogContent,
5611
5619
  {
@@ -5616,17 +5624,17 @@ const SuccessStep = ({
5616
5624
  icon,
5617
5625
  /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogHeader, { className: "z-10 relative p-0", children: /* @__PURE__ */ jsxRuntime.jsx(dialog.DialogTitle, { className: "text-[28px] text-center", children: t2("transaction.success") }) }),
5618
5626
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full space-y-2 mt-5 relative z-10 pb-14", children: [
5619
- metadata?.srcAmountHuman && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between items-center", children: [
5627
+ hasSrcAmount && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between items-center", children: [
5620
5628
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: t2("transaction.bridged") }),
5621
5629
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-1 font-medium", children: [
5622
- formatBalance(metadata.srcAmountHuman, 2),
5630
+ formatSrcAmount(srcAmount ?? 0),
5623
5631
  " ",
5624
- metadata?.srcTokenSymbol,
5632
+ srcTokenSymbol,
5625
5633
  /* @__PURE__ */ jsxRuntime.jsx(
5626
5634
  TokenSymbol,
5627
5635
  {
5628
5636
  className: "w-[18px] h-[18px]",
5629
- symbol: metadata?.srcTokenSymbol
5637
+ symbol: srcTokenSymbol
5630
5638
  }
5631
5639
  )
5632
5640
  ] })
@@ -5971,6 +5979,39 @@ class EvmChainStrategy {
5971
5979
  ...rpcError
5972
5980
  });
5973
5981
  }
5982
+ isNonceResubmissionError(error) {
5983
+ const rpcError = this.getRpcErrorDetails(error);
5984
+ const combined = [rpcError.message, rpcError.shortMessage, rpcError.details].filter(Boolean).join(" ").toLowerCase();
5985
+ return combined.includes("nonce too low") || combined.includes("replacement transaction underpriced");
5986
+ }
5987
+ async sendTransactionWithNonceRetry(walletClient, params) {
5988
+ try {
5989
+ return await walletClient.sendTransaction(params);
5990
+ } catch (error) {
5991
+ if (!this.isNonceResubmissionError(error)) {
5992
+ throw error;
5993
+ }
5994
+ this.logRpcWarning(
5995
+ "Retrying transaction after nonce-related error",
5996
+ error
5997
+ );
5998
+ return await walletClient.sendTransaction(params);
5999
+ }
6000
+ }
6001
+ async writeContractWithNonceRetry(walletClient, params) {
6002
+ try {
6003
+ return await walletClient.writeContract(params);
6004
+ } catch (error) {
6005
+ if (!this.isNonceResubmissionError(error)) {
6006
+ throw error;
6007
+ }
6008
+ this.logRpcWarning(
6009
+ "Retrying contract write after nonce-related error",
6010
+ error
6011
+ );
6012
+ return await walletClient.writeContract(params);
6013
+ }
6014
+ }
5974
6015
  async getBalances(address, tokens) {
5975
6016
  const chainKey = tokens[0]?.chainKey;
5976
6017
  const client = this.resolvePublicClientForChain(chainKey);
@@ -6035,12 +6076,16 @@ class EvmChainStrategy {
6035
6076
  if (!tx?.to) continue;
6036
6077
  const client = this.resolvePublicClientForChain(step.chainKey);
6037
6078
  if (!client) {
6038
- this.logRpcWarning("Skipped network fee estimation: no public client", "no-client", {
6039
- chainKey: step.chainKey,
6040
- stepType: step.type,
6041
- stepIndex: i3 + 1,
6042
- totalSteps: txSteps.length
6043
- });
6079
+ this.logRpcWarning(
6080
+ "Skipped network fee estimation: no public client",
6081
+ "no-client",
6082
+ {
6083
+ chainKey: step.chainKey,
6084
+ stepType: step.type,
6085
+ stepIndex: i3 + 1,
6086
+ totalSteps: txSteps.length
6087
+ }
6088
+ );
6044
6089
  continue;
6045
6090
  }
6046
6091
  try {
@@ -6068,12 +6113,16 @@ class EvmChainStrategy {
6068
6113
  try {
6069
6114
  feePerGas = await client.getGasPrice();
6070
6115
  } catch (gasPriceError) {
6071
- this.logRpcWarning("Failed to get gas price for network fee estimation", gasPriceError, {
6072
- chainKey: step.chainKey,
6073
- stepType: step.type,
6074
- stepIndex: i3 + 1,
6075
- totalSteps: txSteps.length
6076
- });
6116
+ this.logRpcWarning(
6117
+ "Failed to get gas price for network fee estimation",
6118
+ gasPriceError,
6119
+ {
6120
+ chainKey: step.chainKey,
6121
+ stepType: step.type,
6122
+ stepIndex: i3 + 1,
6123
+ totalSteps: txSteps.length
6124
+ }
6125
+ );
6077
6126
  }
6078
6127
  }
6079
6128
  if (gas && feePerGas) {
@@ -6152,7 +6201,9 @@ class EvmChainStrategy {
6152
6201
  const requiredChainId = this.config.chainKeyToId[firstChainKey.toLowerCase()];
6153
6202
  const currentChainId = this.walletClient.chain?.id;
6154
6203
  if (requiredChainId && currentChainId !== requiredChainId) {
6155
- console.log(`Switching from chain ${currentChainId} to ${requiredChainId}`);
6204
+ console.log(
6205
+ `Switching from chain ${currentChainId} to ${requiredChainId}`
6206
+ );
6156
6207
  await this.switchToChain(requiredChainId);
6157
6208
  } else {
6158
6209
  console.log(`Already on correct chain ${currentChainId}`);
@@ -6181,6 +6232,16 @@ class EvmChainStrategy {
6181
6232
  bridgeTxHash = hash;
6182
6233
  }
6183
6234
  lastTxHash = hash;
6235
+ if (step.type === "approve") {
6236
+ const receiptClient = this.resolvePublicClientForChain(step.chainKey);
6237
+ if (!receiptClient) {
6238
+ throw new WalletNotConnectedError("evm");
6239
+ }
6240
+ await receiptClient.waitForTransactionReceipt({
6241
+ hash,
6242
+ confirmations: 1
6243
+ });
6244
+ }
6184
6245
  onStepComplete?.(hash, step.type, i3, totalSteps);
6185
6246
  }
6186
6247
  const hashForTracking = bridgeTxHash ?? lastTxHash;
@@ -6198,15 +6259,6 @@ class EvmChainStrategy {
6198
6259
  throw toChainStrategyError(error, "evm", "transaction");
6199
6260
  }
6200
6261
  }
6201
- async getNextNonce() {
6202
- if (!this.publicClient || !this.config.evmAddress) {
6203
- throw new WalletNotConnectedError("evm");
6204
- }
6205
- return await this.publicClient.getTransactionCount({
6206
- address: this.config.evmAddress,
6207
- blockTag: "pending"
6208
- });
6209
- }
6210
6262
  async executeTransaction(step) {
6211
6263
  const walletClient = this.walletClient;
6212
6264
  if (!walletClient) {
@@ -6219,14 +6271,12 @@ class EvmChainStrategy {
6219
6271
  );
6220
6272
  }
6221
6273
  const tx = step.transaction;
6222
- const nonce = await this.getNextNonce();
6223
- const hash = await walletClient.sendTransaction({
6274
+ const hash = await this.sendTransactionWithNonceRetry(walletClient, {
6224
6275
  to: tx.to,
6225
6276
  data: tx.data,
6226
6277
  account: tx.from || this.config.evmAddress,
6227
6278
  value: tx.value ? BigInt(tx.value) : void 0,
6228
- chain: walletClient.chain,
6229
- nonce
6279
+ chain: walletClient.chain
6230
6280
  });
6231
6281
  return hash;
6232
6282
  }
@@ -6268,16 +6318,17 @@ class EvmChainStrategy {
6268
6318
  });
6269
6319
  if (currentAllowance > 0n) {
6270
6320
  try {
6271
- const resetNonce = await this.getNextNonce();
6272
- const resetHash = await walletClient.writeContract({
6273
- address: tokenAddress,
6274
- abi: ERC20_ABI,
6275
- functionName: "approve",
6276
- args: [spenderAddress, 0n],
6277
- account: this.config.evmAddress,
6278
- chain: walletClient.chain,
6279
- nonce: resetNonce
6280
- });
6321
+ const resetHash = await this.writeContractWithNonceRetry(
6322
+ walletClient,
6323
+ {
6324
+ address: tokenAddress,
6325
+ abi: ERC20_ABI,
6326
+ functionName: "approve",
6327
+ args: [spenderAddress, 0n],
6328
+ account: this.config.evmAddress,
6329
+ chain: walletClient.chain
6330
+ }
6331
+ );
6281
6332
  await publicClient.waitForTransactionReceipt({
6282
6333
  hash: resetHash
6283
6334
  });
@@ -6293,16 +6344,17 @@ class EvmChainStrategy {
6293
6344
  console.log("USDT allowance is 0, no reset needed");
6294
6345
  }
6295
6346
  try {
6296
- const approveNonce = await this.getNextNonce();
6297
- const approveHash = await walletClient.writeContract({
6298
- address: tokenAddress,
6299
- abi: ERC20_ABI,
6300
- functionName: "approve",
6301
- args: [spenderAddress, amount],
6302
- account: this.config.evmAddress,
6303
- chain: walletClient.chain,
6304
- nonce: approveNonce
6305
- });
6347
+ const approveHash = await this.writeContractWithNonceRetry(
6348
+ walletClient,
6349
+ {
6350
+ address: tokenAddress,
6351
+ abi: ERC20_ABI,
6352
+ functionName: "approve",
6353
+ args: [spenderAddress, amount],
6354
+ account: this.config.evmAddress,
6355
+ chain: walletClient.chain
6356
+ }
6357
+ );
6306
6358
  return approveHash;
6307
6359
  } catch (approveError) {
6308
6360
  throw new TransactionFailedError(
@@ -26757,7 +26809,7 @@ class WalletConnectModal {
26757
26809
  }
26758
26810
  async initUi() {
26759
26811
  if (typeof window !== "undefined") {
26760
- await Promise.resolve().then(() => require("./index-CrZzrVbc.cjs"));
26812
+ await Promise.resolve().then(() => require("./index-D4aCX9t_.cjs"));
26761
26813
  const modal = document.createElement("wcm-modal");
26762
26814
  document.body.insertAdjacentElement("beforeend", modal);
26763
26815
  OptionsCtrl.setIsUiLoaded(true);
@@ -27679,4 +27731,4 @@ exports.useSettingsStore = useSettingsStore;
27679
27731
  exports.useSwapModel = useSwapModel;
27680
27732
  exports.useTokensStore = useTokensStore;
27681
27733
  exports.useTransactionStore = useTransactionStore;
27682
- //# sourceMappingURL=index-CCiUu9QP.cjs.map
27734
+ //# sourceMappingURL=index-CEYZ1mEJ.cjs.map