Skip to content

Commit

Permalink
feat: override chain ID generic from options
Browse files Browse the repository at this point in the history
  • Loading branch information
tien committed Jul 5, 2024
1 parent 7d92a85 commit 942348d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/hooks/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ChainId } from "@reactive-dot/core";

// eslint-disable-next-line @typescript-eslint/ban-types
export type ChainHookOptions<T = {}> = T & {
export type ChainHookOptions<TChainId extends ChainId = ChainId, T = {}> = T & {
/**
* Override default chain ID
*/
chainId?: ChainId;
chainId?: TChainId;
};
25 changes: 14 additions & 11 deletions packages/react/src/hooks/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@ export function useMutation<
>["tx"],
) => // eslint-disable-next-line @typescript-eslint/no-explicit-any
Transaction<any, any, any, any>,
TChainId extends ChainId | void = void,
TChainId extends ChainId = ChainId,
>(
action: TAction,
options?: ChainHookOptions<{
/**
* Override default signer
*/
signer?: PolkadotSigner;
/**
* Additional transaction options
*/
txOptions?: TxOptions<ReturnType<TAction>>;
}>,
options?: ChainHookOptions<
TChainId,
{
/**
* Override default signer
*/
signer?: PolkadotSigner;
/**
* Additional transaction options
*/
txOptions?: TxOptions<ReturnType<TAction>>;
}
>,
) {
const chainId = useChainId(options);
const contextSigner = useContext(SignerContext);
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/hooks/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ export function useLazyLoadQueryWithRefresh<
TDescriptor extends TChainId extends void
? CommonDescriptor
: Chains[Exclude<TChainId, void>],
TChainId extends ChainId | void = void,
TChainId extends ChainId = ChainId,
>(
builder: TQuery,
options?: ChainHookOptions,
options?: ChainHookOptions<TChainId>,
): [
data: TQuery extends Falsy
? typeof IDLE
Expand Down Expand Up @@ -156,10 +156,10 @@ export function useLazyLoadQuery<
TDescriptor extends TChainId extends void
? CommonDescriptor
: Chains[Exclude<TChainId, void>],
TChainId extends ChainId | void = void,
TChainId extends ChainId = ChainId,
>(
builder: TQuery,
options?: ChainHookOptions,
options?: ChainHookOptions<TChainId>,
): TQuery extends Falsy
? typeof IDLE
: FalsyGuard<
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/hooks/useTypedApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type { TypedApi } from "polkadot-api";
* @param options - Additional options
* @returns Polkadot-API typed API
*/
export function useTypedApi<TChainId extends ChainId | void = void>(
options?: ChainHookOptions,
export function useTypedApi<TChainId extends ChainId>(
options?: ChainHookOptions<TChainId>,
): TypedApi<
TChainId extends void ? CommonDescriptor : Chains[Exclude<TChainId, void>]
> {
Expand Down

0 comments on commit 942348d

Please sign in to comment.