@xswap-link/sdk 0.10.10 → 0.10.12

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xswap-link/sdk",
3
- "version": "0.10.10",
3
+ "version": "0.10.12",
4
4
  "description": "JavaScript SDK for XSwap platform",
5
5
  "homepage": "https://github.com/xswap-link/xswap-sdk",
6
6
  "repository": {
@@ -2,7 +2,7 @@ import { ArrowDownLongIcon } from "@src/assets/icons";
2
2
 
3
3
  export const ArrowIcon = () => {
4
4
  return (
5
- <div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-14 p-1 border border-solid border-t_text_primary border-opacity-10 rounded-xl bg-t_bg_secondary">
5
+ <div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 p-1 border border-solid border-t_text_primary border-opacity-10 rounded-xl bg-t_bg_secondary">
6
6
  <div className="relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-xl">
7
7
  <div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white">
8
8
  <ArrowDownLongIcon />
@@ -47,7 +47,7 @@ export const SwapPanel = ({ type }: Props) => {
47
47
  <div className={`${type === "destination" && "text-t_text_secondary"}`}>
48
48
  {value}
49
49
  </div>
50
- <div className="opacity-60">${valueUsd}</div>
50
+ {valueUsd && <div className="opacity-60">${valueUsd}</div>}
51
51
  </div>
52
52
  <div className="flex items-center gap-3">
53
53
  <div className="flex flex-col text-right">
@@ -31,7 +31,6 @@ export const SwapButton = () => {
31
31
  srcToken,
32
32
  dstToken,
33
33
  srcValueWei,
34
- srcTokenBalanceWei,
35
34
  isFetchingRoute,
36
35
  isAsyncDataLoaded,
37
36
  hasOnConnectWalletCallback,
@@ -246,7 +245,6 @@ export const SwapButton = () => {
246
245
  solana.address,
247
246
  chainId,
248
247
  srcValueWei,
249
- srcTokenBalanceWei,
250
248
  isFetchingRoute,
251
249
  currentTokenAllowance,
252
250
  bridgeUI,
@@ -1,4 +1,4 @@
1
- import { useState } from "react";
1
+ import { useEffect, useState } from "react";
2
2
  import { UnknownTokenLogo } from "./Unknown";
3
3
  import { Token } from "@src/models";
4
4
 
@@ -13,6 +13,9 @@ export const TokenLogo = ({
13
13
  generatedLogoClassName,
14
14
  }: Props) => {
15
15
  const [errorOcurred, setErrorOccured] = useState(false);
16
+ useEffect(() => {
17
+ setErrorOccured(false);
18
+ }, [token?.address]);
16
19
  if (!token) {
17
20
  return null;
18
21
  }
@@ -5,7 +5,7 @@ import {
5
5
  WidgetIntegrationPayload,
6
6
  } from "@src/models";
7
7
  import { getChains, setApiUrl } from "@src/services";
8
- import { isServer } from "@src/utils";
8
+ import { isServer, resolveTokenAddress } from "@src/utils";
9
9
  import { createWebComponent } from "@src/utils/webComponents";
10
10
  import { useEffect, useState } from "react";
11
11
  import { Spinner } from "../Spinner";
@@ -15,10 +15,10 @@ import { addCustomTokensToChains } from "@src/utils/tokens";
15
15
 
16
16
  const TxWidget = ({
17
17
  integratorId,
18
- dstChain,
19
- dstToken,
20
- srcChain,
21
- srcToken,
18
+ dstChain: dstChainId,
19
+ dstToken: dstTokenId,
20
+ srcChain: srcChainId,
21
+ srcToken: srcTokenId,
22
22
  customContractCalls = [],
23
23
  desc,
24
24
  dstDisplayToken,
@@ -43,6 +43,12 @@ const TxWidget = ({
43
43
  }: WidgetIntegrationPayload) => {
44
44
  const [loading, setLoading] = useState(true);
45
45
  const [supportedChains, setSupportedChains] = useState<Chain[]>([]);
46
+ const [srcTokenAddr, setSrcTokenAddr] = useState<string | undefined>(
47
+ undefined,
48
+ );
49
+ const [dstTokenAddr, setDstTokenAddr] = useState<string | undefined>(
50
+ undefined,
51
+ );
46
52
 
47
53
  useEffect(() => {
48
54
  (async () => {
@@ -76,6 +82,23 @@ const TxWidget = ({
76
82
  }
77
83
  })();
78
84
 
85
+ useEffect(() => {
86
+ const newSrcTokenAddr = resolveTokenAddress(
87
+ srcTokenId,
88
+ srcChainId,
89
+ supportedChains,
90
+ );
91
+
92
+ const newDstTokenAddr = resolveTokenAddress(
93
+ dstTokenId,
94
+ dstChainId,
95
+ supportedChains,
96
+ );
97
+
98
+ setSrcTokenAddr(newSrcTokenAddr);
99
+ setDstTokenAddr(newDstTokenAddr);
100
+ }, [srcTokenId, srcChainId, dstTokenId, dstChainId, supportedChains]);
101
+
79
102
  return (
80
103
  <>
81
104
  <style>{CSS}</style>
@@ -87,10 +110,10 @@ const TxWidget = ({
87
110
  ) : (
88
111
  <TxConfigForm
89
112
  integratorId={integratorId}
90
- dstChainId={dstChain}
91
- dstTokenAddr={dstToken}
92
- srcChainId={srcChain}
93
- srcTokenAddr={srcToken}
113
+ dstChainId={dstChainId}
114
+ dstTokenAddr={dstTokenAddr}
115
+ srcChainId={srcChainId}
116
+ srcTokenAddr={srcTokenAddr}
94
117
  customContractCalls={customContractCalls}
95
118
  desc={desc}
96
119
  dstDisplayTokenAddr={dstDisplayToken}
@@ -782,25 +782,43 @@ export const SwapProvider = ({
782
782
  }, [refreshBalance]);
783
783
  // fetches user all token balances when a wallet address is available and supported chains are loaded.
784
784
  useEffect(() => {
785
+ let isCancelled = false;
786
+
785
787
  if ((evmAddress || solanaAddress) && supportedChains.length > 0) {
786
788
  setIsFetchingBalances(true);
789
+
787
790
  getBalances({
788
791
  walletAddress: evmAddress,
789
792
  solanaWalletAddress: solanaAddress,
790
793
  }).then((balances) => {
791
- setTokenBalances(balances);
792
- setIsFetchingBalances(false);
794
+ if (!isCancelled) {
795
+ setTokenBalances(balances);
796
+ setIsFetchingBalances(false);
797
+ }
793
798
  });
794
799
  }
800
+
801
+ return () => {
802
+ isCancelled = true; // prevent state update from stale async call
803
+ };
795
804
  }, [evmAddress, solanaAddress, supportedChains.length]);
796
805
  // sets the fee token from the source chain's tokens by selecting the native token (AddressZero).
797
806
  useEffect(() => {
798
- setFeeToken(
799
- srcChain?.tokens.find(
800
- ({ address }) =>
801
- address.toLowerCase() === constants.AddressZero.toLowerCase(),
802
- ),
803
- );
807
+ if (srcChain?.chainId === "mainnet-beta") {
808
+ setFeeToken(
809
+ srcChain?.tokens.find(
810
+ ({ address }) =>
811
+ address === "So11111111111111111111111111111111111111112",
812
+ ),
813
+ );
814
+ } else {
815
+ setFeeToken(
816
+ srcChain?.tokens.find(
817
+ ({ address }) =>
818
+ address.toLowerCase() === constants.AddressZero.toLowerCase(),
819
+ ),
820
+ );
821
+ }
804
822
  }, [srcChain]);
805
823
 
806
824
  // =============================================================================