@metamask-previews/assets-controller 13.1.1-preview-58a4a8b71 → 13.1.1-preview-4c8a5dfcb
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 +6 -0
- package/dist/AssetsController.cjs +26 -16
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +10 -0
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.cjs +13 -0
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.mjs +13 -0
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -9,10 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- Bump `@metamask/transaction-controller` from `^69.5.0` to `^69.5.1` ([#9798](https://github.com/MetaMask/core/pull/9798))
|
|
12
13
|
- Bump `@metamask/account-tree-controller` from `^7.6.0` to `^7.6.1` ([#9791](https://github.com/MetaMask/core/pull/9791))
|
|
13
14
|
- Bump `@metamask/accounts-controller` from `^39.0.6` to `^39.0.7` ([#9791](https://github.com/MetaMask/core/pull/9791))
|
|
14
15
|
- Bump `@metamask/keyring-controller` from `^27.1.0` to `^27.1.1` ([#9791](https://github.com/MetaMask/core/pull/9791))
|
|
15
16
|
- Bump `@metamask/network-enablement-controller` from `^6.0.2` to `^6.0.3` ([#9791](https://github.com/MetaMask/core/pull/9791))
|
|
17
|
+
- Bump `@metamask/assets-controllers` from `^111.0.0` to `^111.1.0` ([#9793](https://github.com/MetaMask/core/pull/9793))
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- Preserve pooled-staking balances across Accounts API chain-slice updates (e.g. network switch / `replaceCoveredChainBalances`): exclude staking contract asset IDs from `AccountsApiDataSource` v5/v6 balance processing, and keep prior staked amounts when a merge replace omits them so Accounts API cannot reset staked ETH to missing/0 ([#9753](https://github.com/MetaMask/core/pull/9753))
|
|
16
22
|
|
|
17
23
|
## [13.1.1]
|
|
18
24
|
|
|
@@ -24,6 +24,7 @@ const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
|
24
24
|
const lodash_1 = require("lodash");
|
|
25
25
|
const AccountActivityDataSource_js_1 = require("./data-sources/AccountActivityDataSource.cjs");
|
|
26
26
|
const AccountsApiDataSource_js_1 = require("./data-sources/AccountsApiDataSource.cjs");
|
|
27
|
+
const index_js_1 = require("./data-sources/evm-rpc-services/index.cjs");
|
|
27
28
|
const assets_js_1 = require("./data-sources/evm-rpc-services/utils/assets.cjs");
|
|
28
29
|
const PriceDataSource_js_1 = require("./data-sources/PriceDataSource.cjs");
|
|
29
30
|
const RpcDataSource_js_1 = require("./data-sources/RpcDataSource.cjs");
|
|
@@ -40,7 +41,7 @@ const RpcFallbackMiddleware_js_1 = require("./middlewares/RpcFallbackMiddleware.
|
|
|
40
41
|
const healAssetsInfoMetadata_js_1 = require("./migrations/healAssetsInfoMetadata.cjs");
|
|
41
42
|
const constants_js_1 = require("./utils/constants.cjs");
|
|
42
43
|
const customAssetsRpcSupplement_js_1 = require("./utils/customAssetsRpcSupplement.cjs");
|
|
43
|
-
const
|
|
44
|
+
const index_js_2 = require("./utils/index.cjs");
|
|
44
45
|
const trace_js_1 = require("./utils/trace.cjs");
|
|
45
46
|
const NATIVE_ASSETS_QUERY_KEY = ['nativeAssets'];
|
|
46
47
|
/** Stable empty map so memoized formatters are not busted by `?? {}` identity churn. */
|
|
@@ -169,14 +170,14 @@ function normalizeResponse(response) {
|
|
|
169
170
|
if (response.assetsInfo) {
|
|
170
171
|
normalized.assetsInfo = {};
|
|
171
172
|
for (const [assetId, metadata] of Object.entries(response.assetsInfo)) {
|
|
172
|
-
const normalizedId = (0,
|
|
173
|
+
const normalizedId = (0, index_js_2.normalizeAssetId)(assetId);
|
|
173
174
|
normalized.assetsInfo[normalizedId] = metadata;
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
if (response.assetsPrice) {
|
|
177
178
|
normalized.assetsPrice = {};
|
|
178
179
|
for (const [assetId, price] of Object.entries(response.assetsPrice)) {
|
|
179
|
-
const normalizedId = (0,
|
|
180
|
+
const normalizedId = (0, index_js_2.normalizeAssetId)(assetId);
|
|
180
181
|
normalized.assetsPrice[normalizedId] = price;
|
|
181
182
|
}
|
|
182
183
|
}
|
|
@@ -185,7 +186,7 @@ function normalizeResponse(response) {
|
|
|
185
186
|
for (const [accountId, balances] of Object.entries(response.assetsBalance)) {
|
|
186
187
|
normalized.assetsBalance[accountId] = {};
|
|
187
188
|
for (const [assetId, balance] of Object.entries(balances)) {
|
|
188
|
-
const normalizedId = (0,
|
|
189
|
+
const normalizedId = (0, index_js_2.normalizeAssetId)(assetId);
|
|
189
190
|
normalized.assetsBalance[accountId][normalizedId] = balance;
|
|
190
191
|
}
|
|
191
192
|
}
|
|
@@ -194,7 +195,7 @@ function normalizeResponse(response) {
|
|
|
194
195
|
if (response.detectedAssets) {
|
|
195
196
|
normalized.detectedAssets = {};
|
|
196
197
|
for (const [accountId, assetIds] of Object.entries(response.detectedAssets)) {
|
|
197
|
-
normalized.detectedAssets[accountId] = assetIds.map((assetId) => (0,
|
|
198
|
+
normalized.detectedAssets[accountId] = assetIds.map((assetId) => (0, index_js_2.normalizeAssetId)(assetId));
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
// Preserve errors (chain IDs don't need normalization)
|
|
@@ -237,6 +238,15 @@ function mergeAccountBalances(previousBalances, accountBalances, customAssetIds,
|
|
|
237
238
|
next[customId] = prev ?? { amount: '0' };
|
|
238
239
|
}
|
|
239
240
|
}
|
|
241
|
+
// Staked vault balances are owned by StakedBalanceDataSource. When an
|
|
242
|
+
// Accounts API (or other) chain-slice replace omits them, keep the prior
|
|
243
|
+
// on-chain staked amount instead of clearing it to missing/0.
|
|
244
|
+
for (const [assetId, balance] of Object.entries(previousBalances)) {
|
|
245
|
+
if ((0, index_js_1.isStakingContractAssetId)(assetId) &&
|
|
246
|
+
!Object.prototype.hasOwnProperty.call(next, assetId)) {
|
|
247
|
+
next[assetId] = balance;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
240
250
|
return next;
|
|
241
251
|
}
|
|
242
252
|
// ============================================================================
|
|
@@ -746,7 +756,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
746
756
|
*/
|
|
747
757
|
getExchangeRatesForBridge() {
|
|
748
758
|
const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
|
|
749
|
-
return (0,
|
|
759
|
+
return (0, index_js_2.formatExchangeRatesForBridge)({
|
|
750
760
|
assetsInfo: this.state.assetsInfo,
|
|
751
761
|
assetsPrice: this.state.assetsPrice,
|
|
752
762
|
selectedCurrency: this.state.selectedCurrency,
|
|
@@ -766,7 +776,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
766
776
|
getStateForTransactionPay() {
|
|
767
777
|
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
768
778
|
const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
|
|
769
|
-
return (0,
|
|
779
|
+
return (0, index_js_2.formatStateForTransactionPay)({
|
|
770
780
|
assetsBalance: this.state.assetsBalance,
|
|
771
781
|
assetsInfo: this.state.assetsInfo,
|
|
772
782
|
assetsPrice: this.state.assetsPrice,
|
|
@@ -793,7 +803,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
793
803
|
* @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).
|
|
794
804
|
*/
|
|
795
805
|
async addCustomAsset(accountId, assetId, pendingMetadata) {
|
|
796
|
-
const normalizedAssetId = (0,
|
|
806
|
+
const normalizedAssetId = (0, index_js_2.normalizeAssetId)(assetId);
|
|
797
807
|
log('Adding custom asset', { accountId, assetId: normalizedAssetId });
|
|
798
808
|
this.update((state) => {
|
|
799
809
|
var _a;
|
|
@@ -865,7 +875,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
865
875
|
* @param assetId - The CAIP-19 asset ID to remove.
|
|
866
876
|
*/
|
|
867
877
|
removeCustomAsset(accountId, assetId) {
|
|
868
|
-
const normalizedAssetId = (0,
|
|
878
|
+
const normalizedAssetId = (0, index_js_2.normalizeAssetId)(assetId);
|
|
869
879
|
log('Removing custom asset', { accountId, assetId: normalizedAssetId });
|
|
870
880
|
this.update((state) => {
|
|
871
881
|
if (state.customAssets[accountId]) {
|
|
@@ -900,7 +910,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
900
910
|
* @param assetId - The CAIP-19 asset ID to hide.
|
|
901
911
|
*/
|
|
902
912
|
hideAsset(assetId) {
|
|
903
|
-
const normalizedAssetId = (0,
|
|
913
|
+
const normalizedAssetId = (0, index_js_2.normalizeAssetId)(assetId);
|
|
904
914
|
log('Hiding asset', { assetId: normalizedAssetId });
|
|
905
915
|
this.update((state) => {
|
|
906
916
|
if (!state.assetPreferences[normalizedAssetId]) {
|
|
@@ -915,7 +925,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
915
925
|
* @param assetId - The CAIP-19 asset ID to unhide.
|
|
916
926
|
*/
|
|
917
927
|
unhideAsset(assetId) {
|
|
918
|
-
const normalizedAssetId = (0,
|
|
928
|
+
const normalizedAssetId = (0, index_js_2.normalizeAssetId)(assetId);
|
|
919
929
|
log('Unhiding asset', { assetId: normalizedAssetId });
|
|
920
930
|
this.update((state) => {
|
|
921
931
|
const prefs = state.assetPreferences[normalizedAssetId];
|
|
@@ -1221,7 +1231,7 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
1221
1231
|
queryApiClient.queryClient
|
|
1222
1232
|
.fetchQuery({
|
|
1223
1233
|
queryKey: NATIVE_ASSETS_QUERY_KEY,
|
|
1224
|
-
queryFn:
|
|
1234
|
+
queryFn: index_js_2.buildNativeAssetsFromApi,
|
|
1225
1235
|
staleTime: Infinity,
|
|
1226
1236
|
gcTime: Infinity,
|
|
1227
1237
|
})
|
|
@@ -1234,7 +1244,7 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
1234
1244
|
// #isNativeAsset, #resolveNativeAssetIds) have data available immediately.
|
|
1235
1245
|
// When fetchQuery resolves (currently instant, future: API), it overwrites
|
|
1236
1246
|
// this with potentially fresher data.
|
|
1237
|
-
const initialNativeAssetMap = (0,
|
|
1247
|
+
const initialNativeAssetMap = (0, index_js_2.buildNativeAssetsFromConstant)();
|
|
1238
1248
|
queryApiClient.setCachedData(NATIVE_ASSETS_QUERY_KEY, initialNativeAssetMap);
|
|
1239
1249
|
}, _AssetsController_initializeState = function _AssetsController_initializeState() {
|
|
1240
1250
|
const { enabledNetworkMap } = this.messenger.call('NetworkEnablementController:getState');
|
|
@@ -1604,7 +1614,7 @@ async function _AssetsController_executeMiddlewares(params) {
|
|
|
1604
1614
|
}
|
|
1605
1615
|
}, _AssetsController_normalizeAssetIdOrThrow = function _AssetsController_normalizeAssetIdOrThrow(assetId, methodName) {
|
|
1606
1616
|
try {
|
|
1607
|
-
return (0,
|
|
1617
|
+
return (0, index_js_2.normalizeAssetId)(assetId);
|
|
1608
1618
|
}
|
|
1609
1619
|
catch {
|
|
1610
1620
|
throw new Error(`AssetsController.${methodName}: invalid CAIP-19 assetId "${assetId}"`);
|
|
@@ -1625,7 +1635,7 @@ async function _AssetsController_executeMiddlewares(params) {
|
|
|
1625
1635
|
if (!chainFilter.has(assetId.split('/')[0])) {
|
|
1626
1636
|
continue;
|
|
1627
1637
|
}
|
|
1628
|
-
const normalizedAssetId = (0,
|
|
1638
|
+
const normalizedAssetId = (0, index_js_2.normalizeAssetId)(assetId);
|
|
1629
1639
|
if (prices[normalizedAssetId] ?? prices[assetId]) {
|
|
1630
1640
|
continue;
|
|
1631
1641
|
}
|
|
@@ -1856,7 +1866,7 @@ async function _AssetsController_executeMiddlewares(params) {
|
|
|
1856
1866
|
// exponent form is rewritten) so balances arriving before
|
|
1857
1867
|
// their metadata aren't lossily truncated.
|
|
1858
1868
|
const assetDecimals = metadata[assetId]?.decimals;
|
|
1859
|
-
const newAmount = (0,
|
|
1869
|
+
const newAmount = (0, index_js_2.normalizeAmountString)(balance.amount, assetDecimals);
|
|
1860
1870
|
effective[assetId] = { ...balance, amount: newAmount };
|
|
1861
1871
|
const oldAmount = previousBalance?.amount;
|
|
1862
1872
|
const isNewDefaultNativeZero = oldAmount === undefined &&
|