@@ -815,6 +815,13 @@ type SnapControllerArgs = {
815815 * MetaMetrics event tracking hook.
816816 */
817817 trackEvent : TrackEventHook ;
818+
819+ /**
820+ * A hook that returns a promise that resolves when the onboarding has completed.
821+ *
822+ * @returns A promise that resolves when onboarding is complete.
823+ */
824+ waitForOnboarding : ( ) => Promise < void > ;
818825} ;
819826
820827type AddSnapArgs = {
@@ -932,6 +939,8 @@ export class SnapController extends BaseController<
932939
933940 readonly #trackSnapExport: ReturnType < typeof throttleTracking > ;
934941
942+ readonly #waitForOnboarding: ( ) => Promise < void > ;
943+
935944 constructor ( {
936945 closeAllConnections,
937946 messenger,
@@ -951,6 +960,7 @@ export class SnapController extends BaseController<
951960 getFeatureFlags = ( ) => ( { } ) ,
952961 clientCryptography,
953962 trackEvent,
963+ waitForOnboarding,
954964 } : SnapControllerArgs ) {
955965 super ( {
956966 messenger,
@@ -1034,6 +1044,7 @@ export class SnapController extends BaseController<
10341044 this . #rollbackSnapshots = new Map ( ) ;
10351045 this . #snapsRuntimeData = new Map ( ) ;
10361046 this . #trackEvent = trackEvent ;
1047+ this . #waitForOnboarding = waitForOnboarding ;
10371048
10381049 this . #pollForLastRequestStatus( ) ;
10391050
@@ -1467,7 +1478,7 @@ export class SnapController extends BaseController<
14671478 * Also updates any preinstalled Snaps to the latest allowlisted version.
14681479 */
14691480 async updateRegistry ( ) : Promise < void > {
1470- this . #assertCanUsePlatform( ) ;
1481+ await this . #assertCanUsePlatform( ) ;
14711482 await this . messenger . call ( 'SnapsRegistry:update' ) ;
14721483
14731484 const blockedSnaps = await this . messenger . call (
@@ -1645,9 +1656,12 @@ export class SnapController extends BaseController<
16451656 }
16461657
16471658 /**
1648- * Asserts whether the Snaps platform is allowed to run.
1659+ * Waits for onboarding and then asserts whether the Snaps platform is allowed to run.
16491660 */
1650- #assertCanUsePlatform( ) {
1661+ async #assertCanUsePlatform( ) {
1662+ // Ensure the user has onboarded before allowing access to Snaps.
1663+ await this . #waitForOnboarding( ) ;
1664+
16511665 const flags = this . #getFeatureFlags( ) ;
16521666 assert (
16531667 flags . disableSnaps !== true ,
@@ -1730,7 +1744,7 @@ export class SnapController extends BaseController<
17301744 * @param snapId - The id of the Snap to start.
17311745 */
17321746 async startSnap ( snapId : SnapId ) : Promise < void > {
1733- this . #assertCanUsePlatform( ) ;
1747+ await this . #assertCanUsePlatform( ) ;
17341748 const snap = this . state . snaps [ snapId ] ;
17351749
17361750 if ( ! snap . enabled ) {
@@ -2630,7 +2644,7 @@ export class SnapController extends BaseController<
26302644 origin : string ,
26312645 requestedSnaps : RequestSnapsParams ,
26322646 ) : Promise < RequestSnapsResult > {
2633- this . #assertCanUsePlatform( ) ;
2647+ await this . #assertCanUsePlatform( ) ;
26342648
26352649 const result : RequestSnapsResult = { } ;
26362650
@@ -2916,7 +2930,7 @@ export class SnapController extends BaseController<
29162930 if ( ! automaticUpdate ) {
29172931 this . #assertCanInstallSnaps( ) ;
29182932 }
2919- this . #assertCanUsePlatform( ) ;
2933+ await this . #assertCanUsePlatform( ) ;
29202934
29212935 const snap = this . getExpect ( snapId ) ;
29222936
@@ -3551,7 +3565,7 @@ export class SnapController extends BaseController<
35513565 handler : handlerType ,
35523566 request : rawRequest ,
35533567 } : SnapRpcHookArgs & { snapId : SnapId } ) : Promise < unknown > {
3554- this . #assertCanUsePlatform( ) ;
3568+ await this . #assertCanUsePlatform( ) ;
35553569
35563570 const snap = this . get ( snapId ) ;
35573571
0 commit comments