@xswap-link/sdk 0.13.0 → 0.13.1
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 +8 -0
- package/dist/index.global.js +67 -67
- package/dist/index.js +79 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/index.tsx +2 -2
- package/src/context/SwapProvider.tsx +94 -67
package/dist/index.mjs
CHANGED
|
@@ -20951,6 +20951,7 @@ var SwapProvider = ({
|
|
|
20951
20951
|
const [route, setRoute] = useState3(init2.route);
|
|
20952
20952
|
const routeAbortController = useRef2(null);
|
|
20953
20953
|
const refreshSelectedTokenBalanceNonce = useRef2(crypto.randomUUID());
|
|
20954
|
+
const prevWalletAddresses = useRef2(void 0);
|
|
20954
20955
|
const srcTokenLocked = useMemo5(
|
|
20955
20956
|
() => !!integrationConfig?.srcTokenLocked,
|
|
20956
20957
|
[integrationConfig?.srcTokenLocked]
|
|
@@ -21207,66 +21208,81 @@ var SwapProvider = ({
|
|
|
21207
21208
|
srcToken,
|
|
21208
21209
|
srcValueWei
|
|
21209
21210
|
]);
|
|
21210
|
-
const refreshBalance = useCallback6(
|
|
21211
|
-
|
|
21212
|
-
|
|
21213
|
-
|
|
21214
|
-
|
|
21215
|
-
|
|
21216
|
-
|
|
21217
|
-
|
|
21218
|
-
|
|
21219
|
-
|
|
21220
|
-
|
|
21221
|
-
|
|
21222
|
-
|
|
21223
|
-
|
|
21224
|
-
|
|
21225
|
-
|
|
21226
|
-
|
|
21227
|
-
|
|
21228
|
-
|
|
21229
|
-
|
|
21230
|
-
|
|
21231
|
-
|
|
21232
|
-
|
|
21233
|
-
|
|
21234
|
-
|
|
21235
|
-
|
|
21236
|
-
|
|
21237
|
-
|
|
21238
|
-
|
|
21239
|
-
|
|
21240
|
-
|
|
21241
|
-
|
|
21242
|
-
solanaPublicKey,
|
|
21243
|
-
{
|
|
21244
|
-
programId: SOLANA_TOKEN_PROGRAM_ID
|
|
21211
|
+
const refreshBalance = useCallback6(
|
|
21212
|
+
async (options) => {
|
|
21213
|
+
if (!evmAddress && !solanaAddress || !srcChain?.publicRpcUrls[0] || !srcToken || !srcToken?.address) {
|
|
21214
|
+
return;
|
|
21215
|
+
}
|
|
21216
|
+
const nonce = crypto.randomUUID();
|
|
21217
|
+
refreshSelectedTokenBalanceNonce.current = nonce;
|
|
21218
|
+
setIsFetchingBalance(true);
|
|
21219
|
+
let balance = "0";
|
|
21220
|
+
if (srcChain?.ecosystem === "evm" /* EVM */ && evmAddress) {
|
|
21221
|
+
const balanceFromBackend = tokenBalances[srcChain?.chainId]?.[srcToken.address];
|
|
21222
|
+
if (options?.forceRpc || balanceFromBackend === void 0) {
|
|
21223
|
+
const balanceUI = await getBalanceOf(
|
|
21224
|
+
evmAddress,
|
|
21225
|
+
srcToken.address,
|
|
21226
|
+
srcChain?.publicRpcUrls[0]
|
|
21227
|
+
);
|
|
21228
|
+
balance = humanReadableToWei({
|
|
21229
|
+
amount: balanceUI,
|
|
21230
|
+
decimals: srcToken.decimals
|
|
21231
|
+
});
|
|
21232
|
+
if (options?.forceRpc && balanceFromBackend !== void 0) {
|
|
21233
|
+
const chainId = srcChain.chainId;
|
|
21234
|
+
const tokenAddress = srcToken.address;
|
|
21235
|
+
const freshBalance = balance;
|
|
21236
|
+
setTokenBalances((prev) => ({
|
|
21237
|
+
...prev,
|
|
21238
|
+
[chainId]: {
|
|
21239
|
+
...prev[chainId],
|
|
21240
|
+
[tokenAddress]: freshBalance
|
|
21241
|
+
}
|
|
21242
|
+
}));
|
|
21245
21243
|
}
|
|
21246
|
-
);
|
|
21247
|
-
const token2022Accounts = await connection.getParsedTokenAccountsByOwner(solanaPublicKey, {
|
|
21248
|
-
programId: SOLANA_TOKEN_2022_PROGRAM_ID
|
|
21249
|
-
});
|
|
21250
|
-
const allTokenAccount = [
|
|
21251
|
-
...tokenAccounts.value,
|
|
21252
|
-
...token2022Accounts.value
|
|
21253
|
-
];
|
|
21254
|
-
const tokenAccount = allTokenAccount.find(
|
|
21255
|
-
(account) => account.account.data.parsed.info.mint === srcToken.address
|
|
21256
|
-
);
|
|
21257
|
-
if (!tokenAccount) {
|
|
21258
|
-
balance = "0";
|
|
21259
21244
|
} else {
|
|
21260
|
-
balance =
|
|
21245
|
+
balance = balanceFromBackend;
|
|
21246
|
+
}
|
|
21247
|
+
} else if (srcChain?.ecosystem === "solana" /* SOLANA */ && solanaAddress) {
|
|
21248
|
+
const solanaPublicKey = new PublicKey4(solanaAddress);
|
|
21249
|
+
const connection = new Connection2(srcChain.publicRpcUrls[0]);
|
|
21250
|
+
if (srcToken.address === SOLANA_NATIVE_TOKEN_ADDRESS.toBase58()) {
|
|
21251
|
+
balance = new BigNumberJS3(
|
|
21252
|
+
await connection.getBalance(solanaPublicKey)
|
|
21253
|
+
).toString();
|
|
21254
|
+
} else {
|
|
21255
|
+
const tokenAccounts = await connection.getParsedTokenAccountsByOwner(
|
|
21256
|
+
solanaPublicKey,
|
|
21257
|
+
{
|
|
21258
|
+
programId: SOLANA_TOKEN_PROGRAM_ID
|
|
21259
|
+
}
|
|
21260
|
+
);
|
|
21261
|
+
const token2022Accounts = await connection.getParsedTokenAccountsByOwner(solanaPublicKey, {
|
|
21262
|
+
programId: SOLANA_TOKEN_2022_PROGRAM_ID
|
|
21263
|
+
});
|
|
21264
|
+
const allTokenAccount = [
|
|
21265
|
+
...tokenAccounts.value,
|
|
21266
|
+
...token2022Accounts.value
|
|
21267
|
+
];
|
|
21268
|
+
const tokenAccount = allTokenAccount.find(
|
|
21269
|
+
(account) => account.account.data.parsed.info.mint === srcToken.address
|
|
21270
|
+
);
|
|
21271
|
+
if (!tokenAccount) {
|
|
21272
|
+
balance = "0";
|
|
21273
|
+
} else {
|
|
21274
|
+
balance = tokenAccount.account.data.parsed.info.tokenAmount.amount;
|
|
21275
|
+
}
|
|
21261
21276
|
}
|
|
21262
21277
|
}
|
|
21263
|
-
|
|
21264
|
-
|
|
21265
|
-
|
|
21266
|
-
|
|
21267
|
-
|
|
21268
|
-
|
|
21269
|
-
|
|
21278
|
+
if (nonce !== refreshSelectedTokenBalanceNonce.current) {
|
|
21279
|
+
return;
|
|
21280
|
+
}
|
|
21281
|
+
setSrcTokenBalanceWei(balance);
|
|
21282
|
+
setIsFetchingBalance(false);
|
|
21283
|
+
},
|
|
21284
|
+
[evmAddress, solanaAddress, srcChain, srcToken, tokenBalances]
|
|
21285
|
+
);
|
|
21270
21286
|
const findTokenDataByAddressAndChain = useCallback6(
|
|
21271
21287
|
(tokenAddress, chainId) => {
|
|
21272
21288
|
return supportedTokens[chainId]?.[tokenAddress];
|
|
@@ -21311,8 +21327,11 @@ var SwapProvider = ({
|
|
|
21311
21327
|
quoteRoute();
|
|
21312
21328
|
}, [quoteRoute]);
|
|
21313
21329
|
useEffect2(() => {
|
|
21314
|
-
|
|
21315
|
-
|
|
21330
|
+
const walletAddresses = `${evmAddress ?? ""}:${solanaAddress ?? ""}`;
|
|
21331
|
+
const walletChanged = prevWalletAddresses.current !== void 0 && prevWalletAddresses.current !== walletAddresses;
|
|
21332
|
+
prevWalletAddresses.current = walletAddresses;
|
|
21333
|
+
refreshBalance(walletChanged ? { forceRpc: true } : void 0);
|
|
21334
|
+
}, [refreshBalance, evmAddress, solanaAddress]);
|
|
21316
21335
|
useEffect2(() => {
|
|
21317
21336
|
let isCancelled = false;
|
|
21318
21337
|
if ((evmAddress || solanaAddress) && supportedChains.length > 0) {
|
|
@@ -24667,7 +24686,7 @@ var TxOverview = ({ onCloseClick }) => {
|
|
|
24667
24686
|
handlers: {
|
|
24668
24687
|
onSuccess: (data) => {
|
|
24669
24688
|
setTxStatus(5 /* COMPLETED */);
|
|
24670
|
-
refreshBalance();
|
|
24689
|
+
refreshBalance({ forceRpc: true });
|
|
24671
24690
|
trackTransaction(data);
|
|
24672
24691
|
if (srcChain?.chainId && dstChain?.chainId && srcChain?.chainId !== dstChain?.chainId) {
|
|
24673
24692
|
renderTxStatus(
|
|
@@ -24811,7 +24830,7 @@ var TxOverview = ({ onCloseClick }) => {
|
|
|
24811
24830
|
handlers: {
|
|
24812
24831
|
onSuccess: () => {
|
|
24813
24832
|
setTxStatus(5 /* COMPLETED */);
|
|
24814
|
-
refreshBalance();
|
|
24833
|
+
refreshBalance({ forceRpc: true });
|
|
24815
24834
|
}
|
|
24816
24835
|
},
|
|
24817
24836
|
network: "solana" /* SOLANA */
|