From d32577a29fbb6a2578e92d825f6203e1a3a59369 Mon Sep 17 00:00:00 2001 From: Jonathan Dunlap Date: Thu, 16 Apr 2020 16:20:16 -0700 Subject: [PATCH 1/2] fix passing of id --- src/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1356c09..dd935b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -195,12 +195,14 @@ export class IFrameEthereumProvider extends EventEmitter< */ private async execute( method: string, - params?: TParams + params?: TParams, + optionalId?: number ): Promise< | JsonRpcSucessfulResponseMessage | JsonRpcErrorResponseMessage > { - const id = getUniqueId(); + const id = Number.isNaN(optionalId as any) ? getUniqueId() : optionalId; + const payload: JsonRpcRequestMessage = { jsonrpc: JSON_RPC_VERSION, id, @@ -274,14 +276,18 @@ export class IFrameEthereumProvider extends EventEmitter< * @param callback callback to be called when the provider resolves */ public async sendAsync( - payload: { method: string; params?: any[] }, + payload: { method: string; params?: any[]; id?: number }, callback: ( error: string | null, result: { method: string; params?: any[]; result: any } | any ) => void ): Promise { try { - const result = await this.execute(payload.method, payload.params); + const result = await this.execute( + payload.method, + payload.params, + payload.id + ); callback(null, result); } catch (error) { From 6ec805e837bc5de8f0025a50b51ed1633ead2472 Mon Sep 17 00:00:00 2001 From: Jonathan Dunlap Date: Thu, 16 Apr 2020 16:26:58 -0700 Subject: [PATCH 2/2] set optionalid as number to fix type warning --- src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index dd935b9..2cac6ec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -201,7 +201,9 @@ export class IFrameEthereumProvider extends EventEmitter< | JsonRpcSucessfulResponseMessage | JsonRpcErrorResponseMessage > { - const id = Number.isNaN(optionalId as any) ? getUniqueId() : optionalId; + const id = Number.isNaN(optionalId as any) + ? getUniqueId() + : (optionalId as number); const payload: JsonRpcRequestMessage = { jsonrpc: JSON_RPC_VERSION,