Skip to content

Commit

Permalink
update rpc success response
Browse files Browse the repository at this point in the history
  • Loading branch information
m-aboelenein committed Feb 29, 2024
1 parent 5df44d5 commit cde3670
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/provider/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Params, Requests, Return } from 'src/request';
import { Params, Requests } from '../request';
import type { GetAddressResponse } from '../addresses';
import type { GetCapabilitiesResponse } from '../capabilities';
import type { CreateInscriptionResponse, CreateRepeatInscriptionsResponse } from '../inscriptions';
Expand All @@ -8,13 +8,14 @@ import type {
SignMultipleTransactionsResponse,
SignTransactionResponse,
} from '../transactions';
import { RpcResponse } from '../types';

interface BaseBitcoinProvider {
request: <Method extends keyof Requests>(
method: Method,
options: Params<Method>,
providerId?: string
) => Promise<Return<Method>>;
) => Promise<RpcResponse<Method>>;
listen: (method: string, callback: () => void) => void;
connect: (request: string) => Promise<GetAddressResponse>;
signMessage: (request: string) => Promise<SignMessageResponse>;
Expand Down
5 changes: 3 additions & 2 deletions src/request/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { RpcResponse } from '../types';
import { getProviderById } from '../provider';
import { Params, Requests, Return } from './types';
import { Params, Requests } from './types';

export const request = async <Method extends keyof Requests>(
method: Method,
params: Params<Method>,
providerId?: string
): Promise<Return<Method>> => {
): Promise<RpcResponse<Method>> => {
let provider = window.XverseProviders?.BitcoinProvider;
if (providerId) {
provider = await getProviderById(providerId);
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ export interface RpcErrorResponse<TError extends RpcError = RpcError> extends Rp
export interface RpcSuccessResponse<Method extends keyof Requests> extends RpcBase {
result: Return<Method>;
}

export type RpcResponse<Method extends keyof Requests> =
RpcSuccessResponse<Method> extends RpcSuccessResponse<Method>
? RpcSuccessResponse<Method>
: RpcErrorResponse;

0 comments on commit cde3670

Please sign in to comment.