Skip to content

Commit

Permalink
fix: patch mantle price fix (#29790)
Browse files Browse the repository at this point in the history
## **Description**

PR to patch Mantle price core
[fix](MetaMask/core#5099)

current Mantle price:
https://www.cryptocompare.com/coins/mantle/overview/USDC

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29790?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Add Mantle network from chainList (chainId 5000)
2. Go to MM and you should see correct fiat balance


## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->
<img width="1800" alt="Screenshot 2025-01-17 at 21 18 51"
src="https://github.com/user-attachments/assets/1100b7a1-d143-46fd-98b4-4a064f700aa2"
/>



### **After**

<!-- [screenshots/recordings] -->

<img width="1797" alt="Screenshot 2025-01-17 at 21 17 08"
src="https://github.com/user-attachments/assets/e166c121-b484-4da4-935e-cb43ad1b7fa5"
/>


## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
sahar-fehri authored Jan 20, 2025
1 parent 5887e05 commit 27d2706
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 3 deletions.
108 changes: 108 additions & 0 deletions .yarn/patches/@metamask-assets-controllers-patch-d114308c1b.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
diff --git a/dist/assetsUtil.cjs b/dist/assetsUtil.cjs
index 61246f51500c8cab48f18296a73629fb73454caa..34396ba143e3ebcb04fa2c80f7a35d1abd06710e 100644
--- a/dist/assetsUtil.cjs
+++ b/dist/assetsUtil.cjs
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
-exports.fetchTokenContractExchangeRates = exports.reduceInBatchesSerially = exports.divideIntoBatches = exports.ethersBigNumberToBN = exports.addUrlProtocolPrefix = exports.getFormattedIpfsUrl = exports.getIpfsCIDv1AndPath = exports.removeIpfsProtocolPrefix = exports.isTokenListSupportedForNetwork = exports.isTokenDetectionSupportedForNetwork = exports.SupportedStakedBalanceNetworks = exports.SupportedTokenDetectionNetworks = exports.formatIconUrlWithProxy = exports.formatAggregatorNames = exports.hasNewCollectionFields = exports.compareNftMetadata = exports.TOKEN_PRICES_BATCH_SIZE = void 0;
+exports.getKeyByValue = exports.fetchTokenContractExchangeRates = exports.reduceInBatchesSerially = exports.divideIntoBatches = exports.ethersBigNumberToBN = exports.addUrlProtocolPrefix = exports.getFormattedIpfsUrl = exports.getIpfsCIDv1AndPath = exports.removeIpfsProtocolPrefix = exports.isTokenListSupportedForNetwork = exports.isTokenDetectionSupportedForNetwork = exports.SupportedStakedBalanceNetworks = exports.SupportedTokenDetectionNetworks = exports.formatIconUrlWithProxy = exports.formatAggregatorNames = exports.hasNewCollectionFields = exports.compareNftMetadata = exports.TOKEN_PRICES_BATCH_SIZE = void 0;
const controller_utils_1 = require("@metamask/controller-utils");
const utils_1 = require("@metamask/utils");
const bn_js_1 = __importDefault(require("bn.js"));
@@ -368,4 +368,19 @@ async function fetchTokenContractExchangeRates({ tokenPricesService, nativeCurre
}, {});
}
exports.fetchTokenContractExchangeRates = fetchTokenContractExchangeRates;
+/**
+ * Function to search for a specific value in a given map and return the key
+ * @param map - map input to search value
+ * @param value - the value to search for
+ * @returns returns key that corresponds to the value
+ */
+function getKeyByValue(map, value) {
+ for (const [key, val] of map.entries()) {
+ if (val === value) {
+ return key;
+ }
+ }
+ return null; // Return null if no match is found
+}
+exports.getKeyByValue = getKeyByValue;
//# sourceMappingURL=assetsUtil.cjs.map
\ No newline at end of file
diff --git a/dist/assetsUtil.mjs b/dist/assetsUtil.mjs
index 1e14797c8e1cd48e75287b37c29eb6065daac5e6..c288b56227bd7779982083be4cae9674d01ae1dd 100644
--- a/dist/assetsUtil.mjs
+++ b/dist/assetsUtil.mjs
@@ -354,4 +354,18 @@ export async function fetchTokenContractExchangeRates({ tokenPricesService, nati
};
}, {});
}
+/**
+ * Function to search for a specific value in a given map and return the key
+ * @param map - map input to search value
+ * @param value - the value to search for
+ * @returns returns key that corresponds to the value
+ */
+export function getKeyByValue(map, value) {
+ for (const [key, val] of map.entries()) {
+ if (val === value) {
+ return key;
+ }
+ }
+ return null; // Return null if no match is found
+}
//# sourceMappingURL=assetsUtil.mjs.map
\ No newline at end of file
diff --git a/dist/crypto-compare-service/crypto-compare.cjs b/dist/crypto-compare-service/crypto-compare.cjs
index 4cdf9c15053fb4acbc8aa7cade912e87c7aaf224..7bddcf4322f7825affdf34116778ba08b7676951 100644
--- a/dist/crypto-compare-service/crypto-compare.cjs
+++ b/dist/crypto-compare-service/crypto-compare.cjs
@@ -2,6 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchMultiExchangeRate = exports.fetchExchangeRate = void 0;
const controller_utils_1 = require("@metamask/controller-utils");
+const assetsUtil_1 = require("../assetsUtil.cjs");
/**
* A map from native currency symbol to CryptoCompare identifier.
* This is only needed when the values don't match.
@@ -105,12 +106,14 @@ exports.fetchExchangeRate = fetchExchangeRate;
* @returns Promise resolving to exchange rates for given currencies.
*/
async function fetchMultiExchangeRate(fiatCurrency, cryptocurrencies, includeUSDRate) {
- const url = getMultiPricingURL(cryptocurrencies, [fiatCurrency], includeUSDRate);
+ const fsyms = cryptocurrencies.map((nativeCurrency) => nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency);
+ const url = getMultiPricingURL(fsyms, [fiatCurrency], includeUSDRate);
const response = await (0, controller_utils_1.handleFetch)(url);
handleErrorResponse(response);
const rates = {};
for (const [cryptocurrency, values] of Object.entries(response)) {
- rates[cryptocurrency.toLowerCase()] = {
+ const key = (0, assetsUtil_1.getKeyByValue)(nativeSymbolOverrides, cryptocurrency);
+ rates[key?.toLowerCase() ?? cryptocurrency.toLowerCase()] = {
[fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],
...(includeUSDRate && { usd: values.USD }),
};
diff --git a/dist/crypto-compare-service/crypto-compare.mjs b/dist/crypto-compare-service/crypto-compare.mjs
index 58db2280159669c1b48fb94a9164b8e0be2850a7..74e0560718d42202e9183ff7ff1bfdac1424506e 100644
--- a/dist/crypto-compare-service/crypto-compare.mjs
+++ b/dist/crypto-compare-service/crypto-compare.mjs
@@ -101,12 +101,14 @@ export async function fetchExchangeRate(currency, nativeCurrency, includeUSDRate
* @returns Promise resolving to exchange rates for given currencies.
*/
export async function fetchMultiExchangeRate(fiatCurrency, cryptocurrencies, includeUSDRate) {
- const url = getMultiPricingURL(cryptocurrencies, [fiatCurrency], includeUSDRate);
+ const fsyms = cryptocurrencies.map((nativeCurrency) => nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency);
+ const url = getMultiPricingURL(fsyms, [fiatCurrency], includeUSDRate);
const response = await handleFetch(url);
handleErrorResponse(response);
const rates = {};
for (const [cryptocurrency, values] of Object.entries(response)) {
- rates[cryptocurrency.toLowerCase()] = {
+ const key = getKeyByValue(nativeSymbolOverrides, cryptocurrency);
+ rates[key?.toLowerCase() ?? cryptocurrency.toLowerCase()] = {
[fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],
...(includeUSDRate && { usd: values.USD }),
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
"@metamask/address-book-controller": "^6.0.0",
"@metamask/announcement-controller": "^7.0.0",
"@metamask/approval-controller": "^7.0.0",
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@npm%253A45.1.0%23~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch%3A%3Aversion=45.1.0&hash=cfcadc#~/.yarn/patches/@metamask-assets-controllers-patch-d6ed5f8213.patch",
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@patch%253A@metamask/assets-controllers@npm%25253A45.1.0%2523~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch%253A%253Aversion=45.1.0&hash=cfcadc%23~/.yarn/patches/@metamask-assets-controllers-patch-d6ed5f8213.patch%3A%3Aversion=45.1.0&hash=4e79dd#~/.yarn/patches/@metamask-assets-controllers-patch-d114308c1b.patch",
"@metamask/base-controller": "^7.0.0",
"@metamask/bitcoin-wallet-snap": "^0.8.2",
"@metamask/browser-passworder": "^4.3.0",
Expand Down
43 changes: 41 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5032,7 +5032,7 @@ __metadata:
languageName: node
linkType: hard

"@metamask/assets-controllers@patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@npm%253A45.1.0%23~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch%3A%3Aversion=45.1.0&hash=cfcadc#~/.yarn/patches/@metamask-assets-controllers-patch-d6ed5f8213.patch":
"@metamask/assets-controllers@patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@npm%253A45.1.0%23~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch%3A%3Aversion=45.1.0&hash=cfcadc#~/.yarn/patches/@metamask-assets-controllers-patch-d6ed5f8213.patch::version=45.1.0&hash=4e79dd":
version: 45.1.0
resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@npm%253A45.1.0%23~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch%3A%3Aversion=45.1.0&hash=cfcadc#~/.yarn/patches/@metamask-assets-controllers-patch-d6ed5f8213.patch::version=45.1.0&hash=4e79dd"
dependencies:
Expand Down Expand Up @@ -5071,6 +5071,45 @@ __metadata:
languageName: node
linkType: hard

"@metamask/assets-controllers@patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@patch%253A@metamask/assets-controllers@npm%25253A45.1.0%2523~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch%253A%253Aversion=45.1.0&hash=cfcadc%23~/.yarn/patches/@metamask-assets-controllers-patch-d6ed5f8213.patch%3A%3Aversion=45.1.0&hash=4e79dd#~/.yarn/patches/@metamask-assets-controllers-patch-d114308c1b.patch":
version: 45.1.0
resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@patch%253A@metamask/assets-controllers@npm%25253A45.1.0%2523~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch%253A%253Aversion=45.1.0&hash=cfcadc%23~/.yarn/patches/@metamask-assets-controllers-patch-d6ed5f8213.patch%3A%3Aversion=45.1.0&hash=4e79dd#~/.yarn/patches/@metamask-assets-controllers-patch-d114308c1b.patch::version=45.1.0&hash=c19fd5"
dependencies:
"@ethereumjs/util": "npm:^8.1.0"
"@ethersproject/abi": "npm:^5.7.0"
"@ethersproject/address": "npm:^5.7.0"
"@ethersproject/bignumber": "npm:^5.7.0"
"@ethersproject/contracts": "npm:^5.7.0"
"@ethersproject/providers": "npm:^5.7.0"
"@metamask/abi-utils": "npm:^2.0.3"
"@metamask/base-controller": "npm:^7.0.2"
"@metamask/contract-metadata": "npm:^2.4.0"
"@metamask/controller-utils": "npm:^11.4.3"
"@metamask/eth-query": "npm:^4.0.0"
"@metamask/metamask-eth-abis": "npm:^3.1.1"
"@metamask/polling-controller": "npm:^12.0.1"
"@metamask/rpc-errors": "npm:^7.0.1"
"@metamask/utils": "npm:^10.0.0"
"@types/bn.js": "npm:^5.1.5"
"@types/uuid": "npm:^8.3.0"
async-mutex: "npm:^0.5.0"
bn.js: "npm:^5.2.1"
cockatiel: "npm:^3.1.2"
immer: "npm:^9.0.6"
lodash: "npm:^4.17.21"
multiformats: "npm:^13.1.0"
single-call-balance-checker-abi: "npm:^1.0.0"
uuid: "npm:^8.3.2"
peerDependencies:
"@metamask/accounts-controller": ^20.0.0
"@metamask/approval-controller": ^7.0.0
"@metamask/keyring-controller": ^19.0.0
"@metamask/network-controller": ^22.0.0
"@metamask/preferences-controller": ^15.0.0
checksum: 10/970aa5176aeef96249f19786741265df5d2e5f5bb41d08dc4bb12a6328c0bbefbd6b7aebe4a6546cb2e14e5978af04443e6a83a1546c9cfdfdf4bebdba083a26
languageName: node
linkType: hard

"@metamask/auto-changelog@npm:^2.1.0":
version: 2.6.1
resolution: "@metamask/auto-changelog@npm:2.6.1"
Expand Down Expand Up @@ -26623,7 +26662,7 @@ __metadata:
"@metamask/announcement-controller": "npm:^7.0.0"
"@metamask/api-specs": "npm:^0.9.3"
"@metamask/approval-controller": "npm:^7.0.0"
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@npm%253A45.1.0%23~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch%3A%3Aversion=45.1.0&hash=cfcadc#~/.yarn/patches/@metamask-assets-controllers-patch-d6ed5f8213.patch"
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@patch%253A@metamask/assets-controllers@npm%25253A45.1.0%2523~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch%253A%253Aversion=45.1.0&hash=cfcadc%23~/.yarn/patches/@metamask-assets-controllers-patch-d6ed5f8213.patch%3A%3Aversion=45.1.0&hash=4e79dd#~/.yarn/patches/@metamask-assets-controllers-patch-d114308c1b.patch"
"@metamask/auto-changelog": "npm:^2.1.0"
"@metamask/base-controller": "npm:^7.0.0"
"@metamask/bitcoin-wallet-snap": "npm:^0.8.2"
Expand Down

0 comments on commit 27d2706

Please sign in to comment.