@metamask-previews/assets-controller 3.0.0-preview-f34c64d70 → 3.0.0-preview-b9ae764
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 +2 -0
- 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 -31
- 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 -31
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs +22 -8
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs.map +1 -1
- 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.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs +22 -8
- 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/services.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/services.d.cts +2 -2
- 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 +2 -2
- 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/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- 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))
|
|
12
13
|
- Bump `@metamask/keyring-api` from `^21.5.0` to `^21.6.0` ([#8259](https://github.com/MetaMask/core/pull/8259))
|
|
14
|
+
- Bump `@metamask/transaction-controller` from `^63.0.0` to `^63.1.0` ([#8272](https://github.com/MetaMask/core/pull/8272))
|
|
13
15
|
|
|
14
16
|
## [3.0.0]
|
|
15
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* This file is auto generated by
|
|
3
|
+
* This file is auto generated by `@metamask/messenger/generate-action-types`.
|
|
4
4
|
* Do not edit manually.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -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 by
|
|
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 by `@metamask/messenger/generate-action-types`.\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 by
|
|
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 by `@metamask/messenger/generate-action-types`.\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"]}
|
|
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _RpcDataSource_instances, _RpcDataSource_messenger, _RpcDataSource_onActiveChainsUpdated, _RpcDataSource_timeout, _RpcDataSource_tokenDetectionEnabled, _RpcDataSource_useExternalService, _RpcDataSource_activeChains, _RpcDataSource_chainStatuses, _RpcDataSource_providerCache, _RpcDataSource_activeSubscriptions, _RpcDataSource_unsubscribeTransactionConfirmed, _RpcDataSource_unsubscribeIncomingTransactions, _RpcDataSource_multicallClient, _RpcDataSource_balanceFetcher, _RpcDataSource_tokenDetector, _RpcDataSource_convertToHumanReadable, _RpcDataSource_collectMetadataForBalances, _RpcDataSource_handleBalanceUpdate, _RpcDataSource_handleDetectionUpdate, _RpcDataSource_subscribeToNetworkController, _RpcDataSource_subscribeToTransactionEvents, _RpcDataSource_onTransactionConfirmed, _RpcDataSource_onIncomingTransactions, _RpcDataSource_refreshBalanceForChains, _RpcDataSource_initializeFromNetworkController, _RpcDataSource_updateFromNetworkState, _RpcDataSource_getProvider, _RpcDataSource_getMulticallProvider, _RpcDataSource_clearProviderCache, _RpcDataSource_fetchDecimalsViaRpc, _RpcDataSource_buildNativeAssetId, _RpcDataSource_getExistingAssetsMetadata, _RpcDataSource_getTokenMetadataFromTokenList;
|
|
16
|
+
var _RpcDataSource_instances, _RpcDataSource_messenger, _RpcDataSource_onActiveChainsUpdated, _RpcDataSource_timeout, _RpcDataSource_tokenDetectionEnabled, _RpcDataSource_useExternalService, _RpcDataSource_activeChains, _RpcDataSource_chainStatuses, _RpcDataSource_providerCache, _RpcDataSource_activeSubscriptions, _RpcDataSource_unsubscribeTransactionConfirmed, _RpcDataSource_unsubscribeIncomingTransactions, _RpcDataSource_multicallClient, _RpcDataSource_balanceFetcher, _RpcDataSource_tokenDetector, _RpcDataSource_convertToHumanReadable, _RpcDataSource_collectMetadataForBalances, _RpcDataSource_handleBalanceUpdate, _RpcDataSource_handleDetectionUpdate, _RpcDataSource_subscribeToNetworkController, _RpcDataSource_subscribeToTransactionEvents, _RpcDataSource_onTransactionConfirmed, _RpcDataSource_onIncomingTransactions, _RpcDataSource_refreshBalanceForChains, _RpcDataSource_initializeFromNetworkController, _RpcDataSource_updateFromNetworkState, _RpcDataSource_getProvider, _RpcDataSource_getMulticallProvider, _RpcDataSource_clearProviderCache, _RpcDataSource_fetchDecimalsViaRpc, _RpcDataSource_buildNativeAssetId, _RpcDataSource_tokenFetchInfosForCustomErc20s, _RpcDataSource_getExistingAssetsMetadata, _RpcDataSource_getTokenMetadataFromTokenList;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.createRpcDataSource = exports.RpcDataSource = exports.caipChainIdToHex = void 0;
|
|
19
19
|
const providers_1 = require("@ethersproject/providers");
|
|
@@ -229,8 +229,9 @@ class RpcDataSource extends AbstractDataSource_1.AbstractDataSource {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
try {
|
|
232
|
+
const tokenInfos = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_tokenFetchInfosForCustomErc20s).call(this, chainId, customTokenAddresses);
|
|
232
233
|
// Use BalanceFetcher for batched balance fetching
|
|
233
|
-
const result = await __classPrivateFieldGet(this, _RpcDataSource_balanceFetcher, "f").fetchBalancesForTokens(hexChainId, accountId, address, customTokenAddresses, { includeNative: true });
|
|
234
|
+
const result = await __classPrivateFieldGet(this, _RpcDataSource_balanceFetcher, "f").fetchBalancesForTokens(hexChainId, accountId, address, customTokenAddresses, { includeNative: true }, tokenInfos);
|
|
234
235
|
if (!assetsBalance[accountId]) {
|
|
235
236
|
assetsBalance[accountId] = {};
|
|
236
237
|
}
|
|
@@ -245,7 +246,7 @@ class RpcDataSource extends AbstractDataSource_1.AbstractDataSource {
|
|
|
245
246
|
Object.assign(assetsInfo, balanceMetadata);
|
|
246
247
|
// Convert balances to human-readable format using decimals from
|
|
247
248
|
// assetsInfo state (which includes pendingMetadata from addCustomAsset).
|
|
248
|
-
//
|
|
249
|
+
// Resolution: state → pipeline metadata → RPC `decimals()`; omit balance if still unknown.
|
|
249
250
|
const existingMetadata = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getExistingAssetsMetadata).call(this);
|
|
250
251
|
for (const balance of normalizedBalances) {
|
|
251
252
|
const stateMetadata = existingMetadata[balance.assetId];
|
|
@@ -257,8 +258,10 @@ class RpcDataSource extends AbstractDataSource_1.AbstractDataSource {
|
|
|
257
258
|
decimals = await __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_fetchDecimalsViaRpc).call(this, chainId, parsed.assetReference);
|
|
258
259
|
}
|
|
259
260
|
}
|
|
260
|
-
|
|
261
|
-
|
|
261
|
+
if (decimals === undefined) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
const humanReadableAmount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_convertToHumanReadable).call(this, balance.balance, decimals);
|
|
262
265
|
assetsBalance[accountId][balance.assetId] = {
|
|
263
266
|
amount: humanReadableAmount,
|
|
264
267
|
};
|
|
@@ -356,9 +359,10 @@ class RpcDataSource extends AbstractDataSource_1.AbstractDataSource {
|
|
|
356
359
|
// Add balances for detected tokens (converted to human-readable format)
|
|
357
360
|
for (const balance of result.detectedBalances) {
|
|
358
361
|
const detectedAsset = result.detectedAssets.find((asset) => asset.assetId === balance.assetId);
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
+
if (detectedAsset?.decimals === undefined) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
const humanReadableAmount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_convertToHumanReadable).call(this, balance.balance, detectedAsset.decimals);
|
|
362
366
|
balances[balance.assetId] = {
|
|
363
367
|
amount: humanReadableAmount,
|
|
364
368
|
};
|
|
@@ -556,7 +560,7 @@ exports.RpcDataSource = RpcDataSource;
|
|
|
556
560
|
_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
561
|
const rawAmount = new bignumber_js_1.default(rawBalance);
|
|
558
562
|
const divisor = new bignumber_js_1.default(10).pow(decimals);
|
|
559
|
-
return rawAmount.dividedBy(divisor).
|
|
563
|
+
return rawAmount.dividedBy(divisor).toFixed();
|
|
560
564
|
}, _RpcDataSource_collectMetadataForBalances = function _RpcDataSource_collectMetadataForBalances(balances, chainId) {
|
|
561
565
|
const assetsInfo = {};
|
|
562
566
|
const existingMetadata = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getExistingAssetsMetadata).call(this);
|
|
@@ -585,17 +589,8 @@ _RpcDataSource_messenger = new WeakMap(), _RpcDataSource_onActiveChainsUpdated =
|
|
|
585
589
|
if (tokenListMeta) {
|
|
586
590
|
assetsInfo[balance.assetId] = tokenListMeta;
|
|
587
591
|
}
|
|
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
|
-
}
|
|
592
|
+
// Unknown ERC-20: omit from assetsInfo until decimals are known.
|
|
593
|
+
// #handleBalanceUpdate resolves decimals via RPC or omits the balance.
|
|
599
594
|
}
|
|
600
595
|
}
|
|
601
596
|
}
|
|
@@ -619,20 +614,16 @@ async function _RpcDataSource_handleBalanceUpdate(result) {
|
|
|
619
614
|
// Collect metadata for all balances
|
|
620
615
|
const assetsInfo = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_collectMetadataForBalances).call(this, normalizedBalances, caipChainId);
|
|
621
616
|
// Convert balances to human-readable format.
|
|
622
|
-
//
|
|
617
|
+
// Resolution: state metadata → pipeline metadata; skip if decimals unknown.
|
|
623
618
|
const existingMetadata = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getExistingAssetsMetadata).call(this);
|
|
624
619
|
for (const balance of normalizedBalances) {
|
|
625
620
|
const stateMetadata = existingMetadata[balance.assetId];
|
|
626
621
|
const pipelineMetadata = assetsInfo[balance.assetId];
|
|
627
|
-
|
|
622
|
+
const decimals = stateMetadata?.decimals ?? pipelineMetadata?.decimals;
|
|
628
623
|
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
|
-
}
|
|
624
|
+
continue;
|
|
633
625
|
}
|
|
634
|
-
const
|
|
635
|
-
const humanReadableAmount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_convertToHumanReadable).call(this, balance.balance, resolvedDecimals);
|
|
626
|
+
const humanReadableAmount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_convertToHumanReadable).call(this, balance.balance, decimals);
|
|
636
627
|
newBalances[balance.assetId] = {
|
|
637
628
|
amount: humanReadableAmount,
|
|
638
629
|
};
|
|
@@ -686,9 +677,10 @@ async function _RpcDataSource_handleBalanceUpdate(result) {
|
|
|
686
677
|
for (const balance of result.detectedBalances) {
|
|
687
678
|
// Get decimals from the detected asset metadata
|
|
688
679
|
const detectedAsset = result.detectedAssets.find((asset) => asset.assetId === balance.assetId);
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
680
|
+
if (detectedAsset?.decimals === undefined) {
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
const humanReadableAmount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_convertToHumanReadable).call(this, balance.balance, detectedAsset.decimals);
|
|
692
684
|
newBalances[balance.assetId] = {
|
|
693
685
|
amount: humanReadableAmount,
|
|
694
686
|
};
|
|
@@ -920,6 +912,20 @@ async function _RpcDataSource_fetchDecimalsViaRpc(chainId, tokenAddress) {
|
|
|
920
912
|
}, _RpcDataSource_buildNativeAssetId = function _RpcDataSource_buildNativeAssetId(chainId) {
|
|
921
913
|
const { nativeAssetIdentifiers } = __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('NetworkEnablementController:getState');
|
|
922
914
|
return nativeAssetIdentifiers[chainId] ?? `${chainId}/slip44:60`;
|
|
915
|
+
}, _RpcDataSource_tokenFetchInfosForCustomErc20s = function _RpcDataSource_tokenFetchInfosForCustomErc20s(caipChainId, tokenAddresses) {
|
|
916
|
+
const existingMetadata = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getExistingAssetsMetadata).call(this);
|
|
917
|
+
const infos = [];
|
|
918
|
+
for (const tokenAddress of tokenAddresses) {
|
|
919
|
+
const { reference } = (0, utils_1.parseCaipChainId)(caipChainId);
|
|
920
|
+
const rawAssetId = `eip155:${reference}/erc20:${tokenAddress.toLowerCase()}`;
|
|
921
|
+
const assetId = (0, utils_2.normalizeAssetId)(rawAssetId);
|
|
922
|
+
const decimals = existingMetadata[assetId]?.decimals ??
|
|
923
|
+
__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getTokenMetadataFromTokenList).call(this, assetId)?.decimals;
|
|
924
|
+
if (decimals !== undefined) {
|
|
925
|
+
infos.push({ address: tokenAddress, decimals });
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
return infos;
|
|
923
929
|
}, _RpcDataSource_getExistingAssetsMetadata = function _RpcDataSource_getExistingAssetsMetadata() {
|
|
924
930
|
try {
|
|
925
931
|
const state = __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('AssetsController:getState');
|