Skip to content

Commit

Permalink
feat: add hideHeader flag for preinstalled Snaps (#2713)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeRx authored Sep 11, 2024
1 parent de6fbb1 commit 41b33ed
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/snaps-controllers/src/snaps/SnapController.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5097,6 +5097,45 @@ describe('SnapController', () => {
snapController.destroy();
});

it('supports preinstalled Snaps specifying the hideHeader flag', async () => {
const rootMessenger = getControllerMessenger();
jest.spyOn(rootMessenger, 'call');

// The snap should not have permission initially
rootMessenger.registerActionHandler(
'PermissionController:getPermissions',
() => ({}),
);

const preinstalledSnaps = [
{
snapId: MOCK_SNAP_ID,
manifest: getSnapManifest(),
hideHeader: true,
files: [
{
path: DEFAULT_SOURCE_PATH,
value: stringToBytes(DEFAULT_SNAP_BUNDLE),
},
{
path: DEFAULT_ICON_PATH,
value: stringToBytes(DEFAULT_SNAP_ICON),
},
],
},
];

const snapControllerOptions = getSnapControllerWithEESOptions({
preinstalledSnaps,
rootMessenger,
});
const [snapController] = getSnapControllerWithEES(snapControllerOptions);

expect(snapController.get(MOCK_SNAP_ID)?.hideHeader).toBe(true);

snapController.destroy();
});

it('authorizes permissions needed for snaps', async () => {
const manifest = getSnapManifest();
const rootMessenger = getControllerMessenger();
Expand Down
6 changes: 6 additions & 0 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export interface PreinstalledSnap {
files: PreinstalledSnapFile[];
removable?: boolean;
hidden?: boolean;
hideHeader?: boolean;
}

type SnapRpcHandler = (
Expand Down Expand Up @@ -718,6 +719,7 @@ type SetSnapArgs = Omit<AddSnapArgs, 'location' | 'versionRange'> & {
removable?: boolean;
preinstalled?: boolean;
hidden?: boolean;
hideHeader?: boolean;
};

const defaultState: SnapControllerState = {
Expand Down Expand Up @@ -1125,6 +1127,7 @@ export class SnapController extends BaseController<
files,
removable,
hidden,
hideHeader,
} of preinstalledSnaps) {
const existingSnap = this.get(snapId);
const isAlreadyInstalled = existingSnap !== undefined;
Expand Down Expand Up @@ -1195,6 +1198,7 @@ export class SnapController extends BaseController<
files: filesObject,
removable,
hidden,
hideHeader,
preinstalled: true,
});

Expand Down Expand Up @@ -2865,6 +2869,7 @@ export class SnapController extends BaseController<
removable,
preinstalled,
hidden,
hideHeader,
} = args;

const {
Expand Down Expand Up @@ -2921,6 +2926,7 @@ export class SnapController extends BaseController<
removable,
preinstalled,
hidden,
hideHeader,

id: snapId,
initialConnections: manifest.result.initialConnections,
Expand Down
5 changes: 5 additions & 0 deletions packages/snaps-utils/src/snaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export type Snap = TruncatedSnap & {
* Flag to signal whether this snap should be hidden from the user or not.
*/
hidden?: boolean;

/**
* Flag to signal whether this snap should hide the header in the UI or not.
*/
hideHeader?: boolean;
};

export type TruncatedSnapFields =
Expand Down

0 comments on commit 41b33ed

Please sign in to comment.