@metamask/assets-controllers 83.0.0 → 84.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.
Files changed (142) hide show
  1. package/CHANGELOG.md +37 -2
  2. package/dist/AccountTrackerController.cjs +20 -21
  3. package/dist/AccountTrackerController.cjs.map +1 -1
  4. package/dist/AccountTrackerController.d.cts +4 -3
  5. package/dist/AccountTrackerController.d.cts.map +1 -1
  6. package/dist/AccountTrackerController.d.mts +4 -3
  7. package/dist/AccountTrackerController.d.mts.map +1 -1
  8. package/dist/AccountTrackerController.mjs +20 -21
  9. package/dist/AccountTrackerController.mjs.map +1 -1
  10. package/dist/AssetsContractController.cjs +10 -11
  11. package/dist/AssetsContractController.cjs.map +1 -1
  12. package/dist/AssetsContractController.d.cts +3 -4
  13. package/dist/AssetsContractController.d.cts.map +1 -1
  14. package/dist/AssetsContractController.d.mts +3 -4
  15. package/dist/AssetsContractController.d.mts.map +1 -1
  16. package/dist/AssetsContractController.mjs +10 -11
  17. package/dist/AssetsContractController.mjs.map +1 -1
  18. package/dist/CurrencyRateController.cjs +3 -3
  19. package/dist/CurrencyRateController.cjs.map +1 -1
  20. package/dist/CurrencyRateController.d.cts +4 -3
  21. package/dist/CurrencyRateController.d.cts.map +1 -1
  22. package/dist/CurrencyRateController.d.mts +4 -3
  23. package/dist/CurrencyRateController.d.mts.map +1 -1
  24. package/dist/CurrencyRateController.mjs +3 -3
  25. package/dist/CurrencyRateController.mjs.map +1 -1
  26. package/dist/DeFiPositionsController/DeFiPositionsController.cjs +7 -7
  27. package/dist/DeFiPositionsController/DeFiPositionsController.cjs.map +1 -1
  28. package/dist/DeFiPositionsController/DeFiPositionsController.d.cts +3 -2
  29. package/dist/DeFiPositionsController/DeFiPositionsController.d.cts.map +1 -1
  30. package/dist/DeFiPositionsController/DeFiPositionsController.d.mts +3 -2
  31. package/dist/DeFiPositionsController/DeFiPositionsController.d.mts.map +1 -1
  32. package/dist/DeFiPositionsController/DeFiPositionsController.mjs +7 -7
  33. package/dist/DeFiPositionsController/DeFiPositionsController.mjs.map +1 -1
  34. package/dist/MultichainAssetsController/MultichainAssetsController.cjs +12 -12
  35. package/dist/MultichainAssetsController/MultichainAssetsController.cjs.map +1 -1
  36. package/dist/MultichainAssetsController/MultichainAssetsController.d.cts +3 -2
  37. package/dist/MultichainAssetsController/MultichainAssetsController.d.cts.map +1 -1
  38. package/dist/MultichainAssetsController/MultichainAssetsController.d.mts +3 -2
  39. package/dist/MultichainAssetsController/MultichainAssetsController.d.mts.map +1 -1
  40. package/dist/MultichainAssetsController/MultichainAssetsController.mjs +12 -12
  41. package/dist/MultichainAssetsController/MultichainAssetsController.mjs.map +1 -1
  42. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.cjs +13 -13
  43. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.cjs.map +1 -1
  44. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.cts +4 -3
  45. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.cts.map +1 -1
  46. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.mts +4 -3
  47. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.mts.map +1 -1
  48. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.mjs +13 -13
  49. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.mjs.map +1 -1
  50. package/dist/MultichainBalancesController/MultichainBalancesController.cjs +9 -9
  51. package/dist/MultichainBalancesController/MultichainBalancesController.cjs.map +1 -1
  52. package/dist/MultichainBalancesController/MultichainBalancesController.d.cts +3 -2
  53. package/dist/MultichainBalancesController/MultichainBalancesController.d.cts.map +1 -1
  54. package/dist/MultichainBalancesController/MultichainBalancesController.d.mts +3 -2
  55. package/dist/MultichainBalancesController/MultichainBalancesController.d.mts.map +1 -1
  56. package/dist/MultichainBalancesController/MultichainBalancesController.mjs +9 -9
  57. package/dist/MultichainBalancesController/MultichainBalancesController.mjs.map +1 -1
  58. package/dist/NftController.cjs +25 -25
  59. package/dist/NftController.cjs.map +1 -1
  60. package/dist/NftController.d.cts +3 -3
  61. package/dist/NftController.d.cts.map +1 -1
  62. package/dist/NftController.d.mts +3 -3
  63. package/dist/NftController.d.mts.map +1 -1
  64. package/dist/NftController.mjs +25 -25
  65. package/dist/NftController.mjs.map +1 -1
  66. package/dist/NftDetectionController.cjs +5 -6
  67. package/dist/NftDetectionController.cjs.map +1 -1
  68. package/dist/NftDetectionController.d.cts +5 -5
  69. package/dist/NftDetectionController.d.cts.map +1 -1
  70. package/dist/NftDetectionController.d.mts +5 -5
  71. package/dist/NftDetectionController.d.mts.map +1 -1
  72. package/dist/NftDetectionController.mjs +5 -6
  73. package/dist/NftDetectionController.mjs.map +1 -1
  74. package/dist/RatesController/RatesController.cjs +5 -5
  75. package/dist/RatesController/RatesController.cjs.map +1 -1
  76. package/dist/RatesController/RatesController.d.cts.map +1 -1
  77. package/dist/RatesController/RatesController.d.mts.map +1 -1
  78. package/dist/RatesController/RatesController.mjs +5 -5
  79. package/dist/RatesController/RatesController.mjs.map +1 -1
  80. package/dist/RatesController/types.cjs.map +1 -1
  81. package/dist/RatesController/types.d.cts +3 -2
  82. package/dist/RatesController/types.d.cts.map +1 -1
  83. package/dist/RatesController/types.d.mts +3 -2
  84. package/dist/RatesController/types.d.mts.map +1 -1
  85. package/dist/RatesController/types.mjs.map +1 -1
  86. package/dist/TokenBalancesController.cjs +22 -22
  87. package/dist/TokenBalancesController.cjs.map +1 -1
  88. package/dist/TokenBalancesController.d.cts +3 -2
  89. package/dist/TokenBalancesController.d.cts.map +1 -1
  90. package/dist/TokenBalancesController.d.mts +3 -2
  91. package/dist/TokenBalancesController.d.mts.map +1 -1
  92. package/dist/TokenBalancesController.mjs +22 -22
  93. package/dist/TokenBalancesController.mjs.map +1 -1
  94. package/dist/TokenDetectionController.cjs +24 -24
  95. package/dist/TokenDetectionController.cjs.map +1 -1
  96. package/dist/TokenDetectionController.d.cts +4 -3
  97. package/dist/TokenDetectionController.d.cts.map +1 -1
  98. package/dist/TokenDetectionController.d.mts +4 -3
  99. package/dist/TokenDetectionController.d.mts.map +1 -1
  100. package/dist/TokenDetectionController.mjs +24 -24
  101. package/dist/TokenDetectionController.mjs.map +1 -1
  102. package/dist/TokenListController.cjs +4 -4
  103. package/dist/TokenListController.cjs.map +1 -1
  104. package/dist/TokenListController.d.cts +3 -2
  105. package/dist/TokenListController.d.cts.map +1 -1
  106. package/dist/TokenListController.d.mts +3 -2
  107. package/dist/TokenListController.d.mts.map +1 -1
  108. package/dist/TokenListController.mjs +4 -4
  109. package/dist/TokenListController.mjs.map +1 -1
  110. package/dist/TokenRatesController.cjs +6 -6
  111. package/dist/TokenRatesController.cjs.map +1 -1
  112. package/dist/TokenRatesController.d.cts +3 -2
  113. package/dist/TokenRatesController.d.cts.map +1 -1
  114. package/dist/TokenRatesController.d.mts +3 -2
  115. package/dist/TokenRatesController.d.mts.map +1 -1
  116. package/dist/TokenRatesController.mjs +6 -6
  117. package/dist/TokenRatesController.mjs.map +1 -1
  118. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs +4 -4
  119. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs.map +1 -1
  120. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts +3 -2
  121. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts.map +1 -1
  122. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts +3 -2
  123. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts.map +1 -1
  124. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs +4 -4
  125. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs.map +1 -1
  126. package/dist/TokensController.cjs +17 -17
  127. package/dist/TokensController.cjs.map +1 -1
  128. package/dist/TokensController.d.cts +3 -2
  129. package/dist/TokensController.d.cts.map +1 -1
  130. package/dist/TokensController.d.mts +3 -2
  131. package/dist/TokensController.d.mts.map +1 -1
  132. package/dist/TokensController.mjs +17 -17
  133. package/dist/TokensController.mjs.map +1 -1
  134. package/dist/constants.cjs +2 -1
  135. package/dist/constants.cjs.map +1 -1
  136. package/dist/constants.d.cts.map +1 -1
  137. package/dist/constants.d.mts.map +1 -1
  138. package/dist/constants.mjs +2 -1
  139. package/dist/constants.mjs.map +1 -1
  140. package/dist/selectors/token-selectors.d.cts +8 -8
  141. package/dist/selectors/token-selectors.d.mts +8 -8
  142. package/package.json +25 -24
@@ -30,19 +30,19 @@ const metadata = {
30
30
  fiatCurrency: {
31
31
  includeInStateLogs: true,
32
32
  persist: true,
33
- anonymous: true,
33
+ includeInDebugSnapshot: true,
34
34
  usedInUi: true,
35
35
  },
36
36
  rates: {
37
37
  includeInStateLogs: false,
38
38
  persist: true,
39
- anonymous: true,
39
+ includeInDebugSnapshot: true,
40
40
  usedInUi: true,
41
41
  },
42
42
  cryptocurrencies: {
43
43
  includeInStateLogs: true,
44
44
  persist: true,
45
- anonymous: true,
45
+ includeInDebugSnapshot: true,
46
46
  usedInUi: false,
47
47
  },
48
48
  };
@@ -95,7 +95,7 @@ export class RatesController extends BaseController {
95
95
  if (__classPrivateFieldGet(this, _RatesController_intervalId, "f")) {
96
96
  return;
97
97
  }
98
- this.messagingSystem.publish(`${name}:pollingStarted`);
98
+ this.messenger.publish(`${name}:pollingStarted`);
99
99
  await __classPrivateFieldGet(this, _RatesController_instances, "m", _RatesController_updateRates).call(this);
100
100
  __classPrivateFieldSet(this, _RatesController_intervalId, setInterval(() => {
101
101
  __classPrivateFieldGet(this, _RatesController_instances, "m", _RatesController_executePoll).call(this).catch(console.error);
@@ -110,7 +110,7 @@ export class RatesController extends BaseController {
110
110
  }
111
111
  clearInterval(__classPrivateFieldGet(this, _RatesController_intervalId, "f"));
112
112
  __classPrivateFieldSet(this, _RatesController_intervalId, undefined, "f");
113
- this.messagingSystem.publish(`${name}:pollingStopped`);
113
+ this.messenger.publish(`${name}:pollingStopped`);
114
114
  }
115
115
  /**
116
116
  * Returns the current list of cryptocurrency.
@@ -1 +1 @@
1
- {"version":3,"file":"RatesController.mjs","sourceRoot":"","sources":["../../src/RatesController/RatesController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,KAAK,EAAE,oBAAoB;AAGpC,OAAO,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,4CAAkC;AAQ/F,MAAM,CAAC,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,6BAAW,CAAA;IACX,gCAAc,CAAA;AAChB,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAED,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,QAAQ,GAAG;IACf,YAAY,EAAE;QACZ,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI;KACf;IACD,KAAK,EAAE;QACL,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI;KACf;IACD,gBAAgB,EAAE;QAChB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,YAAY,EAAE,KAAK;IACnB,KAAK,EAAE;QACL,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YACpB,cAAc,EAAE,CAAC;YACjB,cAAc,EAAE,CAAC;SAClB;QACD,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE;YACvB,cAAc,EAAE,CAAC;YACjB,cAAc,EAAE,C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ACf;AACH,CAAC;AAED;;GAEG;AACH,KAAK;IACH,MAAM,uBAAA,IAAI,gEAAa,MAAjB,IAAI,CAAe,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,KAAK;IACH,MAAM,uBAAA,IAAI,6DAAU,MAAd,IAAI,EAAW,KAAK,IAAI,EAAE;QAC9B,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACtD,MAAM,QAAQ,GAGV,MAAM,uBAAA,IAAI,+CAAwB,MAA5B,IAAI,EACZ,YAAY,EACZ,gBAAgB,EAChB,uBAAA,IAAI,uCAAgB,CACrB,CAAC;QAEF,MAAM,YAAY,GAAoB,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC/D,YAAY,CAAC,cAAc,CAAC,GAAG;gBAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,EAAE;gBAC1B,cAAc,EAAE,MAAM,CAAC,YAAY,CAAC;gBACpC,GAAG,CAAC,uBAAA,IAAI,uCAAgB,IAAI,EAAE,iBAAiB,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;aAC/D,CAAC;SACH;QAED,IAAI,CAAC,MAAM,CACT,CAAC,KAAkC,EAAwB,EAAE;YAC3D,OAAO;gBACL,GAAG,KAAK;gBACR,KAAK,EAAE,YAAY;aACpB,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport { Mutex } from 'async-mutex';\nimport type { Draft } from 'immer';\n\nimport { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n ConversionRates,\n RatesControllerState,\n RatesControllerOptions,\n RatesControllerMessenger,\n} from './types';\n\nexport const name = 'RatesController';\n\n/**\n * Supported cryptocurrencies that can be used as a base currency. The value needs to be compatible\n * with CryptoCompare's API which is the default source for the rates.\n *\n * See: https://min-api.cryptocompare.com/documentation?key=Price&cat=multipleSymbolsPriceEndpoint\n */\nexport enum Cryptocurrency {\n Btc = 'btc',\n Solana = 'sol',\n}\n\nconst DEFAULT_INTERVAL = 180000;\n\nconst metadata = {\n fiatCurrency: {\n includeInStateLogs: true,\n persist: true,\n anonymous: true,\n usedInUi: true,\n },\n rates: {\n includeInStateLogs: false,\n persist: true,\n anonymous: true,\n usedInUi: true,\n },\n cryptocurrencies: {\n includeInStateLogs: true,\n persist: true,\n anonymous: true,\n usedInUi: false,\n },\n};\n\nconst defaultState = {\n fiatCurrency: 'usd',\n rates: {\n [Cryptocurrency.Btc]: {\n conversionDate: 0,\n conversionRate: 0,\n },\n [Cryptocurrency.Solana]: {\n conversionDate: 0,\n conversionRate: 0,\n },\n },\n cryptocurrencies: [Cryptocurrency.Btc, Cryptocurrency.Solana],\n};\n\nexport class RatesController extends BaseController<\n typeof name,\n RatesControllerState,\n RatesControllerMessenger\n> {\n readonly #mutex = new Mutex();\n\n readonly #fetchMultiExchangeRate;\n\n readonly #includeUsdRate;\n\n #intervalLength: number;\n\n #intervalId: NodeJS.Timeout | undefined;\n\n /**\n * Creates a RatesController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchMultiExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n */\n constructor({\n interval = DEFAULT_INTERVAL,\n messenger,\n state,\n includeUsdRate,\n fetchMultiExchangeRate = defaultFetchExchangeRate,\n }: RatesControllerOptions) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.#includeUsdRate = includeUsdRate;\n this.#fetchMultiExchangeRate = fetchMultiExchangeRate;\n this.#intervalLength = interval;\n }\n\n /**\n * Executes a function `callback` within a mutex lock to ensure that only one instance of `callback` runs at a time across all invocations of `#withLock`.\n * This method is useful for synchronizing access to a resource or section of code that should not be executed concurrently.\n *\n * @template R - The return type of the function `callback`.\n * @param callback - A callback to execute once the lock is acquired. This callback can be synchronous or asynchronous.\n * @returns A promise that resolves to the result of the function `callback`. The promise is fulfilled once `callback` has completed execution.\n * @example\n * async function criticalLogic() {\n * // Critical logic code goes here.\n * }\n *\n * // Execute criticalLogic within a lock.\n * const result = await this.#withLock(criticalLogic);\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\n async #withLock<R>(callback: () => R) {\n const releaseLock = await this.#mutex.acquire();\n try {\n return callback();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Executes the polling operation to update rates.\n */\n async #executePoll(): Promise<void> {\n await this.#updateRates();\n }\n\n /**\n * Updates the rates by fetching new data.\n */\n async #updateRates(): Promise<void> {\n await this.#withLock(async () => {\n const { fiatCurrency, cryptocurrencies } = this.state;\n const response: Record<\n Cryptocurrency,\n Record<string, number>\n > = await this.#fetchMultiExchangeRate(\n fiatCurrency,\n cryptocurrencies,\n this.#includeUsdRate,\n );\n\n const updatedRates: ConversionRates = {};\n for (const [cryptocurrency, values] of Object.entries(response)) {\n updatedRates[cryptocurrency] = {\n conversionDate: Date.now(),\n conversionRate: values[fiatCurrency],\n ...(this.#includeUsdRate && { usdConversionRate: values.usd }),\n };\n }\n\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n rates: updatedRates,\n };\n },\n );\n });\n }\n\n /**\n * Starts the polling process.\n */\n async start(): Promise<void> {\n if (this.#intervalId) {\n return;\n }\n\n this.messagingSystem.publish(`${name}:pollingStarted`);\n\n await this.#updateRates();\n\n this.#intervalId = setInterval(() => {\n this.#executePoll().catch(console.error);\n }, this.#intervalLength);\n }\n\n /**\n * Stops the polling process.\n */\n async stop(): Promise<void> {\n if (!this.#intervalId) {\n return;\n }\n\n clearInterval(this.#intervalId);\n this.#intervalId = undefined;\n this.messagingSystem.publish(`${name}:pollingStopped`);\n }\n\n /**\n * Returns the current list of cryptocurrency.\n * @returns The cryptocurrency list.\n */\n getCryptocurrencyList(): Cryptocurrency[] {\n const { cryptocurrencies } = this.state;\n return cryptocurrencies;\n }\n\n /**\n * Sets the list of supported cryptocurrencies.\n * @param cryptocurrencies - The list of supported cryptocurrencies.\n */\n async setCryptocurrencyList(\n cryptocurrencies: Cryptocurrency[],\n ): Promise<void> {\n await this.#withLock(() => {\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n cryptocurrencies,\n };\n },\n );\n });\n }\n\n /**\n * Sets the internal fiat currency and update rates accordingly.\n * @param fiatCurrency - The fiat currency.\n */\n async setFiatCurrency(fiatCurrency: string): Promise<void> {\n if (fiatCurrency === '') {\n throw new Error('The currency can not be an empty string');\n }\n\n await this.#withLock(() => {\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n fiatCurrency,\n };\n },\n );\n });\n await this.#updateRates();\n }\n}\n"]}
1
+ {"version":3,"file":"RatesController.mjs","sourceRoot":"","sources":["../../src/RatesController/RatesController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAsB,kCAAkC;AAC/E,OAAO,EAAE,KAAK,EAAE,oBAAoB;AAGpC,OAAO,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,4CAAkC;AAQ/F,MAAM,CAAC,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,6BAAW,CAAA;IACX,gCAAc,CAAA;AAChB,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAED,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,QAAQ,GAAwC;IACpD,YAAY,EAAE;QACZ,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAA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,CAAC,uBAAA,IAAI,uCAAgB,IAAI,EAAE,iBAAiB,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;aAC/D,CAAC;SACH;QAED,IAAI,CAAC,MAAM,CACT,CAAC,KAAkC,EAAwB,EAAE;YAC3D,OAAO;gBACL,GAAG,KAAK;gBACR,KAAK,EAAE,YAAY;aACpB,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { BaseController, type StateMetadata } from '@metamask/base-controller';\nimport { Mutex } from 'async-mutex';\nimport type { Draft } from 'immer';\n\nimport { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n ConversionRates,\n RatesControllerState,\n RatesControllerOptions,\n RatesControllerMessenger,\n} from './types';\n\nexport const name = 'RatesController';\n\n/**\n * Supported cryptocurrencies that can be used as a base currency. The value needs to be compatible\n * with CryptoCompare's API which is the default source for the rates.\n *\n * See: https://min-api.cryptocompare.com/documentation?key=Price&cat=multipleSymbolsPriceEndpoint\n */\nexport enum Cryptocurrency {\n Btc = 'btc',\n Solana = 'sol',\n}\n\nconst DEFAULT_INTERVAL = 180000;\n\nconst metadata: StateMetadata<RatesControllerState> = {\n fiatCurrency: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n rates: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n cryptocurrencies: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n};\n\nconst defaultState = {\n fiatCurrency: 'usd',\n rates: {\n [Cryptocurrency.Btc]: {\n conversionDate: 0,\n conversionRate: 0,\n },\n [Cryptocurrency.Solana]: {\n conversionDate: 0,\n conversionRate: 0,\n },\n },\n cryptocurrencies: [Cryptocurrency.Btc, Cryptocurrency.Solana],\n};\n\nexport class RatesController extends BaseController<\n typeof name,\n RatesControllerState,\n RatesControllerMessenger\n> {\n readonly #mutex = new Mutex();\n\n readonly #fetchMultiExchangeRate;\n\n readonly #includeUsdRate;\n\n #intervalLength: number;\n\n #intervalId: NodeJS.Timeout | undefined;\n\n /**\n * Creates a RatesController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchMultiExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n */\n constructor({\n interval = DEFAULT_INTERVAL,\n messenger,\n state,\n includeUsdRate,\n fetchMultiExchangeRate = defaultFetchExchangeRate,\n }: RatesControllerOptions) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.#includeUsdRate = includeUsdRate;\n this.#fetchMultiExchangeRate = fetchMultiExchangeRate;\n this.#intervalLength = interval;\n }\n\n /**\n * Executes a function `callback` within a mutex lock to ensure that only one instance of `callback` runs at a time across all invocations of `#withLock`.\n * This method is useful for synchronizing access to a resource or section of code that should not be executed concurrently.\n *\n * @template R - The return type of the function `callback`.\n * @param callback - A callback to execute once the lock is acquired. This callback can be synchronous or asynchronous.\n * @returns A promise that resolves to the result of the function `callback`. The promise is fulfilled once `callback` has completed execution.\n * @example\n * async function criticalLogic() {\n * // Critical logic code goes here.\n * }\n *\n * // Execute criticalLogic within a lock.\n * const result = await this.#withLock(criticalLogic);\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\n async #withLock<R>(callback: () => R) {\n const releaseLock = await this.#mutex.acquire();\n try {\n return callback();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Executes the polling operation to update rates.\n */\n async #executePoll(): Promise<void> {\n await this.#updateRates();\n }\n\n /**\n * Updates the rates by fetching new data.\n */\n async #updateRates(): Promise<void> {\n await this.#withLock(async () => {\n const { fiatCurrency, cryptocurrencies } = this.state;\n const response: Record<\n Cryptocurrency,\n Record<string, number>\n > = await this.#fetchMultiExchangeRate(\n fiatCurrency,\n cryptocurrencies,\n this.#includeUsdRate,\n );\n\n const updatedRates: ConversionRates = {};\n for (const [cryptocurrency, values] of Object.entries(response)) {\n updatedRates[cryptocurrency] = {\n conversionDate: Date.now(),\n conversionRate: values[fiatCurrency],\n ...(this.#includeUsdRate && { usdConversionRate: values.usd }),\n };\n }\n\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n rates: updatedRates,\n };\n },\n );\n });\n }\n\n /**\n * Starts the polling process.\n */\n async start(): Promise<void> {\n if (this.#intervalId) {\n return;\n }\n\n this.messenger.publish(`${name}:pollingStarted`);\n\n await this.#updateRates();\n\n this.#intervalId = setInterval(() => {\n this.#executePoll().catch(console.error);\n }, this.#intervalLength);\n }\n\n /**\n * Stops the polling process.\n */\n async stop(): Promise<void> {\n if (!this.#intervalId) {\n return;\n }\n\n clearInterval(this.#intervalId);\n this.#intervalId = undefined;\n this.messenger.publish(`${name}:pollingStopped`);\n }\n\n /**\n * Returns the current list of cryptocurrency.\n * @returns The cryptocurrency list.\n */\n getCryptocurrencyList(): Cryptocurrency[] {\n const { cryptocurrencies } = this.state;\n return cryptocurrencies;\n }\n\n /**\n * Sets the list of supported cryptocurrencies.\n * @param cryptocurrencies - The list of supported cryptocurrencies.\n */\n async setCryptocurrencyList(\n cryptocurrencies: Cryptocurrency[],\n ): Promise<void> {\n await this.#withLock(() => {\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n cryptocurrencies,\n };\n },\n );\n });\n }\n\n /**\n * Sets the internal fiat currency and update rates accordingly.\n * @param fiatCurrency - The fiat currency.\n */\n async setFiatCurrency(fiatCurrency: string): Promise<void> {\n if (fiatCurrency === '') {\n throw new Error('The currency can not be an empty string');\n }\n\n await this.#withLock(() => {\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n fiatCurrency,\n };\n },\n );\n });\n await this.#updateRates();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n RestrictedMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\n\nimport type { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n name as ratesControllerName,\n Cryptocurrency,\n} from './RatesController';\n\n/**\n * Represents the conversion rates from one currency to others, including the conversion date.\n * The `conversionRate` field is a number that maps a cryptocurrency code (e.g., \"BTC\") to its\n * conversion rate.\n * The `usdConversionRate` provides the conversion rate to USD as a number, or `null` if the\n * conversion rate to USD is not available.\n * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.\n */\nexport type Rate = {\n conversionRate: number;\n conversionDate: number;\n usdConversionRate?: number;\n};\n\n/**\n * Represents the conversion rates for multiple cryptocurrencies.\n * Each key is a string representing the cryptocurrency symbol (e.g., \"BTC\", \"SOL\"),\n * and its value is a `Rate` object containing conversion rates from that cryptocurrency\n * to a fiat currencies and an optional USD rate.\n */\nexport type ConversionRates = Record<string, Rate>;\n\n/**\n * Represents the state structure for the RatesController.\n */\nexport type RatesControllerState = {\n /**\n * The fiat currency in which conversion rates are expressed\n * (i.e., the \"to\" currency).\n */\n fiatCurrency: string;\n /**\n * The conversion rates for multiple cryptocurrencies.\n */\n rates: ConversionRates;\n /**\n * A list of supported cryptocurrency symbols.\n * (i.e., the \"from\" currencies).\n */\n cryptocurrencies: Cryptocurrency[];\n};\n\n/**\n * Type definition for RatesController state change events.\n */\nexport type RatesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Type definition for the RatesController polling started event.\n */\nexport type RatesControllerPollingStartedEvent = {\n type: `${typeof ratesControllerName}:pollingStarted`;\n payload: [];\n};\n\n/**\n * Type definition for the RatesController polling stopped event.\n */\nexport type RatesControllerPollingStoppedEvent = {\n type: `${typeof ratesControllerName}:pollingStopped`;\n payload: [];\n};\n\n/**\n * Defines the events that the RatesController can emit.\n */\nexport type RatesControllerEvents =\n | RatesControllerStateChangeEvent\n | RatesControllerPollingStartedEvent\n | RatesControllerPollingStoppedEvent;\n\nexport type RatesControllerGetStateAction = ControllerGetStateAction<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Defines the actions that can be performed to get the state of the RatesController.\n */\nexport type RatesControllerActions = RatesControllerGetStateAction;\n\n/**\n * Defines the actions that the RatesController can perform.\n */\nexport type RatesControllerMessenger = RestrictedMessenger<\n typeof ratesControllerName,\n RatesControllerActions,\n RatesControllerEvents,\n never,\n never\n>;\n\n/**\n * The options required to initialize a RatesController.\n */\nexport type RatesControllerOptions = {\n /**\n * Whether to include USD rates in the conversion rates.\n */\n includeUsdRate: boolean;\n /**\n * The polling interval in milliseconds.\n */\n interval?: number;\n /**\n * The messenger instance for communication.\n */\n messenger: RatesControllerMessenger;\n /**\n * The initial state of the controller.\n */\n state?: Partial<RatesControllerState>;\n /**\n * The function to fetch exchange rates.\n */\n fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;\n};\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n name as ratesControllerName,\n Cryptocurrency,\n} from './RatesController';\n\n/**\n * Represents the conversion rates from one currency to others, including the conversion date.\n * The `conversionRate` field is a number that maps a cryptocurrency code (e.g., \"BTC\") to its\n * conversion rate.\n * The `usdConversionRate` provides the conversion rate to USD as a number, or `null` if the\n * conversion rate to USD is not available.\n * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.\n */\nexport type Rate = {\n conversionRate: number;\n conversionDate: number;\n usdConversionRate?: number;\n};\n\n/**\n * Represents the conversion rates for multiple cryptocurrencies.\n * Each key is a string representing the cryptocurrency symbol (e.g., \"BTC\", \"SOL\"),\n * and its value is a `Rate` object containing conversion rates from that cryptocurrency\n * to a fiat currencies and an optional USD rate.\n */\nexport type ConversionRates = Record<string, Rate>;\n\n/**\n * Represents the state structure for the RatesController.\n */\nexport type RatesControllerState = {\n /**\n * The fiat currency in which conversion rates are expressed\n * (i.e., the \"to\" currency).\n */\n fiatCurrency: string;\n /**\n * The conversion rates for multiple cryptocurrencies.\n */\n rates: ConversionRates;\n /**\n * A list of supported cryptocurrency symbols.\n * (i.e., the \"from\" currencies).\n */\n cryptocurrencies: Cryptocurrency[];\n};\n\n/**\n * Type definition for RatesController state change events.\n */\nexport type RatesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Type definition for the RatesController polling started event.\n */\nexport type RatesControllerPollingStartedEvent = {\n type: `${typeof ratesControllerName}:pollingStarted`;\n payload: [];\n};\n\n/**\n * Type definition for the RatesController polling stopped event.\n */\nexport type RatesControllerPollingStoppedEvent = {\n type: `${typeof ratesControllerName}:pollingStopped`;\n payload: [];\n};\n\n/**\n * Defines the events that the RatesController can emit.\n */\nexport type RatesControllerEvents =\n | RatesControllerStateChangeEvent\n | RatesControllerPollingStartedEvent\n | RatesControllerPollingStoppedEvent;\n\nexport type RatesControllerGetStateAction = ControllerGetStateAction<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Defines the actions that can be performed to get the state of the RatesController.\n */\nexport type RatesControllerActions = RatesControllerGetStateAction;\n\n/**\n * Defines the actions that the RatesController can perform.\n */\nexport type RatesControllerMessenger = Messenger<\n typeof ratesControllerName,\n RatesControllerActions,\n RatesControllerEvents\n>;\n\n/**\n * The options required to initialize a RatesController.\n */\nexport type RatesControllerOptions = {\n /**\n * Whether to include USD rates in the conversion rates.\n */\n includeUsdRate: boolean;\n /**\n * The polling interval in milliseconds.\n */\n interval?: number;\n /**\n * The messenger instance for communication.\n */\n messenger: RatesControllerMessenger;\n /**\n * The initial state of the controller.\n */\n state?: Partial<RatesControllerState>;\n /**\n * The function to fetch exchange rates.\n */\n fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;\n};\n"]}
@@ -1,4 +1,5 @@
1
- import type { RestrictedMessenger, ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import type { Messenger } from "@metamask/messenger";
2
3
  import type { fetchMultiExchangeRate as defaultFetchExchangeRate } from "../crypto-compare-service/index.cjs";
3
4
  import type { name as ratesControllerName, Cryptocurrency } from "./RatesController.cjs";
4
5
  /**
@@ -70,7 +71,7 @@ export type RatesControllerActions = RatesControllerGetStateAction;
70
71
  /**
71
72
  * Defines the actions that the RatesController can perform.
72
73
  */
73
- export type RatesControllerMessenger = RestrictedMessenger<typeof ratesControllerName, RatesControllerActions, RatesControllerEvents, never, never>;
74
+ export type RatesControllerMessenger = Messenger<typeof ratesControllerName, RatesControllerActions, RatesControllerEvents>;
74
75
  /**
75
76
  * The options required to initialize a RatesController.
76
77
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,4CAAkC;AACpG,OAAO,KAAK,EACV,IAAI,IAAI,mBAAmB,EAC3B,cAAc,EACf,8BAA0B;AAE3B;;;;;;;GAOG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;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,EAAE,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAC7B,+BAA+B,GAC/B,kCAAkC,GAClC,kCAAkC,CAAC;AAEvC,MAAM,MAAM,6BAA6B,GAAG,wBAAwB,CAClE,OAAO,mBAAmB,EAC1B,oBAAoB,CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,6BAA6B,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,SAAS,CAC9C,OAAO,mBAAmB,EAC1B,sBAAsB,EACtB,qBAAqB,CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,cAAc,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,EAAE,wBAAwB,CAAC;IACpC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACtC;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,wBAAwB,CAAC;CAC1D,CAAC"}
@@ -1,4 +1,5 @@
1
- import type { RestrictedMessenger, ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import type { Messenger } from "@metamask/messenger";
2
3
  import type { fetchMultiExchangeRate as defaultFetchExchangeRate } from "../crypto-compare-service/index.mjs";
3
4
  import type { name as ratesControllerName, Cryptocurrency } from "./RatesController.mjs";
4
5
  /**
@@ -70,7 +71,7 @@ export type RatesControllerActions = RatesControllerGetStateAction;
70
71
  /**
71
72
  * Defines the actions that the RatesController can perform.
72
73
  */
73
- export type RatesControllerMessenger = RestrictedMessenger<typeof ratesControllerName, RatesControllerActions, RatesControllerEvents, never, never>;
74
+ export type RatesControllerMessenger = Messenger<typeof ratesControllerName, RatesControllerActions, RatesControllerEvents>;
74
75
  /**
75
76
  * The options required to initialize a RatesController.
76
77
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,4CAAkC;AACpG,OAAO,KAAK,EACV,IAAI,IAAI,mBAAmB,EAC3B,cAAc,EACf,8BAA0B;AAE3B;;;;;;;GAOG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC;IACvB;;;OAGG;IACH,gBAAgB,EAAE,cAAc,EAAE,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG,0BAA0B,CACtE,OAAO,mBAAmB,EAC1B,oBAAoB,CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,GAAG,OAAO,mBAAmB,iBAAiB,CAAC;IACrD,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,GAAG,OAAO,mBAAmB,iBAAiB,CAAC;IACrD,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAC7B,+BAA+B,GAC/B,kCAAkC,GAClC,kCAA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.mjs","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n RestrictedMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\n\nimport type { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n name as ratesControllerName,\n Cryptocurrency,\n} from './RatesController';\n\n/**\n * Represents the conversion rates from one currency to others, including the conversion date.\n * The `conversionRate` field is a number that maps a cryptocurrency code (e.g., \"BTC\") to its\n * conversion rate.\n * The `usdConversionRate` provides the conversion rate to USD as a number, or `null` if the\n * conversion rate to USD is not available.\n * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.\n */\nexport type Rate = {\n conversionRate: number;\n conversionDate: number;\n usdConversionRate?: number;\n};\n\n/**\n * Represents the conversion rates for multiple cryptocurrencies.\n * Each key is a string representing the cryptocurrency symbol (e.g., \"BTC\", \"SOL\"),\n * and its value is a `Rate` object containing conversion rates from that cryptocurrency\n * to a fiat currencies and an optional USD rate.\n */\nexport type ConversionRates = Record<string, Rate>;\n\n/**\n * Represents the state structure for the RatesController.\n */\nexport type RatesControllerState = {\n /**\n * The fiat currency in which conversion rates are expressed\n * (i.e., the \"to\" currency).\n */\n fiatCurrency: string;\n /**\n * The conversion rates for multiple cryptocurrencies.\n */\n rates: ConversionRates;\n /**\n * A list of supported cryptocurrency symbols.\n * (i.e., the \"from\" currencies).\n */\n cryptocurrencies: Cryptocurrency[];\n};\n\n/**\n * Type definition for RatesController state change events.\n */\nexport type RatesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Type definition for the RatesController polling started event.\n */\nexport type RatesControllerPollingStartedEvent = {\n type: `${typeof ratesControllerName}:pollingStarted`;\n payload: [];\n};\n\n/**\n * Type definition for the RatesController polling stopped event.\n */\nexport type RatesControllerPollingStoppedEvent = {\n type: `${typeof ratesControllerName}:pollingStopped`;\n payload: [];\n};\n\n/**\n * Defines the events that the RatesController can emit.\n */\nexport type RatesControllerEvents =\n | RatesControllerStateChangeEvent\n | RatesControllerPollingStartedEvent\n | RatesControllerPollingStoppedEvent;\n\nexport type RatesControllerGetStateAction = ControllerGetStateAction<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Defines the actions that can be performed to get the state of the RatesController.\n */\nexport type RatesControllerActions = RatesControllerGetStateAction;\n\n/**\n * Defines the actions that the RatesController can perform.\n */\nexport type RatesControllerMessenger = RestrictedMessenger<\n typeof ratesControllerName,\n RatesControllerActions,\n RatesControllerEvents,\n never,\n never\n>;\n\n/**\n * The options required to initialize a RatesController.\n */\nexport type RatesControllerOptions = {\n /**\n * Whether to include USD rates in the conversion rates.\n */\n includeUsdRate: boolean;\n /**\n * The polling interval in milliseconds.\n */\n interval?: number;\n /**\n * The messenger instance for communication.\n */\n messenger: RatesControllerMessenger;\n /**\n * The initial state of the controller.\n */\n state?: Partial<RatesControllerState>;\n /**\n * The function to fetch exchange rates.\n */\n fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;\n};\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n name as ratesControllerName,\n Cryptocurrency,\n} from './RatesController';\n\n/**\n * Represents the conversion rates from one currency to others, including the conversion date.\n * The `conversionRate` field is a number that maps a cryptocurrency code (e.g., \"BTC\") to its\n * conversion rate.\n * The `usdConversionRate` provides the conversion rate to USD as a number, or `null` if the\n * conversion rate to USD is not available.\n * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.\n */\nexport type Rate = {\n conversionRate: number;\n conversionDate: number;\n usdConversionRate?: number;\n};\n\n/**\n * Represents the conversion rates for multiple cryptocurrencies.\n * Each key is a string representing the cryptocurrency symbol (e.g., \"BTC\", \"SOL\"),\n * and its value is a `Rate` object containing conversion rates from that cryptocurrency\n * to a fiat currencies and an optional USD rate.\n */\nexport type ConversionRates = Record<string, Rate>;\n\n/**\n * Represents the state structure for the RatesController.\n */\nexport type RatesControllerState = {\n /**\n * The fiat currency in which conversion rates are expressed\n * (i.e., the \"to\" currency).\n */\n fiatCurrency: string;\n /**\n * The conversion rates for multiple cryptocurrencies.\n */\n rates: ConversionRates;\n /**\n * A list of supported cryptocurrency symbols.\n * (i.e., the \"from\" currencies).\n */\n cryptocurrencies: Cryptocurrency[];\n};\n\n/**\n * Type definition for RatesController state change events.\n */\nexport type RatesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Type definition for the RatesController polling started event.\n */\nexport type RatesControllerPollingStartedEvent = {\n type: `${typeof ratesControllerName}:pollingStarted`;\n payload: [];\n};\n\n/**\n * Type definition for the RatesController polling stopped event.\n */\nexport type RatesControllerPollingStoppedEvent = {\n type: `${typeof ratesControllerName}:pollingStopped`;\n payload: [];\n};\n\n/**\n * Defines the events that the RatesController can emit.\n */\nexport type RatesControllerEvents =\n | RatesControllerStateChangeEvent\n | RatesControllerPollingStartedEvent\n | RatesControllerPollingStoppedEvent;\n\nexport type RatesControllerGetStateAction = ControllerGetStateAction<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Defines the actions that can be performed to get the state of the RatesController.\n */\nexport type RatesControllerActions = RatesControllerGetStateAction;\n\n/**\n * Defines the actions that the RatesController can perform.\n */\nexport type RatesControllerMessenger = Messenger<\n typeof ratesControllerName,\n RatesControllerActions,\n RatesControllerEvents\n>;\n\n/**\n * The options required to initialize a RatesController.\n */\nexport type RatesControllerOptions = {\n /**\n * Whether to include USD rates in the conversion rates.\n */\n includeUsdRate: boolean;\n /**\n * The polling interval in milliseconds.\n */\n interval?: number;\n /**\n * The messenger instance for communication.\n */\n messenger: RatesControllerMessenger;\n /**\n * The initial state of the controller.\n */\n state?: Partial<RatesControllerState>;\n /**\n * The function to fetch exchange rates.\n */\n fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;\n};\n"]}
@@ -29,7 +29,7 @@ const metadata = {
29
29
  tokenBalances: {
30
30
  includeInStateLogs: false,
31
31
  persist: true,
32
- anonymous: false,
32
+ includeInDebugSnapshot: false,
33
33
  usedInUi: true,
34
34
  },
35
35
  };
@@ -117,17 +117,17 @@ class TokenBalancesController extends (0, polling_controller_1.StaticIntervalPol
117
117
  pendingChanges: new Map(),
118
118
  });
119
119
  _TokenBalancesController_getProvider.set(this, (chainId) => {
120
- const { networkConfigurationsByChainId } = this.messagingSystem.call('NetworkController:getState');
120
+ const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
121
121
  const cfg = networkConfigurationsByChainId[chainId];
122
122
  const { networkClientId } = cfg.rpcEndpoints[cfg.defaultRpcEndpointIndex];
123
- const client = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
123
+ const client = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
124
124
  return new providers_1.Web3Provider(client.provider);
125
125
  });
126
126
  _TokenBalancesController_getNetworkClient.set(this, (chainId) => {
127
- const { networkConfigurationsByChainId } = this.messagingSystem.call('NetworkController:getState');
127
+ const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
128
128
  const cfg = networkConfigurationsByChainId[chainId];
129
129
  const { networkClientId } = cfg.rpcEndpoints[cfg.defaultRpcEndpointIndex];
130
- return this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
130
+ return this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
131
131
  });
132
132
  /**
133
133
  * Creates an AccountsApiBalanceFetcher that only supports chains in the accountsApiChainIds array
@@ -296,11 +296,11 @@ class TokenBalancesController extends (0, polling_controller_1.StaticIntervalPol
296
296
  }
297
297
  // Update native balances in AccountTrackerController
298
298
  if (nativeBalanceUpdates.length > 0) {
299
- this.messagingSystem.call('AccountTrackerController:updateNativeBalances', nativeBalanceUpdates);
299
+ this.messenger.call('AccountTrackerController:updateNativeBalances', nativeBalanceUpdates);
300
300
  }
301
301
  // Import any new tokens that were discovered (balance already updated from websocket)
302
302
  if (newTokens.length > 0) {
303
- await this.messagingSystem.call('TokenDetectionController:addDetectedTokensViaWs', {
303
+ await this.messenger.call('TokenDetectionController:addDetectedTokensViaWs', {
304
304
  tokensSlice: newTokens,
305
305
  chainId: chainId,
306
306
  });
@@ -355,24 +355,24 @@ class TokenBalancesController extends (0, polling_controller_1.StaticIntervalPol
355
355
  ], "f");
356
356
  this.setIntervalLength(interval);
357
357
  // initial token state & subscriptions
358
- const { allTokens, allDetectedTokens, allIgnoredTokens } = this.messagingSystem.call('TokensController:getState');
358
+ const { allTokens, allDetectedTokens, allIgnoredTokens } = this.messenger.call('TokensController:getState');
359
359
  __classPrivateFieldSet(this, _TokenBalancesController_allTokens, allTokens, "f");
360
360
  __classPrivateFieldSet(this, _TokenBalancesController_detectedTokens, allDetectedTokens, "f");
361
361
  __classPrivateFieldSet(this, _TokenBalancesController_allIgnoredTokens, allIgnoredTokens, "f");
362
- this.messagingSystem.subscribe('TokensController:stateChange', (tokensState) => {
362
+ this.messenger.subscribe('TokensController:stateChange', (tokensState) => {
363
363
  __classPrivateFieldGet(this, _TokenBalancesController_onTokensChanged, "f").call(this, tokensState).catch((error) => {
364
364
  console.warn('Error handling token state change:', error);
365
365
  });
366
366
  });
367
- this.messagingSystem.subscribe('NetworkController:stateChange', __classPrivateFieldGet(this, _TokenBalancesController_onNetworkChanged, "f"));
368
- this.messagingSystem.subscribe('KeyringController:accountRemoved', __classPrivateFieldGet(this, _TokenBalancesController_onAccountRemoved, "f"));
367
+ this.messenger.subscribe('NetworkController:stateChange', __classPrivateFieldGet(this, _TokenBalancesController_onNetworkChanged, "f"));
368
+ this.messenger.subscribe('KeyringController:accountRemoved', __classPrivateFieldGet(this, _TokenBalancesController_onAccountRemoved, "f"));
369
369
  // Register action handlers for polling interval control
370
- this.messagingSystem.registerActionHandler(`TokenBalancesController:updateChainPollingConfigs`, this.updateChainPollingConfigs.bind(this));
371
- this.messagingSystem.registerActionHandler(`TokenBalancesController:getChainPollingConfig`, this.getChainPollingConfig.bind(this));
370
+ this.messenger.registerActionHandler(`TokenBalancesController:updateChainPollingConfigs`, this.updateChainPollingConfigs.bind(this));
371
+ this.messenger.registerActionHandler(`TokenBalancesController:getChainPollingConfig`, this.getChainPollingConfig.bind(this));
372
372
  // Subscribe to AccountActivityService balance updates for real-time updates
373
- this.messagingSystem.subscribe('AccountActivityService:balanceUpdated', __classPrivateFieldGet(this, _TokenBalancesController_onAccountActivityBalanceUpdate, "f").bind(this));
373
+ this.messenger.subscribe('AccountActivityService:balanceUpdated', __classPrivateFieldGet(this, _TokenBalancesController_onAccountActivityBalanceUpdate, "f").bind(this));
374
374
  // Subscribe to AccountActivityService status changes for dynamic polling management
375
- this.messagingSystem.subscribe('AccountActivityService:statusChanged', __classPrivateFieldGet(this, _TokenBalancesController_onAccountActivityStatusChanged, "f").bind(this));
375
+ this.messenger.subscribe('AccountActivityService:statusChanged', __classPrivateFieldGet(this, _TokenBalancesController_onAccountActivityStatusChanged, "f").bind(this));
376
376
  }
377
377
  /**
378
378
  * Override to support per-chain polling intervals by grouping chains by interval
@@ -455,8 +455,8 @@ class TokenBalancesController extends (0, polling_controller_1.StaticIntervalPol
455
455
  if (!targetChains.length) {
456
456
  return;
457
457
  }
458
- const { address: selected } = this.messagingSystem.call('AccountsController:getSelectedAccount');
459
- const allAccounts = this.messagingSystem.call('AccountsController:listAccounts');
458
+ const { address: selected } = this.messenger.call('AccountsController:getSelectedAccount');
459
+ const allAccounts = this.messenger.call('AccountsController:listAccounts');
460
460
  const aggregated = [];
461
461
  let remainingChains = [...targetChains];
462
462
  // Try each fetcher in order, removing successfully processed chains
@@ -543,7 +543,7 @@ class TokenBalancesController extends (0, polling_controller_1.StaticIntervalPol
543
543
  this.update(() => next);
544
544
  const nativeBalances = aggregated.filter((r) => r.success && r.token === ZERO_ADDRESS);
545
545
  // Get current AccountTracker state to compare existing balances
546
- const accountTrackerState = this.messagingSystem.call('AccountTrackerController:getState');
546
+ const accountTrackerState = this.messenger.call('AccountTrackerController:getState');
547
547
  // Update native token balances only if they have changed
548
548
  if (nativeBalances.length > 0) {
549
549
  const balanceUpdates = nativeBalances
@@ -558,7 +558,7 @@ class TokenBalancesController extends (0, polling_controller_1.StaticIntervalPol
558
558
  return currentBalance !== update.balance;
559
559
  });
560
560
  if (balanceUpdates.length > 0) {
561
- this.messagingSystem.call('AccountTrackerController:updateNativeBalances', balanceUpdates);
561
+ this.messenger.call('AccountTrackerController:updateNativeBalances', balanceUpdates);
562
562
  }
563
563
  }
564
564
  // Filter and update staked balances in a single batch operation for better performance
@@ -584,7 +584,7 @@ class TokenBalancesController extends (0, polling_controller_1.StaticIntervalPol
584
584
  return currentStakedBalance !== update.stakedBalance;
585
585
  });
586
586
  if (stakedBalanceUpdates.length > 0) {
587
- this.messagingSystem.call('AccountTrackerController:updateStakedBalances', stakedBalanceUpdates);
587
+ this.messenger.call('AccountTrackerController:updateStakedBalances', stakedBalanceUpdates);
588
588
  }
589
589
  }
590
590
  }
@@ -605,8 +605,8 @@ class TokenBalancesController extends (0, polling_controller_1.StaticIntervalPol
605
605
  __classPrivateFieldGet(this, _TokenBalancesController_statusChangeDebouncer, "f").timer = null;
606
606
  }
607
607
  // Unregister action handlers
608
- this.messagingSystem.unregisterActionHandler(`TokenBalancesController:updateChainPollingConfigs`);
609
- this.messagingSystem.unregisterActionHandler(`TokenBalancesController:getChainPollingConfig`);
608
+ this.messenger.unregisterActionHandler(`TokenBalancesController:updateChainPollingConfigs`);
609
+ this.messenger.unregisterActionHandler(`TokenBalancesController:getChainPollingConfig`);
610
610
  super.destroy();
611
611
  }
612
612
  }