@metamask/assets-controllers 51.0.2 → 52.0.0

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/CHANGELOG.md CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [52.0.0]
11
+
12
+ ### Changed
13
+
14
+ - **BREAKING:** Bump `@metamask/keyring-controller` peer dependency to `^20.0.0` ([#5426](https://github.com/MetaMask/core/pull/5426))
15
+ - **BREAKING:** Bump `@metamask/accounts-controller` peer dependency to `^25.0.0` ([#5426](https://github.com/MetaMask/core/pull/5426))
16
+ - **BREAKING:** Bump `@metamask/preferences-controller` peer dependency to `^16.0.0` ([#5426](https://github.com/MetaMask/core/pull/5426))
17
+ - Bump `@metamask/keyring-internal-api` from `^4.0.3` to `^5.0.0` ([#5405](https://github.com/MetaMask/core/pull/5405))
18
+
19
+ ### Fixed
20
+
21
+ - Fixed conversion rates for MANTLE ([#5402](https://github.com/MetaMask/core/pull/5402))
22
+
10
23
  ## [51.0.2]
11
24
 
12
25
  ### Fixed
@@ -1428,7 +1441,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1428
1441
 
1429
1442
  - Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
1430
1443
 
1431
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@51.0.2...HEAD
1444
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@52.0.0...HEAD
1445
+ [52.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@51.0.2...@metamask/assets-controllers@52.0.0
1432
1446
  [51.0.2]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@51.0.1...@metamask/assets-controllers@51.0.2
1433
1447
  [51.0.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@51.0.0...@metamask/assets-controllers@51.0.1
1434
1448
  [51.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@50.0.0...@metamask/assets-controllers@51.0.0
@@ -24,10 +24,8 @@ const CRYPTO_COMPARE_DOMAIN = 'https://min-api.cryptocompare.com';
24
24
  * @returns The API URL for getting the conversion rate.
25
25
  */
26
26
  function getPricingURL(currentCurrency, nativeCurrency, includeUSDRate) {
27
- nativeCurrency = nativeCurrency.toUpperCase();
28
- const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;
29
27
  return (`${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +
30
- `${fsym}&tsyms=${currentCurrency.toUpperCase()}` +
28
+ `${nativeCurrency}&tsyms=${currentCurrency}` +
31
29
  `${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`);
32
30
  }
33
31
  /**
@@ -76,6 +74,10 @@ function handleErrorResponse(json) {
76
74
  * @returns Promise resolving to exchange rate for given currency.
77
75
  */
78
76
  async function fetchExchangeRate(currency, nativeCurrency, includeUSDRate) {
77
+ currency = currency.toUpperCase();
78
+ nativeCurrency = nativeCurrency.toUpperCase();
79
+ currency = nativeSymbolOverrides.get(currency) ?? currency;
80
+ nativeCurrency = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;
79
81
  const json = await (0, controller_utils_1.handleFetch)(getPricingURL(currency, nativeCurrency, includeUSDRate));
80
82
  handleErrorResponse(json);
81
83
  const conversionRate = Number(json[currency.toUpperCase()]);
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-compare.cjs","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":";;;AAAA,iEAAyD;AAEzD,kDAA8C;AAE9C;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,CAAC,KAAK,EAAE,QAAQ,CAAC;IACjB,CAAC,MAAM,EAAE,SAAS,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,mCAAmC,C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,GAAG,CAAC,cAAc,CAAC,IAAI,cAAc,CAC9D,CAAC;IACF,MAAM,GAAG,GAAG,kBAAkB,CAAC,KAAK,EAAE,CAAC,YAAY,CAAC,EAAE,cAAc,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,MAAM,IAAA,8BAAW,EAAC,GAAG,CAAC,CAAC;IACxC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAE9B,MAAM,KAAK,GAA2C,EAAE,CAAC;IACzD,KAAK,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAG3D,EAAE;QACH,MAAM,GAAG,GAAG,IAAA,0BAAa,EAAC,qBAAqB,EAAE,cAAc,CAAC,CAAC;QACjE,KAAK,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,cAAc,CAAC,WAAW,EAAE,CAAC,GAAG;YAC1D,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;YAChE,GAAG,CAAC,cAAc,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;SAC3C,CAAC;KACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA1BD,wDA0BC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getKeyByValue } from '../assetsUtil';\n\n/**\n * A map from native currency symbol to CryptoCompare identifier.\n * This is only needed when the values don't match.\n */\nconst nativeSymbolOverrides = new Map([\n ['MNT', 'MANTLE'],\n ['OMNI', 'OMNINET'],\n]);\n\nconst CRYPTO_COMPARE_DOMAIN = 'https://min-api.cryptocompare.com';\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from the given native currency to\n * the given currency. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param currentCurrency - The currency to get a conversion rate for.\n * @param nativeCurrency - The native currency to convert from.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be\n * included in the response as well.\n * @returns The API URL for getting the conversion rate.\n */\nfunction getPricingURL(\n currentCurrency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n) {\n nativeCurrency = nativeCurrency.toUpperCase();\n const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;\n return (\n `${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +\n `${fsym}&tsyms=${currentCurrency.toUpperCase()}` +\n `${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`\n );\n}\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from a given array of native currencies\n * to the given currencies. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param fsyms - The native currencies to get conversion rates for.\n * @param tsyms - The currencies to convert to.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be included.\n * @returns The API URL for getting the conversion rates.\n */\nfunction getMultiPricingURL(\n fsyms: string[],\n tsyms: string[],\n includeUSDRate = false,\n) {\n const updatedTsyms =\n includeUSDRate && !tsyms.some((t) => t.toUpperCase() === 'USD')\n ? [...tsyms, 'USD']\n : tsyms;\n\n const params = new URLSearchParams();\n params.append('fsyms', fsyms.join(','));\n params.append('tsyms', updatedTsyms.join(','));\n\n const url = new URL(`${CRYPTO_COMPARE_DOMAIN}/data/pricemulti`);\n url.search = params.toString();\n return url.toString();\n}\n\n/**\n * Handles an error response from the CryptoCompare API.\n * Expected error response format\n * { Response: \"Error\", Message: \"...\", HasWarning: false }\n *\n * @param json - The JSON response from the CryptoCompare API.\n * @param json.Response - The response status.\n * @param json.Message - The error message.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction handleErrorResponse(json: { Response?: string; Message?: string }) {\n if (json.Response === 'Error') {\n throw new Error(json.Message);\n }\n}\n\n/**\n * Fetches the exchange rate for a given currency.\n *\n * @param currency - ISO 4217 currency code.\n * @param nativeCurrency - Symbol for base asset.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rate for given currency.\n */\nexport async function fetchExchangeRate(\n currency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n): Promise<{\n conversionRate: number;\n usdConversionRate: number;\n}> {\n const json = await handleFetch(\n getPricingURL(currency, nativeCurrency, includeUSDRate),\n );\n\n handleErrorResponse(json);\n const conversionRate = Number(json[currency.toUpperCase()]);\n\n const usdConversionRate = Number(json.USD);\n if (!Number.isFinite(conversionRate)) {\n throw new Error(\n `Invalid response for ${currency.toUpperCase()}: ${\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n json[currency.toUpperCase()]\n }`,\n );\n }\n\n if (includeUSDRate && !Number.isFinite(usdConversionRate)) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Invalid response for usdConversionRate: ${json.USD}`);\n }\n\n return {\n conversionRate,\n usdConversionRate,\n };\n}\n\n/**\n * Fetches the exchange rates for multiple currencies.\n *\n * @param fiatCurrency - The currency of the rates (ISO 4217).\n * @param cryptocurrencies - The cryptocurrencies to get conversion rates for. Min length: 1. Max length: 300.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rates for given currencies.\n */\nexport async function fetchMultiExchangeRate(\n fiatCurrency: string,\n cryptocurrencies: string[],\n includeUSDRate: boolean,\n): Promise<Record<string, Record<string, number>>> {\n const fsyms = cryptocurrencies.map(\n (nativeCurrency) =>\n nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency,\n );\n const url = getMultiPricingURL(fsyms, [fiatCurrency], includeUSDRate);\n const response = await handleFetch(url);\n handleErrorResponse(response);\n\n const rates: Record<string, Record<string, number>> = {};\n for (const [cryptocurrency, values] of Object.entries(response) as [\n string,\n Record<string, number>,\n ][]) {\n const key = getKeyByValue(nativeSymbolOverrides, cryptocurrency);\n rates[key?.toLowerCase() ?? cryptocurrency.toLowerCase()] = {\n [fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],\n ...(includeUSDRate && { usd: values.USD }),\n };\n }\n\n return rates;\n}\n"]}
1
+ {"version":3,"file":"crypto-compare.cjs","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":";;;AAAA,iEAAyD;AAEzD,kDAA8C;AAE9C;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,CAAC,KAAK,EAAE,QAAQ,CAAC;IACjB,CAAC,MAAM,EAAE,SAAS,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,mCAAmC,CAAC;AAElE;;;;;;;;;;GAUG;AACH,SAAS,aAAa,CACpB,eAAuB,EACvB,cAAsB,EACtB,cAAwB;IAExB,OAAO,CACL,GAAG,qBAAqB,mBAAmB;QAC3C,GAAG,cAAc,UAAU,eAAe,EAAE;QAC5C,GAAG,cAAc,IAAI,eAAe,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAC7E,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,kBAAkB,CACzB,KAAe,EACf,KAAe,EACf,cAAc,GAAG,KAAK;IAEtB,MAAM,YAAY,GAChB,cAAc,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC;QAC7D,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC;QACnB,CAAC,CAAC,KAAK,CAAC;IAEZ,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACxC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC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AC,GAAG,EAAE,CAAC;SAC3C,CAAC;KACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA1BD,wDA0BC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getKeyByValue } from '../assetsUtil';\n\n/**\n * A map from native currency symbol to CryptoCompare identifier.\n * This is only needed when the values don't match.\n */\nconst nativeSymbolOverrides = new Map([\n ['MNT', 'MANTLE'],\n ['OMNI', 'OMNINET'],\n]);\n\nconst CRYPTO_COMPARE_DOMAIN = 'https://min-api.cryptocompare.com';\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from the given native currency to\n * the given currency. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param currentCurrency - The currency to get a conversion rate for.\n * @param nativeCurrency - The native currency to convert from.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be\n * included in the response as well.\n * @returns The API URL for getting the conversion rate.\n */\nfunction getPricingURL(\n currentCurrency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n) {\n return (\n `${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +\n `${nativeCurrency}&tsyms=${currentCurrency}` +\n `${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`\n );\n}\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from a given array of native currencies\n * to the given currencies. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param fsyms - The native currencies to get conversion rates for.\n * @param tsyms - The currencies to convert to.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be included.\n * @returns The API URL for getting the conversion rates.\n */\nfunction getMultiPricingURL(\n fsyms: string[],\n tsyms: string[],\n includeUSDRate = false,\n) {\n const updatedTsyms =\n includeUSDRate && !tsyms.some((t) => t.toUpperCase() === 'USD')\n ? [...tsyms, 'USD']\n : tsyms;\n\n const params = new URLSearchParams();\n params.append('fsyms', fsyms.join(','));\n params.append('tsyms', updatedTsyms.join(','));\n\n const url = new URL(`${CRYPTO_COMPARE_DOMAIN}/data/pricemulti`);\n url.search = params.toString();\n return url.toString();\n}\n\n/**\n * Handles an error response from the CryptoCompare API.\n * Expected error response format\n * { Response: \"Error\", Message: \"...\", HasWarning: false }\n *\n * @param json - The JSON response from the CryptoCompare API.\n * @param json.Response - The response status.\n * @param json.Message - The error message.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction handleErrorResponse(json: { Response?: string; Message?: string }) {\n if (json.Response === 'Error') {\n throw new Error(json.Message);\n }\n}\n\n/**\n * Fetches the exchange rate for a given currency.\n *\n * @param currency - ISO 4217 currency code.\n * @param nativeCurrency - Symbol for base asset.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rate for given currency.\n */\nexport async function fetchExchangeRate(\n currency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n): Promise<{\n conversionRate: number;\n usdConversionRate: number;\n}> {\n currency = currency.toUpperCase();\n nativeCurrency = nativeCurrency.toUpperCase();\n currency = nativeSymbolOverrides.get(currency) ?? currency;\n nativeCurrency = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;\n\n const json = await handleFetch(\n getPricingURL(currency, nativeCurrency, includeUSDRate),\n );\n\n handleErrorResponse(json);\n const conversionRate = Number(json[currency.toUpperCase()]);\n\n const usdConversionRate = Number(json.USD);\n if (!Number.isFinite(conversionRate)) {\n throw new Error(\n `Invalid response for ${currency.toUpperCase()}: ${\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n json[currency.toUpperCase()]\n }`,\n );\n }\n\n if (includeUSDRate && !Number.isFinite(usdConversionRate)) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Invalid response for usdConversionRate: ${json.USD}`);\n }\n\n return {\n conversionRate,\n usdConversionRate,\n };\n}\n\n/**\n * Fetches the exchange rates for multiple currencies.\n *\n * @param fiatCurrency - The currency of the rates (ISO 4217).\n * @param cryptocurrencies - The cryptocurrencies to get conversion rates for. Min length: 1. Max length: 300.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rates for given currencies.\n */\nexport async function fetchMultiExchangeRate(\n fiatCurrency: string,\n cryptocurrencies: string[],\n includeUSDRate: boolean,\n): Promise<Record<string, Record<string, number>>> {\n const fsyms = cryptocurrencies.map(\n (nativeCurrency) =>\n nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency,\n );\n const url = getMultiPricingURL(fsyms, [fiatCurrency], includeUSDRate);\n const response = await handleFetch(url);\n handleErrorResponse(response);\n\n const rates: Record<string, Record<string, number>> = {};\n for (const [cryptocurrency, values] of Object.entries(response) as [\n string,\n Record<string, number>,\n ][]) {\n const key = getKeyByValue(nativeSymbolOverrides, cryptocurrency);\n rates[key?.toLowerCase() ?? cryptocurrency.toLowerCase()] = {\n [fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],\n ...(includeUSDRate && { usd: values.USD }),\n };\n }\n\n return rates;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-compare.d.cts","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"AAsFA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC;IACT,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC,CA6BD;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EAAE,EAC1B,cAAc,EAAE,OAAO,GACtB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAsBjD"}
1
+ {"version":3,"file":"crypto-compare.d.cts","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"AAoFA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC;IACT,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC,CAkCD;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EAAE,EAC1B,cAAc,EAAE,OAAO,GACtB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAsBjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-compare.d.mts","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"AAsFA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC;IACT,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC,CA6BD;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EAAE,EAC1B,cAAc,EAAE,OAAO,GACtB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAsBjD"}
1
+ {"version":3,"file":"crypto-compare.d.mts","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"AAoFA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC;IACT,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC,CAkCD;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EAAE,EAC1B,cAAc,EAAE,OAAO,GACtB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAsBjD"}
@@ -21,10 +21,8 @@ const CRYPTO_COMPARE_DOMAIN = 'https://min-api.cryptocompare.com';
21
21
  * @returns The API URL for getting the conversion rate.
22
22
  */
23
23
  function getPricingURL(currentCurrency, nativeCurrency, includeUSDRate) {
24
- nativeCurrency = nativeCurrency.toUpperCase();
25
- const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;
26
24
  return (`${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +
27
- `${fsym}&tsyms=${currentCurrency.toUpperCase()}` +
25
+ `${nativeCurrency}&tsyms=${currentCurrency}` +
28
26
  `${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`);
29
27
  }
30
28
  /**
@@ -73,6 +71,10 @@ function handleErrorResponse(json) {
73
71
  * @returns Promise resolving to exchange rate for given currency.
74
72
  */
75
73
  export async function fetchExchangeRate(currency, nativeCurrency, includeUSDRate) {
74
+ currency = currency.toUpperCase();
75
+ nativeCurrency = nativeCurrency.toUpperCase();
76
+ currency = nativeSymbolOverrides.get(currency) ?? currency;
77
+ nativeCurrency = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;
76
78
  const json = await handleFetch(getPricingURL(currency, nativeCurrency, includeUSDRate));
77
79
  handleErrorResponse(json);
78
80
  const conversionRate = Number(json[currency.toUpperCase()]);
@@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;QACzD,gFAAgF;QAChF,4EAA4E;QAC5E,MAAM,IAAI,KAAK,CAAC,2CAA2C,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;KACxE;IAED,OAAO;QACL,cAAc;QACd,iBAAiB;KAClB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,YAAoB,EACpB,gBAA0B,EAC1B,cAAuB;IAEvB,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAChC,CAAC,cAAc,EAAE,EAAE,CACjB,qBAAqB,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,cAAc,CAC9D,CAAC;IACF,MAAM,GAAG,GAAG,kBAAkB,CAAC,KAAK,EAAE,CAAC,YAAY,CAAC,EAAE,cAAc,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;IACxC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAE9B,MAAM,KAAK,GAA2C,EAAE,CAAC;IACzD,KAAK,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAG3D,EAAE;QACH,MAAM,GAAG,GAAG,aAAa,CAAC,qBAAqB,EAAE,cAAc,CAAC,CAAC;QACjE,KAAK,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,cAAc,CAAC,WAAW,EAAE,CAAC,GAAG;YAC1D,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;YAChE,GAAG,CAAC,cAAc,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;SAC3C,CAAC;KACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getKeyByValue } from '../assetsUtil';\n\n/**\n * A map from native currency symbol to CryptoCompare identifier.\n * This is only needed when the values don't match.\n */\nconst nativeSymbolOverrides = new Map([\n ['MNT', 'MANTLE'],\n ['OMNI', 'OMNINET'],\n]);\n\nconst CRYPTO_COMPARE_DOMAIN = 'https://min-api.cryptocompare.com';\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from the given native currency to\n * the given currency. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param currentCurrency - The currency to get a conversion rate for.\n * @param nativeCurrency - The native currency to convert from.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be\n * included in the response as well.\n * @returns The API URL for getting the conversion rate.\n */\nfunction getPricingURL(\n currentCurrency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n) {\n nativeCurrency = nativeCurrency.toUpperCase();\n const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;\n return (\n `${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +\n `${fsym}&tsyms=${currentCurrency.toUpperCase()}` +\n `${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`\n );\n}\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from a given array of native currencies\n * to the given currencies. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param fsyms - The native currencies to get conversion rates for.\n * @param tsyms - The currencies to convert to.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be included.\n * @returns The API URL for getting the conversion rates.\n */\nfunction getMultiPricingURL(\n fsyms: string[],\n tsyms: string[],\n includeUSDRate = false,\n) {\n const updatedTsyms =\n includeUSDRate && !tsyms.some((t) => t.toUpperCase() === 'USD')\n ? [...tsyms, 'USD']\n : tsyms;\n\n const params = new URLSearchParams();\n params.append('fsyms', fsyms.join(','));\n params.append('tsyms', updatedTsyms.join(','));\n\n const url = new URL(`${CRYPTO_COMPARE_DOMAIN}/data/pricemulti`);\n url.search = params.toString();\n return url.toString();\n}\n\n/**\n * Handles an error response from the CryptoCompare API.\n * Expected error response format\n * { Response: \"Error\", Message: \"...\", HasWarning: false }\n *\n * @param json - The JSON response from the CryptoCompare API.\n * @param json.Response - The response status.\n * @param json.Message - The error message.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction handleErrorResponse(json: { Response?: string; Message?: string }) {\n if (json.Response === 'Error') {\n throw new Error(json.Message);\n }\n}\n\n/**\n * Fetches the exchange rate for a given currency.\n *\n * @param currency - ISO 4217 currency code.\n * @param nativeCurrency - Symbol for base asset.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rate for given currency.\n */\nexport async function fetchExchangeRate(\n currency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n): Promise<{\n conversionRate: number;\n usdConversionRate: number;\n}> {\n const json = await handleFetch(\n getPricingURL(currency, nativeCurrency, includeUSDRate),\n );\n\n handleErrorResponse(json);\n const conversionRate = Number(json[currency.toUpperCase()]);\n\n const usdConversionRate = Number(json.USD);\n if (!Number.isFinite(conversionRate)) {\n throw new Error(\n `Invalid response for ${currency.toUpperCase()}: ${\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n json[currency.toUpperCase()]\n }`,\n );\n }\n\n if (includeUSDRate && !Number.isFinite(usdConversionRate)) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Invalid response for usdConversionRate: ${json.USD}`);\n }\n\n return {\n conversionRate,\n usdConversionRate,\n };\n}\n\n/**\n * Fetches the exchange rates for multiple currencies.\n *\n * @param fiatCurrency - The currency of the rates (ISO 4217).\n * @param cryptocurrencies - The cryptocurrencies to get conversion rates for. Min length: 1. Max length: 300.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rates for given currencies.\n */\nexport async function fetchMultiExchangeRate(\n fiatCurrency: string,\n cryptocurrencies: string[],\n includeUSDRate: boolean,\n): Promise<Record<string, Record<string, number>>> {\n const fsyms = cryptocurrencies.map(\n (nativeCurrency) =>\n nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency,\n );\n const url = getMultiPricingURL(fsyms, [fiatCurrency], includeUSDRate);\n const response = await handleFetch(url);\n handleErrorResponse(response);\n\n const rates: Record<string, Record<string, number>> = {};\n for (const [cryptocurrency, values] of Object.entries(response) as [\n string,\n Record<string, number>,\n ][]) {\n const key = getKeyByValue(nativeSymbolOverrides, cryptocurrency);\n rates[key?.toLowerCase() ?? cryptocurrency.toLowerCase()] = {\n [fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],\n ...(includeUSDRate && { usd: values.USD }),\n };\n }\n\n return rates;\n}\n"]}
1
+ {"version":3,"file":"crypto-compare.mjs","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAEzD,OAAO,EAAE,aAAa,EAAE,0BAAsB;AAE9C;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,CAAC,KAAK,EAAE,QAAQ,CAAC;IACjB,CAAC,MAAM,EAAE,SAAS,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,mCAAmC,CAAC;AAElE;;;;;;;;;;GAUG;AACH,SAAS,aAAa,CACpB,eAAuB,EACvB,cAAsB,EACtB,cAAwB;IAExB,OAAO,CACL,GAAG,qBAAqB,mBAAmB;QAC3C,GAAG,cAAc,UAAU,eAAe,EAAE;QAC5C,GAAG,cAAc,IAAI,eAAe,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAC7E,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,kBAAkB,CACzB,KAAe,EACf,KAAe,EACf,cAAc,GAAG,KAAK;IAEtB,MAAM,YAAY,GAChB,cAAc,IAAI,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AAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAG3D,EAAE;QACH,MAAM,GAAG,GAAG,aAAa,CAAC,qBAAqB,EAAE,cAAc,CAAC,CAAC;QACjE,KAAK,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,cAAc,CAAC,WAAW,EAAE,CAAC,GAAG;YAC1D,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;YAChE,GAAG,CAAC,cAAc,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;SAC3C,CAAC;KACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getKeyByValue } from '../assetsUtil';\n\n/**\n * A map from native currency symbol to CryptoCompare identifier.\n * This is only needed when the values don't match.\n */\nconst nativeSymbolOverrides = new Map([\n ['MNT', 'MANTLE'],\n ['OMNI', 'OMNINET'],\n]);\n\nconst CRYPTO_COMPARE_DOMAIN = 'https://min-api.cryptocompare.com';\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from the given native currency to\n * the given currency. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param currentCurrency - The currency to get a conversion rate for.\n * @param nativeCurrency - The native currency to convert from.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be\n * included in the response as well.\n * @returns The API URL for getting the conversion rate.\n */\nfunction getPricingURL(\n currentCurrency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n) {\n return (\n `${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +\n `${nativeCurrency}&tsyms=${currentCurrency}` +\n `${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`\n );\n}\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from a given array of native currencies\n * to the given currencies. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param fsyms - The native currencies to get conversion rates for.\n * @param tsyms - The currencies to convert to.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be included.\n * @returns The API URL for getting the conversion rates.\n */\nfunction getMultiPricingURL(\n fsyms: string[],\n tsyms: string[],\n includeUSDRate = false,\n) {\n const updatedTsyms =\n includeUSDRate && !tsyms.some((t) => t.toUpperCase() === 'USD')\n ? [...tsyms, 'USD']\n : tsyms;\n\n const params = new URLSearchParams();\n params.append('fsyms', fsyms.join(','));\n params.append('tsyms', updatedTsyms.join(','));\n\n const url = new URL(`${CRYPTO_COMPARE_DOMAIN}/data/pricemulti`);\n url.search = params.toString();\n return url.toString();\n}\n\n/**\n * Handles an error response from the CryptoCompare API.\n * Expected error response format\n * { Response: \"Error\", Message: \"...\", HasWarning: false }\n *\n * @param json - The JSON response from the CryptoCompare API.\n * @param json.Response - The response status.\n * @param json.Message - The error message.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction handleErrorResponse(json: { Response?: string; Message?: string }) {\n if (json.Response === 'Error') {\n throw new Error(json.Message);\n }\n}\n\n/**\n * Fetches the exchange rate for a given currency.\n *\n * @param currency - ISO 4217 currency code.\n * @param nativeCurrency - Symbol for base asset.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rate for given currency.\n */\nexport async function fetchExchangeRate(\n currency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n): Promise<{\n conversionRate: number;\n usdConversionRate: number;\n}> {\n currency = currency.toUpperCase();\n nativeCurrency = nativeCurrency.toUpperCase();\n currency = nativeSymbolOverrides.get(currency) ?? currency;\n nativeCurrency = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;\n\n const json = await handleFetch(\n getPricingURL(currency, nativeCurrency, includeUSDRate),\n );\n\n handleErrorResponse(json);\n const conversionRate = Number(json[currency.toUpperCase()]);\n\n const usdConversionRate = Number(json.USD);\n if (!Number.isFinite(conversionRate)) {\n throw new Error(\n `Invalid response for ${currency.toUpperCase()}: ${\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n json[currency.toUpperCase()]\n }`,\n );\n }\n\n if (includeUSDRate && !Number.isFinite(usdConversionRate)) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Invalid response for usdConversionRate: ${json.USD}`);\n }\n\n return {\n conversionRate,\n usdConversionRate,\n };\n}\n\n/**\n * Fetches the exchange rates for multiple currencies.\n *\n * @param fiatCurrency - The currency of the rates (ISO 4217).\n * @param cryptocurrencies - The cryptocurrencies to get conversion rates for. Min length: 1. Max length: 300.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rates for given currencies.\n */\nexport async function fetchMultiExchangeRate(\n fiatCurrency: string,\n cryptocurrencies: string[],\n includeUSDRate: boolean,\n): Promise<Record<string, Record<string, number>>> {\n const fsyms = cryptocurrencies.map(\n (nativeCurrency) =>\n nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency,\n );\n const url = getMultiPricingURL(fsyms, [fiatCurrency], includeUSDRate);\n const response = await handleFetch(url);\n handleErrorResponse(response);\n\n const rates: Record<string, Record<string, number>> = {};\n for (const [cryptocurrency, values] of Object.entries(response) as [\n string,\n Record<string, number>,\n ][]) {\n const key = getKeyByValue(nativeSymbolOverrides, cryptocurrency);\n rates[key?.toLowerCase() ?? cryptocurrency.toLowerCase()] = {\n [fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],\n ...(includeUSDRate && { usd: values.USD }),\n };\n }\n\n return rates;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/assets-controllers",
3
- "version": "51.0.2",
3
+ "version": "52.0.0",
4
4
  "description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -77,16 +77,16 @@
77
77
  },
78
78
  "devDependencies": {
79
79
  "@babel/runtime": "^7.23.9",
80
- "@metamask/accounts-controller": "^24.0.1",
80
+ "@metamask/accounts-controller": "^25.0.0",
81
81
  "@metamask/approval-controller": "^7.1.3",
82
82
  "@metamask/auto-changelog": "^3.4.4",
83
83
  "@metamask/ethjs-provider-http": "^0.3.0",
84
- "@metamask/keyring-controller": "^19.2.1",
85
- "@metamask/keyring-internal-api": "^4.0.3",
84
+ "@metamask/keyring-controller": "^20.0.0",
85
+ "@metamask/keyring-internal-api": "^5.0.0",
86
86
  "@metamask/keyring-snap-client": "^4.0.1",
87
87
  "@metamask/network-controller": "^22.2.1",
88
88
  "@metamask/permission-controller": "^11.0.6",
89
- "@metamask/preferences-controller": "^15.0.2",
89
+ "@metamask/preferences-controller": "^16.0.0",
90
90
  "@metamask/providers": "^18.1.1",
91
91
  "@metamask/snaps-controllers": "^9.19.0",
92
92
  "@metamask/snaps-sdk": "^6.17.1",
@@ -105,12 +105,12 @@
105
105
  "webextension-polyfill": "^0.12.0"
106
106
  },
107
107
  "peerDependencies": {
108
- "@metamask/accounts-controller": "^24.0.0",
108
+ "@metamask/accounts-controller": "^25.0.0",
109
109
  "@metamask/approval-controller": "^7.0.0",
110
- "@metamask/keyring-controller": "^19.0.0",
110
+ "@metamask/keyring-controller": "^20.0.0",
111
111
  "@metamask/network-controller": "^22.0.0",
112
112
  "@metamask/permission-controller": "^11.0.0",
113
- "@metamask/preferences-controller": "^15.0.0",
113
+ "@metamask/preferences-controller": "^16.0.0",
114
114
  "@metamask/providers": "^18.1.0",
115
115
  "@metamask/snaps-controllers": "^9.19.0",
116
116
  "webextension-polyfill": "^0.10.0 || ^0.11.0 || ^0.12.0"