@rash2x/bridge-widget 0.6.92 → 0.6.93

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.
@@ -5305,6 +5305,15 @@ class EvmChainStrategy {
5305
5305
  throw toChainStrategyError(error, "evm", "transaction");
5306
5306
  }
5307
5307
  }
5308
+ async getNextNonce() {
5309
+ if (!this.publicClient || !this.config.evmAddress) {
5310
+ throw new WalletNotConnectedError("evm");
5311
+ }
5312
+ return await this.publicClient.getTransactionCount({
5313
+ address: this.config.evmAddress,
5314
+ blockTag: "pending"
5315
+ });
5316
+ }
5308
5317
  async executeTransaction(step) {
5309
5318
  const walletClient = this.walletClient;
5310
5319
  if (!walletClient) {
@@ -5317,12 +5326,14 @@ class EvmChainStrategy {
5317
5326
  );
5318
5327
  }
5319
5328
  const tx = step.transaction;
5329
+ const nonce = await this.getNextNonce();
5320
5330
  const hash = await walletClient.sendTransaction({
5321
5331
  to: tx.to,
5322
5332
  data: tx.data,
5323
5333
  account: tx.from || this.config.evmAddress,
5324
5334
  value: tx.value ? BigInt(tx.value) : void 0,
5325
- chain: walletClient.chain
5335
+ chain: walletClient.chain,
5336
+ nonce
5326
5337
  });
5327
5338
  return hash;
5328
5339
  }
@@ -5364,13 +5375,15 @@ class EvmChainStrategy {
5364
5375
  });
5365
5376
  if (currentAllowance > 0n) {
5366
5377
  try {
5378
+ const resetNonce = await this.getNextNonce();
5367
5379
  const resetHash = await walletClient.writeContract({
5368
5380
  address: tokenAddress,
5369
5381
  abi: ERC20_ABI,
5370
5382
  functionName: "approve",
5371
5383
  args: [spenderAddress, 0n],
5372
5384
  account: this.config.evmAddress,
5373
- chain: walletClient.chain
5385
+ chain: walletClient.chain,
5386
+ nonce: resetNonce
5374
5387
  });
5375
5388
  await publicClient.waitForTransactionReceipt({
5376
5389
  hash: resetHash
@@ -5387,13 +5400,15 @@ class EvmChainStrategy {
5387
5400
  console.log("USDT allowance is 0, no reset needed");
5388
5401
  }
5389
5402
  try {
5403
+ const approveNonce = await this.getNextNonce();
5390
5404
  const approveHash = await walletClient.writeContract({
5391
5405
  address: tokenAddress,
5392
5406
  abi: ERC20_ABI,
5393
5407
  functionName: "approve",
5394
5408
  args: [spenderAddress, amount],
5395
5409
  account: this.config.evmAddress,
5396
- chain: walletClient.chain
5410
+ chain: walletClient.chain,
5411
+ nonce: approveNonce
5397
5412
  });
5398
5413
  return approveHash;
5399
5414
  } catch (approveError) {
@@ -6258,6 +6273,13 @@ class TronChainStrategy {
6258
6273
  } else {
6259
6274
  signedTx = await tronWeb.trx.sign(unsignedTx);
6260
6275
  }
6276
+ const signatures = signedTx.signature;
6277
+ if (!Array.isArray(signatures) || signatures.length === 0) {
6278
+ throw new TransactionFailedError(
6279
+ "tron",
6280
+ "Wallet returned unsigned transaction"
6281
+ );
6282
+ }
6261
6283
  const sent = await tronWeb.trx.sendRawTransaction(signedTx);
6262
6284
  if (!sent?.result || !sent?.txid) {
6263
6285
  throw new TransactionFailedError(
@@ -25760,7 +25782,7 @@ class WalletConnectModal {
25760
25782
  }
25761
25783
  async initUi() {
25762
25784
  if (typeof window !== "undefined") {
25763
- await import("./index--FWEmzfG.js");
25785
+ await import("./index-Ba3TMYQR.js");
25764
25786
  const modal = document.createElement("wcm-modal");
25765
25787
  document.body.insertAdjacentElement("beforeend", modal);
25766
25788
  OptionsCtrl.setIsUiLoaded(true);
@@ -25806,6 +25828,59 @@ const useThemeStore = create((set2) => ({
25806
25828
  }));
25807
25829
  const TRON_MAINNET_CHAIN_ID = "tron:0x2b6653dc";
25808
25830
  const CONNECTION_TIMEOUT = 6e4;
25831
+ function isRecord(value) {
25832
+ return typeof value === "object" && value !== null;
25833
+ }
25834
+ function hasValidSignature(transaction2) {
25835
+ if (!isRecord(transaction2)) return false;
25836
+ const signature = transaction2.signature;
25837
+ return Array.isArray(signature) && signature.length > 0 && signature.every((item) => typeof item === "string" && item.length > 0);
25838
+ }
25839
+ function normalizeSignature(signature) {
25840
+ return signature.replace(/^0x/i, "");
25841
+ }
25842
+ function toSignedTransaction(result, unsignedTx) {
25843
+ if (hasValidSignature(result)) {
25844
+ return result;
25845
+ }
25846
+ if (isRecord(result)) {
25847
+ const nestedTx = result.transaction;
25848
+ if (hasValidSignature(nestedTx)) {
25849
+ return nestedTx;
25850
+ }
25851
+ const nestedSignedTx = result.signedTransaction;
25852
+ if (hasValidSignature(nestedSignedTx)) {
25853
+ return nestedSignedTx;
25854
+ }
25855
+ const signature = result.signature;
25856
+ if (typeof signature === "string" && signature.length > 0) {
25857
+ return {
25858
+ ...unsignedTx,
25859
+ signature: [normalizeSignature(signature)]
25860
+ };
25861
+ }
25862
+ if (Array.isArray(signature) && signature.length > 0 && signature.every((item) => typeof item === "string" && item.length > 0)) {
25863
+ return {
25864
+ ...unsignedTx,
25865
+ signature: signature.map((item) => normalizeSignature(item))
25866
+ };
25867
+ }
25868
+ }
25869
+ if (typeof result === "string" && result.length > 0) {
25870
+ return {
25871
+ ...unsignedTx,
25872
+ signature: [normalizeSignature(result)]
25873
+ };
25874
+ }
25875
+ return null;
25876
+ }
25877
+ function isUserRejectedError(error) {
25878
+ if (isRecord(error) && typeof error.code === "number" && error.code === 4001) {
25879
+ return true;
25880
+ }
25881
+ const msg = error instanceof Error ? error.message.toLowerCase() : "";
25882
+ return msg.includes("user rejected") || msg.includes("rejected by user");
25883
+ }
25809
25884
  function useTronWalletConnect(projectId) {
25810
25885
  const { address, isConnected, isConnecting } = useTronWalletConnectStore();
25811
25886
  const { setAddress, setActions, reset } = useTronWalletConnectStore();
@@ -25986,11 +26061,41 @@ function useTronWalletConnect(projectId) {
25986
26061
  throw new Error("WalletConnect not connected");
25987
26062
  }
25988
26063
  try {
25989
- const result = await providerRef.current.request({
25990
- method: "tron_signTransaction",
25991
- params: [transaction2]
25992
- });
25993
- return result;
26064
+ const requestVariants = [
26065
+ [transaction2],
26066
+ [transaction2, address],
26067
+ [{ transaction: transaction2, address }],
26068
+ { transaction: transaction2, address }
26069
+ ];
26070
+ let lastResponse;
26071
+ let lastError;
26072
+ for (const params of requestVariants) {
26073
+ try {
26074
+ const result = await providerRef.current.request(
26075
+ {
26076
+ method: "tron_signTransaction",
26077
+ params
26078
+ },
26079
+ TRON_MAINNET_CHAIN_ID
26080
+ );
26081
+ lastResponse = result;
26082
+ const signedTx = toSignedTransaction(result, transaction2);
26083
+ if (signedTx) {
26084
+ return signedTx;
26085
+ }
26086
+ } catch (error) {
26087
+ if (isUserRejectedError(error)) {
26088
+ throw error;
26089
+ }
26090
+ lastError = error;
26091
+ }
26092
+ }
26093
+ if (lastError) {
26094
+ throw lastError;
26095
+ }
26096
+ throw new Error(
26097
+ `WalletConnect returned unsigned transaction: ${JSON.stringify(lastResponse)}`
26098
+ );
25994
26099
  } catch (error) {
25995
26100
  console.error("TRON WalletConnect transaction signing failed:", error);
25996
26101
  throw error;
@@ -26516,4 +26621,4 @@ export {
26516
26621
  getQuoteFees as y,
26517
26622
  calculateMinReceived as z
26518
26623
  };
26519
- //# sourceMappingURL=index-j6yDeMSt.js.map
26624
+ //# sourceMappingURL=index-BDIi-D7p.js.map