Skip to content

Commit

Permalink
Merge pull request #56 from cosmology-tech/helper-func-client-resolver
Browse files Browse the repository at this point in the history
string for rpc resolver
  • Loading branch information
Zetazzz authored Oct 30, 2024
2 parents bd42dd0 + b6b98f7 commit 7bb81d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 7 additions & 4 deletions libs/interchainjs/src/helper-func-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


import { BinaryReader, BinaryWriter } from "./binary";
import { getRpcClient } from "./extern";
import { Rpc } from "./helpers";

export interface QueryBuilderOptions<TReq, TRes> {
Expand All @@ -22,7 +23,9 @@ export function buildQuery<TReq, TRes>(opts: QueryBuilderOptions<TReq, TRes>) {

// if opts.getRpcInstance is a function, call it to get the Rpc instance
if(typeof opts.getRpcInstance === 'function') {
rpc = opts.getRpcInstance();
rpc = await opts.getRpcInstance();
} else if(typeof opts.getRpcInstance === 'string') {
rpc = await getRpcClient(opts.getRpcInstance);
} else {
rpc = opts.getRpcInstance;
}
Expand Down Expand Up @@ -78,7 +81,7 @@ export function buildTx<TMsg>(opts: TxBuilderOptions) {

// if opts.getSigningClient is a function, call it to get the SigningClient instance
if(typeof opts.getSigningClient === 'function') {
client = opts.getSigningClient();
client = await opts.getSigningClient();
} else {
client = opts.getSigningClient;
}
Expand Down Expand Up @@ -181,5 +184,5 @@ export interface AminoConverter {
toAmino: (data: any) => any;
}

export type SigningClientResolver = ISigningClient | (() => ISigningClient | undefined);
export type RpcResolver = Rpc | (() => Rpc | undefined);
export type SigningClientResolver = ISigningClient | (() => Promise<ISigningClient> | undefined);
export type RpcResolver = string | Rpc | (() => Promise<Rpc> | undefined);
10 changes: 7 additions & 3 deletions libs/interchainjs/src/react-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ export function buildUseQuery<TReq, TRes>(opts: UseQueryBuilderOptions<TReq, TRe
let rpcResolver: RpcResolver;

if(!getRpcInstance) {
const key = rpcClientQueryKey || DEFAULT_RPC_CLIENT_QUERY_KEY;
const queryKey = rpcEndpoint ? [key, rpcEndpoint] : [key];
rpcResolver = queryClient.getQueryData<Rpc>(queryKey);
if(rpcEndpoint && typeof rpcEndpoint === 'string') {
rpcResolver = rpcEndpoint;
} else {
const key = rpcClientQueryKey || DEFAULT_RPC_CLIENT_QUERY_KEY;
const queryKey = rpcEndpoint ? [key, rpcEndpoint] : [key];
rpcResolver = queryClient.getQueryData<Rpc>(queryKey);
}
} else {
rpcResolver = getRpcInstance;
}
Expand Down

0 comments on commit 7bb81d1

Please sign in to comment.