Skip to content

Commit 6664fae

Browse files
wip: Add isReady state property
1 parent 1e95bcd commit 6664fae

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

packages/snaps-controllers/src/snaps/SnapController.test.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10624,6 +10624,8 @@ describe('SnapController', () => {
1062410624

1062510625
await waitForStateChange(messenger);
1062610626

10627+
await waitForStateChange(messenger);
10628+
1062710629
expect(snapController.isRunning(MOCK_SNAP_ID)).toBe(true);
1062810630

1062910631
await new Promise((resolve) => setTimeout(resolve, 100));
@@ -10647,6 +10649,7 @@ describe('SnapController', () => {
1064710649
);
1064810650

1064910651
expect(snapController.state).toStrictEqual({
10652+
isReady: false,
1065010653
snaps: {},
1065110654
snapStates: {},
1065210655
unencryptedSnapStates: {},
@@ -12997,7 +13000,11 @@ describe('SnapController', () => {
1299713000
controller.metadata,
1299813001
'includeInDebugSnapshot',
1299913002
),
13000-
).toMatchInlineSnapshot(`{}`);
13003+
).toMatchInlineSnapshot(`
13004+
{
13005+
"isReady": false,
13006+
}
13007+
`);
1300113008
});
1300213009

1300313010
describe('includeInStateLogs', () => {
@@ -13012,6 +13019,7 @@ describe('SnapController', () => {
1301213019
),
1301313020
).toMatchInlineSnapshot(`
1301413021
{
13022+
"isReady": false,
1301513023
"snaps": {},
1301613024
}
1301713025
`);

packages/snaps-controllers/src/snaps/SnapController.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ export type SnapControllerState = {
318318
snaps: StoredSnaps;
319319
snapStates: Record<SnapId, string | null>;
320320
unencryptedSnapStates: Record<SnapId, string | null>;
321+
isReady: boolean;
321322
};
322323

323324
export type PersistedSnapControllerState = SnapControllerState & {
@@ -854,6 +855,7 @@ const defaultState: SnapControllerState = {
854855
snaps: {},
855856
snapStates: {},
856857
unencryptedSnapStates: {},
858+
isReady: false,
857859
};
858860

859861
/**
@@ -965,6 +967,12 @@ export class SnapController extends BaseController<
965967
super({
966968
messenger,
967969
metadata: {
970+
isReady: {
971+
includeInStateLogs: true,
972+
includeInDebugSnapshot: true,
973+
persist: false,
974+
usedInUi: false,
975+
},
968976
snapStates: {
969977
includeInStateLogs: false,
970978
persist: true,
@@ -1722,8 +1730,16 @@ export class SnapController extends BaseController<
17221730
await this.#ensureOnboardingComplete();
17231731

17241732
const flags = this.#getFeatureFlags();
1733+
1734+
const isReady = flags.disableSnaps !== true;
1735+
if (this.state.isReady !== isReady) {
1736+
this.update((state) => {
1737+
state.isReady = isReady;
1738+
});
1739+
}
1740+
17251741
assert(
1726-
flags.disableSnaps !== true,
1742+
isReady,
17271743
'The Snaps platform requires basic functionality to be used. Enable basic functionality in the settings to use the Snaps platform.',
17281744
);
17291745
}
@@ -2387,6 +2403,7 @@ export class SnapController extends BaseController<
23872403
snapIds.forEach((snapId) => this.#revokeAllSnapPermissions(snapId));
23882404

23892405
this.update((state) => {
2406+
state.isReady = false;
23902407
state.snaps = {};
23912408
state.snapStates = {};
23922409
state.unencryptedSnapStates = {};

0 commit comments

Comments
 (0)