@xswap-link/sdk 0.12.1 → 0.12.2

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.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "JavaScript SDK for XSwap platform",
5
5
  "homepage": "https://github.com/xswap-link/xswap-sdk",
6
6
  "repository": {
@@ -110,6 +110,7 @@ export const TxConfigForm = (props: TxConfigFormProps) => {
110
110
  integratorFee,
111
111
  integratorFeeReceiverAddress,
112
112
  highlightedDstTokens,
113
+ wagmiConfig: providedWagmiConfig,
113
114
  } = normalizedProps;
114
115
 
115
116
  const onBackdropClick = (e: MouseEvent) => {
@@ -122,8 +123,11 @@ export const TxConfigForm = (props: TxConfigFormProps) => {
122
123
  };
123
124
 
124
125
  const wagmiConfig = useMemo(
125
- () => getWagmiConfig(supportedChains),
126
- [supportedChains],
126
+ () =>
127
+ providedWagmiConfig ??
128
+ window.xPayWagmiConfig ??
129
+ getWagmiConfig(supportedChains),
130
+ [providedWagmiConfig, supportedChains],
127
131
  );
128
132
 
129
133
  useEffect(() => {
@@ -223,6 +227,7 @@ export const openTxConfigForm = async ({
223
227
  srcTokenLocked,
224
228
  srcChainLocked,
225
229
  override,
230
+ wagmiConfig,
226
231
  }: TxConfigFormPayload): Promise<UnifiedRoute> => {
227
232
  try {
228
233
  if (xpayRoot === null) {
@@ -267,6 +272,7 @@ export const openTxConfigForm = async ({
267
272
  srcTokenLocked={srcTokenLocked}
268
273
  srcChainLocked={srcChainLocked}
269
274
  override={override}
275
+ wagmiConfig={wagmiConfig}
270
276
  />,
271
277
  );
272
278
  });
@@ -51,7 +51,13 @@ export const TxWidgetWCWrapped = ({
51
51
  integratorFee,
52
52
  integratorFeeReceiverAddress,
53
53
  highlightedDstTokens,
54
+ wagmiConfig,
54
55
  }: WidgetIntegrationPayload) => {
56
+ // Must be synchronous: the WC mounts its inner React tree before useEffect fires.
57
+ if (typeof window !== "undefined") {
58
+ window.xPayWagmiConfig = wagmiConfig;
59
+ }
60
+
55
61
  useEffect(() => {
56
62
  // We couldn't find a way to pass a function to the web component created by @r2wc/core.
57
63
  // It is assigned to window to be accessed later from within the web component.
@@ -4,7 +4,7 @@ import { defineChain, Transport } from "viem";
4
4
  import * as WagmiChains from "viem/chains";
5
5
  import { mainnet } from "viem/chains";
6
6
  import { Config, createConfig, createStorage, http } from "@wagmi/core";
7
- import { walletConnect } from "@wagmi/connectors";
7
+ import { injected, walletConnect } from "@wagmi/connectors";
8
8
 
9
9
  const storage = createStorage({
10
10
  key: "xpay.wagmi.store",
@@ -18,6 +18,7 @@ export const getWagmiConfig = (supportedChains: Chain[]): Config => {
18
18
  chains,
19
19
  transports,
20
20
  connectors: [
21
+ injected(),
21
22
  walletConnect({
22
23
  projectId: "c392898b45ac587a280b5eb33e92aeb0",
23
24
  showQrModal: true,
@@ -673,19 +673,24 @@ export const SwapProvider = ({
673
673
 
674
674
  const nonce = crypto.randomUUID();
675
675
  refreshSelectedTokenBalanceNonce.current = nonce;
676
-
677
676
  setIsFetchingBalance(true);
678
677
  let balance = "0";
679
678
  if (srcChain?.ecosystem === Ecosystem.EVM && evmAddress) {
680
- const balanceUI = await getBalanceOf(
681
- evmAddress,
682
- srcToken.address,
683
- srcChain?.publicRpcUrls[0],
684
- );
685
- balance = humanReadableToWei({
686
- amount: balanceUI,
687
- decimals: srcToken.decimals,
688
- });
679
+ const balanceFromBackend =
680
+ tokenBalances[srcChain?.chainId]?.[srcToken.address];
681
+ if (balanceFromBackend === undefined) {
682
+ const balanceUI = await getBalanceOf(
683
+ evmAddress,
684
+ srcToken.address,
685
+ srcChain?.publicRpcUrls[0],
686
+ );
687
+ balance = humanReadableToWei({
688
+ amount: balanceUI,
689
+ decimals: srcToken.decimals,
690
+ });
691
+ } else {
692
+ balance = balanceFromBackend;
693
+ }
689
694
  } else if (srcChain?.ecosystem === Ecosystem.SOLANA && solanaAddress) {
690
695
  const solanaPublicKey = new PublicKey(solanaAddress);
691
696
  const connection = new Connection(srcChain.publicRpcUrls[0]!);
@@ -719,7 +724,6 @@ export const SwapProvider = ({
719
724
  }
720
725
  }
721
726
  }
722
-
723
727
  if (nonce !== refreshSelectedTokenBalanceNonce.current) {
724
728
  return;
725
729
  }
@@ -727,7 +731,7 @@ export const SwapProvider = ({
727
731
  setSrcTokenBalanceWei(balance);
728
732
 
729
733
  setIsFetchingBalance(false);
730
- }, [evmAddress, solanaAddress, srcChain, srcToken]);
734
+ }, [evmAddress, solanaAddress, srcChain, srcToken, tokenBalances]);
731
735
  // retrieves token details for a given token address and chain from supported tokens mapping. (including imported tokens)
732
736
  const findTokenDataByAddressAndChain = useCallback(
733
737
  (tokenAddress: string, chainId: string): Token | undefined => {
@@ -796,10 +800,8 @@ export const SwapProvider = ({
796
800
  // fetches user all token balances when a wallet address is available and supported chains are loaded.
797
801
  useEffect(() => {
798
802
  let isCancelled = false;
799
-
800
803
  if ((evmAddress || solanaAddress) && supportedChains.length > 0) {
801
804
  setIsFetchingBalances(true);
802
-
803
805
  getBalances({
804
806
  walletAddress: evmAddress,
805
807
  solanaWalletAddress: solanaAddress,
@@ -1,4 +1,5 @@
1
1
  import { ContractCall, Transaction } from "@src/models";
2
+ import { Config } from "@wagmi/core";
2
3
 
3
4
  export type ModalIntegrationThemeStyles = {
4
5
  mainAccentLight?: string;
@@ -71,4 +72,5 @@ export type ModalIntegrationPayload = {
71
72
  integratorFee?: number;
72
73
  integratorFeeReceiverAddress?: string;
73
74
  highlightedDstTokens?: string[];
75
+ wagmiConfig?: Config;
74
76
  };
@@ -1,4 +1,5 @@
1
1
  import { ContractCall, ModalIntegrationStyles, Transaction } from "@src/models";
2
+ import { Config } from "@wagmi/core";
2
3
 
3
4
  export type WidgetIntegrationPayload = {
4
5
  integratorId: string;
@@ -33,4 +34,5 @@ export type WidgetIntegrationPayload = {
33
34
  integratorFee?: number;
34
35
  integratorFeeReceiverAddress?: string;
35
36
  highlightedDstTokens?: string[];
37
+ wagmiConfig?: Config;
36
38
  };
@@ -26,6 +26,7 @@ export const openTransactionModal = async ({
26
26
  onSrcChainChange,
27
27
  bridge,
28
28
  highlightedDstTokens,
29
+ wagmiConfig,
29
30
  }: ModalIntegrationPayload) => {
30
31
  const supportedChains: Chain[] = (await getChains()).filter(
31
32
  ({ web3Environment, swapSupported, bridgeSupported }) =>
@@ -66,6 +67,7 @@ export const openTransactionModal = async ({
66
67
  onSrcChainChange,
67
68
  bridge,
68
69
  highlightedDstTokens,
70
+ wagmiConfig,
69
71
  });
70
72
  };
71
73
 
@@ -1,4 +1,5 @@
1
1
  import { Transaction } from "@src/models";
2
+ import { Config } from "@wagmi/core";
2
3
 
3
4
  declare global {
4
5
  interface Window {
@@ -12,5 +13,6 @@ declare global {
12
13
  ) => void;
13
14
  xPayOnSrcChainChange?: (chain: string | undefined) => void;
14
15
  xPayOnConnectWallet?: () => void;
16
+ xPayWagmiConfig?: Config;
15
17
  }
16
18
  }