Conversation
| } | ||
|
|
||
| const prices: Record<Caip19AssetId, AssetPrice> = {}; | ||
|
|
There was a problem hiding this comment.
Moved the logic that validates the result from the API here and added an extra check to verify that the USD price is also there.
This also allows us to remove this logic from the two places that were calling this private method.
| export type AssetPrice = | ||
| | FungibleAssetPrice | ||
| | NFTAssetPrice | ||
| | (BaseAssetPrice & { [key: string]: Json }); |
There was a problem hiding this comment.
I have made some minor adjustment to this type, which also addresses this TODO I added to the client (https://github.com/MetaMask/metamask-extension/blob/main/shared/modules/selectors/assets-migration.ts#L715).
It's very convenient to have a type discriminator field with unions of very different types, as that allows typescript to to perform type guards easily.
For that reason, I added an assetPriceType with a specific value for each type and removed the generic (BaseAssetPrice & { [key: string]: Json }), as it is not used anywhere and it's unlikely it'll ever be needed. If it ever is needed, we can add it then and create a new type for it.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| @@ -190,7 +190,7 @@ export type AssetMetadata = | |||
| * Base price attributes. | |||
| */ | |||
| export type BaseAssetPrice = { | |||
There was a problem hiding this comment.
Make all the price types extend this one, which is the absolutely bare minimum needed.
Explanation
References
Checklist
Note
Medium Risk
Medium risk because it changes the
AssetPrice/FungibleAssetPricetype shape (addsassetPriceType/usdPriceand narrows the union), which may be breaking for downstream consumers, and it increases Price API usage by fetching USD in addition to the selected currency.Overview
Price fetching now queries the spot-prices API for both the selected currency and USD (in parallel when needed) and returns a normalized
assetsPricemap that includesprice(selected currency),usdPrice,lastUpdated, andassetPriceType: 'fungible'.Types were updated to make prices a discriminated union (
assetPriceType), factor shared fields intoBaseAssetPrice, addusdPricetoFungibleAssetPrice, and narrowAssetPricetoFungibleAssetPrice | NFTAssetPrice.Written by Cursor Bugbot for commit 647c5e1. This will update automatically on new commits. Configure here.