Skip to content

Commit 6846d79

Browse files
committed
Filter out non-controllers from ComposableController input
1 parent 0cb9c98 commit 6846d79

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

app/core/Engine.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -462,22 +462,6 @@ type Controllers = {
462462
SwapsController: SwapsController;
463463
};
464464

465-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
466-
type NonControllers = {
467-
AssetsContractController: AssetsContractController;
468-
NftDetectionController: NftDetectionController;
469-
TokenDetectionController: TokenDetectionController;
470-
};
471-
472-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
473-
type NonControllerNames = keyof NonControllers;
474-
475-
const NONCONTROLLER_NAMES = [
476-
'AssetsContractController',
477-
'NftDetectionController',
478-
'TokenDetectionController',
479-
] as const;
480-
481465
/**
482466
* Controllers that area always instantiated
483467
*/
@@ -488,6 +472,24 @@ type RequiredControllers = Omit<Controllers, 'PPOMController'>;
488472
*/
489473
type OptionalControllers = Pick<Controllers, 'PPOMController'>;
490474

475+
/**
476+
* Messageable modules that are part of the Engine's context, but are not defined with state.
477+
* TODO: Replace with type guard once consistent inheritance for non-controllers is implemented. See: https://github.com/MetaMask/decisions/pull/41
478+
*/
479+
const STATELESS_NON_CONTROLLER_NAMES = [
480+
'AssetsContractController',
481+
'NftDetectionController',
482+
'TokenDetectionController',
483+
] as const;
484+
485+
/**
486+
* Controllers that are defined with state.
487+
*/
488+
type StatefulControllers = Omit<
489+
Controllers,
490+
(typeof STATELESS_NON_CONTROLLER_NAMES)[number]
491+
>;
492+
491493
/**
492494
* Combines required and optional controllers for the Engine context type.
493495
*/
@@ -530,7 +532,7 @@ export class Engine {
530532
*/
531533
datamodel: ComposableController<
532534
EngineState,
533-
Exclude<Controllers[keyof Controllers], NonControllers[NonControllerNames]>
535+
StatefulControllers[keyof StatefulControllers]
534536
>;
535537

536538
/**
@@ -1780,18 +1782,15 @@ export class Engine {
17801782

17811783
this.datamodel = new ComposableController<
17821784
EngineState,
1783-
Exclude<
1784-
Controllers[keyof Controllers],
1785-
NonControllers[keyof NonControllers]
1786-
>
1785+
StatefulControllers[keyof StatefulControllers]
17871786
>({
17881787
controllers: controllers.filter(
17891788
(
17901789
controller,
1791-
): controller is Exclude<
1792-
Controllers[keyof Controllers],
1793-
NonControllers[keyof NonControllers]
1794-
> => !NONCONTROLLER_NAMES.find((name) => name === controller.name),
1790+
): controller is StatefulControllers[keyof StatefulControllers] =>
1791+
!STATELESS_NON_CONTROLLER_NAMES.find(
1792+
(name) => name === controller.name,
1793+
),
17951794
),
17961795
messenger: this.controllerMessenger.getRestricted({
17971796
name: 'ComposableController',

0 commit comments

Comments
 (0)