@talismn/balances-react 0.8.2 → 0.9.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.
@@ -1,12 +1,12 @@
|
|
1
1
|
import { AnyBalanceModule, Hydrate } from "@talismn/balances";
|
2
|
-
import {
|
2
|
+
import { CoinsApiConfig } from "@talismn/token-rates";
|
3
3
|
export declare const balanceModuleCreatorsAtom: import("jotai").PrimitiveAtom<((hydrate: Hydrate) => AnyBalanceModule)[]> & {
|
4
4
|
init: ((hydrate: Hydrate) => AnyBalanceModule)[];
|
5
5
|
};
|
6
6
|
export declare const onfinalityApiKeyAtom: import("jotai").PrimitiveAtom<string | undefined> & {
|
7
7
|
init: string | undefined;
|
8
8
|
};
|
9
|
-
export declare const
|
9
|
+
export declare const coinsApiConfigAtom: import("jotai").WritableAtom<CoinsApiConfig, [Partial<CoinsApiConfig>], void>;
|
10
10
|
export declare const enableTestnetsAtom: import("jotai").PrimitiveAtom<boolean> & {
|
11
11
|
init: boolean;
|
12
12
|
};
|
@@ -23,9 +23,7 @@ export type BalancesConfig = {
|
|
23
23
|
* This key will be used in place of any public onfinality RPCs
|
24
24
|
*/
|
25
25
|
onfinalityApiKey?: string;
|
26
|
-
|
27
|
-
coingeckoApiKeyName?: string;
|
28
|
-
coingeckoApiKeyValue?: string;
|
26
|
+
coinsApiUrl?: string;
|
29
27
|
/** Enables balances fetching for tokens on testnet chains. */
|
30
28
|
withTestnets?: boolean;
|
31
29
|
/**
|
@@ -77,4 +75,4 @@ export type BalancesConfig = {
|
|
77
75
|
enabledTokens?: string[];
|
78
76
|
children?: ReactNode;
|
79
77
|
};
|
80
|
-
export declare const BalancesProvider: ({ balanceModules, onfinalityApiKey,
|
78
|
+
export declare const BalancesProvider: ({ balanceModules, onfinalityApiKey, coinsApiUrl, withTestnets, enabledChains, enabledTokens, children, }: BalancesConfig) => import("react/jsx-runtime").JSX.Element;
|
@@ -26,17 +26,10 @@ var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
26
26
|
|
27
27
|
const balanceModuleCreatorsAtom = jotai.atom(balances.defaultBalanceModules);
|
28
28
|
const onfinalityApiKeyAtom = jotai.atom(undefined);
|
29
|
-
const
|
30
|
-
const
|
31
|
-
|
32
|
-
|
33
|
-
const apiKeyValue = options.apiKeyValue ?? tokenRates.DEFAULT_COINGECKO_CONFIG.apiKeyValue;
|
34
|
-
set(innerCoingeckoConfigAtom, {
|
35
|
-
apiUrl,
|
36
|
-
apiKeyName,
|
37
|
-
apiKeyValue
|
38
|
-
});
|
39
|
-
});
|
29
|
+
const innerCoinsApiConfigAtom = jotai.atom(tokenRates.DEFAULT_COINSAPI_CONFIG);
|
30
|
+
const coinsApiConfigAtom = jotai.atom(get => get(innerCoinsApiConfigAtom), (_get, set, options) => set(innerCoinsApiConfigAtom, {
|
31
|
+
apiUrl: options.apiUrl ?? tokenRates.DEFAULT_COINSAPI_CONFIG.apiUrl
|
32
|
+
}));
|
40
33
|
const enableTestnetsAtom = jotai.atom(false);
|
41
34
|
const enabledChainsAtom = jotai.atom(undefined);
|
42
35
|
const enabledTokensAtom = jotai.atom(undefined);
|
@@ -45,75 +38,7 @@ const enabledTokensAtom = jotai.atom(undefined);
|
|
45
38
|
const allAddressesAtom = jotai.atom([]);
|
46
39
|
|
47
40
|
var packageJson = {
|
48
|
-
name: "@talismn/balances-react"
|
49
|
-
version: "0.8.2",
|
50
|
-
author: "Talisman",
|
51
|
-
homepage: "https://talisman.xyz",
|
52
|
-
license: "GPL-3.0-or-later",
|
53
|
-
publishConfig: {
|
54
|
-
access: "public"
|
55
|
-
},
|
56
|
-
repository: {
|
57
|
-
directory: "packages/balances-react",
|
58
|
-
type: "git",
|
59
|
-
url: "https://github.com/talismansociety/talisman.git"
|
60
|
-
},
|
61
|
-
main: "dist/talismn-balances-react.cjs.js",
|
62
|
-
module: "dist/talismn-balances-react.esm.js",
|
63
|
-
files: [
|
64
|
-
"/dist"
|
65
|
-
],
|
66
|
-
engines: {
|
67
|
-
node: ">=18"
|
68
|
-
},
|
69
|
-
scripts: {
|
70
|
-
test: "jest",
|
71
|
-
lint: "eslint src --max-warnings 0",
|
72
|
-
clean: "rm -rf dist .turbo node_modules"
|
73
|
-
},
|
74
|
-
dependencies: {
|
75
|
-
"@talismn/balances": "workspace:*",
|
76
|
-
"@talismn/chain-connector": "workspace:*",
|
77
|
-
"@talismn/chain-connector-evm": "workspace:*",
|
78
|
-
"@talismn/chaindata-provider": "workspace:*",
|
79
|
-
"@talismn/connection-meta": "workspace:*",
|
80
|
-
"@talismn/scale": "workspace:*",
|
81
|
-
"@talismn/token-rates": "workspace:*",
|
82
|
-
"@talismn/util": "workspace:*",
|
83
|
-
anylogger: "^1.0.11",
|
84
|
-
"blueimp-md5": "2.19.0",
|
85
|
-
dexie: "^4.0.9",
|
86
|
-
"dexie-react-hooks": "^1.1.7",
|
87
|
-
jotai: "~2",
|
88
|
-
"jotai-effect": "~1",
|
89
|
-
lodash: "4.17.21",
|
90
|
-
"react-use": "^17.5.1",
|
91
|
-
rxjs: "^7.8.1"
|
92
|
-
},
|
93
|
-
devDependencies: {
|
94
|
-
"@talismn/eslint-config": "workspace:*",
|
95
|
-
"@talismn/tsconfig": "workspace:*",
|
96
|
-
"@types/jest": "^29.5.14",
|
97
|
-
"@types/lodash": "^4.17.12",
|
98
|
-
"@types/react": "^18.3.12",
|
99
|
-
eslint: "^8.57.1",
|
100
|
-
jest: "^29.7.0",
|
101
|
-
react: "^18.3.1",
|
102
|
-
"ts-jest": "^29.2.5",
|
103
|
-
typescript: "^5.6.3"
|
104
|
-
},
|
105
|
-
peerDependencies: {
|
106
|
-
"@polkadot/util-crypto": "*",
|
107
|
-
react: "*",
|
108
|
-
"react-dom": "*"
|
109
|
-
},
|
110
|
-
eslintConfig: {
|
111
|
-
root: true,
|
112
|
-
"extends": [
|
113
|
-
"@talismn/eslint-config/react"
|
114
|
-
]
|
115
|
-
}
|
116
|
-
};
|
41
|
+
name: "@talismn/balances-react"};
|
117
42
|
|
118
43
|
var log = anylogger__default.default(packageJson.name);
|
119
44
|
|
@@ -122,7 +47,10 @@ var log = anylogger__default.default(packageJson.name);
|
|
122
47
|
// Add a new backend by implementing the BalancesPersistBackend interface
|
123
48
|
// configureStore can be called with a different indexedDB table
|
124
49
|
*/
|
125
|
-
|
50
|
+
const {
|
51
|
+
persistData,
|
52
|
+
retrieveData
|
53
|
+
} = balances.configureStore();
|
126
54
|
|
127
55
|
/**
|
128
56
|
// Persistence backend for localStorage
|
@@ -314,7 +242,7 @@ const tokenRatesFetcherAtomEffect = jotaiEffect.atomEffect(get => {
|
|
314
242
|
const abort = new AbortController();
|
315
243
|
|
316
244
|
// we have to get these synchronously so that jotai knows to restart our timer when they change
|
317
|
-
const
|
245
|
+
const coinsApiConfig = get(coinsApiConfigAtom);
|
318
246
|
const tokensByIdPromise = get(tokensByIdAtom);
|
319
247
|
(async () => {
|
320
248
|
const tokensById = await tokensByIdPromise;
|
@@ -325,7 +253,7 @@ const tokenRatesFetcherAtomEffect = jotaiEffect.atomEffect(get => {
|
|
325
253
|
const hydrate = async () => {
|
326
254
|
try {
|
327
255
|
if (abort.signal.aborted) return; // don't fetch if aborted
|
328
|
-
const tokenRates$1 = await tokenRates.fetchTokenRates(tokensById,
|
256
|
+
const tokenRates$1 = await tokenRates.fetchTokenRates(tokensById, tokenRates.ALL_CURRENCY_IDS, coinsApiConfig);
|
329
257
|
const putTokenRates = Object.entries(tokenRates$1).map(([tokenId, rates]) => ({
|
330
258
|
tokenId,
|
331
259
|
rates
|
@@ -345,7 +273,7 @@ const tokenRatesFetcherAtomEffect = jotaiEffect.atomEffect(get => {
|
|
345
273
|
setTimeout(hydrate, loopMs);
|
346
274
|
} catch (error) {
|
347
275
|
const retrying = !abort.signal.aborted;
|
348
|
-
const messageParts = ["Failed to fetch tokenRates", retrying && `retrying in ${Math.round(retryTimeout / 1000)} seconds`, !retrying && `giving up (timer no longer needed)`].filter(
|
276
|
+
const messageParts = ["Failed to fetch tokenRates", retrying && `retrying in ${Math.round(retryTimeout / 1000)} seconds`, !retrying && `giving up (timer no longer needed)`].filter(util.isTruthy);
|
349
277
|
log.error(messageParts.join(", "), error);
|
350
278
|
if (abort.signal.aborted) return; // don't schedule retry if aborted
|
351
279
|
setTimeout(hydrate, retryTimeout);
|
@@ -641,9 +569,7 @@ const useTokenRate = tokenId => useTokenRates()[tokenId ?? ""] ?? undefined;
|
|
641
569
|
const BalancesProvider = ({
|
642
570
|
balanceModules,
|
643
571
|
onfinalityApiKey,
|
644
|
-
|
645
|
-
coingeckoApiKeyName,
|
646
|
-
coingeckoApiKeyValue,
|
572
|
+
coinsApiUrl,
|
647
573
|
withTestnets,
|
648
574
|
enabledChains,
|
649
575
|
enabledTokens,
|
@@ -657,14 +583,12 @@ const BalancesProvider = ({
|
|
657
583
|
react.useEffect(() => {
|
658
584
|
setOnfinalityApiKey(onfinalityApiKey);
|
659
585
|
}, [onfinalityApiKey, setOnfinalityApiKey]);
|
660
|
-
const
|
586
|
+
const setCoinsApiConfig = jotai.useSetAtom(coinsApiConfigAtom);
|
661
587
|
react.useEffect(() => {
|
662
|
-
|
663
|
-
apiUrl:
|
664
|
-
apiKeyName: coingeckoApiKeyName,
|
665
|
-
apiKeyValue: coingeckoApiKeyValue
|
588
|
+
setCoinsApiConfig({
|
589
|
+
apiUrl: coinsApiUrl
|
666
590
|
});
|
667
|
-
}, [
|
591
|
+
}, [coinsApiUrl, setCoinsApiConfig]);
|
668
592
|
const setEnableTestnets = jotai.useSetAtom(enableTestnetsAtom);
|
669
593
|
react.useEffect(() => {
|
670
594
|
setEnableTestnets(withTestnets ?? false);
|
@@ -722,7 +646,7 @@ exports.chaindataProviderAtom = chaindataProviderAtom;
|
|
722
646
|
exports.chainsAtom = chainsAtom;
|
723
647
|
exports.chainsByGenesisHashAtom = chainsByGenesisHashAtom;
|
724
648
|
exports.chainsByIdAtom = chainsByIdAtom;
|
725
|
-
exports.
|
649
|
+
exports.coinsApiConfigAtom = coinsApiConfigAtom;
|
726
650
|
exports.cryptoWaitReadyAtom = cryptoWaitReadyAtom;
|
727
651
|
exports.enableTestnetsAtom = enableTestnetsAtom;
|
728
652
|
exports.enabledChainsAtom = enabledChainsAtom;
|
@@ -26,17 +26,10 @@ var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
26
26
|
|
27
27
|
const balanceModuleCreatorsAtom = jotai.atom(balances.defaultBalanceModules);
|
28
28
|
const onfinalityApiKeyAtom = jotai.atom(undefined);
|
29
|
-
const
|
30
|
-
const
|
31
|
-
|
32
|
-
|
33
|
-
const apiKeyValue = options.apiKeyValue ?? tokenRates.DEFAULT_COINGECKO_CONFIG.apiKeyValue;
|
34
|
-
set(innerCoingeckoConfigAtom, {
|
35
|
-
apiUrl,
|
36
|
-
apiKeyName,
|
37
|
-
apiKeyValue
|
38
|
-
});
|
39
|
-
});
|
29
|
+
const innerCoinsApiConfigAtom = jotai.atom(tokenRates.DEFAULT_COINSAPI_CONFIG);
|
30
|
+
const coinsApiConfigAtom = jotai.atom(get => get(innerCoinsApiConfigAtom), (_get, set, options) => set(innerCoinsApiConfigAtom, {
|
31
|
+
apiUrl: options.apiUrl ?? tokenRates.DEFAULT_COINSAPI_CONFIG.apiUrl
|
32
|
+
}));
|
40
33
|
const enableTestnetsAtom = jotai.atom(false);
|
41
34
|
const enabledChainsAtom = jotai.atom(undefined);
|
42
35
|
const enabledTokensAtom = jotai.atom(undefined);
|
@@ -45,75 +38,7 @@ const enabledTokensAtom = jotai.atom(undefined);
|
|
45
38
|
const allAddressesAtom = jotai.atom([]);
|
46
39
|
|
47
40
|
var packageJson = {
|
48
|
-
name: "@talismn/balances-react"
|
49
|
-
version: "0.8.2",
|
50
|
-
author: "Talisman",
|
51
|
-
homepage: "https://talisman.xyz",
|
52
|
-
license: "GPL-3.0-or-later",
|
53
|
-
publishConfig: {
|
54
|
-
access: "public"
|
55
|
-
},
|
56
|
-
repository: {
|
57
|
-
directory: "packages/balances-react",
|
58
|
-
type: "git",
|
59
|
-
url: "https://github.com/talismansociety/talisman.git"
|
60
|
-
},
|
61
|
-
main: "dist/talismn-balances-react.cjs.js",
|
62
|
-
module: "dist/talismn-balances-react.esm.js",
|
63
|
-
files: [
|
64
|
-
"/dist"
|
65
|
-
],
|
66
|
-
engines: {
|
67
|
-
node: ">=18"
|
68
|
-
},
|
69
|
-
scripts: {
|
70
|
-
test: "jest",
|
71
|
-
lint: "eslint src --max-warnings 0",
|
72
|
-
clean: "rm -rf dist .turbo node_modules"
|
73
|
-
},
|
74
|
-
dependencies: {
|
75
|
-
"@talismn/balances": "workspace:*",
|
76
|
-
"@talismn/chain-connector": "workspace:*",
|
77
|
-
"@talismn/chain-connector-evm": "workspace:*",
|
78
|
-
"@talismn/chaindata-provider": "workspace:*",
|
79
|
-
"@talismn/connection-meta": "workspace:*",
|
80
|
-
"@talismn/scale": "workspace:*",
|
81
|
-
"@talismn/token-rates": "workspace:*",
|
82
|
-
"@talismn/util": "workspace:*",
|
83
|
-
anylogger: "^1.0.11",
|
84
|
-
"blueimp-md5": "2.19.0",
|
85
|
-
dexie: "^4.0.9",
|
86
|
-
"dexie-react-hooks": "^1.1.7",
|
87
|
-
jotai: "~2",
|
88
|
-
"jotai-effect": "~1",
|
89
|
-
lodash: "4.17.21",
|
90
|
-
"react-use": "^17.5.1",
|
91
|
-
rxjs: "^7.8.1"
|
92
|
-
},
|
93
|
-
devDependencies: {
|
94
|
-
"@talismn/eslint-config": "workspace:*",
|
95
|
-
"@talismn/tsconfig": "workspace:*",
|
96
|
-
"@types/jest": "^29.5.14",
|
97
|
-
"@types/lodash": "^4.17.12",
|
98
|
-
"@types/react": "^18.3.12",
|
99
|
-
eslint: "^8.57.1",
|
100
|
-
jest: "^29.7.0",
|
101
|
-
react: "^18.3.1",
|
102
|
-
"ts-jest": "^29.2.5",
|
103
|
-
typescript: "^5.6.3"
|
104
|
-
},
|
105
|
-
peerDependencies: {
|
106
|
-
"@polkadot/util-crypto": "*",
|
107
|
-
react: "*",
|
108
|
-
"react-dom": "*"
|
109
|
-
},
|
110
|
-
eslintConfig: {
|
111
|
-
root: true,
|
112
|
-
"extends": [
|
113
|
-
"@talismn/eslint-config/react"
|
114
|
-
]
|
115
|
-
}
|
116
|
-
};
|
41
|
+
name: "@talismn/balances-react"};
|
117
42
|
|
118
43
|
var log = anylogger__default.default(packageJson.name);
|
119
44
|
|
@@ -122,7 +47,10 @@ var log = anylogger__default.default(packageJson.name);
|
|
122
47
|
// Add a new backend by implementing the BalancesPersistBackend interface
|
123
48
|
// configureStore can be called with a different indexedDB table
|
124
49
|
*/
|
125
|
-
|
50
|
+
const {
|
51
|
+
persistData,
|
52
|
+
retrieveData
|
53
|
+
} = balances.configureStore();
|
126
54
|
|
127
55
|
/**
|
128
56
|
// Persistence backend for localStorage
|
@@ -314,7 +242,7 @@ const tokenRatesFetcherAtomEffect = jotaiEffect.atomEffect(get => {
|
|
314
242
|
const abort = new AbortController();
|
315
243
|
|
316
244
|
// we have to get these synchronously so that jotai knows to restart our timer when they change
|
317
|
-
const
|
245
|
+
const coinsApiConfig = get(coinsApiConfigAtom);
|
318
246
|
const tokensByIdPromise = get(tokensByIdAtom);
|
319
247
|
(async () => {
|
320
248
|
const tokensById = await tokensByIdPromise;
|
@@ -325,7 +253,7 @@ const tokenRatesFetcherAtomEffect = jotaiEffect.atomEffect(get => {
|
|
325
253
|
const hydrate = async () => {
|
326
254
|
try {
|
327
255
|
if (abort.signal.aborted) return; // don't fetch if aborted
|
328
|
-
const tokenRates$1 = await tokenRates.fetchTokenRates(tokensById,
|
256
|
+
const tokenRates$1 = await tokenRates.fetchTokenRates(tokensById, tokenRates.ALL_CURRENCY_IDS, coinsApiConfig);
|
329
257
|
const putTokenRates = Object.entries(tokenRates$1).map(([tokenId, rates]) => ({
|
330
258
|
tokenId,
|
331
259
|
rates
|
@@ -345,7 +273,7 @@ const tokenRatesFetcherAtomEffect = jotaiEffect.atomEffect(get => {
|
|
345
273
|
setTimeout(hydrate, loopMs);
|
346
274
|
} catch (error) {
|
347
275
|
const retrying = !abort.signal.aborted;
|
348
|
-
const messageParts = ["Failed to fetch tokenRates", retrying && `retrying in ${Math.round(retryTimeout / 1000)} seconds`, !retrying && `giving up (timer no longer needed)`].filter(
|
276
|
+
const messageParts = ["Failed to fetch tokenRates", retrying && `retrying in ${Math.round(retryTimeout / 1000)} seconds`, !retrying && `giving up (timer no longer needed)`].filter(util.isTruthy);
|
349
277
|
log.error(messageParts.join(", "), error);
|
350
278
|
if (abort.signal.aborted) return; // don't schedule retry if aborted
|
351
279
|
setTimeout(hydrate, retryTimeout);
|
@@ -641,9 +569,7 @@ const useTokenRate = tokenId => useTokenRates()[tokenId ?? ""] ?? undefined;
|
|
641
569
|
const BalancesProvider = ({
|
642
570
|
balanceModules,
|
643
571
|
onfinalityApiKey,
|
644
|
-
|
645
|
-
coingeckoApiKeyName,
|
646
|
-
coingeckoApiKeyValue,
|
572
|
+
coinsApiUrl,
|
647
573
|
withTestnets,
|
648
574
|
enabledChains,
|
649
575
|
enabledTokens,
|
@@ -657,14 +583,12 @@ const BalancesProvider = ({
|
|
657
583
|
react.useEffect(() => {
|
658
584
|
setOnfinalityApiKey(onfinalityApiKey);
|
659
585
|
}, [onfinalityApiKey, setOnfinalityApiKey]);
|
660
|
-
const
|
586
|
+
const setCoinsApiConfig = jotai.useSetAtom(coinsApiConfigAtom);
|
661
587
|
react.useEffect(() => {
|
662
|
-
|
663
|
-
apiUrl:
|
664
|
-
apiKeyName: coingeckoApiKeyName,
|
665
|
-
apiKeyValue: coingeckoApiKeyValue
|
588
|
+
setCoinsApiConfig({
|
589
|
+
apiUrl: coinsApiUrl
|
666
590
|
});
|
667
|
-
}, [
|
591
|
+
}, [coinsApiUrl, setCoinsApiConfig]);
|
668
592
|
const setEnableTestnets = jotai.useSetAtom(enableTestnetsAtom);
|
669
593
|
react.useEffect(() => {
|
670
594
|
setEnableTestnets(withTestnets ?? false);
|
@@ -722,7 +646,7 @@ exports.chaindataProviderAtom = chaindataProviderAtom;
|
|
722
646
|
exports.chainsAtom = chainsAtom;
|
723
647
|
exports.chainsByGenesisHashAtom = chainsByGenesisHashAtom;
|
724
648
|
exports.chainsByIdAtom = chainsByIdAtom;
|
725
|
-
exports.
|
649
|
+
exports.coinsApiConfigAtom = coinsApiConfigAtom;
|
726
650
|
exports.cryptoWaitReadyAtom = cryptoWaitReadyAtom;
|
727
651
|
exports.enableTestnetsAtom = enableTestnetsAtom;
|
728
652
|
exports.enabledChainsAtom = enabledChainsAtom;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { atom, useSetAtom, useAtom, useAtomValue } from 'jotai';
|
2
|
-
import {
|
3
|
-
import { defaultBalanceModules, configureStore,
|
2
|
+
import { useMemo, useEffect } from 'react';
|
3
|
+
import { defaultBalanceModules, configureStore, decompress, compress, MiniMetadataUpdater, EvmTokenFetcher, hydrateChaindataAndMiniMetadata, updateCustomMiniMetadata, updateEvmTokens, db, Balances, getBalanceId, balances } from '@talismn/balances';
|
4
4
|
export { evmErc20TokenId, evmNativeTokenId, subAssetTokenId, subEquilibriumTokenId, subNativeTokenId, subPsp22TokenId, subTokensTokenId } from '@talismn/balances';
|
5
|
-
import {
|
5
|
+
import { DEFAULT_COINSAPI_CONFIG, db as db$1, fetchTokenRates, ALL_CURRENCY_IDS } from '@talismn/token-rates';
|
6
6
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
7
|
-
import { firstThenDebounce, isEthereumAddress } from '@talismn/util';
|
7
|
+
import { firstThenDebounce, isTruthy, isEthereumAddress } from '@talismn/util';
|
8
8
|
import { atomEffect } from 'jotai-effect';
|
9
9
|
import { atomWithObservable } from 'jotai/utils';
|
10
10
|
import { isEqual as isEqual$1 } from 'lodash';
|
@@ -20,17 +20,10 @@ import isEqual from 'lodash/isEqual';
|
|
20
20
|
|
21
21
|
const balanceModuleCreatorsAtom = atom(defaultBalanceModules);
|
22
22
|
const onfinalityApiKeyAtom = atom(undefined);
|
23
|
-
const
|
24
|
-
const
|
25
|
-
|
26
|
-
|
27
|
-
const apiKeyValue = options.apiKeyValue ?? DEFAULT_COINGECKO_CONFIG.apiKeyValue;
|
28
|
-
set(innerCoingeckoConfigAtom, {
|
29
|
-
apiUrl,
|
30
|
-
apiKeyName,
|
31
|
-
apiKeyValue
|
32
|
-
});
|
33
|
-
});
|
23
|
+
const innerCoinsApiConfigAtom = atom(DEFAULT_COINSAPI_CONFIG);
|
24
|
+
const coinsApiConfigAtom = atom(get => get(innerCoinsApiConfigAtom), (_get, set, options) => set(innerCoinsApiConfigAtom, {
|
25
|
+
apiUrl: options.apiUrl ?? DEFAULT_COINSAPI_CONFIG.apiUrl
|
26
|
+
}));
|
34
27
|
const enableTestnetsAtom = atom(false);
|
35
28
|
const enabledChainsAtom = atom(undefined);
|
36
29
|
const enabledTokensAtom = atom(undefined);
|
@@ -39,75 +32,7 @@ const enabledTokensAtom = atom(undefined);
|
|
39
32
|
const allAddressesAtom = atom([]);
|
40
33
|
|
41
34
|
var packageJson = {
|
42
|
-
name: "@talismn/balances-react"
|
43
|
-
version: "0.8.2",
|
44
|
-
author: "Talisman",
|
45
|
-
homepage: "https://talisman.xyz",
|
46
|
-
license: "GPL-3.0-or-later",
|
47
|
-
publishConfig: {
|
48
|
-
access: "public"
|
49
|
-
},
|
50
|
-
repository: {
|
51
|
-
directory: "packages/balances-react",
|
52
|
-
type: "git",
|
53
|
-
url: "https://github.com/talismansociety/talisman.git"
|
54
|
-
},
|
55
|
-
main: "dist/talismn-balances-react.cjs.js",
|
56
|
-
module: "dist/talismn-balances-react.esm.js",
|
57
|
-
files: [
|
58
|
-
"/dist"
|
59
|
-
],
|
60
|
-
engines: {
|
61
|
-
node: ">=18"
|
62
|
-
},
|
63
|
-
scripts: {
|
64
|
-
test: "jest",
|
65
|
-
lint: "eslint src --max-warnings 0",
|
66
|
-
clean: "rm -rf dist .turbo node_modules"
|
67
|
-
},
|
68
|
-
dependencies: {
|
69
|
-
"@talismn/balances": "workspace:*",
|
70
|
-
"@talismn/chain-connector": "workspace:*",
|
71
|
-
"@talismn/chain-connector-evm": "workspace:*",
|
72
|
-
"@talismn/chaindata-provider": "workspace:*",
|
73
|
-
"@talismn/connection-meta": "workspace:*",
|
74
|
-
"@talismn/scale": "workspace:*",
|
75
|
-
"@talismn/token-rates": "workspace:*",
|
76
|
-
"@talismn/util": "workspace:*",
|
77
|
-
anylogger: "^1.0.11",
|
78
|
-
"blueimp-md5": "2.19.0",
|
79
|
-
dexie: "^4.0.9",
|
80
|
-
"dexie-react-hooks": "^1.1.7",
|
81
|
-
jotai: "~2",
|
82
|
-
"jotai-effect": "~1",
|
83
|
-
lodash: "4.17.21",
|
84
|
-
"react-use": "^17.5.1",
|
85
|
-
rxjs: "^7.8.1"
|
86
|
-
},
|
87
|
-
devDependencies: {
|
88
|
-
"@talismn/eslint-config": "workspace:*",
|
89
|
-
"@talismn/tsconfig": "workspace:*",
|
90
|
-
"@types/jest": "^29.5.14",
|
91
|
-
"@types/lodash": "^4.17.12",
|
92
|
-
"@types/react": "^18.3.12",
|
93
|
-
eslint: "^8.57.1",
|
94
|
-
jest: "^29.7.0",
|
95
|
-
react: "^18.3.1",
|
96
|
-
"ts-jest": "^29.2.5",
|
97
|
-
typescript: "^5.6.3"
|
98
|
-
},
|
99
|
-
peerDependencies: {
|
100
|
-
"@polkadot/util-crypto": "*",
|
101
|
-
react: "*",
|
102
|
-
"react-dom": "*"
|
103
|
-
},
|
104
|
-
eslintConfig: {
|
105
|
-
root: true,
|
106
|
-
"extends": [
|
107
|
-
"@talismn/eslint-config/react"
|
108
|
-
]
|
109
|
-
}
|
110
|
-
};
|
35
|
+
name: "@talismn/balances-react"};
|
111
36
|
|
112
37
|
var log = anylogger(packageJson.name);
|
113
38
|
|
@@ -116,7 +41,10 @@ var log = anylogger(packageJson.name);
|
|
116
41
|
// Add a new backend by implementing the BalancesPersistBackend interface
|
117
42
|
// configureStore can be called with a different indexedDB table
|
118
43
|
*/
|
119
|
-
|
44
|
+
const {
|
45
|
+
persistData,
|
46
|
+
retrieveData
|
47
|
+
} = configureStore();
|
120
48
|
|
121
49
|
/**
|
122
50
|
// Persistence backend for localStorage
|
@@ -308,7 +236,7 @@ const tokenRatesFetcherAtomEffect = atomEffect(get => {
|
|
308
236
|
const abort = new AbortController();
|
309
237
|
|
310
238
|
// we have to get these synchronously so that jotai knows to restart our timer when they change
|
311
|
-
const
|
239
|
+
const coinsApiConfig = get(coinsApiConfigAtom);
|
312
240
|
const tokensByIdPromise = get(tokensByIdAtom);
|
313
241
|
(async () => {
|
314
242
|
const tokensById = await tokensByIdPromise;
|
@@ -319,7 +247,7 @@ const tokenRatesFetcherAtomEffect = atomEffect(get => {
|
|
319
247
|
const hydrate = async () => {
|
320
248
|
try {
|
321
249
|
if (abort.signal.aborted) return; // don't fetch if aborted
|
322
|
-
const tokenRates = await fetchTokenRates(tokensById,
|
250
|
+
const tokenRates = await fetchTokenRates(tokensById, ALL_CURRENCY_IDS, coinsApiConfig);
|
323
251
|
const putTokenRates = Object.entries(tokenRates).map(([tokenId, rates]) => ({
|
324
252
|
tokenId,
|
325
253
|
rates
|
@@ -339,7 +267,7 @@ const tokenRatesFetcherAtomEffect = atomEffect(get => {
|
|
339
267
|
setTimeout(hydrate, loopMs);
|
340
268
|
} catch (error) {
|
341
269
|
const retrying = !abort.signal.aborted;
|
342
|
-
const messageParts = ["Failed to fetch tokenRates", retrying && `retrying in ${Math.round(retryTimeout / 1000)} seconds`, !retrying && `giving up (timer no longer needed)`].filter(
|
270
|
+
const messageParts = ["Failed to fetch tokenRates", retrying && `retrying in ${Math.round(retryTimeout / 1000)} seconds`, !retrying && `giving up (timer no longer needed)`].filter(isTruthy);
|
343
271
|
log.error(messageParts.join(", "), error);
|
344
272
|
if (abort.signal.aborted) return; // don't schedule retry if aborted
|
345
273
|
setTimeout(hydrate, retryTimeout);
|
@@ -635,9 +563,7 @@ const useTokenRate = tokenId => useTokenRates()[tokenId ?? ""] ?? undefined;
|
|
635
563
|
const BalancesProvider = ({
|
636
564
|
balanceModules,
|
637
565
|
onfinalityApiKey,
|
638
|
-
|
639
|
-
coingeckoApiKeyName,
|
640
|
-
coingeckoApiKeyValue,
|
566
|
+
coinsApiUrl,
|
641
567
|
withTestnets,
|
642
568
|
enabledChains,
|
643
569
|
enabledTokens,
|
@@ -651,14 +577,12 @@ const BalancesProvider = ({
|
|
651
577
|
useEffect(() => {
|
652
578
|
setOnfinalityApiKey(onfinalityApiKey);
|
653
579
|
}, [onfinalityApiKey, setOnfinalityApiKey]);
|
654
|
-
const
|
580
|
+
const setCoinsApiConfig = useSetAtom(coinsApiConfigAtom);
|
655
581
|
useEffect(() => {
|
656
|
-
|
657
|
-
apiUrl:
|
658
|
-
apiKeyName: coingeckoApiKeyName,
|
659
|
-
apiKeyValue: coingeckoApiKeyValue
|
582
|
+
setCoinsApiConfig({
|
583
|
+
apiUrl: coinsApiUrl
|
660
584
|
});
|
661
|
-
}, [
|
585
|
+
}, [coinsApiUrl, setCoinsApiConfig]);
|
662
586
|
const setEnableTestnets = useSetAtom(enableTestnetsAtom);
|
663
587
|
useEffect(() => {
|
664
588
|
setEnableTestnets(withTestnets ?? false);
|
@@ -676,4 +600,4 @@ const BalancesProvider = ({
|
|
676
600
|
});
|
677
601
|
};
|
678
602
|
|
679
|
-
export { BalancesProvider, allAddressesAtom, allBalancesAtom, balanceModuleCreatorsAtom, balanceModulesAtom, balancesPersistBackendAtom, chainConnectorsAtom, chaindataAtom, chaindataProviderAtom, chainsAtom, chainsByGenesisHashAtom, chainsByIdAtom,
|
603
|
+
export { BalancesProvider, allAddressesAtom, allBalancesAtom, balanceModuleCreatorsAtom, balanceModulesAtom, balancesPersistBackendAtom, chainConnectorsAtom, chaindataAtom, chaindataProviderAtom, chainsAtom, chainsByGenesisHashAtom, chainsByIdAtom, coinsApiConfigAtom, cryptoWaitReadyAtom, enableTestnetsAtom, enabledChainsAtom, enabledTokensAtom, evmNetworksAtom, evmNetworksByIdAtom, getStaleChains, miniMetadataHydratedAtom, miniMetadatasAtom, onfinalityApiKeyAtom, tokenRatesAtom, tokensAtom, tokensByIdAtom, useBalances, useBalancesStatus, useChain, useChainConnectors, useChaindata, useChaindataProvider, useChains, useChainsByGenesisHash, useEvmNetwork, useEvmNetworks, useMiniMetadatas, useSetBalancesAddresses, useToken, useTokenRate, useTokenRates, useTokens };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/balances-react",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.9.1",
|
4
4
|
"author": "Talisman",
|
5
5
|
"homepage": "https://talisman.xyz",
|
6
6
|
"license": "GPL-3.0-or-later",
|
@@ -30,14 +30,14 @@
|
|
30
30
|
"lodash": "4.17.21",
|
31
31
|
"react-use": "^17.5.1",
|
32
32
|
"rxjs": "^7.8.1",
|
33
|
-
"@talismn/balances": "0.
|
34
|
-
"@talismn/chain-connector": "0.
|
35
|
-
"@talismn/chaindata-provider": "0.
|
36
|
-
"@talismn/
|
37
|
-
"@talismn/
|
38
|
-
"@talismn/chain-connector-evm": "0.
|
39
|
-
"@talismn/token-rates": "
|
40
|
-
"@talismn/util": "0.
|
33
|
+
"@talismn/balances": "0.9.1",
|
34
|
+
"@talismn/chain-connector": "0.10.0",
|
35
|
+
"@talismn/chaindata-provider": "0.10.0",
|
36
|
+
"@talismn/connection-meta": "0.2.6",
|
37
|
+
"@talismn/scale": "0.1.1",
|
38
|
+
"@talismn/chain-connector-evm": "0.10.0",
|
39
|
+
"@talismn/token-rates": "2.0.1",
|
40
|
+
"@talismn/util": "0.4.0"
|
41
41
|
},
|
42
42
|
"devDependencies": {
|
43
43
|
"@types/jest": "^29.5.14",
|