Skip to content
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
9 changes: 0 additions & 9 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -1591,15 +1591,6 @@ export function setupController(

controller.rejectAllPendingApprovals();
}

// Updates the snaps registry and check for newly blocked snaps to block if the user has at least one snap installed that isn't preinstalled.
if (
Object.values(controller.snapController.state.snaps).some(
(snap) => !snap.preinstalled,
)
) {
controller.snapController.updateRegistry();
}
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('SnapControllerInit', () => {
rejectInvalidPlatformVersion: false,
requireAllowlist: false,
forcePreinstalledSnaps: false,
autoUpdatePreinstalledSnaps: false,
},
getFeatureFlags: expect.any(Function),
getMnemonicSeed: expect.any(Function),
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/controller-init/snaps/snap-controller-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const SnapControllerInit: ControllerInitFunction<
const rejectInvalidPlatformVersion = getBooleanFlag(
process.env.REJECT_INVALID_SNAPS_PLATFORM_VERSION,
);
const autoUpdatePreinstalledSnaps = getBooleanFlag(
process.env.AUTO_UPDATE_PREINSTALLED_SNAPS,
);

///: BEGIN:ONLY_INCLUDE_IF(build-flask)
const forcePreinstalledSnaps = getBooleanFlag(
Expand Down Expand Up @@ -112,6 +115,7 @@ export const SnapControllerInit: ControllerInitFunction<
allowLocalSnaps,
requireAllowlist,
rejectInvalidPlatformVersion,
autoUpdatePreinstalledSnaps,
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
forcePreinstalledSnaps,
///: END:ONLY_INCLUDE_IF
Expand Down
15 changes: 15 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ import {
previousValueComparator,
initializeRpcProviderDomains,
getPlatform,
getBooleanFlag,
} from './lib/util';
import createMetamaskMiddleware from './lib/createMetamaskMiddleware';
import {
Expand Down Expand Up @@ -1373,6 +1374,20 @@ export default class MetamaskController extends EventEmitter {
if (usePhishDetect) {
this.phishingController.maybeUpdateState();
}

if (
getBooleanFlag(process.env.AUTO_UPDATE_PREINSTALLED_SNAPS) ||
// Check for newly blocked snaps to block if the user has at least one snap installed that isn't preinstalled.
Object.values(this.snapController.state.snaps).some(
(snap) => !snap.preinstalled,
)
) {
try {
this.snapController.updateRegistry();
} catch {
// Ignore
}
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ env:
- METAMASK_SHIELD_ENABLED: 'false'

# Snaps
- AUTO_UPDATE_PREINSTALLED_SNAPS: 'true'
# This should only be used for local testing, and should not be enabled in any
# production builds (including beta and Flask).
- FORCE_PREINSTALLED_SNAPS: 'false'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
"@metamask/shield-controller": "^1.1.0",
"@metamask/signature-controller": "^35.0.0",
"@metamask/smart-transactions-controller": "^20.0.0",
"@metamask/snaps-controllers": "^16.1.0",
"@metamask/snaps-controllers": "^16.1.1",
"@metamask/snaps-execution-environments": "^10.2.3",
"@metamask/snaps-rpc-methods": "^14.1.0",
"@metamask/snaps-sdk": "^10.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@
"SnapInsightsController": { "insights": "object" },
"SnapInterfaceController": { "interfaces": "object" },
"SnapsRegistry": {
"database": null,
"lastUpdated": null,
"database": "object",
"lastUpdated": "number",
Comment on lines +354 to +355
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why these changed now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The registry was likely not updated in these tests before because the fixture didn't have any third party Snaps. Before this PR we would only update the registry if you had a third party Snap that could have been blocked.

"databaseUnavailable": "boolean"
},
"SubjectMetadataController": { "subjectMetadata": "object" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@
"cryptocurrencies": ["btc", "sol"],
"snaps": "object",
"events": "object",
"database": null,
"lastUpdated": null,
"database": "object",
"lastUpdated": "number",
"databaseUnavailable": "boolean",
"interfaces": "object",
"insights": "object",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7678,9 +7678,9 @@ __metadata:
languageName: node
linkType: hard

"@metamask/snaps-controllers@npm:^16.1.0":
version: 16.1.0
resolution: "@metamask/snaps-controllers@npm:16.1.0"
"@metamask/snaps-controllers@npm:^16.1.1":
version: 16.1.1
resolution: "@metamask/snaps-controllers@npm:16.1.1"
dependencies:
"@metamask/approval-controller": "npm:^8.0.0"
"@metamask/base-controller": "npm:^9.0.0"
Expand Down Expand Up @@ -7716,7 +7716,7 @@ __metadata:
peerDependenciesMeta:
"@metamask/snaps-execution-environments":
optional: true
checksum: 10/9af230904002608d73de7d9b87e9e63dda304da2f68fc1cf813b0d43a222edb1d359ba82921f7f88b1e066b39c72a7a73fab90c824907e0b3bcfe84de6b1bc46
checksum: 10/c7a01e952ae8d5ac98532c76fd7a02053885d55e0c3800fc621e728844e855c08cca4634a5c6e679ce3ada7ec5176452b2e18d0edd81d065bf4a4ea8e183ea07
languageName: node
linkType: hard

Expand Down Expand Up @@ -32075,7 +32075,7 @@ __metadata:
"@metamask/smart-transactions-controller": "npm:^20.0.0"
"@metamask/snap-account-abstraction-keyring-site": "npm:^1.0.0"
"@metamask/snap-simple-keyring-site": "npm:^2.0.0"
"@metamask/snaps-controllers": "npm:^16.1.0"
"@metamask/snaps-controllers": "npm:^16.1.1"
"@metamask/snaps-execution-environments": "npm:^10.2.3"
"@metamask/snaps-rpc-methods": "npm:^14.1.0"
"@metamask/snaps-sdk": "npm:^10.1.0"
Expand Down
Loading