@talismn/balances 0.0.0-pr2138-20250815050905 → 0.0.0-pr2139-20250815131219
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.
@@ -18,6 +18,7 @@ export declare class BalancesProvider {
|
|
18
18
|
private get storedMiniMetadataMapById$();
|
19
19
|
getBalances$(addressesByTokenId: Record<TokenId, Address[]>): Observable<BalancesResult>;
|
20
20
|
fetchBalances(addressesByTokenId: Record<TokenId, Address[]>): Promise<IBalance[]>;
|
21
|
+
getDetectedTokensId$(address: string): Observable<TokenId[]>;
|
21
22
|
private getNetworkBalances$;
|
22
23
|
private getPolkadotNetworkModuleBalances$;
|
23
24
|
private getEthereumNetworkModuleBalances$;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { TokenId, TokenType } from "@talismn/chaindata-provider";
|
2
|
+
export declare const setDetectedTokenIds: (address: string, type: TokenType, tokenIds: TokenId[]) => void;
|
3
|
+
export declare const getDetectedTokensIds$: (address: string) => import("rxjs").Observable<string[]>;
|
@@ -1772,6 +1772,17 @@ const buildNetworkStorageCoders = (chainId, miniMetadata, coders) => {
|
|
1772
1772
|
return null;
|
1773
1773
|
};
|
1774
1774
|
|
1775
|
+
const tokenIdsByAddress = new rxjs.BehaviorSubject({});
|
1776
|
+
const setDetectedTokenIds = (address, type, tokenIds) => {
|
1777
|
+
// keep token ids from other token types (will be useful once we add token2022)
|
1778
|
+
const otherTokens = tokenIdsByAddress.value[address]?.filter(id => chaindataProvider.parseTokenId(id).type !== type) ?? [];
|
1779
|
+
tokenIdsByAddress.next({
|
1780
|
+
...tokenIdsByAddress.value,
|
1781
|
+
[address]: otherTokens.concat(tokenIds).sort()
|
1782
|
+
});
|
1783
|
+
};
|
1784
|
+
const getDetectedTokensIds$ = address => tokenIdsByAddress.pipe(rxjs.map(ownedTokens => ownedTokens[address] ?? []), rxjs.distinctUntilChanged(lodashEs.isEqual));
|
1785
|
+
|
1775
1786
|
const SPL_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
1776
1787
|
const fetchBalances$6 = async ({
|
1777
1788
|
networkId,
|
@@ -1809,6 +1820,9 @@ const fetchBalances$6 = async ({
|
|
1809
1820
|
return null;
|
1810
1821
|
}
|
1811
1822
|
}).filter(util.isNotNil);
|
1823
|
+
|
1824
|
+
// allows the wallet to detect new tokens, and enable them automatically
|
1825
|
+
setDetectedTokenIds(address, MODULE_TYPE$6, balances.map(b => b.tokenId));
|
1812
1826
|
return [address, balances];
|
1813
1827
|
}));
|
1814
1828
|
const allBalancesByKey = lodashEs.keyBy(balancesPerAddress.flatMap(([, addressBalances]) => addressBalances), b => getBalanceKey(b.tokenId, b.address));
|
@@ -6729,6 +6743,9 @@ class BalancesProvider {
|
|
6729
6743
|
balances
|
6730
6744
|
}) => balances)));
|
6731
6745
|
}
|
6746
|
+
getDetectedTokensId$(address) {
|
6747
|
+
return getDetectedTokensIds$(address);
|
6748
|
+
}
|
6732
6749
|
getNetworkBalances$(networkId, addressesByTokenId) {
|
6733
6750
|
const network$ = this.#chaindataProvider.getNetworkById$(networkId);
|
6734
6751
|
const tokensMapById$ = this.#chaindataProvider.getTokensMapById$();
|
@@ -1772,6 +1772,17 @@ const buildNetworkStorageCoders = (chainId, miniMetadata, coders) => {
|
|
1772
1772
|
return null;
|
1773
1773
|
};
|
1774
1774
|
|
1775
|
+
const tokenIdsByAddress = new rxjs.BehaviorSubject({});
|
1776
|
+
const setDetectedTokenIds = (address, type, tokenIds) => {
|
1777
|
+
// keep token ids from other token types (will be useful once we add token2022)
|
1778
|
+
const otherTokens = tokenIdsByAddress.value[address]?.filter(id => chaindataProvider.parseTokenId(id).type !== type) ?? [];
|
1779
|
+
tokenIdsByAddress.next({
|
1780
|
+
...tokenIdsByAddress.value,
|
1781
|
+
[address]: otherTokens.concat(tokenIds).sort()
|
1782
|
+
});
|
1783
|
+
};
|
1784
|
+
const getDetectedTokensIds$ = address => tokenIdsByAddress.pipe(rxjs.map(ownedTokens => ownedTokens[address] ?? []), rxjs.distinctUntilChanged(lodashEs.isEqual));
|
1785
|
+
|
1775
1786
|
const SPL_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
1776
1787
|
const fetchBalances$6 = async ({
|
1777
1788
|
networkId,
|
@@ -1809,6 +1820,9 @@ const fetchBalances$6 = async ({
|
|
1809
1820
|
return null;
|
1810
1821
|
}
|
1811
1822
|
}).filter(util.isNotNil);
|
1823
|
+
|
1824
|
+
// allows the wallet to detect new tokens, and enable them automatically
|
1825
|
+
setDetectedTokenIds(address, MODULE_TYPE$6, balances.map(b => b.tokenId));
|
1812
1826
|
return [address, balances];
|
1813
1827
|
}));
|
1814
1828
|
const allBalancesByKey = lodashEs.keyBy(balancesPerAddress.flatMap(([, addressBalances]) => addressBalances), b => getBalanceKey(b.tokenId, b.address));
|
@@ -6729,6 +6743,9 @@ class BalancesProvider {
|
|
6729
6743
|
balances
|
6730
6744
|
}) => balances)));
|
6731
6745
|
}
|
6746
|
+
getDetectedTokensId$(address) {
|
6747
|
+
return getDetectedTokensIds$(address);
|
6748
|
+
}
|
6732
6749
|
getNetworkBalances$(networkId, addressesByTokenId) {
|
6733
6750
|
const network$ = this.#chaindataProvider.getNetworkById$(networkId);
|
6734
6751
|
const tokensMapById$ = this.#chaindataProvider.getTokensMapById$();
|
@@ -5,7 +5,7 @@ import { parseAbi, erc20Abi, getContract, ContractFunctionExecutionError, hexToS
|
|
5
5
|
import { assign, omit, isEqual, uniq, keyBy, toPairs, keys, fromPairs, values } from 'lodash-es';
|
6
6
|
import z from 'zod/v4';
|
7
7
|
import anylogger from 'anylogger';
|
8
|
-
import { of, Observable, distinctUntilChanged, map, timer, switchMap, from, firstValueFrom, combineLatest,
|
8
|
+
import { of, Observable, distinctUntilChanged, BehaviorSubject, map, timer, switchMap, from, firstValueFrom, combineLatest, shareReplay, startWith, filter, defer, catchError, EMPTY, tap } from 'rxjs';
|
9
9
|
import BigNumber from 'bignumber.js';
|
10
10
|
import { PublicKey, SystemProgram } from '@solana/web3.js';
|
11
11
|
import { isNotNil, BigMath, isArrayOf, isBigInt, planckToTokens, isAbortError, getSharedObservable, keepAlive, isTruthy } from '@talismn/util';
|
@@ -1763,6 +1763,17 @@ const buildNetworkStorageCoders = (chainId, miniMetadata, coders) => {
|
|
1763
1763
|
return null;
|
1764
1764
|
};
|
1765
1765
|
|
1766
|
+
const tokenIdsByAddress = new BehaviorSubject({});
|
1767
|
+
const setDetectedTokenIds = (address, type, tokenIds) => {
|
1768
|
+
// keep token ids from other token types (will be useful once we add token2022)
|
1769
|
+
const otherTokens = tokenIdsByAddress.value[address]?.filter(id => parseTokenId(id).type !== type) ?? [];
|
1770
|
+
tokenIdsByAddress.next({
|
1771
|
+
...tokenIdsByAddress.value,
|
1772
|
+
[address]: otherTokens.concat(tokenIds).sort()
|
1773
|
+
});
|
1774
|
+
};
|
1775
|
+
const getDetectedTokensIds$ = address => tokenIdsByAddress.pipe(map(ownedTokens => ownedTokens[address] ?? []), distinctUntilChanged(isEqual));
|
1776
|
+
|
1766
1777
|
const SPL_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
1767
1778
|
const fetchBalances$6 = async ({
|
1768
1779
|
networkId,
|
@@ -1800,6 +1811,9 @@ const fetchBalances$6 = async ({
|
|
1800
1811
|
return null;
|
1801
1812
|
}
|
1802
1813
|
}).filter(isNotNil);
|
1814
|
+
|
1815
|
+
// allows the wallet to detect new tokens, and enable them automatically
|
1816
|
+
setDetectedTokenIds(address, MODULE_TYPE$6, balances.map(b => b.tokenId));
|
1803
1817
|
return [address, balances];
|
1804
1818
|
}));
|
1805
1819
|
const allBalancesByKey = keyBy(balancesPerAddress.flatMap(([, addressBalances]) => addressBalances), b => getBalanceKey(b.tokenId, b.address));
|
@@ -6720,6 +6734,9 @@ class BalancesProvider {
|
|
6720
6734
|
balances
|
6721
6735
|
}) => balances)));
|
6722
6736
|
}
|
6737
|
+
getDetectedTokensId$(address) {
|
6738
|
+
return getDetectedTokensIds$(address);
|
6739
|
+
}
|
6723
6740
|
getNetworkBalances$(networkId, addressesByTokenId) {
|
6724
6741
|
const network$ = this.#chaindataProvider.getNetworkById$(networkId);
|
6725
6742
|
const tokensMapById$ = this.#chaindataProvider.getTokensMapById$();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/balances",
|
3
|
-
"version": "0.0.0-
|
3
|
+
"version": "0.0.0-pr2139-20250815131219",
|
4
4
|
"author": "Talisman",
|
5
5
|
"homepage": "https://talisman.xyz",
|
6
6
|
"license": "GPL-3.0-or-later",
|
@@ -38,14 +38,14 @@
|
|
38
38
|
"scale-ts": "^1.6.1",
|
39
39
|
"viem": "^2.27.3",
|
40
40
|
"zod": "^3.25.76",
|
41
|
-
"@talismn/chain-connectors": "0.0.0-
|
42
|
-
"@talismn/
|
43
|
-
"@talismn/sapi": "0.0.0-
|
44
|
-
"@talismn/
|
41
|
+
"@talismn/chain-connectors": "0.0.0-pr2139-20250815131219",
|
42
|
+
"@talismn/chaindata-provider": "0.0.0-pr2139-20250815131219",
|
43
|
+
"@talismn/sapi": "0.0.0-pr2139-20250815131219",
|
44
|
+
"@talismn/crypto": "0.0.0-pr2139-20250815131219",
|
45
|
+
"@talismn/solana": "0.0.0-pr2139-20250815131219",
|
45
46
|
"@talismn/scale": "0.2.0",
|
46
|
-
"@talismn/
|
47
|
-
"@talismn/
|
48
|
-
"@talismn/util": "0.0.0-pr2138-20250815050905"
|
47
|
+
"@talismn/token-rates": "0.0.0-pr2139-20250815131219",
|
48
|
+
"@talismn/util": "0.0.0-pr2139-20250815131219"
|
49
49
|
},
|
50
50
|
"devDependencies": {
|
51
51
|
"@polkadot/api-contract": "16.1.2",
|