From cde3670dd545644eaf2d9f645257bdae28ef194e Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Thu, 29 Feb 2024 13:08:34 +0200 Subject: [PATCH] update rpc success response --- src/provider/types.ts | 5 +++-- src/request/index.ts | 5 +++-- src/types.ts | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/provider/types.ts b/src/provider/types.ts index 58aa0da..8ae6099 100644 --- a/src/provider/types.ts +++ b/src/provider/types.ts @@ -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'; @@ -8,13 +8,14 @@ import type { SignMultipleTransactionsResponse, SignTransactionResponse, } from '../transactions'; +import { RpcResponse } from '../types'; interface BaseBitcoinProvider { request: ( method: Method, options: Params, providerId?: string - ) => Promise>; + ) => Promise>; listen: (method: string, callback: () => void) => void; connect: (request: string) => Promise; signMessage: (request: string) => Promise; diff --git a/src/request/index.ts b/src/request/index.ts index 990b782..b9a8f55 100644 --- a/src/request/index.ts +++ b/src/request/index.ts @@ -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: Method, params: Params, providerId?: string -): Promise> => { +): Promise> => { let provider = window.XverseProviders?.BitcoinProvider; if (providerId) { provider = await getProviderById(providerId); diff --git a/src/types.ts b/src/types.ts index e1beea9..8a0f1d0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -62,3 +62,8 @@ export interface RpcErrorResponse extends Rp export interface RpcSuccessResponse extends RpcBase { result: Return; } + +export type RpcResponse = + RpcSuccessResponse extends RpcSuccessResponse + ? RpcSuccessResponse + : RpcErrorResponse;