@rash2x/bridge-widget 0.1.18 → 0.1.20

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.
@@ -170,7 +170,7 @@ const initialState = {
170
170
  };
171
171
  const useTokensStore = create$1((set) => ({
172
172
  ...initialState,
173
- setTokens: async (data) => {
173
+ setTokens: (data) => {
174
174
  set({ tokens: data, assetMatrix: buildAssetMatrix(data) });
175
175
  },
176
176
  setSelectedToken: (data) => {
@@ -1086,7 +1086,9 @@ function useBalances(chainKey, address, priorityTokenSymbol) {
1086
1086
  const tokensList = [];
1087
1087
  for (const [, byChain] of Object.entries(assetMatrix)) {
1088
1088
  const token = byChain[chainKey];
1089
- if (token) tokensList.push(token);
1089
+ if (token && token.address && token.address.length > 2) {
1090
+ tokensList.push(token);
1091
+ }
1090
1092
  }
1091
1093
  return tokensList;
1092
1094
  }, [assetMatrix, chainKey]);
@@ -1094,7 +1096,10 @@ function useBalances(chainKey, address, priorityTokenSymbol) {
1094
1096
  if (!priorityTokenSymbol || !chainKey || !assetMatrix) return void 0;
1095
1097
  const normalizedSymbol = normalizeTickerSymbol$1(priorityTokenSymbol);
1096
1098
  const token = assetMatrix[normalizedSymbol]?.[chainKey];
1097
- return token;
1099
+ if (token && token.address && token.address.length > 2) {
1100
+ return token;
1101
+ }
1102
+ return void 0;
1098
1103
  }, [priorityTokenSymbol, chainKey, assetMatrix]);
1099
1104
  const query = useQuery({
1100
1105
  queryKey: ["balances", chainKey, address, priorityTokenSymbol],
@@ -1109,7 +1114,7 @@ function useBalances(chainKey, address, priorityTokenSymbol) {
1109
1114
  priorityToken
1110
1115
  );
1111
1116
  },
1112
- enabled: !!address && !!chainKey && tokensOnChain.length > 0 && isAddressValidForChain(chainKey, address),
1117
+ enabled: !!address && !!chainKey && !!assetMatrix && tokensOnChain.length > 0 && isAddressValidForChain(chainKey, address),
1113
1118
  staleTime: 6e4,
1114
1119
  gcTime: 5 * 6e4,
1115
1120
  refetchOnWindowFocus: false,
@@ -2854,7 +2859,7 @@ const Details = () => {
2854
2859
  })();
2855
2860
  const currentSlippageText = formatPercentage(slippageBps);
2856
2861
  const routeText = quote?.route ? getRouteDisplayName(quote.route) : t2(`settings.routePresets.${routePriority}`);
2857
- return /* @__PURE__ */ jsx(Accordion, { type: "single", collapsible: true, className: "w-full", children: /* @__PURE__ */ jsxs(AccordionItem, { value: "item-1", className: "bg-muted rounded-lg", children: [
2862
+ return /* @__PURE__ */ jsx(Accordion, { type: "single", collapsible: true, className: "w-full", children: /* @__PURE__ */ jsxs(AccordionItem, { value: "item-1", className: "bg-muted rounded", children: [
2858
2863
  /* @__PURE__ */ jsx(AccordionTrigger, { className: "w-full gap-1 items-center py-6 px-5 rounded-b-lg data-[state=open]:pb-3", children: /* @__PURE__ */ jsxs("div", { className: "w-full flex items-center justify-between", children: [
2859
2864
  /* @__PURE__ */ jsx("p", { className: "text-sm font-normal text-priority leading-4", children: t2("bridge.youWillReceive", { defaultValue: "You will receive" }) }),
2860
2865
  /* @__PURE__ */ jsxs("div", { className: "bg-transparent hover:bg-transparent shadow-none h-4 p-0 px-0 py-0 flex items-center gap-2", children: [
@@ -3206,10 +3211,11 @@ function useBridgeTransaction() {
3206
3211
  dstChainKey: quote.dstChainKey
3207
3212
  };
3208
3213
  console.log(steps);
3209
- const txResult = await strategy.executeSteps(steps, context);
3210
- if (txResult?.hash) {
3211
- txStore.setSrcHash(txResult.hash);
3214
+ const txResult = await strategy.executeSteps(steps, context, (hash) => {
3215
+ txStore.setSrcHash(hash);
3212
3216
  txStore.updateStatus("processing");
3217
+ });
3218
+ if (txResult?.hash) {
3213
3219
  strategy.waitForCompletion(txResult.hash, context).then((result) => {
3214
3220
  if (result.completed) {
3215
3221
  if (result.dstTxHash) {
@@ -5675,7 +5681,7 @@ const TransactionManager = () => {
5675
5681
  return /* @__PURE__ */ jsx(Dialog, { open: true, onOpenChange: () => {
5676
5682
  }, children: /* @__PURE__ */ jsx(DialogContent, { showCloseButton: false, className: "p-0 gap-0 border-none max-w-[calc(100%-2rem)] sm:max-w-md", children: step }) });
5677
5683
  };
5678
- const useTokensRequest = () => {
5684
+ const useTokens = () => {
5679
5685
  const { setTokens, setSelectedToken, setSelectedAssetSymbol } = useTokensStore();
5680
5686
  const query = useQuery({
5681
5687
  queryKey: ["tokens"],
@@ -5710,7 +5716,7 @@ const useTokensRequest = () => {
5710
5716
  }, [query.isError, query.error]);
5711
5717
  return { ...query };
5712
5718
  };
5713
- const useChainsRequest = () => {
5719
+ const useChains = () => {
5714
5720
  const { setChains, setFromChain } = useChainsStore();
5715
5721
  const query = useQuery({
5716
5722
  queryKey: ["chains"],
@@ -5767,7 +5773,7 @@ class ChainStrategyRegistry {
5767
5773
  async getBalances(chainKey, address, tokens, priorityToken) {
5768
5774
  const strategy = this.getStrategy(chainKey);
5769
5775
  if (!strategy) return {};
5770
- return await strategy.getBalances(address, tokens, chainKey, priorityToken);
5776
+ return await strategy.getBalances(address, tokens, priorityToken);
5771
5777
  }
5772
5778
  isAddressValid(chainKey, address) {
5773
5779
  const strategy = this.getStrategy(chainKey);
@@ -5878,7 +5884,7 @@ function parseTonAddress(address) {
5878
5884
  }
5879
5885
  return Address$1.parse(address);
5880
5886
  }
5881
- async function getEvmBalances(publicClient, address, tokens, chainKey, priorityToken) {
5887
+ async function getEvmBalances(publicClient, address, tokens, priorityToken) {
5882
5888
  const balances = {};
5883
5889
  try {
5884
5890
  if (!address || !isAddress(address)) {
@@ -5893,51 +5899,49 @@ async function getEvmBalances(publicClient, address, tokens, chainKey, priorityT
5893
5899
  (t2) => !isNativeAddress(t2.address) && isAddress(t2.address)
5894
5900
  );
5895
5901
  if (priorityToken) {
5896
- if (priorityToken.chainKey !== chainKey) {
5897
- console.debug(
5898
- `Skipping priority token ${priorityToken.symbol}: chain mismatch (expected ${chainKey}, got ${priorityToken.chainKey})`
5899
- );
5900
- } else {
5901
- try {
5902
- const isPriorityNative = isNativeAddress(priorityToken.address);
5903
- if (isPriorityNative) {
5904
- const ethBalance = await publicClient.getBalance({
5905
- address
5906
- });
5907
- const balance = parseFloat(
5908
- formatUnits(ethBalance, priorityToken.decimals)
5909
- );
5910
- if (balance > 0) {
5911
- balances[priorityToken.symbol] = { balance, address };
5912
- }
5913
- } else if (isAddress(priorityToken.address)) {
5914
- const tokenBalance = await publicClient.readContract({
5915
- address: priorityToken.address,
5916
- abi: [
5917
- {
5918
- name: "balanceOf",
5919
- type: "function",
5920
- stateMutability: "view",
5921
- inputs: [{ name: "owner", type: "address" }],
5922
- outputs: [{ name: "balance", type: "uint256" }]
5923
- }
5924
- ],
5925
- functionName: "balanceOf",
5926
- args: [address]
5927
- });
5928
- const balance = parseFloat(
5929
- formatUnits(tokenBalance, priorityToken.decimals)
5930
- );
5931
- if (balance > 0) {
5932
- balances[priorityToken.symbol] = { balance, address };
5933
- }
5902
+ try {
5903
+ const isPriorityNative = isNativeAddress(priorityToken.address);
5904
+ console.log(priorityToken);
5905
+ console.log(isPriorityNative);
5906
+ if (isPriorityNative) {
5907
+ const ethBalance = await publicClient.getBalance({
5908
+ address
5909
+ });
5910
+ const balance = parseFloat(
5911
+ formatUnits(ethBalance, priorityToken.decimals)
5912
+ );
5913
+ if (balance > 0) {
5914
+ balances[priorityToken.symbol] = { balance, address };
5934
5915
  }
5935
- } catch (error) {
5936
- console.debug(
5937
- `Failed to get priority token balance for ${priorityToken.symbol}:`,
5938
- error
5916
+ } else if (isAddress(priorityToken.address)) {
5917
+ const tokenBalance = await publicClient.readContract({
5918
+ address: priorityToken.address,
5919
+ abi: [
5920
+ {
5921
+ name: "balanceOf",
5922
+ type: "function",
5923
+ stateMutability: "view",
5924
+ inputs: [{ name: "owner", type: "address" }],
5925
+ outputs: [{ name: "balance", type: "uint256" }]
5926
+ }
5927
+ ],
5928
+ functionName: "balanceOf",
5929
+ args: [address]
5930
+ });
5931
+ console.log(tokenBalance);
5932
+ const balance = parseFloat(
5933
+ formatUnits(tokenBalance, priorityToken.decimals)
5939
5934
  );
5935
+ console.log(balance);
5936
+ if (balance > 0) {
5937
+ balances[priorityToken.symbol] = { balance, address };
5938
+ }
5940
5939
  }
5940
+ } catch (error) {
5941
+ console.debug(
5942
+ `Failed to get priority token balance for ${priorityToken.symbol}:`,
5943
+ error
5944
+ );
5941
5945
  }
5942
5946
  }
5943
5947
  for (const token of nativeTokens) {
@@ -6033,7 +6037,7 @@ async function getEvmBalances(publicClient, address, tokens, chainKey, priorityT
6033
6037
  }
6034
6038
  return balances;
6035
6039
  }
6036
- async function getTonBalances(address, tokens, chainKey, customTonClient, tonApiKey) {
6040
+ async function getTonBalances(address, tokens, customTonClient, tonApiKey) {
6037
6041
  const balances = {};
6038
6042
  try {
6039
6043
  if (!isTonFriendlyAddress(address)) {
@@ -6192,7 +6196,7 @@ class EvmChainStrategy {
6192
6196
  getConnectLabel(t2) {
6193
6197
  return t2("wallets.connectEvmWallet");
6194
6198
  }
6195
- async getBalances(address, tokens, chainKey, priorityToken) {
6199
+ async getBalances(address, tokens, priorityToken) {
6196
6200
  if (!this.publicClient) {
6197
6201
  console.warn("No publicClient available for balance query");
6198
6202
  return {};
@@ -6201,7 +6205,6 @@ class EvmChainStrategy {
6201
6205
  this.publicClient,
6202
6206
  address,
6203
6207
  tokens,
6204
- chainKey,
6205
6208
  priorityToken
6206
6209
  );
6207
6210
  }
@@ -6273,7 +6276,7 @@ class EvmChainStrategy {
6273
6276
  throw new InvalidStepsError("evm", "Missing transaction data in steps");
6274
6277
  }
6275
6278
  }
6276
- async executeSteps(steps) {
6279
+ async executeSteps(steps, _context, onFirstHash) {
6277
6280
  if (!this.isConnected() || !this.provider) {
6278
6281
  throw new WalletNotConnectedError("evm");
6279
6282
  }
@@ -6287,11 +6290,17 @@ class EvmChainStrategy {
6287
6290
  if (step.type === "approve") {
6288
6291
  const hash = await this.approveTransaction(step);
6289
6292
  console.log(`Approval transaction hash: ${hash}`);
6290
- if (!firstTxHash) firstTxHash = hash;
6293
+ if (!firstTxHash) {
6294
+ firstTxHash = hash;
6295
+ onFirstHash?.(hash);
6296
+ }
6291
6297
  } else if (step.type === "bridge") {
6292
6298
  const hash = await this.executeTransaction(step);
6293
6299
  console.log(`Bridge transaction hash: ${hash}`);
6294
- if (!firstTxHash) firstTxHash = hash;
6300
+ if (!firstTxHash) {
6301
+ firstTxHash = hash;
6302
+ onFirstHash?.(hash);
6303
+ }
6295
6304
  } else {
6296
6305
  throw new InvalidStepsError(
6297
6306
  "evm",
@@ -6559,11 +6568,10 @@ class TonChainStrategy {
6559
6568
  getConnectLabel(t2) {
6560
6569
  return t2("wallets.connectTonWallet");
6561
6570
  }
6562
- async getBalances(address, tokens, chainKey) {
6571
+ async getBalances(address, tokens) {
6563
6572
  return await getTonBalances(
6564
6573
  address,
6565
6574
  tokens,
6566
- chainKey,
6567
6575
  this.config.tonClient,
6568
6576
  this.config.tonApiKey
6569
6577
  );
@@ -6627,7 +6635,7 @@ class TonChainStrategy {
6627
6635
  }
6628
6636
  }
6629
6637
  }
6630
- async executeSteps(steps) {
6638
+ async executeSteps(steps, _context, onFirstHash) {
6631
6639
  if (!this.isConnected() || !this.config.tonConnectUI) {
6632
6640
  throw new WalletNotConnectedError("ton");
6633
6641
  }
@@ -6653,9 +6661,11 @@ class TonChainStrategy {
6653
6661
  const result = await this.config.tonConnectUI.sendTransaction(
6654
6662
  transaction2
6655
6663
  );
6664
+ const hash = result.boc;
6665
+ onFirstHash?.(hash);
6656
6666
  return {
6657
6667
  chainKey: "ton",
6658
- hash: result.boc
6668
+ hash
6659
6669
  };
6660
6670
  } catch (error) {
6661
6671
  throw toChainStrategyError(error, "ton", "transaction");
@@ -6864,7 +6874,7 @@ class TronChainStrategy {
6864
6874
  throw new InvalidTransactionDataError("tron", "Missing transaction data");
6865
6875
  }
6866
6876
  }
6867
- async executeSteps(steps) {
6877
+ async executeSteps(steps, _context, onFirstHash) {
6868
6878
  console.log("executeSteps");
6869
6879
  const tronWeb = this.getTronWeb();
6870
6880
  if (!tronWeb) {
@@ -6879,6 +6889,7 @@ class TronChainStrategy {
6879
6889
  throw new WalletNotConnectedError("tron");
6880
6890
  }
6881
6891
  let lastTxId;
6892
+ let isFirstHash = true;
6882
6893
  for (const step of steps) {
6883
6894
  if (String(step.chainKey).toLowerCase() !== "tron") continue;
6884
6895
  const tx = step.transaction;
@@ -6944,6 +6955,10 @@ class TronChainStrategy {
6944
6955
  }
6945
6956
  const { txid } = await this.signAndBroadcast(tronWeb, unsigned);
6946
6957
  lastTxId = txid;
6958
+ if (isFirstHash) {
6959
+ onFirstHash?.(txid);
6960
+ isFirstHash = false;
6961
+ }
6947
6962
  }
6948
6963
  if (!lastTxId) {
6949
6964
  throw new TransactionFailedError(
@@ -7500,8 +7515,8 @@ const EvaaBridgeContent = ({
7500
7515
  onChainChange
7501
7516
  } = {}) => {
7502
7517
  const { t: t2 } = useBridgeTranslation();
7503
- useTokensRequest();
7504
- useChainsRequest();
7518
+ useTokens();
7519
+ useChains();
7505
7520
  const swap = useSwapModel();
7506
7521
  const { fromChain, toChain } = swap;
7507
7522
  const { selectedAssetSymbol, assetMatrix } = useTokensStore();