Skip to content

Commit

Permalink
Remove the svgIcon property from Snap state (#172)
Browse files Browse the repository at this point in the history
This PR removes the `svgIcon` property from the `Snap` interface and stops storing it in state. Instead, the `svgIcon` is emitted with the `snapAdded` event. This change is to avoid storing potentially large SVG icons in state in multiple places (in our usage, both the `SnapController` and `SubjectMetadataController`).
  • Loading branch information
rekmarks authored Dec 18, 2021
1 parent 722b518 commit 19a114a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
3 changes: 0 additions & 3 deletions packages/controllers/src/snaps/SnapController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ const getSnapObject = ({
status = SnapStatus.stopped,
enabled = true,
sourceCode = FAKE_SNAP_SOURCE_CODE,
svgIcon = null,
} = {}): Snap => {
return {
initialPermissions,
Expand All @@ -227,7 +226,6 @@ const getSnapObject = ({
status,
enabled,
sourceCode,
svgIcon,
} as const;
};

Expand Down Expand Up @@ -451,7 +449,6 @@ describe('SnapController', () => {
permissionName: 'fooperm',
version: '0.0.1',
sourceCode,
svgIcon: null,
id: 'npm:foo',
manifest: getSnapManifest({
shasum: getSnapSourceShasum(sourceCode),
Expand Down
15 changes: 7 additions & 8 deletions packages/controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ export type Snap = {
*/
status: SnapStatus;

/**
* The SVG icon of the Snap.
*/
svgIcon: string | null;

/**
* The version of the Snap.
*/
Expand Down Expand Up @@ -176,7 +171,7 @@ export type SnapStateChange = {
*/
export type SnapAdded = {
type: `${typeof controllerName}:snapAdded`;
payload: [snapId: string, snap: Snap];
payload: [snapId: string, snap: Snap, svgIcon: string | undefined];
};

/**
Expand Down Expand Up @@ -1037,7 +1032,6 @@ export class SnapController extends BaseController<
manifest,
permissionName: SNAP_PREFIX + snapId, // so we can easily correlate them
sourceCode,
svgIcon: svgIcon ?? null,
status: snapStatusStateMachineConfig.initial,
version: manifest.version,
};
Expand All @@ -1054,7 +1048,12 @@ export class SnapController extends BaseController<
state.snaps[snapId] = snap;
});

this.messagingSystem.publish(`SnapController:snapAdded`, snapId, snap);
this.messagingSystem.publish(
`SnapController:snapAdded`,
snapId,
snap,
svgIcon,
);
return snap;
}

Expand Down

0 comments on commit 19a114a

Please sign in to comment.