Skip to content

Commit

Permalink
Apply optimized preview build of @metamask/composable-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Nov 25, 2024
1 parent 328f858 commit 5ceb81c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 70 deletions.
109 changes: 46 additions & 63 deletions app/core/Engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1466,72 +1466,55 @@ export class Engine {
}),
};

// Avoiding `Object.values` and `getKnownPropertyNames` for performance benefits: https://www.measurethat.net/Benchmarks/Show/7173/0/objectvalues-vs-reduce
const controllers = (
Object.keys(this.context) as (keyof Controllers)[]
).reduce<Controllers[keyof Controllers][]>(
(controllers, controllerName) => {
const controller = this.context[controllerName];
if (controller) {
controllers.push(controller);
}
return controllers;
const childControllers = Object.assign({}, this.context);
STATELESS_NON_CONTROLLER_NAMES.forEach((name) => {
delete childControllers[name];
});
this.datamodel = new ComposableController<EngineState, StatefulControllers>(
{
// Avoiding type-safe filter operation with type predicate for performance reasons
controllers: childControllers as StatefulControllers,
messenger: this.controllerMessenger.getRestricted({
name: 'ComposableController',
allowedActions: [],
allowedEvents: [
'AccountsController:stateChange',
'AccountTrackerController:stateChange',
'AddressBookController:stateChange',
'ApprovalController:stateChange',
'CurrencyRateController:stateChange',
'GasFeeController:stateChange',
'KeyringController:stateChange',
'LoggingController:stateChange',
'NetworkController:stateChange',
'NftController:stateChange',
'PermissionController:stateChange',
'PhishingController:stateChange',
'PPOMController:stateChange',
'PreferencesController:stateChange',
'SelectedNetworkController:stateChange',
'SignatureController:stateChange',
'SmartTransactionsController:stateChange',
'SwapsController:stateChange',
'TokenBalancesController:stateChange',
'TokenListController:stateChange',
'TokenRatesController:stateChange',
'TokensController:stateChange',
'TransactionController:stateChange',
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
'SnapController:stateChange',
'SnapsRegistry:stateChange',
'SubjectMetadataController:stateChange',
'AuthenticationController:stateChange',
'UserStorageController:stateChange',
'NotificationServicesController:stateChange',
'NotificationServicesPushController:stateChange',
///: END:ONLY_INCLUDE_IF
],
}),
},
[],
);

this.datamodel = new ComposableController<
EngineState,
StatefulControllers[keyof StatefulControllers]
>({
controllers: controllers.filter(
(
controller,
): controller is StatefulControllers[keyof StatefulControllers] =>
!STATELESS_NON_CONTROLLER_NAMES.find(
(name) => name === controller.name,
),
),
messenger: this.controllerMessenger.getRestricted({
name: 'ComposableController',
allowedActions: [],
allowedEvents: [
'AccountsController:stateChange',
'AccountTrackerController:stateChange',
'AddressBookController:stateChange',
'ApprovalController:stateChange',
'CurrencyRateController:stateChange',
'GasFeeController:stateChange',
'KeyringController:stateChange',
'LoggingController:stateChange',
'NetworkController:stateChange',
'NftController:stateChange',
'PermissionController:stateChange',
'PhishingController:stateChange',
'PPOMController:stateChange',
'PreferencesController:stateChange',
'SelectedNetworkController:stateChange',
'SignatureController:stateChange',
'SmartTransactionsController:stateChange',
'SwapsController:stateChange',
'TokenBalancesController:stateChange',
'TokenListController:stateChange',
'TokenRatesController:stateChange',
'TokensController:stateChange',
'TransactionController:stateChange',
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
'SnapController:stateChange',
'SnapsRegistry:stateChange',
'SubjectMetadataController:stateChange',
'AuthenticationController:stateChange',
'UserStorageController:stateChange',
'NotificationServicesController:stateChange',
'NotificationServicesPushController:stateChange',
///: END:ONLY_INCLUDE_IF
],
}),
});

const { NftController: nfts } = this.context;

if (process.env.MM_OPENSEA_KEY) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"@metamask/approval-controller": "^7.1.0",
"@metamask/assets-controllers": "^43.1.1",
"@metamask/base-controller": "^7.0.1",
"@metamask/composable-controller": "^9.0.0",
"@metamask/composable-controller": "npm:@metamask-previews/composable-controller@9.0.1-preview-9d476a5",
"@metamask/controller-utils": "^11.3.0",
"@metamask/design-tokens": "^4.0.0",
"@metamask/eth-ledger-bridge-keyring": "^6.0.0",
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4162,7 +4162,7 @@
"@metamask/utils" "^9.1.0"
immer "^9.0.6"

"@metamask/base-controller@^7.0.0", "@metamask/base-controller@^7.0.1", "@metamask/base-controller@^7.0.2":
"@metamask/base-controller@^7.0.1", "@metamask/base-controller@^7.0.2":
version "7.0.2"
resolved "https://registry.yarnpkg.com/@metamask/base-controller/-/base-controller-7.0.2.tgz#bf908858215cd4f7d072b3b0f7f0946cf886ee49"
integrity sha512-zeZ5QPKedGT/r2M1NsT4lE7z4u9ciSNcOXG2vUdmfA+QT9YLwIm5+t56UGku3ZTjKGxDn9Ukca3BEkRc57Gt0A==
Expand Down Expand Up @@ -4192,12 +4192,12 @@
"@metamask/utils" "^8.2.0"
"@types/eslint" "^8.44.7"

"@metamask/composable-controller@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@metamask/composable-controller/-/composable-controller-9.0.0.tgz#3e0cd8b782a3772f7e6f1dc4f4253a7b7e55d9b2"
integrity sha512-D1XKK8MkE5g/lzdDpLSiNL1Vp7Y4scKzeScgbQpL4qOcdj/Dx0UQujZ2fjPwkAwto/nwzeFUnZn2Nwj1fhn5lQ==
"@metamask/composable-controller@npm:@metamask-previews/composable-controller@9.0.1-preview-9d476a5":
version "9.0.1-preview-9d476a5"
resolved "https://registry.yarnpkg.com/@metamask-previews/composable-controller/-/composable-controller-9.0.1-preview-9d476a5.tgz#8584e18d66bbe44da83f3f9b7018c8bd8ac93709"
integrity sha512-jYc5TEYpwOKyuO9Sg5vfWIb3l+FzQ9vnPuBlx/GPqk4Ea92t/1dTcwIY+9E46GdO9w9Nj2Kw1tbpV2QVFCp77w==
dependencies:
"@metamask/base-controller" "^7.0.0"
"@metamask/base-controller" "^7.0.2"

"@metamask/contract-metadata@^2.4.0":
version "2.5.0"
Expand Down

0 comments on commit 5ceb81c

Please sign in to comment.