|
| 1 | +import { Messenger } from '@metamask/base-controller'; |
| 2 | +import { |
| 3 | + AccountsControllerAccountAddedEvent, |
| 4 | + AccountsControllerListMultichainAccountsAction, |
| 5 | +} from '@metamask/accounts-controller'; |
| 6 | +import { |
| 7 | + CurrencyRateStateChange, |
| 8 | + GetCurrencyRateState, |
| 9 | + MultichainAssetsControllerStateChangeEvent, |
| 10 | + MultichainAssetsControllerGetStateAction, |
| 11 | +} from '@metamask/assets-controllers'; |
| 12 | +import { |
| 13 | + KeyringControllerLockEvent, |
| 14 | + KeyringControllerUnlockEvent, |
| 15 | +} from '@metamask/keyring-controller'; |
| 16 | +import { HandleSnapRequest } from '@metamask/snaps-controllers'; |
| 17 | + |
| 18 | +type Actions = |
| 19 | + | HandleSnapRequest |
| 20 | + | AccountsControllerListMultichainAccountsAction |
| 21 | + | GetCurrencyRateState |
| 22 | + | MultichainAssetsControllerGetStateAction; |
| 23 | + |
| 24 | +type Events = |
| 25 | + | KeyringControllerLockEvent |
| 26 | + | KeyringControllerUnlockEvent |
| 27 | + | AccountsControllerAccountAddedEvent |
| 28 | + | CurrencyRateStateChange |
| 29 | + | MultichainAssetsControllerStateChangeEvent; |
| 30 | + |
| 31 | +export type MultiChainAssetsRatesControllerMessenger = ReturnType< |
| 32 | + typeof getMultiChainAssetsRatesControllerMessenger |
| 33 | +>; |
| 34 | + |
| 35 | +/** |
| 36 | + * Get a restricted messenger for the Multichain Assets Rate controller. This is scoped to the |
| 37 | + * actions and events that the multichain Assets Rate controller is allowed to handle. |
| 38 | + * |
| 39 | + * @param messenger - The controller messenger to restrict. |
| 40 | + * @returns The restricted controller messenger. |
| 41 | + */ |
| 42 | +export function getMultiChainAssetsRatesControllerMessenger( |
| 43 | + messenger: Messenger<Actions, Events>, |
| 44 | +) { |
| 45 | + return messenger.getRestricted({ |
| 46 | + name: 'MultiChainAssetsRatesController', |
| 47 | + allowedEvents: [ |
| 48 | + 'AccountsController:accountAdded', |
| 49 | + 'KeyringController:lock', |
| 50 | + 'KeyringController:unlock', |
| 51 | + 'CurrencyRateController:stateChange', |
| 52 | + 'MultichainAssetsController:stateChange', |
| 53 | + ], |
| 54 | + allowedActions: [ |
| 55 | + 'AccountsController:listMultichainAccounts', |
| 56 | + 'SnapController:handleRequest', |
| 57 | + 'CurrencyRateController:getState', |
| 58 | + 'MultichainAssetsController:getState', |
| 59 | + ], |
| 60 | + }); |
| 61 | +} |
0 commit comments