Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment thread
GuillaumeRx marked this conversation as resolved.

### 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 15 additions & 2 deletions packages/assets-controllers/src/CurrencyRateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -45,19 +46,26 @@ export type CurrencyRateState = {

const name = 'CurrencyRateController';

const MESSENGER_EXPOSED_METHODS = [
'setCurrentCurrency',
'updateExchangeRate',
] as const;
Comment thread
GuillaumeRx marked this conversation as resolved.

export type CurrencyRateStateChange = ControllerStateChangeEvent<
typeof name,
CurrencyRateState
>;

export type CurrencyRateControllerEvents = CurrencyRateStateChange;

export type GetCurrencyRateState = ControllerGetStateAction<
export type CurrencyRateControllerGetStateAction = ControllerGetStateAction<
Comment thread
GuillaumeRx marked this conversation as resolved.
typeof name,
CurrencyRateState
>;

export type CurrencyRateControllerActions = GetCurrencyRateState;
export type CurrencyRateControllerActions =
| CurrencyRateControllerGetStateAction
| CurrencyRateControllerMethodActions;

type AllowedActions =
| NetworkControllerGetNetworkClientByIdAction
Expand Down Expand Up @@ -168,6 +176,11 @@ export class CurrencyRateController extends StaticIntervalPollingController<Curr
this.#useExternalServices = useExternalServices;
this.setIntervalLength(interval);
this.#tokenPricesService = tokenPricesService;

this.messenger.registerMethodActionHandlers(
this,
MESSENGER_EXPOSED_METHODS,
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import type { Draft } from 'immer';
import type {
CurrencyRateState,
CurrencyRateStateChange,
GetCurrencyRateState,
CurrencyRateControllerGetStateAction,
} from '../CurrencyRateController';
import type {
MultichainAssetsControllerGetStateAction,
Expand Down Expand Up @@ -121,7 +121,7 @@ export type MultichainAssetsRatesControllerEvents =
export type AllowedActions =
| SnapControllerHandleRequestAction
| AccountsControllerListMultichainAccountsAction
| GetCurrencyRateState
| CurrencyRateControllerGetStateAction
| MultichainAssetsControllerGetStateAction
| AccountsControllerGetSelectedMultichainAccountAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Messenger } from '@metamask/messenger';
import type { Hex } from '@metamask/utils';

import { formatIconUrlWithProxy } from '../assetsUtil';
import type { GetCurrencyRateState } from '../CurrencyRateController';
import type { CurrencyRateControllerGetStateAction } from '../CurrencyRateController';
import type { AbstractTokenPricesService } from '../token-prices-service';
import {
fetchTokenMetadata,
Expand Down Expand Up @@ -61,7 +61,7 @@ export type TokenSearchDiscoveryDataControllerActions =
/**
* All actions that {@link TokenSearchDiscoveryDataController} calls internally.
*/
export type AllowedActions = GetCurrencyRateState;
export type AllowedActions = CurrencyRateControllerGetStateAction;

/**
* The event that {@link TokenSearchDiscoveryDataController} publishes when updating
Expand Down
4 changes: 4 additions & 0 deletions packages/assets-controllers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export {
AssetsContractController,
} from './AssetsContractController';
export * from './CurrencyRateController';
export type {
CurrencyRateControllerSetCurrentCurrencyAction,
CurrencyRateControllerUpdateExchangeRateAction,
} from './CurrencyRateController-method-action-types';
export type {
NftControllerState,
NftControllerMessenger,
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { AccountsControllerGetAccountByAddressAction } from '@metamask/accounts-controller';
import type { AssetsControllerGetExchangeRatesForBridgeAction } from '@metamask/assets-controller';
import type {
GetCurrencyRateState,
CurrencyRateControllerGetStateAction,
MultichainAssetsRatesControllerGetStateAction,
TokenRatesControllerGetStateAction,
} from '@metamask/assets-controllers';
Expand Down Expand Up @@ -436,7 +436,7 @@ export type BridgeControllerEvents = BridgeControllerStateChangeEvent;
export type AllowedActions =
| AccountsControllerGetAccountByAddressAction
| AuthenticationControllerGetBearerTokenAction
| GetCurrencyRateState
| CurrencyRateControllerGetStateAction
| TokenRatesControllerGetStateAction
| MultichainAssetsRatesControllerGetStateAction
| SnapControllerHandleRequestAction
Expand Down
Loading