Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Fix send id #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,16 @@ export class IFrameEthereumProvider extends EventEmitter<
*/
private async execute<TParams, TResult, TErrorData>(
method: string,
params?: TParams
params?: TParams,
optionalId?: number
): Promise<
| JsonRpcSucessfulResponseMessage<TResult>
| JsonRpcErrorResponseMessage<TErrorData>
> {
const id = getUniqueId();
const id = Number.isNaN(optionalId as any)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should check for undefined values, if optionalId value is undefined then id will be undefined too

? getUniqueId()
: (optionalId as number);

const payload: JsonRpcRequestMessage = {
jsonrpc: JSON_RPC_VERSION,
id,
Expand Down Expand Up @@ -274,14 +278,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<void> {
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) {
Expand Down