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

Improve SnapController constructor typing #2023

Merged
merged 1 commit into from
Dec 8, 2023
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
4 changes: 2 additions & 2 deletions packages/snaps-controllers/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"branches": 90.07,
"branches": 90.09,
"functions": 96.35,
"lines": 97.3,
"lines": 97.31,
"statements": 96.99
}
24 changes: 13 additions & 11 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,32 +531,32 @@ type SnapControllerMessenger = RestrictedControllerMessenger<
>;

type FeatureFlags = {
requireAllowlist?: true;
allowLocalSnaps?: true;
requireAllowlist?: boolean;
allowLocalSnaps?: boolean;
};

type SnapControllerArgs = {
/**
* A teardown function that allows the host to clean up its instrumentation
* for a running snap.
*/
closeAllConnections: CloseAllConnectionsFunction;
closeAllConnections?: CloseAllConnectionsFunction;

/**
* A list of permissions that are allowed to be dynamic, meaning they can be revoked from the snap whenever.
*/
dynamicPermissions: string[];
dynamicPermissions?: string[];

/**
* The names of endowment permissions whose values are the names of JavaScript
* APIs that will be added to the snap execution environment at runtime.
*/
environmentEndowmentPermissions: string[];
environmentEndowmentPermissions?: string[];

/**
* Excluded permissions with its associated error message used to forbid certain permssions.
*/
excludedPermissions: Record<string, string>;
excludedPermissions?: Record<string, string>;

/**
* The function that will be used by the controller fo make network requests.
Expand Down Expand Up @@ -666,7 +666,7 @@ export class SnapController extends BaseController<
SnapControllerState,
SnapControllerMessenger
> {
#closeAllConnections: CloseAllConnectionsFunction;
#closeAllConnections?: CloseAllConnectionsFunction;

#dynamicPermissions: string[];

Expand Down Expand Up @@ -1265,7 +1265,7 @@ export class SnapController extends BaseController<
runtime.pendingOutboundRequests = 0;
try {
if (this.isRunning(snapId)) {
this.#closeAllConnections(snapId);
this.#closeAllConnections?.(snapId);
await this.#terminateSnap(snapId);
}
} finally {
Expand Down Expand Up @@ -1444,9 +1444,11 @@ export class SnapController extends BaseController<
*/
async clearState() {
const snapIds = Object.keys(this.state.snaps);
snapIds.forEach((snapId) => {
this.#closeAllConnections(snapId);
});
if (this.#closeAllConnections) {
snapIds.forEach((snapId) => {
this.#closeAllConnections?.(snapId);
Mrtenz marked this conversation as resolved.
Show resolved Hide resolved
});
}

await this.messagingSystem.call('ExecutionService:terminateAllSnaps');
snapIds.forEach((snapId) => this.#revokeAllSnapPermissions(snapId));
Expand Down