Skip to content

Commit

Permalink
Merge pull request #3996 from kr-nikunj/sendAsync-response-fix
Browse files Browse the repository at this point in the history
sendAsync method result response formatted
  • Loading branch information
ganchoradkov authored Dec 20, 2023
2 parents 471ce77 + da1200e commit 91af38e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion providers/ethereum-provider/src/EthereumProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "./types";
import { Metadata, Namespace, UniversalProvider } from "@walletconnect/universal-provider";
import { SessionTypes, SignClientTypes } from "@walletconnect/types";
import { JsonRpcResult } from "@walletconnect/jsonrpc-types";
import {
STORAGE_KEY,
REQUIRED_METHODS,
Expand Down Expand Up @@ -241,7 +242,7 @@ export class EthereumProvider implements IEthereumProvider {

public sendAsync(
args: RequestArguments,
callback: (error: Error | null, response: any) => void,
callback: (error: Error | null, response: JsonRpcResult) => void,
): void {
this.signer.sendAsync(args, callback, this.formatChainId(this.chainId));
}
Expand Down
9 changes: 6 additions & 3 deletions providers/universal-provider/src/UniversalProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SignClient, { PROPOSAL_EXPIRY_MESSAGE } from "@walletconnect/sign-client";
import { SessionTypes } from "@walletconnect/types";
import { JsonRpcResult } from "@walletconnect/jsonrpc-types";
import { getSdkError, isValidArray, parseNamespaceKey } from "@walletconnect/utils";
import { getDefaultLoggerOptions, Logger, pino } from "@walletconnect/logger";
import {
Expand Down Expand Up @@ -34,6 +35,7 @@ import {

import { RELAY_URL, LOGGER, STORAGE, PROVIDER_EVENTS } from "./constants";
import EventEmitter from "events";
import { formatJsonRpcResult } from "@walletconnect/jsonrpc-utils";

export class UniversalProvider implements IUniversalProvider {
public client!: SignClient;
Expand Down Expand Up @@ -87,12 +89,13 @@ export class UniversalProvider implements IUniversalProvider {

public sendAsync(
args: RequestArguments,
callback: (error: Error | null, response: any) => void,
callback: (error: Error | null, response: JsonRpcResult) => void,
chain?: string | undefined,
): void {
const id = new Date().getTime();
this.request(args, chain)
.then((response) => callback(null, response))
.catch((error) => callback(error, undefined));
.then((response) => callback(null, formatJsonRpcResult(id, response)))
.catch((error) => callback(error, undefined as any));
}

public async enable(): Promise<ProviderAccounts> {
Expand Down
3 changes: 2 additions & 1 deletion providers/universal-provider/src/types/providers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SignClient from "@walletconnect/sign-client";
import { SessionTypes } from "@walletconnect/types";
import { JsonRpcResult } from "@walletconnect/jsonrpc-types";

import {
RpcProvidersMap,
Expand Down Expand Up @@ -34,7 +35,7 @@ export interface IUniversalProvider extends IEthereumProvider {
request: <T = unknown>(args: RequestArguments, chain?: string) => Promise<T>;
sendAsync: (
args: RequestArguments,
callback: (error: Error | null, response: any) => void,
callback: (error: Error | null, response: JsonRpcResult) => void,
chain?: string,
) => void;
pair: (pairingTopic: string | undefined) => Promise<SessionTypes.Struct>;
Expand Down

0 comments on commit 91af38e

Please sign in to comment.