diff --git a/packages/snaps-controllers/src/interface/SnapInterfaceController.test.tsx b/packages/snaps-controllers/src/interface/SnapInterfaceController.test.tsx index 90831604ed..5f10a1b856 100644 --- a/packages/snaps-controllers/src/interface/SnapInterfaceController.test.tsx +++ b/packages/snaps-controllers/src/interface/SnapInterfaceController.test.tsx @@ -101,7 +101,7 @@ describe('SnapInterfaceController', () => { }), ]); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, @@ -143,7 +143,7 @@ describe('SnapInterfaceController', () => { /> ); - const interfaceId = await rootMessenger.call( + const interfaceId = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, @@ -192,7 +192,7 @@ describe('SnapInterfaceController', () => { ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, @@ -234,7 +234,7 @@ describe('SnapInterfaceController', () => { ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, @@ -310,7 +310,7 @@ describe('SnapInterfaceController', () => { ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, @@ -387,7 +387,7 @@ describe('SnapInterfaceController', () => { ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, @@ -438,7 +438,7 @@ describe('SnapInterfaceController', () => { ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, @@ -473,7 +473,7 @@ describe('SnapInterfaceController', () => { ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, @@ -513,14 +513,14 @@ describe('SnapInterfaceController', () => { ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, { foo: 'a'.repeat(5_000_000) }, ), - ).rejects.toThrow('A Snap interface context may not be larger than 5 MB'); + ).toThrow('A Snap interface context may not be larger than 5 MB'); }); it('throws if a link is on the phishing list', async () => { @@ -548,13 +548,13 @@ describe('SnapInterfaceController', () => { }), ]); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, ), - ).rejects.toThrow('Invalid URL: The specified URL is not allowed.'); + ).toThrow('Invalid URL: The specified URL is not allowed.'); expect(rootMessenger.call).toHaveBeenNthCalledWith( 2, @@ -588,13 +588,13 @@ describe('SnapInterfaceController', () => { ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, ), - ).rejects.toThrow('Invalid URL: The specified URL is not allowed.'); + ).toThrow('Invalid URL: The specified URL is not allowed.'); expect(rootMessenger.call).toHaveBeenNthCalledWith( 2, @@ -628,15 +628,13 @@ describe('SnapInterfaceController', () => { ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, ), - ).rejects.toThrow( - 'Invalid URL: The Snap being navigated to is not installed.', - ); + ).toThrow('Invalid URL: The Snap being navigated to is not installed.'); expect(rootMessenger.call).toHaveBeenNthCalledWith( 2, @@ -686,13 +684,13 @@ describe('SnapInterfaceController', () => { ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, ), - ).rejects.toThrow( + ).toThrow( 'Could not find account for address: solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv', ); @@ -719,13 +717,13 @@ describe('SnapInterfaceController', () => { const components = panel([image(``)]); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, ), - ).rejects.toThrow('A Snap UI may not be larger than 10 MB.'); + ).toThrow('A Snap UI may not be larger than 10 MB.'); }); it('throws if JSX UI content is too large', async () => { @@ -748,13 +746,13 @@ describe('SnapInterfaceController', () => { ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, ), - ).rejects.toThrow('A Snap UI may not be larger than 10 MB.'); + ).toThrow('A Snap UI may not be larger than 10 MB.'); }); it('throws if text content is too large', async () => { @@ -771,13 +769,13 @@ describe('SnapInterfaceController', () => { const components = panel([text('[foo](https://foo.bar)'.repeat(2500))]); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, ), - ).rejects.toThrow('The text in a Snap UI may not be larger than 50 kB.'); + ).toThrow('The text in a Snap UI may not be larger than 50 kB.'); }); }); @@ -797,7 +795,7 @@ describe('SnapInterfaceController', () => { children: [input({ name: 'bar' })], }); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, @@ -827,7 +825,7 @@ describe('SnapInterfaceController', () => { children: [input({ name: 'bar' })], }); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, @@ -883,13 +881,13 @@ describe('SnapInterfaceController', () => { children: [input({ name: 'baz' })], }); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, ); - await rootMessenger.call( + rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, id, @@ -932,13 +930,13 @@ describe('SnapInterfaceController', () => { ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, ); - await rootMessenger.call( + rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, id, @@ -977,7 +975,7 @@ describe('SnapInterfaceController', () => { const context = { foo: 'bar' }; - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, @@ -986,7 +984,7 @@ describe('SnapInterfaceController', () => { const newContext = { foo: 'baz' }; - await rootMessenger.call( + rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, id, @@ -1031,14 +1029,14 @@ describe('SnapInterfaceController', () => { const context = { foo: 'bar' }; - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, context, ); - await rootMessenger.call( + rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, id, @@ -1090,20 +1088,20 @@ describe('SnapInterfaceController', () => { }), ]); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, id, newContent, ), - ).rejects.toThrow('Invalid URL: The specified URL is not allowed.'); + ).toThrow('Invalid URL: The specified URL is not allowed.'); expect(rootMessenger.call).toHaveBeenNthCalledWith( 3, @@ -1146,20 +1144,20 @@ describe('SnapInterfaceController', () => { ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, id, newElement, ), - ).rejects.toThrow('Invalid URL: The specified URL is not allowed.'); + ).toThrow('Invalid URL: The specified URL is not allowed.'); expect(rootMessenger.call).toHaveBeenNthCalledWith( 3, @@ -1190,20 +1188,20 @@ describe('SnapInterfaceController', () => { const newContent = panel([image('')]); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, id, newContent, ), - ).rejects.toThrow('A Snap UI may not be larger than 10 MB.'); + ).toThrow('A Snap UI may not be larger than 10 MB.'); }); it('throws if JSX UI content is too large', async () => { @@ -1235,20 +1233,20 @@ describe('SnapInterfaceController', () => { ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, id, newElement, ), - ).rejects.toThrow('A Snap UI may not be larger than 10 MB.'); + ).toThrow('A Snap UI may not be larger than 10 MB.'); }); it('throws if text content is too large', async () => { @@ -1268,20 +1266,20 @@ describe('SnapInterfaceController', () => { const newContent = panel([text('[foo](https://foo.bar)'.repeat(2500))]); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, components, ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, id, newContent, ), - ).rejects.toThrow('The text in a Snap UI may not be larger than 50 kB.'); + ).toThrow('The text in a Snap UI may not be larger than 50 kB.'); }); it('throws if the interface does not exist', async () => { @@ -1296,14 +1294,14 @@ describe('SnapInterfaceController', () => { const content = form({ name: 'foo', children: [input({ name: 'bar' })] }); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, 'foo', content, ), - ).rejects.toThrow("Interface with id 'foo' not found."); + ).toThrow("Interface with id 'foo' not found."); }); it('throws if the interface is updated by another snap', async () => { @@ -1323,20 +1321,20 @@ describe('SnapInterfaceController', () => { children: [input({ name: 'baz' })], }); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, content, ); - await expect( + expect(() => rootMessenger.call( 'SnapInterfaceController:updateInterface', 'foo' as SnapId, id, newContent, ), - ).rejects.toThrow('Interface not created by foo.'); + ).toThrow('Interface not created by foo.'); }); it('can select an account owned by the snap', async () => { @@ -1397,13 +1395,13 @@ describe('SnapInterfaceController', () => { ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, element, ); - await rootMessenger.call( + rootMessenger.call( 'SnapInterfaceController:updateInterface', MOCK_SNAP_ID, id, @@ -1443,7 +1441,7 @@ describe('SnapInterfaceController', () => { const newState = { foo: { bar: 'baz' } }; - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, content, @@ -1493,7 +1491,7 @@ describe('SnapInterfaceController', () => { }, }; - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, content, @@ -1528,7 +1526,7 @@ describe('SnapInterfaceController', () => { const content = form({ name: 'foo', children: [input({ name: 'bar' })] }); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, content, @@ -1569,7 +1567,7 @@ describe('SnapInterfaceController', () => { approvalControllerMock.acceptRequest.bind(approvalControllerMock), ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, @@ -1648,7 +1646,7 @@ describe('SnapInterfaceController', () => { approvalControllerMock.acceptRequest.bind(approvalControllerMock), ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, @@ -1693,7 +1691,7 @@ describe('SnapInterfaceController', () => { approvalControllerMock.acceptRequest.bind(approvalControllerMock), ); - const id = await rootMessenger.call( + const id = rootMessenger.call( 'SnapInterfaceController:createInterface', MOCK_SNAP_ID, diff --git a/packages/snaps-controllers/src/interface/SnapInterfaceController.ts b/packages/snaps-controllers/src/interface/SnapInterfaceController.ts index 2a29d8788e..81a1378ba0 100644 --- a/packages/snaps-controllers/src/interface/SnapInterfaceController.ts +++ b/packages/snaps-controllers/src/interface/SnapInterfaceController.ts @@ -277,14 +277,14 @@ export class SnapInterfaceController extends BaseController< * @param contentType - The type of content. * @returns The newly interface id. */ - async createInterface( + createInterface( snapId: SnapId, content: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType, ) { const element = getJsxInterface(content); - await this.#validateContent(element); + this.#validateContent(element); validateInterfaceContext(context); const id = nanoid(); @@ -333,7 +333,7 @@ export class SnapInterfaceController extends BaseController< * @param content - The new content. * @param context - An optional interface context object. */ - async updateInterface( + updateInterface( snapId: SnapId, id: string, content: ComponentOrElement, @@ -341,7 +341,7 @@ export class SnapInterfaceController extends BaseController< ) { this.#validateArgs(snapId, id); const element = getJsxInterface(content); - await this.#validateContent(element); + this.#validateContent(element); validateInterfaceContext(context); const oldState = this.state.interfaces[id].state; @@ -543,7 +543,7 @@ export class SnapInterfaceController extends BaseController< * * @param element - The JSX element to verify. */ - async #validateContent(element: JSXElement) { + #validateContent(element: JSXElement) { // We assume the validity of this JSON to be validated by the caller. // E.g., in the RPC method implementation. const size = getJsonSizeUnsafe(element); diff --git a/packages/snaps-rpc-methods/src/permitted/createInterface.ts b/packages/snaps-rpc-methods/src/permitted/createInterface.ts index 1dd983036f..bd3b6ade0c 100644 --- a/packages/snaps-rpc-methods/src/permitted/createInterface.ts +++ b/packages/snaps-rpc-methods/src/permitted/createInterface.ts @@ -32,7 +32,7 @@ export type CreateInterfaceMethodHooks = { ui: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType, - ) => Promise; + ) => string; }; export const createInterfaceHandler: PermittedHandlerExport< @@ -67,13 +67,13 @@ export type CreateInterfaceParameters = InferMatching< * @param hooks.createInterface - The function to create the interface. * @returns Nothing. */ -async function getCreateInterfaceImplementation( +function getCreateInterfaceImplementation( req: JsonRpcRequest, res: PendingJsonRpcResponse, _next: unknown, end: JsonRpcEngineEndCallback, { createInterface }: CreateInterfaceMethodHooks, -): Promise { +): void { const { params } = req; try { @@ -81,7 +81,7 @@ async function getCreateInterfaceImplementation( const { ui, context } = validatedParams; - res.result = await createInterface(ui, context); + res.result = createInterface(ui, context); } catch (error) { return end(error); } diff --git a/packages/snaps-rpc-methods/src/permitted/updateInterface.ts b/packages/snaps-rpc-methods/src/permitted/updateInterface.ts index b79312f93e..43480a97af 100644 --- a/packages/snaps-rpc-methods/src/permitted/updateInterface.ts +++ b/packages/snaps-rpc-methods/src/permitted/updateInterface.ts @@ -38,7 +38,7 @@ export type UpdateInterfaceMethodHooks = { id: string, ui: ComponentOrElement, context?: InterfaceContext, - ) => Promise; + ) => void; }; export const updateInterfaceHandler: PermittedHandlerExport< @@ -74,13 +74,13 @@ export type UpdateInterfaceParameters = InferMatching< * @param hooks.updateInterface - The function to update the interface. * @returns Nothing. */ -async function getUpdateInterfaceImplementation( +function getUpdateInterfaceImplementation( req: JsonRpcRequest, res: PendingJsonRpcResponse, _next: unknown, end: JsonRpcEngineEndCallback, { updateInterface }: UpdateInterfaceMethodHooks, -): Promise { +): void { const { params } = req; try { @@ -88,7 +88,7 @@ async function getUpdateInterfaceImplementation( const { id, ui, context } = validatedParams; - await updateInterface(id, ui, context); + updateInterface(id, ui, context); res.result = null; } catch (error) { return end(error); diff --git a/packages/snaps-simulation/src/interface.test.tsx b/packages/snaps-simulation/src/interface.test.tsx index 9ab14131b0..0d7e9abf62 100644 --- a/packages/snaps-simulation/src/interface.test.tsx +++ b/packages/snaps-simulation/src/interface.test.tsx @@ -555,7 +555,7 @@ describe('clickElement', () => { it('sends a ButtonClickEvent to the snap', async () => { const content = button({ value: 'foo', name: 'bar' }); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -592,7 +592,7 @@ describe('clickElement', () => { button({ value: 'baz', name: 'baz', buttonType: ButtonType.Submit }), ]); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -657,7 +657,7 @@ describe('clickElement', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -718,7 +718,7 @@ describe('clickElement', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -781,7 +781,7 @@ describe('clickElement', () => { it('throws if there is no button with the given name in the interface', async () => { const content = button({ value: 'foo', name: 'foo' }); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -804,7 +804,7 @@ describe('clickElement', () => { it('throws if the element is not a button', async () => { const content = input({ value: 'foo', name: 'foo' }); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -827,7 +827,7 @@ describe('clickElement', () => { it('unwraps errors', async () => { const content = button({ value: 'foo', name: 'foo' }); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -889,7 +889,7 @@ describe('typeInField', () => { const content = input('bar'); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -938,7 +938,7 @@ describe('typeInField', () => { /> ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -980,7 +980,7 @@ describe('typeInField', () => { it('throws if there is no inputs in the interface', async () => { const content = text('bar'); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1002,7 +1002,7 @@ describe('typeInField', () => { it('throws if the element is not an input', async () => { const content = button({ value: 'foo', name: 'foo' }); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1049,7 +1049,7 @@ describe('selectInDropdown', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1096,7 +1096,7 @@ describe('selectInDropdown', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1122,7 +1122,7 @@ describe('selectInDropdown', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1144,7 +1144,7 @@ describe('selectInDropdown', () => { it('throws if the element is not a dropdown', async () => { const content = ; - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1188,7 +1188,7 @@ describe('uploadFile', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1249,7 +1249,7 @@ describe('uploadFile', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1307,7 +1307,7 @@ describe('uploadFile', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1341,7 +1341,7 @@ describe('getInterface', () => { const { store, runSaga } = createStore(options); const content = text('foo'); - const id = await interfaceController.createInterface(MOCK_SNAP_ID, content); + const id = interfaceController.createInterface(MOCK_SNAP_ID, content); const type = DialogType.Alert; const ui = { type: DIALOG_APPROVAL_TYPES[type], id }; @@ -1382,7 +1382,7 @@ describe('getInterface', () => { ).toPromise(); const content = text('foo'); - const id = await interfaceController.createInterface(MOCK_SNAP_ID, content); + const id = interfaceController.createInterface(MOCK_SNAP_ID, content); const type = DialogType.Alert; const ui = { type: DIALOG_APPROVAL_TYPES[type], id }; store.dispatch(setInterface(ui)); @@ -1409,7 +1409,7 @@ describe('getInterface', () => { const { store, runSaga } = createStore(options); const content = button({ value: 'foo', name: 'foo' }); - const id = await interfaceController.createInterface(MOCK_SNAP_ID, content); + const id = interfaceController.createInterface(MOCK_SNAP_ID, content); const type = DialogType.Alert; const ui = { type: DIALOG_APPROVAL_TYPES[type], id }; @@ -1453,7 +1453,7 @@ describe('getInterface', () => { const { store, runSaga } = createStore(options); const content = input('foo'); - const id = await interfaceController.createInterface(MOCK_SNAP_ID, content); + const id = interfaceController.createInterface(MOCK_SNAP_ID, content); const type = DialogType.Alert; const ui = { type: DIALOG_APPROVAL_TYPES[type], id }; @@ -1503,7 +1503,7 @@ describe('getInterface', () => { ); - const id = await interfaceController.createInterface(MOCK_SNAP_ID, content); + const id = interfaceController.createInterface(MOCK_SNAP_ID, content); const type = DialogType.Alert; const ui = { type: DIALOG_APPROVAL_TYPES[type], id }; @@ -1552,7 +1552,7 @@ describe('getInterface', () => { ); - const id = await interfaceController.createInterface(MOCK_SNAP_ID, content); + const id = interfaceController.createInterface(MOCK_SNAP_ID, content); const type = DialogType.Alert; const ui = { type: DIALOG_APPROVAL_TYPES[type], id }; @@ -1606,7 +1606,7 @@ describe('getInterface', () => { ); - const id = await interfaceController.createInterface(MOCK_SNAP_ID, content); + const id = interfaceController.createInterface(MOCK_SNAP_ID, content); const type = DialogType.Alert; const ui = { type: DIALOG_APPROVAL_TYPES[type], id }; @@ -1622,7 +1622,7 @@ describe('getInterface', () => { const promise = result.waitForUpdate(); - await interfaceController.updateInterface( + interfaceController.updateInterface( MOCK_SNAP_ID, id, Hello world!, @@ -1661,7 +1661,7 @@ describe('selectFromRadioGroup', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1708,7 +1708,7 @@ describe('selectFromRadioGroup', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1734,7 +1734,7 @@ describe('selectFromRadioGroup', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1756,7 +1756,7 @@ describe('selectFromRadioGroup', () => { it('throws if the element is not a RadioGroup', async () => { const content = ; - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1943,7 +1943,7 @@ describe('selectFromSelector', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -1997,7 +1997,7 @@ describe('selectFromSelector', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -2026,7 +2026,7 @@ describe('selectFromSelector', () => { ); - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -2051,7 +2051,7 @@ describe('selectFromSelector', () => { const content = ; - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -2087,7 +2087,7 @@ describe('waitForUpdate', () => { it('waits for the interface content to update', async () => { const content = ; - const interfaceId = await interfaceController.createInterface( + const interfaceId = interfaceController.createInterface( MOCK_SNAP_ID, content, ); @@ -2100,7 +2100,7 @@ describe('waitForUpdate', () => { content, ); - await interfaceController.updateInterface( + interfaceController.updateInterface( MOCK_SNAP_ID, interfaceId, Hello world!, diff --git a/packages/snaps-simulation/src/methods/hooks/interface.test.ts b/packages/snaps-simulation/src/methods/hooks/interface.test.ts index 143c15de96..35ebd1ac3f 100644 --- a/packages/snaps-simulation/src/methods/hooks/interface.test.ts +++ b/packages/snaps-simulation/src/methods/hooks/interface.test.ts @@ -58,7 +58,7 @@ describe('getGetInterfaceImplementation', () => { const content = text('bar'); - const id = await interfaceController.createInterface(MOCK_SNAP_ID, content); + const id = interfaceController.createInterface(MOCK_SNAP_ID, content); const result = fn(MOCK_SNAP_ID, id); diff --git a/packages/snaps-simulation/src/request.test.tsx b/packages/snaps-simulation/src/request.test.tsx index 92fddaa74c..1b88865e45 100644 --- a/packages/snaps-simulation/src/request.test.tsx +++ b/packages/snaps-simulation/src/request.test.tsx @@ -144,7 +144,7 @@ describe('handleRequest', () => { }); const content = text('foo'); - const id = await interfaceController.createInterface( + const id = interfaceController.createInterface( 'local:http://localhost:4242' as SnapId, content, ); @@ -362,7 +362,7 @@ describe('getInterfaceApi', () => { }); const content = text('foo'); - const id = await interfaceController.createInterface(MOCK_SNAP_ID, content); + const id = interfaceController.createInterface(MOCK_SNAP_ID, content); const getInterface = await getInterfaceApi( { id }, diff --git a/packages/snaps-simulation/src/request.ts b/packages/snaps-simulation/src/request.ts index fd380ae0aa..a519784776 100644 --- a/packages/snaps-simulation/src/request.ts +++ b/packages/snaps-simulation/src/request.ts @@ -213,7 +213,7 @@ export async function getInterfaceFromResult( 'The Snap returned an invalid interface.', ); - const id = await controllerMessenger.call( + const id = controllerMessenger.call( 'SnapInterfaceController:createInterface', snapId, result.content as ComponentOrElement, diff --git a/packages/snaps-simulation/src/simulation.test.ts b/packages/snaps-simulation/src/simulation.test.ts index 19ce17933f..162a320465 100644 --- a/packages/snaps-simulation/src/simulation.test.ts +++ b/packages/snaps-simulation/src/simulation.test.ts @@ -476,7 +476,7 @@ describe('getPermittedHooks', () => { runSaga, ); - await createInterface(content); + createInterface(content); expect(controllerMessenger.call).toHaveBeenCalledWith( 'SnapInterfaceController:createInterface', @@ -514,9 +514,9 @@ describe('getPermittedHooks', () => { runSaga, ); - const id = await createInterface(text('foo')); + const id = createInterface(text('foo')); - await updateInterface(id, content); + updateInterface(id, content); expect(controllerMessenger.call).toHaveBeenNthCalledWith( 2, @@ -555,7 +555,7 @@ describe('getPermittedHooks', () => { runSaga, ); - const id = await createInterface(text('foo')); + const id = createInterface(text('foo')); const result = getInterfaceState(id); @@ -596,7 +596,7 @@ describe('getPermittedHooks', () => { runSaga, ); - const id = await createInterface(text('foo'), { bar: 'baz' }); + const id = createInterface(text('foo'), { bar: 'baz' }); const result = getInterfaceContext(id); @@ -629,10 +629,7 @@ describe('getPermittedHooks', () => { const snapFiles = await fetchSnap(snapId, location); - const id = await snapInterfaceController.createInterface( - snapId, - text('foo'), - ); + const id = snapInterfaceController.createInterface(snapId, text('foo')); const { resolveInterface } = getPermittedHooks( snapId, diff --git a/packages/snaps-simulation/src/simulation.ts b/packages/snaps-simulation/src/simulation.ts index 33d774f09d..b2e98d0eae 100644 --- a/packages/snaps-simulation/src/simulation.ts +++ b/packages/snaps-simulation/src/simulation.ts @@ -230,10 +230,7 @@ export type PermittedMiddlewareHooks = { * @param context - The context of the interface. * @returns The ID of the created interface. */ - createInterface: ( - content: Component, - context?: InterfaceContext, - ) => Promise; + createInterface: (content: Component, context?: InterfaceContext) => string; /** * A hook that updates an interface for the Snap. This hook is bound to the @@ -242,7 +239,7 @@ export type PermittedMiddlewareHooks = { * @param id - The ID of the interface to update. * @param content - The content of the interface. */ - updateInterface: (id: string, content: Component) => Promise; + updateInterface: (id: string, content: Component) => void; /** * A hook that gets the state of an interface for the Snap. This hook is bound @@ -477,13 +474,13 @@ export function getPermittedHooks( getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) => await getSnapFile(snapFiles.auxiliaryFiles, path, encoding), - createInterface: async (...args) => + createInterface: (...args) => controllerMessenger.call( 'SnapInterfaceController:createInterface', snapId, ...args, ), - updateInterface: async (...args) => + updateInterface: (...args) => controllerMessenger.call( 'SnapInterfaceController:updateInterface', snapId,