Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add hideHeader flag for preinstalled Snaps #2713

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1848,7 +1848,7 @@
});

// This isn't stable in CI unfortunately
it.skip('throws if the Snap is terminated while executing', async () => {

Check warning on line 1851 in packages/snaps-controllers/src/snaps/SnapController.test.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (@metamask/snaps-controllers)

Disabled test
const { manifest, sourceCode, svgIcon } =
await getMockSnapFilesWithUpdatedChecksum({
sourceCode: `
Expand Down Expand Up @@ -5097,6 +5097,45 @@
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
Loading