@metamask/assets-controller 3.0.0 → 3.1.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 +21 -1
- package/dist/AssetsController-method-action-types.cjs +1 -1
- package/dist/AssetsController-method-action-types.cjs.map +1 -1
- package/dist/AssetsController-method-action-types.d.cts +1 -1
- package/dist/AssetsController-method-action-types.d.mts +1 -1
- package/dist/AssetsController-method-action-types.mjs +1 -1
- package/dist/AssetsController-method-action-types.mjs.map +1 -1
- package/dist/data-sources/RpcDataSource.cjs +37 -35
- package/dist/data-sources/RpcDataSource.cjs.map +1 -1
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -1
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -1
- package/dist/data-sources/RpcDataSource.mjs +37 -35
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.cjs +3 -6
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.mjs +1 -4
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/index.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/index.d.cts +1 -1
- package/dist/data-sources/evm-rpc-services/index.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/index.d.mts +1 -1
- package/dist/data-sources/evm-rpc-services/index.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/index.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs +104 -79
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.cts +20 -8
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.mts +20 -8
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs +102 -77
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.cjs +4 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.mjs +4 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/assets.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/assets.d.cts +2 -2
- package/dist/data-sources/evm-rpc-services/types/assets.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/assets.d.mts +2 -2
- package/dist/data-sources/evm-rpc-services/types/assets.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/assets.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/index.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/index.d.cts +1 -1
- package/dist/data-sources/evm-rpc-services/types/index.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/index.d.mts +1 -1
- package/dist/data-sources/evm-rpc-services/types/index.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/index.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/services.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/services.d.cts +11 -19
- package/dist/data-sources/evm-rpc-services/types/services.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/services.d.mts +11 -19
- package/dist/data-sources/evm-rpc-services/types/services.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/services.mjs.map +1 -1
- package/dist/utils/constants.cjs +5 -0
- package/dist/utils/constants.cjs.map +1 -0
- package/dist/utils/constants.d.cts +2 -0
- package/dist/utils/constants.d.cts.map +1 -0
- package/dist/utils/constants.d.mts +2 -0
- package/dist/utils/constants.d.mts.map +1 -0
- package/dist/utils/constants.mjs +2 -0
- package/dist/utils/constants.mjs.map +1 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [3.1.1]
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Refactored `BalanceFetcher` and `RpcDataSource` to ensure the correct `assetId` is used for EVM native assets that are not ETH ([#8284](https://github.com/MetaMask/core/pull/8284))
|
|
15
|
+
|
|
16
|
+
## [3.1.0]
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- EVM RPC balance pipeline (`RpcDataSource`, `BalanceFetcher`, `TokenDetector`) no longer falls back to 18 decimals for ERC-20 when decimals are unknown; human-readable balances and `detectedBalances` entries are omitted until decimals are available from state, token list metadata, or on-chain `decimals()` (native token handling unchanged) ([#8267](https://github.com/MetaMask/core/pull/8267))
|
|
21
|
+
- Bump `@metamask/keyring-api` from `^21.5.0` to `^21.6.0` ([#8259](https://github.com/MetaMask/core/pull/8259))
|
|
22
|
+
- Bump `@metamask/transaction-controller` from `^63.0.0` to `^63.1.0` ([#8272](https://github.com/MetaMask/core/pull/8272))
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- fix: move `selectedAccountGroup` to top-level persisted state ([#8245](https://github.com/MetaMask/core/pull/8245))
|
|
27
|
+
|
|
10
28
|
## [3.0.0]
|
|
11
29
|
|
|
12
30
|
### Added
|
|
@@ -190,7 +208,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
190
208
|
- Refactor `RpcDataSource` to delegate polling to `BalanceFetcher` and `TokenDetector` services ([#7709](https://github.com/MetaMask/core/pull/7709))
|
|
191
209
|
- Refactor `BalanceFetcher` and `TokenDetector` to extend `StaticIntervalPollingControllerOnly` for independent polling management ([#7709](https://github.com/MetaMask/core/pull/7709))
|
|
192
210
|
|
|
193
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@3.
|
|
211
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@3.1.1...HEAD
|
|
212
|
+
[3.1.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@3.1.0...@metamask/assets-controller@3.1.1
|
|
213
|
+
[3.1.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@3.0.0...@metamask/assets-controller@3.1.0
|
|
194
214
|
[3.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@2.4.0...@metamask/assets-controller@3.0.0
|
|
195
215
|
[2.4.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@2.3.0...@metamask/assets-controller@2.4.0
|
|
196
216
|
[2.3.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@2.2.0...@metamask/assets-controller@2.3.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController-method-action-types.cjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated
|
|
1
|
+
{"version":3,"file":"AssetsController-method-action-types.cjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController';\n\nexport type AssetsControllerGetAssetsAction = {\n type: `AssetsController:getAssets`;\n handler: AssetsController['getAssets'];\n};\n\nexport type AssetsControllerGetAssetsBalanceAction = {\n type: `AssetsController:getAssetsBalance`;\n handler: AssetsController['getAssetsBalance'];\n};\n\nexport type AssetsControllerGetAssetMetadataAction = {\n type: `AssetsController:getAssetMetadata`;\n handler: AssetsController['getAssetMetadata'];\n};\n\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\n};\n\n/**\n * Returns exchange rates in the format expected by the bridge controller\n * (conversionRates, currencyRates, marketData, currentCurrency) so that\n * when useAssetsControllerForRates is true the bridge can use a single\n * action instead of MultichainAssetsRatesController, TokenRatesController,\n * and CurrencyRateController.\n *\n * @returns Bridge-compatible exchange rate state derived from assetsPrice and selectedCurrency.\n */\nexport type AssetsControllerGetExchangeRatesForBridgeAction = {\n type: `AssetsController:getExchangeRatesForBridge`;\n handler: AssetsController['getExchangeRatesForBridge'];\n};\n\n/**\n * Returns state in the legacy format expected by transaction-pay-controller\n * (TokenBalancesController, AccountTrackerController, TokensController,\n * TokenRatesController, CurrencyRateController shapes) so that when\n * useAssetsController is true the transaction-pay-controller can use a\n * single action instead of five separate getState calls.\n *\n * @returns Legacy-compatible state for transaction-pay-controller.\n */\nexport type AssetsControllerGetStateForTransactionPayAction = {\n type: `AssetsController:getStateForTransactionPay`;\n handler: AssetsController['getStateForTransactionPay'];\n};\n\n/**\n * Add a custom asset for an account.\n * Custom assets are included in subscription and fetch operations.\n * Adding a custom asset also unhides it if it was previously hidden.\n *\n * When `pendingMetadata` is provided (e.g. from the extension's pending-tokens\n * flow), the token metadata is persisted immediately into `assetsInfo` so the\n * UI can render it without waiting for the next pipeline fetch.\n *\n * @param accountId - The account ID to add the custom asset for.\n * @param assetId - The CAIP-19 asset ID to add.\n * @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).\n */\nexport type AssetsControllerAddCustomAssetAction = {\n type: `AssetsController:addCustomAsset`;\n handler: AssetsController['addCustomAsset'];\n};\n\n/**\n * Remove a custom asset from an account.\n *\n * @param accountId - The account ID to remove the custom asset from.\n * @param assetId - The CAIP-19 asset ID to remove.\n */\nexport type AssetsControllerRemoveCustomAssetAction = {\n type: `AssetsController:removeCustomAsset`;\n handler: AssetsController['removeCustomAsset'];\n};\n\n/**\n * Get all custom assets for an account.\n *\n * @param accountId - The account ID to get custom assets for.\n * @returns Array of CAIP-19 asset IDs for the account's custom assets.\n */\nexport type AssetsControllerGetCustomAssetsAction = {\n type: `AssetsController:getCustomAssets`;\n handler: AssetsController['getCustomAssets'];\n};\n\n/**\n * Hide an asset globally.\n * Hidden assets are excluded from the asset list returned by getAssets.\n * The hidden state is stored in assetPreferences.\n *\n * @param assetId - The CAIP-19 asset ID to hide.\n */\nexport type AssetsControllerHideAssetAction = {\n type: `AssetsController:hideAsset`;\n handler: AssetsController['hideAsset'];\n};\n\n/**\n * Unhide an asset globally.\n *\n * @param assetId - The CAIP-19 asset ID to unhide.\n */\nexport type AssetsControllerUnhideAssetAction = {\n type: `AssetsController:unhideAsset`;\n handler: AssetsController['unhideAsset'];\n};\n\n/**\n * Union of all AssetsController action types.\n */\nexport type AssetsControllerMethodActions =\n | AssetsControllerGetAssetsAction\n | AssetsControllerGetAssetsBalanceAction\n | AssetsControllerGetAssetMetadataAction\n | AssetsControllerGetAssetsPriceAction\n | AssetsControllerGetExchangeRatesForBridgeAction\n | AssetsControllerGetStateForTransactionPayAction\n | AssetsControllerAddCustomAssetAction\n | AssetsControllerRemoveCustomAssetAction\n | AssetsControllerGetCustomAssetsAction\n | AssetsControllerHideAssetAction\n | AssetsControllerUnhideAssetAction;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController-method-action-types.mjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated
|
|
1
|
+
{"version":3,"file":"AssetsController-method-action-types.mjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController';\n\nexport type AssetsControllerGetAssetsAction = {\n type: `AssetsController:getAssets`;\n handler: AssetsController['getAssets'];\n};\n\nexport type AssetsControllerGetAssetsBalanceAction = {\n type: `AssetsController:getAssetsBalance`;\n handler: AssetsController['getAssetsBalance'];\n};\n\nexport type AssetsControllerGetAssetMetadataAction = {\n type: `AssetsController:getAssetMetadata`;\n handler: AssetsController['getAssetMetadata'];\n};\n\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\n};\n\n/**\n * Returns exchange rates in the format expected by the bridge controller\n * (conversionRates, currencyRates, marketData, currentCurrency) so that\n * when useAssetsControllerForRates is true the bridge can use a single\n * action instead of MultichainAssetsRatesController, TokenRatesController,\n * and CurrencyRateController.\n *\n * @returns Bridge-compatible exchange rate state derived from assetsPrice and selectedCurrency.\n */\nexport type AssetsControllerGetExchangeRatesForBridgeAction = {\n type: `AssetsController:getExchangeRatesForBridge`;\n handler: AssetsController['getExchangeRatesForBridge'];\n};\n\n/**\n * Returns state in the legacy format expected by transaction-pay-controller\n * (TokenBalancesController, AccountTrackerController, TokensController,\n * TokenRatesController, CurrencyRateController shapes) so that when\n * useAssetsController is true the transaction-pay-controller can use a\n * single action instead of five separate getState calls.\n *\n * @returns Legacy-compatible state for transaction-pay-controller.\n */\nexport type AssetsControllerGetStateForTransactionPayAction = {\n type: `AssetsController:getStateForTransactionPay`;\n handler: AssetsController['getStateForTransactionPay'];\n};\n\n/**\n * Add a custom asset for an account.\n * Custom assets are included in subscription and fetch operations.\n * Adding a custom asset also unhides it if it was previously hidden.\n *\n * When `pendingMetadata` is provided (e.g. from the extension's pending-tokens\n * flow), the token metadata is persisted immediately into `assetsInfo` so the\n * UI can render it without waiting for the next pipeline fetch.\n *\n * @param accountId - The account ID to add the custom asset for.\n * @param assetId - The CAIP-19 asset ID to add.\n * @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).\n */\nexport type AssetsControllerAddCustomAssetAction = {\n type: `AssetsController:addCustomAsset`;\n handler: AssetsController['addCustomAsset'];\n};\n\n/**\n * Remove a custom asset from an account.\n *\n * @param accountId - The account ID to remove the custom asset from.\n * @param assetId - The CAIP-19 asset ID to remove.\n */\nexport type AssetsControllerRemoveCustomAssetAction = {\n type: `AssetsController:removeCustomAsset`;\n handler: AssetsController['removeCustomAsset'];\n};\n\n/**\n * Get all custom assets for an account.\n *\n * @param accountId - The account ID to get custom assets for.\n * @returns Array of CAIP-19 asset IDs for the account's custom assets.\n */\nexport type AssetsControllerGetCustomAssetsAction = {\n type: `AssetsController:getCustomAssets`;\n handler: AssetsController['getCustomAssets'];\n};\n\n/**\n * Hide an asset globally.\n * Hidden assets are excluded from the asset list returned by getAssets.\n * The hidden state is stored in assetPreferences.\n *\n * @param assetId - The CAIP-19 asset ID to hide.\n */\nexport type AssetsControllerHideAssetAction = {\n type: `AssetsController:hideAsset`;\n handler: AssetsController['hideAsset'];\n};\n\n/**\n * Unhide an asset globally.\n *\n * @param assetId - The CAIP-19 asset ID to unhide.\n */\nexport type AssetsControllerUnhideAssetAction = {\n type: `AssetsController:unhideAsset`;\n handler: AssetsController['unhideAsset'];\n};\n\n/**\n * Union of all AssetsController action types.\n */\nexport type AssetsControllerMethodActions =\n | AssetsControllerGetAssetsAction\n | AssetsControllerGetAssetsBalanceAction\n | AssetsControllerGetAssetMetadataAction\n | AssetsControllerGetAssetsPriceAction\n | AssetsControllerGetExchangeRatesForBridgeAction\n | AssetsControllerGetStateForTransactionPayAction\n | AssetsControllerAddCustomAssetAction\n | AssetsControllerRemoveCustomAssetAction\n | AssetsControllerGetCustomAssetsAction\n | AssetsControllerHideAssetAction\n | AssetsControllerUnhideAssetAction;\n"]}
|
|
@@ -24,6 +24,7 @@ const AbstractDataSource_1 = require("./AbstractDataSource.cjs");
|
|
|
24
24
|
const evm_rpc_services_1 = require("./evm-rpc-services/index.cjs");
|
|
25
25
|
const logger_1 = require("../logger.cjs");
|
|
26
26
|
const utils_2 = require("../utils/index.cjs");
|
|
27
|
+
const constants_1 = require("../utils/constants.cjs");
|
|
27
28
|
const CONTROLLER_NAME = 'RpcDataSource';
|
|
28
29
|
const DEFAULT_BALANCE_INTERVAL = 30000; // 30 seconds
|
|
29
30
|
const DEFAULT_DETECTION_INTERVAL = 180000; // 3 minutes
|
|
@@ -211,16 +212,28 @@ class RpcDataSource extends AbstractDataSource_1.AbstractDataSource {
|
|
|
211
212
|
const { address, id: accountId } = account;
|
|
212
213
|
for (const chainId of chainsForAccount) {
|
|
213
214
|
const hexChainId = (0, exports.caipChainIdToHex)(chainId);
|
|
214
|
-
//
|
|
215
|
-
const
|
|
215
|
+
// Build a single AssetFetchEntry[] for native + custom ERC-20s
|
|
216
|
+
const nativeAssetId = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_buildNativeAssetId).call(this, chainId);
|
|
217
|
+
const assetsToFetch = [
|
|
218
|
+
{ assetId: nativeAssetId, address: constants_1.ZERO_ADDRESS },
|
|
219
|
+
];
|
|
216
220
|
if (request.customAssets) {
|
|
221
|
+
const existingMetadata = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getExistingAssetsMetadata).call(this);
|
|
217
222
|
for (const assetId of request.customAssets) {
|
|
218
223
|
try {
|
|
219
224
|
const parsed = (0, utils_1.parseCaipAssetType)(assetId);
|
|
220
225
|
const assetChainId = `${parsed.chain.namespace}:${parsed.chain.reference}`;
|
|
221
226
|
if (assetChainId === chainId &&
|
|
222
227
|
parsed.assetNamespace === 'erc20') {
|
|
223
|
-
|
|
228
|
+
const tokenAddress = parsed.assetReference.toLowerCase();
|
|
229
|
+
const normalizedId = (0, utils_2.normalizeAssetId)(assetId);
|
|
230
|
+
const decimals = existingMetadata[normalizedId]?.decimals ??
|
|
231
|
+
__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getTokenMetadataFromTokenList).call(this, normalizedId)?.decimals;
|
|
232
|
+
assetsToFetch.push({
|
|
233
|
+
assetId,
|
|
234
|
+
address: tokenAddress,
|
|
235
|
+
decimals,
|
|
236
|
+
});
|
|
224
237
|
}
|
|
225
238
|
}
|
|
226
239
|
catch {
|
|
@@ -229,8 +242,7 @@ class RpcDataSource extends AbstractDataSource_1.AbstractDataSource {
|
|
|
229
242
|
}
|
|
230
243
|
}
|
|
231
244
|
try {
|
|
232
|
-
|
|
233
|
-
const result = await __classPrivateFieldGet(this, _RpcDataSource_balanceFetcher, "f").fetchBalancesForTokens(hexChainId, accountId, address, customTokenAddresses, { includeNative: true });
|
|
245
|
+
const result = await __classPrivateFieldGet(this, _RpcDataSource_balanceFetcher, "f").fetchBalancesForAssets(hexChainId, accountId, address, assetsToFetch);
|
|
234
246
|
if (!assetsBalance[accountId]) {
|
|
235
247
|
assetsBalance[accountId] = {};
|
|
236
248
|
}
|
|
@@ -245,7 +257,7 @@ class RpcDataSource extends AbstractDataSource_1.AbstractDataSource {
|
|
|
245
257
|
Object.assign(assetsInfo, balanceMetadata);
|
|
246
258
|
// Convert balances to human-readable format using decimals from
|
|
247
259
|
// assetsInfo state (which includes pendingMetadata from addCustomAsset).
|
|
248
|
-
//
|
|
260
|
+
// Resolution: state → pipeline metadata → RPC `decimals()`; omit balance if still unknown.
|
|
249
261
|
const existingMetadata = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getExistingAssetsMetadata).call(this);
|
|
250
262
|
for (const balance of normalizedBalances) {
|
|
251
263
|
const stateMetadata = existingMetadata[balance.assetId];
|
|
@@ -257,8 +269,10 @@ class RpcDataSource extends AbstractDataSource_1.AbstractDataSource {
|
|
|
257
269
|
decimals = await __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_fetchDecimalsViaRpc).call(this, chainId, parsed.assetReference);
|
|
258
270
|
}
|
|
259
271
|
}
|
|
260
|
-
|
|
261
|
-
|
|
272
|
+
if (decimals === undefined) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const humanReadableAmount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_convertToHumanReadable).call(this, balance.balance, decimals);
|
|
262
276
|
assetsBalance[accountId][balance.assetId] = {
|
|
263
277
|
amount: humanReadableAmount,
|
|
264
278
|
};
|
|
@@ -269,7 +283,6 @@ class RpcDataSource extends AbstractDataSource_1.AbstractDataSource {
|
|
|
269
283
|
if (!assetsBalance[accountId]) {
|
|
270
284
|
assetsBalance[accountId] = {};
|
|
271
285
|
}
|
|
272
|
-
const nativeAssetId = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_buildNativeAssetId).call(this, chainId);
|
|
273
286
|
assetsBalance[accountId][nativeAssetId] = { amount: '0' };
|
|
274
287
|
// Even on error, include native token metadata
|
|
275
288
|
const chainStatus = __classPrivateFieldGet(this, _RpcDataSource_chainStatuses, "f")[chainId];
|
|
@@ -356,9 +369,10 @@ class RpcDataSource extends AbstractDataSource_1.AbstractDataSource {
|
|
|
356
369
|
// Add balances for detected tokens (converted to human-readable format)
|
|
357
370
|
for (const balance of result.detectedBalances) {
|
|
358
371
|
const detectedAsset = result.detectedAssets.find((asset) => asset.assetId === balance.assetId);
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
372
|
+
if (detectedAsset?.decimals === undefined) {
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
const humanReadableAmount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_convertToHumanReadable).call(this, balance.balance, detectedAsset.decimals);
|
|
362
376
|
balances[balance.assetId] = {
|
|
363
377
|
amount: humanReadableAmount,
|
|
364
378
|
};
|
|
@@ -556,7 +570,7 @@ exports.RpcDataSource = RpcDataSource;
|
|
|
556
570
|
_RpcDataSource_messenger = new WeakMap(), _RpcDataSource_onActiveChainsUpdated = new WeakMap(), _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = new WeakMap(), _RpcDataSource_useExternalService = new WeakMap(), _RpcDataSource_activeChains = new WeakMap(), _RpcDataSource_chainStatuses = new WeakMap(), _RpcDataSource_providerCache = new WeakMap(), _RpcDataSource_activeSubscriptions = new WeakMap(), _RpcDataSource_unsubscribeTransactionConfirmed = new WeakMap(), _RpcDataSource_unsubscribeIncomingTransactions = new WeakMap(), _RpcDataSource_multicallClient = new WeakMap(), _RpcDataSource_balanceFetcher = new WeakMap(), _RpcDataSource_tokenDetector = new WeakMap(), _RpcDataSource_instances = new WeakSet(), _RpcDataSource_convertToHumanReadable = function _RpcDataSource_convertToHumanReadable(rawBalance, decimals) {
|
|
557
571
|
const rawAmount = new bignumber_js_1.default(rawBalance);
|
|
558
572
|
const divisor = new bignumber_js_1.default(10).pow(decimals);
|
|
559
|
-
return rawAmount.dividedBy(divisor).
|
|
573
|
+
return rawAmount.dividedBy(divisor).toFixed();
|
|
560
574
|
}, _RpcDataSource_collectMetadataForBalances = function _RpcDataSource_collectMetadataForBalances(balances, chainId) {
|
|
561
575
|
const assetsInfo = {};
|
|
562
576
|
const existingMetadata = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getExistingAssetsMetadata).call(this);
|
|
@@ -585,17 +599,8 @@ _RpcDataSource_messenger = new WeakMap(), _RpcDataSource_onActiveChainsUpdated =
|
|
|
585
599
|
if (tokenListMeta) {
|
|
586
600
|
assetsInfo[balance.assetId] = tokenListMeta;
|
|
587
601
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
// Use 18 decimals (the standard for most ERC20 tokens)
|
|
591
|
-
// to ensure consistent human-readable balance format.
|
|
592
|
-
assetsInfo[balance.assetId] = {
|
|
593
|
-
type: 'erc20',
|
|
594
|
-
symbol: '',
|
|
595
|
-
name: '',
|
|
596
|
-
decimals: 18,
|
|
597
|
-
};
|
|
598
|
-
}
|
|
602
|
+
// Unknown ERC-20: omit from assetsInfo until decimals are known.
|
|
603
|
+
// #handleBalanceUpdate resolves decimals via RPC or omits the balance.
|
|
599
604
|
}
|
|
600
605
|
}
|
|
601
606
|
}
|
|
@@ -619,20 +624,16 @@ async function _RpcDataSource_handleBalanceUpdate(result) {
|
|
|
619
624
|
// Collect metadata for all balances
|
|
620
625
|
const assetsInfo = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_collectMetadataForBalances).call(this, normalizedBalances, caipChainId);
|
|
621
626
|
// Convert balances to human-readable format.
|
|
622
|
-
//
|
|
627
|
+
// Resolution: state metadata → pipeline metadata; skip if decimals unknown.
|
|
623
628
|
const existingMetadata = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getExistingAssetsMetadata).call(this);
|
|
624
629
|
for (const balance of normalizedBalances) {
|
|
625
630
|
const stateMetadata = existingMetadata[balance.assetId];
|
|
626
631
|
const pipelineMetadata = assetsInfo[balance.assetId];
|
|
627
|
-
|
|
632
|
+
const decimals = stateMetadata?.decimals ?? pipelineMetadata?.decimals;
|
|
628
633
|
if (decimals === undefined) {
|
|
629
|
-
|
|
630
|
-
if (parsed.assetNamespace === 'erc20') {
|
|
631
|
-
decimals = await __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_fetchDecimalsViaRpc).call(this, caipChainId, parsed.assetReference);
|
|
632
|
-
}
|
|
634
|
+
continue;
|
|
633
635
|
}
|
|
634
|
-
const
|
|
635
|
-
const humanReadableAmount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_convertToHumanReadable).call(this, balance.balance, resolvedDecimals);
|
|
636
|
+
const humanReadableAmount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_convertToHumanReadable).call(this, balance.balance, decimals);
|
|
636
637
|
newBalances[balance.assetId] = {
|
|
637
638
|
amount: humanReadableAmount,
|
|
638
639
|
};
|
|
@@ -686,9 +687,10 @@ async function _RpcDataSource_handleBalanceUpdate(result) {
|
|
|
686
687
|
for (const balance of result.detectedBalances) {
|
|
687
688
|
// Get decimals from the detected asset metadata
|
|
688
689
|
const detectedAsset = result.detectedAssets.find((asset) => asset.assetId === balance.assetId);
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
690
|
+
if (detectedAsset?.decimals === undefined) {
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
const humanReadableAmount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_convertToHumanReadable).call(this, balance.balance, detectedAsset.decimals);
|
|
692
694
|
newBalances[balance.assetId] = {
|
|
693
695
|
amount: humanReadableAmount,
|
|
694
696
|
};
|