@silentswap/react 0.0.56 → 0.0.58
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.
|
@@ -11,7 +11,7 @@ export type BalancesContextType = {
|
|
|
11
11
|
totalUsdValue: number;
|
|
12
12
|
errors: Record<string, string>;
|
|
13
13
|
refetch: () => Promise<void>;
|
|
14
|
-
refetchChains: (chainIds: (number | 'solana')[]) => Promise<void>;
|
|
14
|
+
refetchChains: (chainIds: (number | 'solana' | 'bitcoin')[]) => Promise<void>;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Provider for user balances across all supported chains
|
|
@@ -8,7 +8,7 @@ import { getAssociatedTokenAddress } from '@solana/spl-token';
|
|
|
8
8
|
import { PublicKey } from '@solana/web3.js';
|
|
9
9
|
import { useAssetsContext } from './AssetsContext.js';
|
|
10
10
|
import { usePrices } from '../hooks/usePrices.js';
|
|
11
|
-
import { isSolanaAsset, parseSolanaCaip19, isSolanaNativeToken, isSplToken, isEvmNativeToken, isBitcoinAsset, SB58_CHAIN_ID_SOLANA_MAINNET, A_VIEM_CHAINS, BITCOIN_CHAIN_ID, } from '@silentswap/sdk';
|
|
11
|
+
import { isSolanaAsset, parseSolanaCaip19, isSolanaNativeToken, isSplToken, isEvmNativeToken, isBitcoinAsset, isBitcoinMainnetAsset, SB58_CHAIN_ID_SOLANA_MAINNET, A_VIEM_CHAINS, BITCOIN_CHAIN_ID, } from '@silentswap/sdk';
|
|
12
12
|
const BalancesContext = createContext(undefined);
|
|
13
13
|
// Custom RPC endpoints from 0xrpc.io (fast, free, private public RPC)
|
|
14
14
|
// Reference: https://0xrpc.io
|
|
@@ -366,10 +366,12 @@ const fetchSolanaBalances = async (solAddress, solanaRpcUrl, assets, getUnitValu
|
|
|
366
366
|
return { balances: {}, error: errorMsg };
|
|
367
367
|
}
|
|
368
368
|
};
|
|
369
|
-
// Utility: Fetch Bitcoin native balances using Mempool.space API
|
|
369
|
+
// Utility: Fetch Bitcoin native balances using Mempool.space API (BTC only).
|
|
370
|
+
// Mempool.space is Bitcoin mainnet only; do not assign this balance to BCH or other bip122 chains.
|
|
370
371
|
const fetchBitcoinNativeBalances = async (bitcoinAddress, a_assets_native, getUnitValueUsd) => {
|
|
371
372
|
const updatedBalances = {};
|
|
372
|
-
|
|
373
|
+
const a_btc_only = a_assets_native.filter((a) => isBitcoinMainnetAsset(a.caip19));
|
|
374
|
+
if (a_btc_only.length === 0)
|
|
373
375
|
return updatedBalances;
|
|
374
376
|
try {
|
|
375
377
|
// Fetch balance from Mempool.space API (free, no auth required)
|
|
@@ -384,7 +386,7 @@ const fetchBitcoinNativeBalances = async (bitcoinAddress, a_assets_native, getUn
|
|
|
384
386
|
const funded = BigInt(data.chain_stats?.funded_txo_sum || 0);
|
|
385
387
|
const spent = BigInt(data.chain_stats?.spent_txo_sum || 0);
|
|
386
388
|
const xg_balance = funded - spent;
|
|
387
|
-
await Promise.all(
|
|
389
|
+
await Promise.all(a_btc_only.map(async (k_asset) => {
|
|
388
390
|
let x_value_usd = 0;
|
|
389
391
|
try {
|
|
390
392
|
x_value_usd = await getUnitValueUsd(k_asset, xg_balance);
|
|
@@ -515,7 +517,7 @@ export const BalancesProvider = ({ children, evmAddress, solAddress, solanaRpcUr
|
|
|
515
517
|
finally {
|
|
516
518
|
setLoading(false);
|
|
517
519
|
}
|
|
518
|
-
}, [evmAddress, solAddress, solanaRpcUrl, assets, assetsLoading, getUnitValueUsd]);
|
|
520
|
+
}, [evmAddress, solAddress, bitcoinAddress, bitcoinRpcUrl, solanaRpcUrl, assets, assetsLoading, getUnitValueUsd]);
|
|
519
521
|
// Refetch balances for specific chains only
|
|
520
522
|
const refetchChains = useCallback(async (chainIds) => {
|
|
521
523
|
if (assetsLoading || chainIds.length === 0)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silentswap/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.58",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@bigmi/core": "^0.6.5",
|
|
26
26
|
"@ensdomains/ensjs": "^4.2.0",
|
|
27
|
-
"@silentswap/sdk": "0.0.
|
|
28
|
-
"@silentswap/ui-kit": "0.0.
|
|
27
|
+
"@silentswap/sdk": "0.0.58",
|
|
28
|
+
"@silentswap/ui-kit": "0.0.58",
|
|
29
29
|
"@solana/codecs-strings": "^5.1.0",
|
|
30
30
|
"@solana/kit": "^5.1.0",
|
|
31
31
|
"@solana/rpc": "^5.1.0",
|