diff --git a/packages/assets-controllers/CHANGELOG.md b/packages/assets-controllers/CHANGELOG.md index 80662fac603..b2211ffd559 100644 --- a/packages/assets-controllers/CHANGELOG.md +++ b/packages/assets-controllers/CHANGELOG.md @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Expose missing public `CurrencyRateController` methods through its messenger ([#8561](https://github.com/MetaMask/core/pull/8561)) + - The following actions are now available: + - `CurrencyRateController:setCurrentCurrency` + - `CurrencyRateController:updateExchangeRate` + - Corresponding action types (e.g. `CurrencyRateControllerSetCurrentCurrencyAction`) are available as well. + +### Changed + +- **BREAKING:** Standardize names of `CurrencyRateController` messenger action types ([#8561](https://github.com/MetaMask/core/pull/8561)) + - The `GetCurrencyRateState` messenger action has been renamed to `CurrencyRateControllerGetStateAction` to follow the convention. You will need to update imports appropriately. + - These changes only affect the types. The action type strings themselves have not changed, so you do not need to update the list of actions you pass when initializing `CurrencyRateController` messenger. + ## [104.3.0] ### Added diff --git a/packages/assets-controllers/src/CurrencyRateController-method-action-types.ts b/packages/assets-controllers/src/CurrencyRateController-method-action-types.ts new file mode 100644 index 00000000000..d8a71ecc84e --- /dev/null +++ b/packages/assets-controllers/src/CurrencyRateController-method-action-types.ts @@ -0,0 +1,33 @@ +/** + * This file is auto generated. + * Do not edit manually. + */ + +import type { CurrencyRateController } from './CurrencyRateController'; + +/** + * Sets a currency to track. + * + * @param currentCurrency - ISO 4217 currency code. + */ +export type CurrencyRateControllerSetCurrentCurrencyAction = { + type: `CurrencyRateController:setCurrentCurrency`; + handler: CurrencyRateController['setCurrentCurrency']; +}; + +/** + * Updates the exchange rate for the current currency and native currency pairs. + * + * @param nativeCurrencies - The native currency symbols to fetch exchange rates for. + */ +export type CurrencyRateControllerUpdateExchangeRateAction = { + type: `CurrencyRateController:updateExchangeRate`; + handler: CurrencyRateController['updateExchangeRate']; +}; + +/** + * Union of all CurrencyRateController action types. + */ +export type CurrencyRateControllerMethodActions = + | CurrencyRateControllerSetCurrentCurrencyAction + | CurrencyRateControllerUpdateExchangeRateAction; diff --git a/packages/assets-controllers/src/CurrencyRateController.ts b/packages/assets-controllers/src/CurrencyRateController.ts index d6266083c4c..981f5434585 100644 --- a/packages/assets-controllers/src/CurrencyRateController.ts +++ b/packages/assets-controllers/src/CurrencyRateController.ts @@ -17,6 +17,7 @@ import { StaticIntervalPollingController } from '@metamask/polling-controller'; import type { Hex } from '@metamask/utils'; import { Mutex } from 'async-mutex'; +import type { CurrencyRateControllerMethodActions } from './CurrencyRateController-method-action-types'; import type { AbstractTokenPricesService } from './token-prices-service/abstract-token-prices-service'; import { getNativeTokenAddress } from './token-prices-service/codefi-v2'; @@ -45,6 +46,11 @@ export type CurrencyRateState = { const name = 'CurrencyRateController'; +const MESSENGER_EXPOSED_METHODS = [ + 'setCurrentCurrency', + 'updateExchangeRate', +] as const; + export type CurrencyRateStateChange = ControllerStateChangeEvent< typeof name, CurrencyRateState @@ -52,12 +58,14 @@ export type CurrencyRateStateChange = ControllerStateChangeEvent< export type CurrencyRateControllerEvents = CurrencyRateStateChange; -export type GetCurrencyRateState = ControllerGetStateAction< +export type CurrencyRateControllerGetStateAction = ControllerGetStateAction< typeof name, CurrencyRateState >; -export type CurrencyRateControllerActions = GetCurrencyRateState; +export type CurrencyRateControllerActions = + | CurrencyRateControllerGetStateAction + | CurrencyRateControllerMethodActions; type AllowedActions = | NetworkControllerGetNetworkClientByIdAction @@ -168,6 +176,11 @@ export class CurrencyRateController extends StaticIntervalPollingController