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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('snap_sendWebSocketMessage', () => {
it('throws if the origin does not have permission', async () => {
const { implementation } = sendWebSocketMessageHandler;

const sendWebSocketMessage = jest.fn();
const sendWebSocketMessage = jest.fn().mockResolvedValue(undefined);
const hasPermission = jest.fn().mockReturnValue(false);
const hooks = { hasPermission, sendWebSocketMessage };

Expand Down Expand Up @@ -63,7 +63,7 @@ describe('snap_sendWebSocketMessage', () => {
it('throws if invalid parameters are passed', async () => {
const { implementation } = sendWebSocketMessageHandler;

const sendWebSocketMessage = jest.fn();
const sendWebSocketMessage = jest.fn().mockResolvedValue(undefined);
const hasPermission = jest.fn().mockReturnValue(true);
const hooks = { hasPermission, sendWebSocketMessage };

Expand Down Expand Up @@ -103,7 +103,7 @@ describe('snap_sendWebSocketMessage', () => {
it('sends a WebSocket message and returns null', async () => {
const { implementation } = sendWebSocketMessageHandler;

const sendWebSocketMessage = jest.fn();
const sendWebSocketMessage = jest.fn().mockResolvedValue(undefined);
const hasPermission = jest.fn().mockReturnValue(true);
const hooks = { hasPermission, sendWebSocketMessage };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const hookNames: MethodHooksObject<SendWebSocketMessageMethodHooks> = {

export type SendWebSocketMessageMethodHooks = {
hasPermission: (permissionName: string) => boolean;
sendWebSocketMessage: (id: string, data: string | number[]) => void;
sendWebSocketMessage: (id: string, data: string | number[]) => Promise<void>;
};

const SendWebSocketMessageParametersStruct = object({
Expand Down Expand Up @@ -66,13 +66,13 @@ export const sendWebSocketMessageHandler: PermittedHandlerExport<
* @param hooks.sendWebSocketMessage - The function to send a WebSocket message.
* @returns Nothing.
*/
function sendWebSocketMessageImplementation(
async function sendWebSocketMessageImplementation(
req: JsonRpcRequest<SendWebSocketMessageParameters>,
res: PendingJsonRpcResponse<SendWebSocketMessageResult>,
_next: unknown,
end: JsonRpcEngineEndCallback,
{ hasPermission, sendWebSocketMessage }: SendWebSocketMessageMethodHooks,
): void {
): Promise<void> {
if (!hasPermission(SnapEndowments.NetworkAccess)) {
return end(providerErrors.unauthorized());
}
Expand All @@ -81,7 +81,7 @@ function sendWebSocketMessageImplementation(

try {
const { id, message } = getValidatedParams(params);
sendWebSocketMessage(id, message);
await sendWebSocketMessage(id, message);
res.result = null;
} catch (error) {
return end(error);
Expand Down
Loading