Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
feat: use objects in snap -> controller methods
Browse files Browse the repository at this point in the history
  • Loading branch information
danroc committed Jun 22, 2023
1 parent bd7aaf6 commit 5a9e2f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/snap-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ export class SnapKeyring extends EventEmitter {
message: SnapMessage,
): Promise<Json> {
assert(message, SnapMessageStruct);
const [method, params] = message;
const { method, params } = message;
switch (method) {
case 'update':
case 'delete':
case 'create': {
case 'updateAccount':
case 'deleteAccount':
case 'createAccount': {
await this.#syncAccounts(snapId);
return null;
}
Expand All @@ -101,7 +101,7 @@ export class SnapKeyring extends EventEmitter {
);
}

case 'submit': {
case 'submitResponse': {
const { id, result } = params as any; // FIXME: add a struct for this
this.#resolveRequest(id, result);
return true;
Expand Down
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { JsonStruct } from '@metamask/utils';
import { Infer, string, tuple, union } from 'superstruct';
import { Infer, array, object, record, string, union } from 'superstruct';

export const SnapMessageStruct = union([
tuple([string()]),
tuple([string(), JsonStruct]),
]);
export const SnapMessageStruct = object({
method: string(),
params: union([array(JsonStruct), record(string(), JsonStruct)]),
});

/**
* Message sent by the snap to manage accounts and requests.
Expand Down

0 comments on commit 5a9e2f4

Please sign in to comment.