Skip to content

Commit

Permalink
Simplify types
Browse files Browse the repository at this point in the history
  • Loading branch information
aryzing committed Feb 26, 2024
1 parent 6fa19e9 commit aab4c9e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
7 changes: 2 additions & 5 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 { Request } from 'src/request';
import type { GetAddressResponse } from '../addresses';
import type { GetCapabilitiesResponse } from '../capabilities';
import type { CreateInscriptionResponse, CreateRepeatInscriptionsResponse } from '../inscriptions';
Expand All @@ -10,10 +10,7 @@ import type {
} from '../transactions';

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

export const request = async <Method extends keyof Requests>(
method: Method,
params: Params<Method>,
providerId?: string
): Promise<Return<Method>> => {
export const request: Request = async (method, params, providerId?: string) => {
let provider = window.XverseProviders?.BitcoinProvider;
if (providerId) {
provider = await getProviderById(providerId);
Expand Down
4 changes: 2 additions & 2 deletions src/request/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Requests {
export type Return<Method> = Method extends keyof Requests ? Requests[Method]['result'] : unknown;
export type Params<Method> = Method extends keyof Requests ? Requests[Method]['params'] : unknown;

export type Request<Method extends keyof Requests | string> = (
export type Request = <Method extends keyof Requests>(
requestMethod: Method,
params: Params<Method>
) => Return<Method>;
) => Promise<Return<Method>>;

0 comments on commit aab4c9e

Please sign in to comment.