@metamask-previews/assets-controller 9.1.0-preview-aabb3f2e3 → 9.1.0-preview-ba933fc1b
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/dist/AssetsController.cjs +51 -26
- 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 +51 -26
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/RpcDataSource.cjs +3 -2
- 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 +3 -2
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +3 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +3 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1396,30 +1396,44 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1396
1396
|
const metadata = state.assetsInfo;
|
|
1397
1397
|
const balances = state.assetsBalance;
|
|
1398
1398
|
const prices = state.assetsPrice;
|
|
1399
|
-
if (normalizedResponse.assetsInfo
|
|
1400
|
-
|
|
1401
|
-
|
|
1399
|
+
if (normalizedResponse.assetsInfo) {
|
|
1400
|
+
if (mode === 'update') {
|
|
1401
|
+
// Balance-only refresh: patch amounts without overwriting metadata,
|
|
1402
|
+
// but seed entries that are missing so RPC-only chains (e.g.
|
|
1403
|
+
// Avalanche) can render native balances on first fetch.
|
|
1404
|
+
for (const [key, value] of Object.entries(normalizedResponse.assetsInfo)) {
|
|
1405
|
+
if (metadata[key]) {
|
|
1406
|
+
continue;
|
|
1407
|
+
}
|
|
1408
|
+
metadata[key] = value;
|
|
1402
1409
|
changedMetadata.push(key);
|
|
1403
1410
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1411
|
+
}
|
|
1412
|
+
else {
|
|
1413
|
+
for (const [key, value] of Object.entries(normalizedResponse.assetsInfo)) {
|
|
1414
|
+
if (!(0, lodash_1.isEqual)(previousState.assetsInfo[key], value)) {
|
|
1415
|
+
changedMetadata.push(key);
|
|
1416
|
+
}
|
|
1417
|
+
const existing = metadata[key];
|
|
1418
|
+
const incoming = value;
|
|
1419
|
+
// When the API returns no symbol or name for this token, it has no
|
|
1420
|
+
// real knowledge of it (e.g. a user-deployed token not indexed by
|
|
1421
|
+
// the API). Preserve richer metadata already in state (e.g. from
|
|
1422
|
+
// pendingMetadata set by addCustomAsset) so that the correct
|
|
1423
|
+
// decimals/symbol/name/image are not overwritten with empty values.
|
|
1424
|
+
if (existing && !incoming.symbol && !incoming.name) {
|
|
1425
|
+
metadata[key] = {
|
|
1426
|
+
...existing,
|
|
1427
|
+
...incoming,
|
|
1428
|
+
symbol: existing.symbol,
|
|
1429
|
+
name: existing.name,
|
|
1430
|
+
decimals: existing.decimals ?? incoming.decimals,
|
|
1431
|
+
image: existing.image ?? incoming.image,
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1434
|
+
else {
|
|
1435
|
+
metadata[key] = value;
|
|
1436
|
+
}
|
|
1423
1437
|
}
|
|
1424
1438
|
}
|
|
1425
1439
|
}
|
|
@@ -1515,10 +1529,21 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1515
1529
|
balances[accountId] = effective;
|
|
1516
1530
|
}
|
|
1517
1531
|
}
|
|
1518
|
-
// Update prices in state
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1532
|
+
// Update prices in state. Update mode only seeds missing entries so
|
|
1533
|
+
// balance-only refreshes do not clobber existing price data.
|
|
1534
|
+
if (normalizedResponse.assetsPrice) {
|
|
1535
|
+
if (mode === 'update') {
|
|
1536
|
+
for (const [key, value] of Object.entries(normalizedResponse.assetsPrice)) {
|
|
1537
|
+
if (prices[key]) {
|
|
1538
|
+
continue;
|
|
1539
|
+
}
|
|
1540
|
+
prices[key] = value;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
else {
|
|
1544
|
+
for (const [key, value] of Object.entries(normalizedResponse.assetsPrice)) {
|
|
1545
|
+
prices[key] = value;
|
|
1546
|
+
}
|
|
1522
1547
|
}
|
|
1523
1548
|
}
|
|
1524
1549
|
});
|