Skip to content

Commit

Permalink
wip: config types
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Aug 22, 2023
1 parent fcae6e0 commit 06eb64a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 45 deletions.
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@
"vitepress@1.0.0-rc.4": "patches/vitepress@1.0.0-rc.4.patch"
},
"peerDependencyRules": {
"ignoreMissing": [
"@algolia/client-search",
"esbuild",
"react",
"search-insights"
]
"ignoreMissing": ["@algolia/client-search", "react", "search-insights"]
}
},
"knip": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/query/getTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type GetTransactionOptions<
export function getTransactionQueryOptions<
config extends Config,
chainId extends config['chains'][number]['id'] | undefined,
>(config: Config, options: GetTransactionOptions<config, chainId> = {}) {
>(config: config, options: GetTransactionOptions<config, chainId> = {}) {
return {
async queryFn({ queryKey }) {
const {
Expand Down
35 changes: 19 additions & 16 deletions packages/react/src/hooks/useTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GetTransactionError, ResolvedRegister } from '@wagmi/core'
import type { Config, GetTransactionError, ResolvedRegister } from '@wagmi/core'
import { type Evaluate } from '@wagmi/core/internal'
import {
type GetTransactionData,
Expand All @@ -8,6 +8,7 @@ import {
getTransactionQueryOptions,
} from '@wagmi/core/query'

import type { ConfigParameter } from '../types/properties.js'
import {
type UseQueryParameters,
type UseQueryResult,
Expand All @@ -16,35 +17,37 @@ import {
import { useChainId } from './useChainId.js'
import { useConfig } from './useConfig.js'

type ChainId = ResolvedRegister['config']['chains'][number]['id']

export type UseTransactionParameters<
chainId extends ChainId | undefined = undefined,
selectData = GetTransactionData<ResolvedRegister['config'], chainId>,
config extends Config = Config,
chainId extends config['chains'][number]['id'] | undefined = undefined,
selectData = GetTransactionData<config, chainId>,
> = Evaluate<
GetTransactionOptions<ResolvedRegister['config'], chainId> &
GetTransactionOptions<config, chainId> &
UseQueryParameters<
GetTransactionQueryFnData<ResolvedRegister['config'], chainId>,
GetTransactionQueryFnData<config, chainId>,
GetTransactionError,
selectData,
GetTransactionQueryKey<ResolvedRegister['config'], chainId>
>
GetTransactionQueryKey<config, chainId>
> &
ConfigParameter<config>
>

export type UseTransactionReturnType<
chainId extends ChainId | undefined = undefined,
selectData = GetTransactionData<ResolvedRegister['config'], chainId>,
config extends Config = Config,
chainId extends config['chains'][number]['id'] | undefined = undefined,
selectData = GetTransactionData<config, chainId>,
> = UseQueryResult<selectData, GetTransactionError>

/** https://wagmi.sh/react/hooks/useTransaction */
export function useTransaction<
chainId extends ChainId | undefined = undefined,
selectData = GetTransactionData<ResolvedRegister['config'], chainId>,
config extends Config = ResolvedRegister['config'],
chainId extends config['chains'][number]['id'] | undefined = undefined,
selectData = GetTransactionData<config, chainId>,
>(
parameters: UseTransactionParameters<chainId, selectData> = {},
): UseTransactionReturnType<chainId, selectData> {
parameters: UseTransactionParameters<config, chainId, selectData> = {},
): UseTransactionReturnType<config, chainId, selectData> {
const { blockHash, blockNumber, blockTag, hash, ...query } = parameters
const config = useConfig()
const config = useConfig(parameters)

const chainId = parameters.chainId ?? useChainId()
const queryOptions = getTransactionQueryOptions(config, {
Expand Down
12 changes: 12 additions & 0 deletions packages/react/src/hooks/useWaitForTransactionReceipt.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expectTypeOf, test } from 'vitest'

import { useWaitForTransactionReceipt } from './useWaitForTransactionReceipt.js'

test('select data', async () => {
const result = useWaitForTransactionReceipt({
select(data) {
return data?.blockNumber
},
})
expectTypeOf(result.data).toEqualTypeOf<bigint | undefined>()
})
41 changes: 19 additions & 22 deletions packages/react/src/hooks/useWaitForTransactionReceipt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
Config,
ResolvedRegister,
WaitForTransactionReceiptError,
} from '@wagmi/core'
Expand All @@ -19,42 +20,38 @@ import {
import { useChainId } from './useChainId.js'
import { useConfig } from './useConfig.js'

type ChainId = ResolvedRegister['config']['chains'][number]['id']

export type UseWaitForTransactionReceiptParameters<
chainId extends ChainId | undefined = undefined,
selectData = WaitForTransactionReceiptData<
ResolvedRegister['config'],
chainId
>,
config extends Config = Config,
chainId extends config['chains'][number]['id'] | undefined = undefined,
selectData = WaitForTransactionReceiptData<config, chainId>,
> = Evaluate<
WaitForTransactionReceiptOptions<ResolvedRegister['config'], chainId> &
WaitForTransactionReceiptOptions<config, chainId> &
UseQueryParameters<
WaitForTransactionReceiptQueryFnData<ResolvedRegister['config'], chainId>,
WaitForTransactionReceiptQueryFnData<config, chainId>,
WaitForTransactionReceiptError,
selectData,
WaitForTransactionReceiptQueryKey<ResolvedRegister['config'], chainId>
WaitForTransactionReceiptQueryKey<config, chainId>
>
>

export type UseWaitForTransactionReceiptReturnType<
chainId extends ChainId | undefined = undefined,
selectData = WaitForTransactionReceiptData<
ResolvedRegister['config'],
chainId
>,
config extends Config = Config,
chainId extends config['chains'][number]['id'] | undefined = undefined,
selectData = WaitForTransactionReceiptData<config, chainId>,
> = UseQueryResult<selectData, WaitForTransactionReceiptError>

/** https://wagmi.sh/react/hooks/useWaitForTransactionReceipt */
export function useWaitForTransactionReceipt<
chainId extends ChainId | undefined = undefined,
selectData = WaitForTransactionReceiptData<
ResolvedRegister['config'],
chainId
>,
config extends Config = ResolvedRegister['config'],
chainId extends config['chains'][number]['id'] | undefined = undefined,
selectData = WaitForTransactionReceiptData<config, chainId>,
>(
parameters: UseWaitForTransactionReceiptParameters<chainId, selectData> = {},
): UseWaitForTransactionReceiptReturnType<chainId, selectData> {
parameters: UseWaitForTransactionReceiptParameters<
config,
chainId,
selectData
> = {},
): UseWaitForTransactionReceiptReturnType<config, chainId, selectData> {
const { hash, ...query } = parameters
const config = useConfig()

Expand Down

1 comment on commit 06eb64a

@vercel
Copy link

@vercel vercel bot commented on 06eb64a Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wagmi-v2 – ./docs

wagmi-v2-wagmi-dev.vercel.app
wagmi-v2.vercel.app
wagmi-v2-git-alpha-wagmi-dev.vercel.app
alpha.wagmi.sh

Please sign in to comment.