Skip to content

Commit 047bcb4

Browse files
chore: Make interface actions synchronous
1 parent e60a89d commit 047bcb4

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

packages/snaps-controllers/src/interface/SnapInterfaceController.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,14 @@ export class SnapInterfaceController extends BaseController<
253253
* @param contentType - The type of content.
254254
* @returns The newly interface id.
255255
*/
256-
async createInterface(
256+
createInterface(
257257
snapId: SnapId,
258258
content: ComponentOrElement,
259259
context?: InterfaceContext,
260260
contentType?: ContentType,
261261
) {
262262
const element = getJsxInterface(content);
263-
await this.#validateContent(element);
263+
this.#validateContent(element);
264264
validateInterfaceContext(context);
265265

266266
const id = nanoid();
@@ -270,8 +270,6 @@ export class SnapInterfaceController extends BaseController<
270270
});
271271

272272
this.update((draftState) => {
273-
// @ts-expect-error - TS2589: Type instantiation is excessively deep and
274-
// possibly infinite.
275273
draftState.interfaces[id] = {
276274
snapId,
277275
content: castDraft(element),
@@ -305,15 +303,15 @@ export class SnapInterfaceController extends BaseController<
305303
* @param content - The new content.
306304
* @param context - An optional interface context object.
307305
*/
308-
async updateInterface(
306+
updateInterface(
309307
snapId: SnapId,
310308
id: string,
311309
content: ComponentOrElement,
312310
context?: InterfaceContext,
313311
) {
314312
this.#validateArgs(snapId, id);
315313
const element = getJsxInterface(content);
316-
await this.#validateContent(element);
314+
this.#validateContent(element);
317315
validateInterfaceContext(context);
318316

319317
const oldState = this.state.interfaces[id].state;
@@ -480,7 +478,7 @@ export class SnapInterfaceController extends BaseController<
480478
*
481479
* @param element - The JSX element to verify.
482480
*/
483-
async #validateContent(element: JSXElement) {
481+
#validateContent(element: JSXElement) {
484482
// We assume the validity of this JSON to be validated by the caller.
485483
// E.g., in the RPC method implementation.
486484
const size = getJsonSizeUnsafe(element);

packages/snaps-rpc-methods/src/permitted/createInterface.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export type CreateInterfaceMethodHooks = {
3232
ui: ComponentOrElement,
3333
context?: InterfaceContext,
3434
contentType?: ContentType,
35-
) => Promise<string>;
35+
) => string;
3636
};
3737

3838
export const createInterfaceHandler: PermittedHandlerExport<
@@ -67,21 +67,21 @@ export type CreateInterfaceParameters = InferMatching<
6767
* @param hooks.createInterface - The function to create the interface.
6868
* @returns Nothing.
6969
*/
70-
async function getCreateInterfaceImplementation(
70+
function getCreateInterfaceImplementation(
7171
req: JsonRpcRequest<CreateInterfaceParameters>,
7272
res: PendingJsonRpcResponse<CreateInterfaceResult>,
7373
_next: unknown,
7474
end: JsonRpcEngineEndCallback,
7575
{ createInterface }: CreateInterfaceMethodHooks,
76-
): Promise<void> {
76+
): void {
7777
const { params } = req;
7878

7979
try {
8080
const validatedParams = getValidatedParams(params);
8181

8282
const { ui, context } = validatedParams;
8383

84-
res.result = await createInterface(ui, context);
84+
res.result = createInterface(ui, context);
8585
} catch (error) {
8686
return end(error);
8787
}

packages/snaps-rpc-methods/src/permitted/updateInterface.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export type UpdateInterfaceMethodHooks = {
3838
id: string,
3939
ui: ComponentOrElement,
4040
context?: InterfaceContext,
41-
) => Promise<void>;
41+
) => void;
4242
};
4343

4444
export const updateInterfaceHandler: PermittedHandlerExport<
@@ -74,21 +74,21 @@ export type UpdateInterfaceParameters = InferMatching<
7474
* @param hooks.updateInterface - The function to update the interface.
7575
* @returns Nothing.
7676
*/
77-
async function getUpdateInterfaceImplementation(
77+
function getUpdateInterfaceImplementation(
7878
req: JsonRpcRequest<UpdateInterfaceParameters>,
7979
res: PendingJsonRpcResponse<UpdateInterfaceResult>,
8080
_next: unknown,
8181
end: JsonRpcEngineEndCallback,
8282
{ updateInterface }: UpdateInterfaceMethodHooks,
83-
): Promise<void> {
83+
): void {
8484
const { params } = req;
8585

8686
try {
8787
const validatedParams = getValidatedParams(params);
8888

8989
const { id, ui, context } = validatedParams;
9090

91-
await updateInterface(id, ui, context);
91+
updateInterface(id, ui, context);
9292
res.result = null;
9393
} catch (error) {
9494
return end(error);

0 commit comments

Comments
 (0)