@metamask-previews/assets-controller 11.0.0-preview-924c21f38 → 11.0.0-preview-40d5fb1e2
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 +0 -18
- package/dist/AssetsController-method-action-types.cjs.map +1 -1
- package/dist/AssetsController-method-action-types.d.cts +1 -23
- package/dist/AssetsController-method-action-types.d.cts.map +1 -1
- package/dist/AssetsController-method-action-types.d.mts +1 -23
- package/dist/AssetsController-method-action-types.d.mts.map +1 -1
- package/dist/AssetsController-method-action-types.mjs.map +1 -1
- package/dist/AssetsController.cjs +51 -99
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +1 -21
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +1 -21
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +51 -99
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.cjs +9 -95
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.cts +1 -8
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.mts +1 -8
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.mjs +9 -95
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
- package/dist/data-sources/TokenDataSource.cjs +12 -73
- package/dist/data-sources/TokenDataSource.cjs.map +1 -1
- package/dist/data-sources/TokenDataSource.d.cts +1 -4
- package/dist/data-sources/TokenDataSource.d.cts.map +1 -1
- package/dist/data-sources/TokenDataSource.d.mts +1 -4
- package/dist/data-sources/TokenDataSource.d.mts.map +1 -1
- package/dist/data-sources/TokenDataSource.mjs +12 -73
- package/dist/data-sources/TokenDataSource.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.cjs +27 -86
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.d.cts +3 -4
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.d.mts +3 -4
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.mjs +27 -86
- package/dist/data-sources/evm-rpc-services/clients/TokensApiClient.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/utils/formatExchangeRatesForBridge.cjs +7 -36
- package/dist/utils/formatExchangeRatesForBridge.cjs.map +1 -1
- package/dist/utils/formatExchangeRatesForBridge.d.cts +14 -20
- package/dist/utils/formatExchangeRatesForBridge.d.cts.map +1 -1
- package/dist/utils/formatExchangeRatesForBridge.d.mts +14 -20
- package/dist/utils/formatExchangeRatesForBridge.d.mts.map +1 -1
- package/dist/utils/formatExchangeRatesForBridge.mjs +5 -34
- package/dist/utils/formatExchangeRatesForBridge.mjs.map +1 -1
- package/dist/utils/formatStateForTransactionPay.cjs +9 -40
- package/dist/utils/formatStateForTransactionPay.cjs.map +1 -1
- package/dist/utils/formatStateForTransactionPay.d.cts +17 -23
- package/dist/utils/formatStateForTransactionPay.d.cts.map +1 -1
- package/dist/utils/formatStateForTransactionPay.d.mts +17 -23
- package/dist/utils/formatStateForTransactionPay.d.mts.map +1 -1
- package/dist/utils/formatStateForTransactionPay.mjs +7 -38
- package/dist/utils/formatStateForTransactionPay.mjs.map +1 -1
- package/dist/utils/index.cjs +1 -4
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +5 -5
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +5 -5
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +3 -3
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/normalizeAssetId.cjs +3 -17
- package/dist/utils/normalizeAssetId.cjs.map +1 -1
- package/dist/utils/normalizeAssetId.d.cts +1 -10
- package/dist/utils/normalizeAssetId.d.cts.map +1 -1
- package/dist/utils/normalizeAssetId.d.mts +1 -10
- package/dist/utils/normalizeAssetId.d.mts.map +1 -1
- package/dist/utils/normalizeAssetId.mjs +1 -19
- package/dist/utils/normalizeAssetId.mjs.map +1 -1
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,27 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- `AccountsApiDataSource` now selects the Accounts API balances endpoint version from the `RemoteFeatureFlagController` (`assetsAccountsApiV6` flag, read per fetch off the shared messenger, default v5) so the v6 endpoint is gated consistently across clients (extension, mobile) without each client wiring a getter. The flag is read as a JSON variation shaped `{ value: boolean }` (same shape as `backendWebSocketConnection`). Adds a required `messenger` option and `RemoteFeatureFlagController:getState` to `AccountsApiDataSourceAllowedActions`. Only `category: 'token'` rows from the v6 response are consumed (DeFi positions are ignored) to preserve parity with v5 ([#9344](https://github.com/MetaMask/core/pull/9344))
|
|
13
|
-
- Add `getAsset(accountId, assetId)` method and `AssetsController:getAsset` messenger action that returns the combined `Asset` (balance, metadata, price) for a single account/asset pair from controller state, or `undefined` when a complete renderable asset is not available ([#9521](https://github.com/MetaMask/core/pull/9521))
|
|
14
|
-
|
|
15
10
|
### Changed
|
|
16
11
|
|
|
17
|
-
- Persist `assetsPrice` in `AssetsController` state so last-known prices survive app restart / state rehydration (refreshed on the next price fetch via existing `PriceDataSource` TTL) ([#9566](https://github.com/MetaMask/core/pull/9566))
|
|
18
|
-
- Memoize hot-path asset ID / legacy-format conversions to cut repeated keccak256 (`toChecksumAddress`) and CAIP parsing ([#9555](https://github.com/MetaMask/core/pull/9555))
|
|
19
|
-
- `normalizeAssetId` uses lodash `memoize` so already-normalized IDs skip re-checksumming across the pipeline
|
|
20
|
-
- `formatExchangeRatesForBridge` caches the last result on input identity (`===` for BaseController slices, lodash `isEqual` for rebuilt native maps); exports `FormatExchangeRatesForBridgeParams`
|
|
21
|
-
- `formatStateForTransactionPay` caches the last result the same way (`isEqual` for rebuilt `accounts` / `nativeAssetIdentifiers`); exports `FormatStateForTransactionPayParams`
|
|
22
|
-
- `#getNativeAssetMap` returns a stable empty object when uncached so memoized formatters are not busted by `?? {}` identity churn
|
|
23
|
-
- `TokenDataSource` EVM spam filtering now uses per-chain floors from Token API `GET /v1/suggestedOccurrenceFloors` (`queryApiClient.token.fetchV1SuggestedOccurrenceFloors`) instead of a hardcoded minimum of 3 occurrences. Chains missing from the response (or a failed floors fetch) still fall back to 3 ([#9537](https://github.com/MetaMask/core/pull/9537))
|
|
24
|
-
- `TokensApiClient` (used by `RpcDataSource` / `TokenDetector`) now sets the token-list `occurrenceFloor` query param from the same Token API `GET /v1/suggestedOccurrenceFloors` endpoint (cached 1h), replacing the hardcoded Linea/MegaETH/Tempo special cases. Missing chains or failed fetches fall back to 3 ([#9537](https://github.com/MetaMask/core/pull/9537))
|
|
25
12
|
- Bump `@metamask/network-enablement-controller` from `^5.5.0` to `^5.6.0` ([#9520](https://github.com/MetaMask/core/pull/9520))
|
|
26
|
-
- Bump `@metamask/phishing-controller` from `^17.2.1` to `^17.3.0` ([#9532](https://github.com/MetaMask/core/pull/9532))
|
|
27
|
-
|
|
28
|
-
### Fixed
|
|
29
|
-
|
|
30
|
-
- `TokenDataSource` now also fetches token metadata for assets present in `assetsBalance` that are missing `assetsInfo` (previously only detected assets without metadata were enriched) ([#9547](https://github.com/MetaMask/core/pull/9547))
|
|
31
13
|
|
|
32
14
|
## [11.0.0]
|
|
33
15
|
|
|
@@ -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.\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\
|
|
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 * Set the current currency.\n *\n * @param selectedCurrency - The ISO 4217 currency code to set.\n */\nexport type AssetsControllerSetSelectedCurrencyAction = {\n type: `AssetsController:setSelectedCurrency`;\n handler: AssetsController['setSelectedCurrency'];\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 | AssetsControllerSetSelectedCurrencyAction;\n"]}
|
|
@@ -15,28 +15,6 @@ export type AssetsControllerGetAssetMetadataAction = {
|
|
|
15
15
|
type: `AssetsController:getAssetMetadata`;
|
|
16
16
|
handler: AssetsController['getAssetMetadata'];
|
|
17
17
|
};
|
|
18
|
-
/**
|
|
19
|
-
* Get a single combined asset (balance + metadata + price + computed
|
|
20
|
-
* `fiatValue`) for an account directly from controller state.
|
|
21
|
-
*
|
|
22
|
-
* Reuses the same state-composition and filtering logic as `getAssets`
|
|
23
|
-
* (balance and metadata are required, a missing price falls back to
|
|
24
|
-
* `{ price: 0, lastUpdated: 0 }` with `fiatValue: 0`, and hidden or
|
|
25
|
-
* otherwise filtered assets are excluded) so the returned shape never
|
|
26
|
-
* drifts from `getAssets`. Reads from current state only and does not
|
|
27
|
-
* trigger a data-source refresh.
|
|
28
|
-
*
|
|
29
|
-
* @param accountId - The account ID (`InternalAccount.id`, not an address).
|
|
30
|
-
* @param assetId - The CAIP-19 asset ID including chain scope
|
|
31
|
-
* (e.g. `eip155:1/erc20:0x...`).
|
|
32
|
-
* @returns The combined `Asset`, or `undefined` when no complete
|
|
33
|
-
* renderable asset (balance + metadata) exists for the account/asset pair.
|
|
34
|
-
* @throws If `accountId` is empty or `assetId` is not a valid CAIP-19 asset ID.
|
|
35
|
-
*/
|
|
36
|
-
export type AssetsControllerGetAssetAction = {
|
|
37
|
-
type: `AssetsController:getAsset`;
|
|
38
|
-
handler: AssetsController['getAsset'];
|
|
39
|
-
};
|
|
40
18
|
export type AssetsControllerGetAssetsPriceAction = {
|
|
41
19
|
type: `AssetsController:getAssetsPrice`;
|
|
42
20
|
handler: AssetsController['getAssetsPrice'];
|
|
@@ -136,5 +114,5 @@ export type AssetsControllerSetSelectedCurrencyAction = {
|
|
|
136
114
|
/**
|
|
137
115
|
* Union of all AssetsController action types.
|
|
138
116
|
*/
|
|
139
|
-
export type AssetsControllerMethodActions = AssetsControllerGetAssetsAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction |
|
|
117
|
+
export type AssetsControllerMethodActions = AssetsControllerGetAssetsAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction | AssetsControllerGetAssetsPriceAction | AssetsControllerGetExchangeRatesForBridgeAction | AssetsControllerGetStateForTransactionPayAction | AssetsControllerAddCustomAssetAction | AssetsControllerRemoveCustomAssetAction | AssetsControllerGetCustomAssetsAction | AssetsControllerHideAssetAction | AssetsControllerUnhideAssetAction | AssetsControllerSetSelectedCurrencyAction;
|
|
140
118
|
//# sourceMappingURL=AssetsController-method-action-types.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"AssetsController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,gBAAgB,CAAC,2BAA2B,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,gBAAgB,CAAC,2BAA2B,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,+BAA+B,GAC/B,sCAAsC,GACtC,sCAAsC,GACtC,oCAAoC,GACpC,+CAA+C,GAC/C,+CAA+C,GAC/C,oCAAoC,GACpC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA+B,GAC/B,iCAAiC,GACjC,yCAAyC,CAAC"}
|
|
@@ -15,28 +15,6 @@ export type AssetsControllerGetAssetMetadataAction = {
|
|
|
15
15
|
type: `AssetsController:getAssetMetadata`;
|
|
16
16
|
handler: AssetsController['getAssetMetadata'];
|
|
17
17
|
};
|
|
18
|
-
/**
|
|
19
|
-
* Get a single combined asset (balance + metadata + price + computed
|
|
20
|
-
* `fiatValue`) for an account directly from controller state.
|
|
21
|
-
*
|
|
22
|
-
* Reuses the same state-composition and filtering logic as `getAssets`
|
|
23
|
-
* (balance and metadata are required, a missing price falls back to
|
|
24
|
-
* `{ price: 0, lastUpdated: 0 }` with `fiatValue: 0`, and hidden or
|
|
25
|
-
* otherwise filtered assets are excluded) so the returned shape never
|
|
26
|
-
* drifts from `getAssets`. Reads from current state only and does not
|
|
27
|
-
* trigger a data-source refresh.
|
|
28
|
-
*
|
|
29
|
-
* @param accountId - The account ID (`InternalAccount.id`, not an address).
|
|
30
|
-
* @param assetId - The CAIP-19 asset ID including chain scope
|
|
31
|
-
* (e.g. `eip155:1/erc20:0x...`).
|
|
32
|
-
* @returns The combined `Asset`, or `undefined` when no complete
|
|
33
|
-
* renderable asset (balance + metadata) exists for the account/asset pair.
|
|
34
|
-
* @throws If `accountId` is empty or `assetId` is not a valid CAIP-19 asset ID.
|
|
35
|
-
*/
|
|
36
|
-
export type AssetsControllerGetAssetAction = {
|
|
37
|
-
type: `AssetsController:getAsset`;
|
|
38
|
-
handler: AssetsController['getAsset'];
|
|
39
|
-
};
|
|
40
18
|
export type AssetsControllerGetAssetsPriceAction = {
|
|
41
19
|
type: `AssetsController:getAssetsPrice`;
|
|
42
20
|
handler: AssetsController['getAssetsPrice'];
|
|
@@ -136,5 +114,5 @@ export type AssetsControllerSetSelectedCurrencyAction = {
|
|
|
136
114
|
/**
|
|
137
115
|
* Union of all AssetsController action types.
|
|
138
116
|
*/
|
|
139
|
-
export type AssetsControllerMethodActions = AssetsControllerGetAssetsAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction |
|
|
117
|
+
export type AssetsControllerMethodActions = AssetsControllerGetAssetsAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction | AssetsControllerGetAssetsPriceAction | AssetsControllerGetExchangeRatesForBridgeAction | AssetsControllerGetStateForTransactionPayAction | AssetsControllerAddCustomAssetAction | AssetsControllerRemoveCustomAssetAction | AssetsControllerGetCustomAssetsAction | AssetsControllerHideAssetAction | AssetsControllerUnhideAssetAction | AssetsControllerSetSelectedCurrencyAction;
|
|
140
118
|
//# sourceMappingURL=AssetsController-method-action-types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"AssetsController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,gBAAgB,CAAC,2BAA2B,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,gBAAgB,CAAC,2BAA2B,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,+BAA+B,GAC/B,sCAAsC,GACtC,sCAAsC,GACtC,oCAAoC,GACpC,+CAA+C,GAC/C,+CAA+C,GAC/C,oCAAoC,GACpC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA+B,GAC/B,iCAAiC,GACjC,yCAAyC,CAAC"}
|
|
@@ -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.\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\
|
|
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 * Set the current currency.\n *\n * @param selectedCurrency - The ISO 4217 currency code to set.\n */\nexport type AssetsControllerSetSelectedCurrencyAction = {\n type: `AssetsController:setSelectedCurrency`;\n handler: AssetsController['setSelectedCurrency'];\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 | AssetsControllerSetSelectedCurrencyAction;\n"]}
|
|
@@ -13,7 +13,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _AssetsController_instances, _AssetsController_isEnabled, _AssetsController_isBasicFunctionality, _AssetsController_defaultUpdateInterval, _AssetsController_trace, _AssetsController_captureException, _AssetsController_firstInitFetchReported, _AssetsController_stateSizeReported, _AssetsController_emitTrace, _AssetsController_emitStateSizeTrace, _AssetsController_uiOpen, _AssetsController_keyringUnlocked, _AssetsController_controllerMutex, _AssetsController_accountRefreshMutex, _AssetsController_activeSubscriptions, _AssetsController_enabledChains, _AssetsController_lastKnownAccountIds, _AssetsController_getSelectedAccounts, _AssetsController_backendWebsocketDataSource, _AssetsController_accountsApiDataSource, _AssetsController_snapDataSource, _AssetsController_rpcDataSource, _AssetsController_stakedBalanceDataSource, _AssetsController_allBalanceDataSources_get, _AssetsController_priceDataSource, _AssetsController_detectionMiddleware, _AssetsController_customAssetGraduationMiddleware, _AssetsController_rpcFallbackMiddleware, _AssetsController_tokenDataSource, _AssetsController_unsubscribeBasicFunctionality, _AssetsController_queryApiClient, _AssetsController_onActiveChainsUpdated, _AssetsController_initializeNativeAssetsMap, _AssetsController_initializeState, _AssetsController_extractEnabledChains, _AssetsController_normalizeChainReference, _AssetsController_subscribeToEvents, _AssetsController_onUnapprovedTransactionAdded, _AssetsController_onTransactionConfirmed, _AssetsController_onAccountActivityBalanceUpdated, _AssetsController_updateActive, _AssetsController_handleAccountTreeStateChange, _AssetsController_runAccountTreeRefresh, _AssetsController_runStartupRefresh, _AssetsController_registerActionHandlers, _AssetsController_handleActiveChainsUpdate, _AssetsController_executeMiddlewares, _AssetsController_fetchMissingPricesWithoutCache, _AssetsController_getNativeAssetMap, _AssetsController_isNativeAsset, _AssetsController_getAssetType, _AssetsController_resolveNativeAssetIds, _AssetsController_getNativeAssetIdsForEnabledChains, _AssetsController_getNativeAssetIdsForAccount, _AssetsController_getSlowPipelineChainIds, _AssetsController_ensureNativeBalancesDefaultZero, _AssetsController_ensureDefaultTrackedAssetsSeeded, _AssetsController_updateState, _AssetsController_getAssetsFromState,
|
|
16
|
+
var _AssetsController_instances, _AssetsController_isEnabled, _AssetsController_isBasicFunctionality, _AssetsController_defaultUpdateInterval, _AssetsController_trace, _AssetsController_captureException, _AssetsController_firstInitFetchReported, _AssetsController_stateSizeReported, _AssetsController_emitTrace, _AssetsController_emitStateSizeTrace, _AssetsController_uiOpen, _AssetsController_keyringUnlocked, _AssetsController_controllerMutex, _AssetsController_accountRefreshMutex, _AssetsController_activeSubscriptions, _AssetsController_enabledChains, _AssetsController_lastKnownAccountIds, _AssetsController_getSelectedAccounts, _AssetsController_backendWebsocketDataSource, _AssetsController_accountsApiDataSource, _AssetsController_snapDataSource, _AssetsController_rpcDataSource, _AssetsController_stakedBalanceDataSource, _AssetsController_allBalanceDataSources_get, _AssetsController_priceDataSource, _AssetsController_detectionMiddleware, _AssetsController_customAssetGraduationMiddleware, _AssetsController_rpcFallbackMiddleware, _AssetsController_tokenDataSource, _AssetsController_unsubscribeBasicFunctionality, _AssetsController_queryApiClient, _AssetsController_onActiveChainsUpdated, _AssetsController_initializeNativeAssetsMap, _AssetsController_initializeState, _AssetsController_extractEnabledChains, _AssetsController_normalizeChainReference, _AssetsController_subscribeToEvents, _AssetsController_onUnapprovedTransactionAdded, _AssetsController_onTransactionConfirmed, _AssetsController_onAccountActivityBalanceUpdated, _AssetsController_updateActive, _AssetsController_handleAccountTreeStateChange, _AssetsController_runAccountTreeRefresh, _AssetsController_runStartupRefresh, _AssetsController_registerActionHandlers, _AssetsController_handleActiveChainsUpdate, _AssetsController_executeMiddlewares, _AssetsController_fetchMissingPricesWithoutCache, _AssetsController_getNativeAssetMap, _AssetsController_isNativeAsset, _AssetsController_getAssetType, _AssetsController_resolveNativeAssetIds, _AssetsController_getNativeAssetIdsForEnabledChains, _AssetsController_getNativeAssetIdsForAccount, _AssetsController_getSlowPipelineChainIds, _AssetsController_ensureNativeBalancesDefaultZero, _AssetsController_ensureDefaultTrackedAssetsSeeded, _AssetsController_updateState, _AssetsController_getAssetsFromState, _AssetsController_shouldHideNativeToken, _AssetsController_tokenStandardToAssetType, _AssetsController_start, _AssetsController_stop, _AssetsController_subscribeAssets, _AssetsController_subscribeAssetsBalance, _AssetsController_subscribeRpcCustomAssetsSupplement, _AssetsController_unsubscribeBySubscriptionKey, _AssetsController_subscribeStakedBalance, _AssetsController_buildChainToAccountsMap, _AssetsController_subscribeDataSource, _AssetsController_unsubscribeDataSource, _AssetsController_buildDataRequest, _AssetsController_getEnabledChainsForAccount, _AssetsController_handleAccountGroupChanged, _AssetsController_handleEnabledNetworksChanged, _AssetsController_handleNetworkAdded, _AssetsController_refreshActiveChainsOnNetworkSwitch, _AssetsController_getSelectedEvmChainIdFromNetworkState, _AssetsController_handleNetworkDidChange, _AssetsController_refreshAssetsAfterNetworkChange, _AssetsController_refreshAssetsAfterNetworkAdded;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.AssetsController = exports.getDefaultAssetsControllerState = void 0;
|
|
19
19
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -43,8 +43,6 @@ const constants_1 = require("./utils/constants.cjs");
|
|
|
43
43
|
const customAssetsRpcSupplement_1 = require("./utils/customAssetsRpcSupplement.cjs");
|
|
44
44
|
const processAccountActivityBalanceUpdates_1 = require("./utils/processAccountActivityBalanceUpdates.cjs");
|
|
45
45
|
const NATIVE_ASSETS_QUERY_KEY = ['nativeAssets'];
|
|
46
|
-
/** Stable empty map so memoized formatters are not busted by `?? {}` identity churn. */
|
|
47
|
-
const EMPTY_NATIVE_ASSET_MAP = {};
|
|
48
46
|
// ============================================================================
|
|
49
47
|
// CONTROLLER CONSTANTS
|
|
50
48
|
// ============================================================================
|
|
@@ -54,7 +52,6 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
54
52
|
'getAssets',
|
|
55
53
|
'getAssetsBalance',
|
|
56
54
|
'getAssetMetadata',
|
|
57
|
-
'getAsset',
|
|
58
55
|
'getAssetsPrice',
|
|
59
56
|
'getExchangeRatesForBridge',
|
|
60
57
|
'getStateForTransactionPay',
|
|
@@ -118,7 +115,7 @@ const stateMetadata = {
|
|
|
118
115
|
usedInUi: true,
|
|
119
116
|
},
|
|
120
117
|
assetsPrice: {
|
|
121
|
-
persist:
|
|
118
|
+
persist: false,
|
|
122
119
|
includeInStateLogs: false,
|
|
123
120
|
includeInDebugSnapshot: false,
|
|
124
121
|
usedInUi: true,
|
|
@@ -358,7 +355,6 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
358
355
|
getAssetType: (assetId) => __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getAssetType).call(this, assetId),
|
|
359
356
|
}), "f");
|
|
360
357
|
__classPrivateFieldSet(this, _AssetsController_accountsApiDataSource, new AccountsApiDataSource_1.AccountsApiDataSource({
|
|
361
|
-
messenger: this.messenger,
|
|
362
358
|
queryApiClient,
|
|
363
359
|
onActiveChainsUpdated: __classPrivateFieldGet(this, _AssetsController_onActiveChainsUpdated, "f"),
|
|
364
360
|
...accountsApiDataSourceConfig,
|
|
@@ -570,39 +566,6 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
570
566
|
getAssetMetadata(assetId) {
|
|
571
567
|
return this.state.assetsInfo[assetId];
|
|
572
568
|
}
|
|
573
|
-
/**
|
|
574
|
-
* Get a single combined asset (balance + metadata + price + computed
|
|
575
|
-
* `fiatValue`) for an account directly from controller state.
|
|
576
|
-
*
|
|
577
|
-
* Reuses the same state-composition and filtering logic as `getAssets`
|
|
578
|
-
* (balance and metadata are required, a missing price falls back to
|
|
579
|
-
* `{ price: 0, lastUpdated: 0 }` with `fiatValue: 0`, and hidden or
|
|
580
|
-
* otherwise filtered assets are excluded) so the returned shape never
|
|
581
|
-
* drifts from `getAssets`. Reads from current state only and does not
|
|
582
|
-
* trigger a data-source refresh.
|
|
583
|
-
*
|
|
584
|
-
* @param accountId - The account ID (`InternalAccount.id`, not an address).
|
|
585
|
-
* @param assetId - The CAIP-19 asset ID including chain scope
|
|
586
|
-
* (e.g. `eip155:1/erc20:0x...`).
|
|
587
|
-
* @returns The combined `Asset`, or `undefined` when no complete
|
|
588
|
-
* renderable asset (balance + metadata) exists for the account/asset pair.
|
|
589
|
-
* @throws If `accountId` is empty or `assetId` is not a valid CAIP-19 asset ID.
|
|
590
|
-
*/
|
|
591
|
-
getAsset(accountId, assetId) {
|
|
592
|
-
if (typeof accountId !== 'string' || accountId.length === 0) {
|
|
593
|
-
throw new Error('AssetsController.getAsset: accountId must be a non-empty string');
|
|
594
|
-
}
|
|
595
|
-
let normalizedAssetId;
|
|
596
|
-
try {
|
|
597
|
-
normalizedAssetId = (0, utils_2.normalizeAssetId)(assetId);
|
|
598
|
-
}
|
|
599
|
-
catch {
|
|
600
|
-
throw new Error(`AssetsController.getAsset: invalid CAIP-19 assetId "${assetId}"`);
|
|
601
|
-
}
|
|
602
|
-
return __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getAssetFromState).call(this, accountId, normalizedAssetId, {
|
|
603
|
-
assetTypeSet: new Set(['fungible']),
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
569
|
async getAssetsPrice(accounts, options) {
|
|
607
570
|
const assets = await this.getAssets(accounts, {
|
|
608
571
|
chainIds: options?.chainIds,
|
|
@@ -998,7 +961,6 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
998
961
|
this.messenger.unregisterActionHandler('AssetsController:getAssets');
|
|
999
962
|
this.messenger.unregisterActionHandler('AssetsController:getAssetsBalance');
|
|
1000
963
|
this.messenger.unregisterActionHandler('AssetsController:getAssetMetadata');
|
|
1001
|
-
this.messenger.unregisterActionHandler('AssetsController:getAsset');
|
|
1002
964
|
this.messenger.unregisterActionHandler('AssetsController:getAssetsPrice');
|
|
1003
965
|
this.messenger.unregisterActionHandler('AssetsController:getExchangeRatesForBridge');
|
|
1004
966
|
this.messenger.unregisterActionHandler('AssetsController:getStateForTransactionPay');
|
|
@@ -1493,7 +1455,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1493
1455
|
log('Failed to fetch missing prices', { error });
|
|
1494
1456
|
});
|
|
1495
1457
|
}, _AssetsController_getNativeAssetMap = function _AssetsController_getNativeAssetMap() {
|
|
1496
|
-
return (__classPrivateFieldGet(this, _AssetsController_queryApiClient, "f").getCachedData(NATIVE_ASSETS_QUERY_KEY) ??
|
|
1458
|
+
return (__classPrivateFieldGet(this, _AssetsController_queryApiClient, "f").getCachedData(NATIVE_ASSETS_QUERY_KEY) ?? {});
|
|
1497
1459
|
}, _AssetsController_isNativeAsset = function _AssetsController_isNativeAsset(assetId) {
|
|
1498
1460
|
const parsed = (0, utils_1.parseCaipAssetType)(assetId);
|
|
1499
1461
|
if (parsed.assetNamespace === 'slip44') {
|
|
@@ -1786,74 +1748,64 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1786
1748
|
releaseLock();
|
|
1787
1749
|
}
|
|
1788
1750
|
}, _AssetsController_getAssetsFromState = function _AssetsController_getAssetsFromState(accounts, chainIds, assetTypes) {
|
|
1789
|
-
const result =
|
|
1751
|
+
const result = {};
|
|
1790
1752
|
// Convert to Sets for O(1) lookups
|
|
1791
1753
|
const chainIdSet = new Set(chainIds);
|
|
1792
1754
|
const assetTypeSet = new Set(assetTypes);
|
|
1793
1755
|
for (const account of accounts) {
|
|
1794
|
-
result[account.id] =
|
|
1756
|
+
result[account.id] = {};
|
|
1795
1757
|
const accountBalances = this.state.assetsBalance[account.id] ?? {};
|
|
1796
|
-
for (const assetId of Object.
|
|
1758
|
+
for (const [assetId, balance] of Object.entries(accountBalances)) {
|
|
1797
1759
|
const typedAssetId = assetId;
|
|
1798
|
-
const
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
if (asset) {
|
|
1803
|
-
result[account.id][typedAssetId] = asset;
|
|
1760
|
+
const metadataRaw = this.state.assetsInfo[typedAssetId];
|
|
1761
|
+
// Skip assets without metadata
|
|
1762
|
+
if (!metadataRaw) {
|
|
1763
|
+
continue;
|
|
1804
1764
|
}
|
|
1765
|
+
const metadata = metadataRaw;
|
|
1766
|
+
// Skip hidden assets (assetPreferences)
|
|
1767
|
+
const prefs = this.state.assetPreferences[typedAssetId];
|
|
1768
|
+
if (prefs?.hidden) {
|
|
1769
|
+
continue;
|
|
1770
|
+
}
|
|
1771
|
+
const assetChainId = extractChainId(typedAssetId);
|
|
1772
|
+
// Skip native tokens on Tempo networks
|
|
1773
|
+
if (__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_shouldHideNativeToken).call(this, assetChainId, metadata)) {
|
|
1774
|
+
continue;
|
|
1775
|
+
}
|
|
1776
|
+
if (!chainIdSet.has(assetChainId)) {
|
|
1777
|
+
continue;
|
|
1778
|
+
}
|
|
1779
|
+
// Filter by asset type
|
|
1780
|
+
const tokenAssetType = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_tokenStandardToAssetType).call(this, metadata.type);
|
|
1781
|
+
if (!assetTypeSet.has(tokenAssetType)) {
|
|
1782
|
+
continue;
|
|
1783
|
+
}
|
|
1784
|
+
const typedBalance = balance;
|
|
1785
|
+
const priceRaw = this.state.assetsPrice[typedAssetId];
|
|
1786
|
+
const price = priceRaw ?? {
|
|
1787
|
+
price: 0,
|
|
1788
|
+
lastUpdated: 0,
|
|
1789
|
+
};
|
|
1790
|
+
// Compute fiat value using BigNumber for precision
|
|
1791
|
+
// Note: typedBalance.amount is already in human-readable format (e.g., "1" for 1 ETH)
|
|
1792
|
+
// so we do NOT divide by 10^decimals here
|
|
1793
|
+
const balanceAmount = new bignumber_js_1.default(typedBalance.amount || '0');
|
|
1794
|
+
const fiatValue = balanceAmount
|
|
1795
|
+
.multipliedBy(price.price || 0)
|
|
1796
|
+
.toNumber();
|
|
1797
|
+
const asset = {
|
|
1798
|
+
id: typedAssetId,
|
|
1799
|
+
chainId: assetChainId,
|
|
1800
|
+
balance: typedBalance,
|
|
1801
|
+
metadata,
|
|
1802
|
+
price,
|
|
1803
|
+
fiatValue,
|
|
1804
|
+
};
|
|
1805
|
+
result[account.id][typedAssetId] = asset;
|
|
1805
1806
|
}
|
|
1806
1807
|
}
|
|
1807
1808
|
return result;
|
|
1808
|
-
}, _AssetsController_getAssetFromState = function _AssetsController_getAssetFromState(accountId, assetId, filters) {
|
|
1809
|
-
const balance = this.state.assetsBalance[accountId]?.[assetId];
|
|
1810
|
-
// Skip assets without a balance entry
|
|
1811
|
-
if (!balance) {
|
|
1812
|
-
return undefined;
|
|
1813
|
-
}
|
|
1814
|
-
const metadata = this.state.assetsInfo[assetId];
|
|
1815
|
-
// Skip assets without metadata
|
|
1816
|
-
if (!metadata) {
|
|
1817
|
-
return undefined;
|
|
1818
|
-
}
|
|
1819
|
-
// Skip hidden assets (assetPreferences)
|
|
1820
|
-
const prefs = this.state.assetPreferences[assetId];
|
|
1821
|
-
if (prefs?.hidden) {
|
|
1822
|
-
return undefined;
|
|
1823
|
-
}
|
|
1824
|
-
const assetChainId = extractChainId(assetId);
|
|
1825
|
-
// Skip native tokens on Tempo networks
|
|
1826
|
-
if (__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_shouldHideNativeToken).call(this, assetChainId, metadata)) {
|
|
1827
|
-
return undefined;
|
|
1828
|
-
}
|
|
1829
|
-
if (filters?.chainIdSet && !filters.chainIdSet.has(assetChainId)) {
|
|
1830
|
-
return undefined;
|
|
1831
|
-
}
|
|
1832
|
-
// Filter by asset type
|
|
1833
|
-
if (filters?.assetTypeSet) {
|
|
1834
|
-
const tokenAssetType = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_tokenStandardToAssetType).call(this, metadata.type);
|
|
1835
|
-
if (!filters.assetTypeSet.has(tokenAssetType)) {
|
|
1836
|
-
return undefined;
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
const priceRaw = this.state.assetsPrice[assetId];
|
|
1840
|
-
const price = priceRaw ?? {
|
|
1841
|
-
price: 0,
|
|
1842
|
-
lastUpdated: 0,
|
|
1843
|
-
};
|
|
1844
|
-
// Compute fiat value using BigNumber for precision
|
|
1845
|
-
// Note: balance.amount is already in human-readable format (e.g., "1" for 1 ETH)
|
|
1846
|
-
// so we do NOT divide by 10^decimals here
|
|
1847
|
-
const balanceAmount = new bignumber_js_1.default(balance.amount || '0');
|
|
1848
|
-
const fiatValue = balanceAmount.multipliedBy(price.price || 0).toNumber();
|
|
1849
|
-
return {
|
|
1850
|
-
id: assetId,
|
|
1851
|
-
chainId: assetChainId,
|
|
1852
|
-
balance,
|
|
1853
|
-
metadata,
|
|
1854
|
-
price,
|
|
1855
|
-
fiatValue,
|
|
1856
|
-
};
|
|
1857
1809
|
}, _AssetsController_shouldHideNativeToken = function _AssetsController_shouldHideNativeToken(chainId, metadata) {
|
|
1858
1810
|
// Check if it's a chain that should skip native tokens
|
|
1859
1811
|
if (!(0, assets_1.shouldSkipNativeForCaipChainId)(chainId)) {
|