Skip to content

Commit

Permalink
Add origin parameter to snapInstalled and snapUpdated events (#1867)
Browse files Browse the repository at this point in the history
Adds an origin parameter to the emitted `snapInstalled` and
`snapUpdated` events.
  • Loading branch information
FrederikBolding authored Oct 18, 2023
1 parent adc3145 commit 752afe9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
25 changes: 20 additions & 5 deletions packages/snaps-controllers/src/snaps/SnapController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,14 @@ describe('SnapController', () => {
});
}),
new Promise<void>((resolve) => {
messenger.subscribe('SnapController:snapInstalled', (truncatedSnap) => {
expect(truncatedSnap).toStrictEqual(getTruncatedSnap());
resolve();
});
messenger.subscribe(
'SnapController:snapInstalled',
(truncatedSnap, origin) => {
expect(truncatedSnap).toStrictEqual(getTruncatedSnap());
expect(origin).toStrictEqual(MOCK_ORIGIN);
resolve();
},
);
}),
]);

Expand Down Expand Up @@ -3912,6 +3916,11 @@ describe('SnapController', () => {
);

expect(onSnapUpdated).toHaveBeenCalledTimes(1);
expect(onSnapUpdated).toHaveBeenCalledWith(
newSnapTruncated,
'1.0.0',
MOCK_ORIGIN,
);
expect(onSnapAdded).toHaveBeenCalledTimes(1);

controller.destroy();
Expand Down Expand Up @@ -5993,6 +6002,7 @@ describe('SnapController', () => {
'SnapController:snapUpdated',
getTruncatedSnap(),
'0.9.0',
MOCK_ORIGIN,
);

await new Promise((resolve) => setTimeout(resolve, 10));
Expand Down Expand Up @@ -6045,7 +6055,11 @@ describe('SnapController', () => {
() => false,
);

messenger.publish('SnapController:snapInstalled', getTruncatedSnap());
messenger.publish(
'SnapController:snapInstalled',
getTruncatedSnap(),
MOCK_ORIGIN,
);

await new Promise((resolve) => setTimeout(resolve, 10));

Expand Down Expand Up @@ -6093,6 +6107,7 @@ describe('SnapController', () => {
'SnapController:snapUpdated',
getTruncatedSnap(),
'0.9.0',
MOCK_ORIGIN,
);
await new Promise((resolve) => setTimeout(resolve, 10));

Expand Down
7 changes: 5 additions & 2 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export type SnapBlocked = {
*/
export type SnapInstalled = {
type: `${typeof controllerName}:snapInstalled`;
payload: [snap: TruncatedSnap];
payload: [snap: TruncatedSnap, origin: string];
};

/**
Expand Down Expand Up @@ -429,7 +429,7 @@ export type SnapUnblocked = {
*/
export type SnapUpdated = {
type: `${typeof controllerName}:snapUpdated`;
payload: [snap: TruncatedSnap, oldVersion: string];
payload: [snap: TruncatedSnap, oldVersion: string, origin: string];
};

/**
Expand Down Expand Up @@ -1720,6 +1720,7 @@ export class SnapController extends BaseController<
this.messagingSystem.publish(
`SnapController:snapInstalled`,
this.getTruncatedExpect(snapId),
origin,
),
);

Expand All @@ -1728,6 +1729,7 @@ export class SnapController extends BaseController<
`SnapController:snapUpdated`,
this.getTruncatedExpect(snapId),
oldVersion,
origin,
),
);

Expand Down Expand Up @@ -2035,6 +2037,7 @@ export class SnapController extends BaseController<
'SnapController:snapUpdated',
truncatedSnap,
snap.version,
origin,
);
}

Expand Down

0 comments on commit 752afe9

Please sign in to comment.