-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathtoken-detection-controller-messenger.ts
More file actions
98 lines (93 loc) · 2.92 KB
/
token-detection-controller-messenger.ts
File metadata and controls
98 lines (93 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {
Messenger,
MessengerActions,
MessengerEvents,
} from '@metamask/messenger';
import {
AssetsContractControllerGetBalancesInSingleCallAction,
TokenDetectionControllerMessenger,
} from '@metamask/assets-controllers';
import { RootMessenger } from '../types';
import { AnalyticsControllerActions } from '@metamask/analytics-controller';
/**
* Get the messenger for the token detection controller. This is scoped to the
* token detection controller is allowed to handle.
*
* @param rootMessenger - The root messenger.
* @returns The TokenDetectionControllerMessenger.
*/
export function getTokenDetectionControllerMessenger(
rootMessenger: RootMessenger,
): TokenDetectionControllerMessenger {
const messenger = new Messenger<
'TokenDetectionController',
MessengerActions<TokenDetectionControllerMessenger>,
MessengerEvents<TokenDetectionControllerMessenger>,
RootMessenger
>({
namespace: 'TokenDetectionController',
parent: rootMessenger,
});
rootMessenger.delegate({
actions: [
'AccountsController:getAccount',
'AccountsController:getSelectedAccount',
'KeyringController:getState',
'NetworkController:getNetworkClientById',
'NetworkController:getNetworkConfigurationByNetworkClientId',
'NetworkController:getState',
'TokensController:getState',
'TokensController:addDetectedTokens',
'PreferencesController:getState',
'TokensController:addTokens',
'NetworkController:findNetworkClientIdByChainId',
],
events: [
'AccountsController:selectedEvmAccountChange',
'KeyringController:lock',
'KeyringController:unlock',
'NetworkController:networkDidChange',
'PreferencesController:stateChange',
'TransactionController:transactionConfirmed',
],
messenger,
});
return messenger;
}
type AllowedInitializationActions =
| AssetsContractControllerGetBalancesInSingleCallAction
| AnalyticsControllerActions;
type AllowedInitializationEvents = never;
export type TokenDetectionControllerInitMessenger = ReturnType<
typeof getTokenDetectionControllerInitMessenger
>;
/**
* Get the messenger for the token detection controller initialization. This is scoped to the
* actions and events that the token detection controller is allowed to handle during
* initialization.
*
* @param rootMessenger - The root messenger.
* @returns The TokenDetectionControllerInitMessenger.
*/
export function getTokenDetectionControllerInitMessenger(
rootMessenger: RootMessenger,
) {
const messenger = new Messenger<
'TokenDetectionControllerInit',
AllowedInitializationActions,
AllowedInitializationEvents,
RootMessenger
>({
namespace: 'TokenDetectionControllerInit',
parent: rootMessenger,
});
rootMessenger.delegate({
actions: [
'AssetsContractController:getBalancesInSingleCall',
'AnalyticsController:trackEvent',
],
events: [],
messenger,
});
return messenger;
}