@rash2x/bridge-widget 0.1.19 → 0.1.21

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,
@@ -2171,7 +2176,9 @@ const SwapButton = () => {
2171
2176
  };
2172
2177
  const WalletBalance = (props) => {
2173
2178
  const { value, isLoading = false } = props;
2174
- if (isLoading) {
2179
+ const hasNoData = !value || value === "0" || value === "0.00" || value === "0.0";
2180
+ const shouldShowSkeleton = isLoading && hasNoData;
2181
+ if (shouldShowSkeleton) {
2175
2182
  return /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-center", children: [
2176
2183
  /* @__PURE__ */ jsx(WalletIcon, { className: "text-muted-foreground" }),
2177
2184
  /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-16 rounded-md" })
@@ -2854,7 +2861,7 @@ const Details = () => {
2854
2861
  })();
2855
2862
  const currentSlippageText = formatPercentage(slippageBps);
2856
2863
  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: [
2864
+ return /* @__PURE__ */ jsx(Accordion, { type: "single", collapsible: true, className: "w-full", children: /* @__PURE__ */ jsxs(AccordionItem, { value: "item-1", className: "bg-muted rounded", children: [
2858
2865
  /* @__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
2866
  /* @__PURE__ */ jsx("p", { className: "text-sm font-normal text-priority leading-4", children: t2("bridge.youWillReceive", { defaultValue: "You will receive" }) }),
2860
2867
  /* @__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 +3213,11 @@ function useBridgeTransaction() {
3206
3213
  dstChainKey: quote.dstChainKey
3207
3214
  };
3208
3215
  console.log(steps);
3209
- const txResult = await strategy.executeSteps(steps, context);
3210
- if (txResult?.hash) {
3211
- txStore.setSrcHash(txResult.hash);
3216
+ const txResult = await strategy.executeSteps(steps, context, (hash) => {
3217
+ txStore.setSrcHash(hash);
3212
3218
  txStore.updateStatus("processing");
3219
+ });
3220
+ if (txResult?.hash) {
3213
3221
  strategy.waitForCompletion(txResult.hash, context).then((result) => {
3214
3222
  if (result.completed) {
3215
3223
  if (result.dstTxHash) {
@@ -5675,7 +5683,7 @@ const TransactionManager = () => {
5675
5683
  return /* @__PURE__ */ jsx(Dialog, { open: true, onOpenChange: () => {
5676
5684
  }, 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
5685
  };
5678
- const useTokensRequest = () => {
5686
+ const useTokens = () => {
5679
5687
  const { setTokens, setSelectedToken, setSelectedAssetSymbol } = useTokensStore();
5680
5688
  const query = useQuery({
5681
5689
  queryKey: ["tokens"],
@@ -5710,7 +5718,7 @@ const useTokensRequest = () => {
5710
5718
  }, [query.isError, query.error]);
5711
5719
  return { ...query };
5712
5720
  };
5713
- const useChainsRequest = () => {
5721
+ const useChains = () => {
5714
5722
  const { setChains, setFromChain } = useChainsStore();
5715
5723
  const query = useQuery({
5716
5724
  queryKey: ["chains"],
@@ -5767,7 +5775,7 @@ class ChainStrategyRegistry {
5767
5775
  async getBalances(chainKey, address, tokens, priorityToken) {
5768
5776
  const strategy = this.getStrategy(chainKey);
5769
5777
  if (!strategy) return {};
5770
- return await strategy.getBalances(address, tokens, chainKey, priorityToken);
5778
+ return await strategy.getBalances(address, tokens, priorityToken);
5771
5779
  }
5772
5780
  isAddressValid(chainKey, address) {
5773
5781
  const strategy = this.getStrategy(chainKey);
@@ -5878,7 +5886,7 @@ function parseTonAddress(address) {
5878
5886
  }
5879
5887
  return Address$1.parse(address);
5880
5888
  }
5881
- async function getEvmBalances(publicClient, address, tokens, chainKey, priorityToken) {
5889
+ async function getEvmBalances(publicClient, address, tokens, priorityToken) {
5882
5890
  const balances = {};
5883
5891
  try {
5884
5892
  if (!address || !isAddress(address)) {
@@ -5890,49 +5898,47 @@ async function getEvmBalances(publicClient, address, tokens, chainKey, priorityT
5890
5898
  }
5891
5899
  const nativeTokens = tokens.filter((t2) => isNativeAddress(t2.address));
5892
5900
  const erc20Tokens = tokens.filter(
5893
- (t2) => !isNativeAddress(t2.address) && isAddress(t2.address)
5901
+ (t2) => !isNativeAddress(t2.address) && isAddress(t2.address) && (!priorityToken || t2.address !== priorityToken.address)
5894
5902
  );
5895
5903
  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
- }
5904
+ try {
5905
+ const isPriorityNative = isNativeAddress(priorityToken.address);
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) {
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
+ const balance = parseFloat(
5932
+ formatUnits(tokenBalance, priorityToken.decimals)
5933
+ );
5934
+ if (balance > 0) {
5935
+ balances[priorityToken.symbol] = { balance, address };
5936
+ }
5937
+ }
5938
+ } catch (error) {
5939
+ const errorMessage = error instanceof Error ? error.message : String(error);
5940
+ const isZeroDataError = errorMessage.includes('returned no data ("0x")');
5941
+ if (!isZeroDataError) {
5936
5942
  console.debug(
5937
5943
  `Failed to get priority token balance for ${priorityToken.symbol}:`,
5938
5944
  error
@@ -6033,7 +6039,7 @@ async function getEvmBalances(publicClient, address, tokens, chainKey, priorityT
6033
6039
  }
6034
6040
  return balances;
6035
6041
  }
6036
- async function getTonBalances(address, tokens, chainKey, customTonClient, tonApiKey) {
6042
+ async function getTonBalances(address, tokens, customTonClient, tonApiKey) {
6037
6043
  const balances = {};
6038
6044
  try {
6039
6045
  if (!isTonFriendlyAddress(address)) {
@@ -6192,7 +6198,7 @@ class EvmChainStrategy {
6192
6198
  getConnectLabel(t2) {
6193
6199
  return t2("wallets.connectEvmWallet");
6194
6200
  }
6195
- async getBalances(address, tokens, chainKey, priorityToken) {
6201
+ async getBalances(address, tokens, priorityToken) {
6196
6202
  if (!this.publicClient) {
6197
6203
  console.warn("No publicClient available for balance query");
6198
6204
  return {};
@@ -6201,7 +6207,6 @@ class EvmChainStrategy {
6201
6207
  this.publicClient,
6202
6208
  address,
6203
6209
  tokens,
6204
- chainKey,
6205
6210
  priorityToken
6206
6211
  );
6207
6212
  }
@@ -6273,7 +6278,7 @@ class EvmChainStrategy {
6273
6278
  throw new InvalidStepsError("evm", "Missing transaction data in steps");
6274
6279
  }
6275
6280
  }
6276
- async executeSteps(steps) {
6281
+ async executeSteps(steps, _context, onFirstHash) {
6277
6282
  if (!this.isConnected() || !this.provider) {
6278
6283
  throw new WalletNotConnectedError("evm");
6279
6284
  }
@@ -6287,11 +6292,17 @@ class EvmChainStrategy {
6287
6292
  if (step.type === "approve") {
6288
6293
  const hash = await this.approveTransaction(step);
6289
6294
  console.log(`Approval transaction hash: ${hash}`);
6290
- if (!firstTxHash) firstTxHash = hash;
6295
+ if (!firstTxHash) {
6296
+ firstTxHash = hash;
6297
+ onFirstHash?.(hash);
6298
+ }
6291
6299
  } else if (step.type === "bridge") {
6292
6300
  const hash = await this.executeTransaction(step);
6293
6301
  console.log(`Bridge transaction hash: ${hash}`);
6294
- if (!firstTxHash) firstTxHash = hash;
6302
+ if (!firstTxHash) {
6303
+ firstTxHash = hash;
6304
+ onFirstHash?.(hash);
6305
+ }
6295
6306
  } else {
6296
6307
  throw new InvalidStepsError(
6297
6308
  "evm",
@@ -6559,11 +6570,10 @@ class TonChainStrategy {
6559
6570
  getConnectLabel(t2) {
6560
6571
  return t2("wallets.connectTonWallet");
6561
6572
  }
6562
- async getBalances(address, tokens, chainKey) {
6573
+ async getBalances(address, tokens) {
6563
6574
  return await getTonBalances(
6564
6575
  address,
6565
6576
  tokens,
6566
- chainKey,
6567
6577
  this.config.tonClient,
6568
6578
  this.config.tonApiKey
6569
6579
  );
@@ -6627,7 +6637,7 @@ class TonChainStrategy {
6627
6637
  }
6628
6638
  }
6629
6639
  }
6630
- async executeSteps(steps) {
6640
+ async executeSteps(steps, _context, onFirstHash) {
6631
6641
  if (!this.isConnected() || !this.config.tonConnectUI) {
6632
6642
  throw new WalletNotConnectedError("ton");
6633
6643
  }
@@ -6653,9 +6663,11 @@ class TonChainStrategy {
6653
6663
  const result = await this.config.tonConnectUI.sendTransaction(
6654
6664
  transaction2
6655
6665
  );
6666
+ const hash = result.boc;
6667
+ onFirstHash?.(hash);
6656
6668
  return {
6657
6669
  chainKey: "ton",
6658
- hash: result.boc
6670
+ hash
6659
6671
  };
6660
6672
  } catch (error) {
6661
6673
  throw toChainStrategyError(error, "ton", "transaction");
@@ -6864,7 +6876,7 @@ class TronChainStrategy {
6864
6876
  throw new InvalidTransactionDataError("tron", "Missing transaction data");
6865
6877
  }
6866
6878
  }
6867
- async executeSteps(steps) {
6879
+ async executeSteps(steps, _context, onFirstHash) {
6868
6880
  console.log("executeSteps");
6869
6881
  const tronWeb = this.getTronWeb();
6870
6882
  if (!tronWeb) {
@@ -6879,6 +6891,7 @@ class TronChainStrategy {
6879
6891
  throw new WalletNotConnectedError("tron");
6880
6892
  }
6881
6893
  let lastTxId;
6894
+ let isFirstHash = true;
6882
6895
  for (const step of steps) {
6883
6896
  if (String(step.chainKey).toLowerCase() !== "tron") continue;
6884
6897
  const tx = step.transaction;
@@ -6944,6 +6957,10 @@ class TronChainStrategy {
6944
6957
  }
6945
6958
  const { txid } = await this.signAndBroadcast(tronWeb, unsigned);
6946
6959
  lastTxId = txid;
6960
+ if (isFirstHash) {
6961
+ onFirstHash?.(txid);
6962
+ isFirstHash = false;
6963
+ }
6947
6964
  }
6948
6965
  if (!lastTxId) {
6949
6966
  throw new TransactionFailedError(
@@ -7500,8 +7517,8 @@ const EvaaBridgeContent = ({
7500
7517
  onChainChange
7501
7518
  } = {}) => {
7502
7519
  const { t: t2 } = useBridgeTranslation();
7503
- useTokensRequest();
7504
- useChainsRequest();
7520
+ useTokens();
7521
+ useChains();
7505
7522
  const swap = useSwapModel();
7506
7523
  const { fromChain, toChain } = swap;
7507
7524
  const { selectedAssetSymbol, assetMatrix } = useTokensStore();