From 013573f141050e2d16af54a58601e560a5b62362 Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Sun, 28 Jan 2024 11:31:15 -0800 Subject: [PATCH] patch handling of missing price --- .../@metamask+assets-controllers+7.0.0.patch | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/patches/@metamask+assets-controllers+7.0.0.patch b/patches/@metamask+assets-controllers+7.0.0.patch index 8ccd8e49c6d..2fa84cce08f 100644 --- a/patches/@metamask+assets-controllers+7.0.0.patch +++ b/patches/@metamask+assets-controllers+7.0.0.patch @@ -843,7 +843,7 @@ index 8bb7c20..d0dfdee 100644 //# sourceMappingURL=TokenRatesController.d.ts.map \ No newline at end of file diff --git a/node_modules/@metamask/assets-controllers/dist/TokenRatesController.js b/node_modules/@metamask/assets-controllers/dist/TokenRatesController.js -index e3f81e9..4368f85 100644 +index e3f81e9..d1e389b 100644 --- a/node_modules/@metamask/assets-controllers/dist/TokenRatesController.js +++ b/node_modules/@metamask/assets-controllers/dist/TokenRatesController.js @@ -8,37 +8,61 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge @@ -1320,7 +1320,7 @@ index e3f81e9..4368f85 100644 + initialResult: {}, + }); + return Object.entries(tokenPricesByTokenAddress).reduce((obj, [tokenAddress, tokenPrice]) => { -+ return Object.assign(Object.assign({}, obj), { [tokenAddress]: tokenPrice.value }); ++ return Object.assign(Object.assign({}, obj), { [tokenAddress]: tokenPrice === null || tokenPrice === void 0 ? void 0 : tokenPrice.value }); + }, {}); + }); +}, _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency = function _TokenRatesController_fetchAndMapExchangeRatesForUnsupportedNativeCurrency({ tokenAddresses, nativeCurrency, }) { @@ -1864,7 +1864,7 @@ index ea0eaab..e528b48 100644 \ No newline at end of file diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.d.ts b/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.d.ts new file mode 100644 -index 0000000..7d4d0eb +index 0000000..4680852 --- /dev/null +++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/abstract-token-prices-service.d.ts @@ -0,0 +1,62 @@ @@ -1911,7 +1911,7 @@ index 0000000..7d4d0eb + chainId: ChainId; + tokenAddresses: TokenAddress[]; + currency: Currency; -+ }): Promise>; ++ }): Promise>>; + /** + * Type guard for whether the API can return token prices for the given chain + * ID. @@ -1959,7 +1959,7 @@ index 0000000..178484b \ No newline at end of file diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.d.ts b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.d.ts new file mode 100644 -index 0000000..dbae7a1 +index 0000000..d60c43b --- /dev/null +++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.d.ts @@ -0,0 +1,80 @@ @@ -2022,7 +2022,7 @@ index 0000000..dbae7a1 + chainId: SupportedChainId; + tokenAddresses: Hex[]; + currency: SupportedCurrency; -+ }): Promise>; ++ }): Promise>>; + /** + * Type guard for whether the API can return token prices for the given chain + * ID. @@ -2054,10 +2054,10 @@ index 0000000..c8c9c66 \ No newline at end of file diff --git a/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.js b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.js new file mode 100644 -index 0000000..a751d3a +index 0000000..58f98f5 --- /dev/null +++ b/node_modules/@metamask/assets-controllers/dist/token-prices-service/codefi-v2.js -@@ -0,0 +1,327 @@ +@@ -0,0 +1,330 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } @@ -2346,14 +2346,17 @@ index 0000000..a751d3a + const lowercasedCurrency = currency.toLowerCase(); + const price = (_a = pricesByCurrencyByTokenAddress[lowercasedTokenAddress]) === null || _a === void 0 ? void 0 : _a[lowercasedCurrency]; + if (!price) { -+ throw new Error(`Could not find price for "${tokenAddress}" in "${currency}"`); ++ // console error instead of throwing to not interrupt the fetching of other tokens in case just one fails ++ console.error(`Could not find price for "${tokenAddress}" in "${currency}"`); + } + const tokenPrice = { + tokenAddress, + value: price, + currency, + }; -+ return Object.assign(Object.assign({}, obj), { [tokenAddress]: tokenPrice }); ++ return Object.assign(Object.assign({}, obj), (tokenPrice.value !== undefined ++ ? { [tokenAddress]: tokenPrice } ++ : {})); + }, {}); + }); + }