@xswap-link/sdk 0.10.11 → 0.10.13
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/CHANGELOG.md +12 -0
- package/dist/index.global.js +456 -456
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +2 -1
- package/polyfills/buffer.js +12 -0
- package/src/context/SwapProvider.tsx +11 -2
- package/tsup.config.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xswap-link/sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.13",
|
|
4
4
|
"description": "JavaScript SDK for XSwap platform",
|
|
5
5
|
"homepage": "https://github.com/xswap-link/xswap-sdk",
|
|
6
6
|
"repository": {
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"async-retry": "^1.3.3",
|
|
48
48
|
"bignumber.js": "4.0.4",
|
|
49
49
|
"bn.js": "^5.2.2",
|
|
50
|
+
"buffer": "^6.0.3",
|
|
50
51
|
"crypto": "npm:crypto-browserify@latest",
|
|
51
52
|
"date-fns": "^3.6.0",
|
|
52
53
|
"ethers": "5.7.2",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Buffer } from "buffer";
|
|
2
|
+
|
|
3
|
+
// Conditionally polyfill Node.js Buffer for browser environments.
|
|
4
|
+
// To enable this, set: window.XSwapSDKConfig = { enableBufferPolyfill: true } before loading the SDK.
|
|
5
|
+
const shouldPolyfill =
|
|
6
|
+
typeof window !== "undefined" &&
|
|
7
|
+
typeof window.Buffer === "undefined" &&
|
|
8
|
+
window?.XSwapSDKConfig?.enableBufferPolyfill === true;
|
|
9
|
+
|
|
10
|
+
if (shouldPolyfill) {
|
|
11
|
+
window.Buffer = Buffer;
|
|
12
|
+
}
|
|
@@ -782,16 +782,25 @@ 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
|
-
|
|
792
|
-
|
|
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(() => {
|