Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: patch handling of missing token price #8421

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions patches/@metamask+assets-controllers+7.0.0.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, }) {
Expand Down Expand Up @@ -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 @@
Expand Down Expand Up @@ -1911,7 +1911,7 @@ index 0000000..7d4d0eb
+ chainId: ChainId;
+ tokenAddresses: TokenAddress[];
+ currency: Currency;
+ }): Promise<TokenPricesByTokenAddress<TokenAddress, Currency>>;
+ }): Promise<Partial<TokenPricesByTokenAddress<TokenAddress, Currency>>>;
+ /**
+ * Type guard for whether the API can return token prices for the given chain
+ * ID.
Expand Down Expand Up @@ -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 @@
Expand Down Expand Up @@ -2022,7 +2022,7 @@ index 0000000..dbae7a1
+ chainId: SupportedChainId;
+ tokenAddresses: Hex[];
+ currency: SupportedCurrency;
+ }): Promise<TokenPricesByTokenAddress<Hex, SupportedCurrency>>;
+ }): Promise<Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>>;
+ /**
+ * Type guard for whether the API can return token prices for the given chain
+ * ID.
Expand Down Expand Up @@ -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); }); }
Expand Down Expand Up @@ -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 }
+ : {}));
+ }, {});
+ });
+ }
Expand Down
Loading