This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from unicape/1.x
feat: add useEnsText & usePrepareTransactionRequest & useTransactionC…
- Loading branch information
Showing
8 changed files
with
294 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@use-wagmi/nuxt": minor | ||
"use-wagmi": minor | ||
--- | ||
|
||
add useEnsText & usePrepareTransactionRequest & useTransactionConfirmations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use client' | ||
|
||
import type { Config, GetEnsTextErrorType, ResolvedRegister } from '@wagmi/core' | ||
import { type Evaluate } from '@wagmi/core/internal' | ||
import { | ||
type GetEnsTextData, | ||
type GetEnsTextOptions, | ||
type GetEnsTextQueryFnData, | ||
type GetEnsTextQueryKey, | ||
getEnsTextQueryOptions, | ||
} from '@wagmi/core/query' | ||
|
||
import { computed } from 'vue-demi' | ||
import type { | ||
ConfigParameter, | ||
DeepUnwrapRef, | ||
MaybeRefDeep, | ||
QueryParameter, | ||
} from '../types.js' | ||
import { cloneDeepUnref } from '../utils/cloneDeepUnref.js' | ||
import { type UseQueryReturnType, useQuery } from '../utils/query.js' | ||
import { useChainId } from './useChainId.js' | ||
import { useConfig } from './useConfig.js' | ||
|
||
export type UseEnsTextParameters< | ||
config extends Config = Config, | ||
selectData = GetEnsTextData, | ||
> = MaybeRefDeep< | ||
Evaluate< | ||
GetEnsTextOptions<config> & | ||
ConfigParameter<config> & | ||
QueryParameter< | ||
GetEnsTextQueryFnData, | ||
GetEnsTextErrorType, | ||
selectData, | ||
GetEnsTextQueryKey<config> | ||
> | ||
> | ||
> | ||
|
||
export type UseEnsTextReturnType<selectData = GetEnsTextData> = | ||
UseQueryReturnType<selectData, GetEnsTextErrorType> | ||
|
||
/** https://wagmi.sh/react/api/hooks/useEnsText */ | ||
export function useEnsText< | ||
config extends Config = ResolvedRegister['config'], | ||
selectData = GetEnsTextData, | ||
>( | ||
parameters: UseEnsTextParameters<config, selectData> = {}, | ||
): UseEnsTextReturnType<selectData> { | ||
const config = useConfig(parameters) | ||
const chainId = useChainId() | ||
|
||
const queryOptions = computed(() => { | ||
const _parameters = cloneDeepUnref< | ||
DeepUnwrapRef<UseEnsTextParameters<config, selectData>> | ||
>(parameters as any) | ||
|
||
const { key, name, query = {} } = _parameters | ||
const options = getEnsTextQueryOptions(config, { | ||
..._parameters, | ||
chainId: _parameters.chainId ?? chainId.value, | ||
}) | ||
const enabled = Boolean(key && name && (query.enabled ?? true)) | ||
|
||
return { | ||
...query, | ||
...options, | ||
enabled, | ||
} | ||
}) | ||
|
||
return useQuery(queryOptions as any) as UseEnsTextReturnType<selectData> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
'use client' | ||
|
||
import { | ||
type Config, | ||
type PrepareTransactionRequestErrorType, | ||
type ResolvedRegister, | ||
} from '@wagmi/core' | ||
import { | ||
type PrepareTransactionRequestData, | ||
type PrepareTransactionRequestOptions, | ||
type PrepareTransactionRequestQueryKey, | ||
prepareTransactionRequestQueryOptions, | ||
} from '@wagmi/core/query' | ||
import type { PrepareTransactionRequestQueryFnData } from '@wagmi/core/query' | ||
import { type PrepareTransactionRequestParameterType as viem_PrepareTransactionRequestParameterType } from 'viem' | ||
|
||
import { computed } from 'vue-demi' | ||
import { | ||
type ConfigParameter, | ||
type MaybeRefDeep, | ||
type QueryParameter, | ||
} from '../types.js' | ||
import { cloneDeepUnref } from '../utils/cloneDeepUnref.js' | ||
import { type UseQueryReturnType, useQuery } from '../utils/query.js' | ||
import { useChainId } from './useChainId.js' | ||
import { useConfig } from './useConfig.js' | ||
|
||
export type UsePrepareTransactionRequestParameters< | ||
parameterType extends viem_PrepareTransactionRequestParameterType = viem_PrepareTransactionRequestParameterType, | ||
config extends Config = Config, | ||
chainId extends config['chains'][number]['id'] | undefined = undefined, | ||
selectData = PrepareTransactionRequestData<parameterType, config, chainId>, | ||
> = MaybeRefDeep< | ||
PrepareTransactionRequestOptions<parameterType, config, chainId> & | ||
ConfigParameter<config> & | ||
QueryParameter< | ||
PrepareTransactionRequestQueryFnData<parameterType, config, chainId>, | ||
PrepareTransactionRequestErrorType, | ||
selectData, | ||
PrepareTransactionRequestQueryKey<parameterType, config, chainId> | ||
> | ||
> | ||
|
||
export type UsePrepareTransactionRequestReturnType< | ||
parameterType extends viem_PrepareTransactionRequestParameterType = viem_PrepareTransactionRequestParameterType, | ||
config extends Config = Config, | ||
chainId extends config['chains'][number]['id'] | undefined = undefined, | ||
selectData = PrepareTransactionRequestData<parameterType, config, chainId>, | ||
> = UseQueryReturnType<selectData, PrepareTransactionRequestErrorType> | ||
|
||
/** https://wagmi.sh/react/api/hooks/usePrepareTransactionRequest */ | ||
export function usePrepareTransactionRequest< | ||
parameterType extends viem_PrepareTransactionRequestParameterType, | ||
config extends Config = ResolvedRegister['config'], | ||
chainId extends config['chains'][number]['id'] | undefined = undefined, | ||
selectData = PrepareTransactionRequestData<parameterType, config, chainId>, | ||
>( | ||
parameters: UsePrepareTransactionRequestParameters< | ||
parameterType, | ||
config, | ||
chainId, | ||
selectData | ||
> = {} as any, | ||
): UsePrepareTransactionRequestReturnType< | ||
parameterType, | ||
config, | ||
chainId, | ||
selectData | ||
> { | ||
const config = useConfig(parameters) | ||
const chainId = useChainId() | ||
|
||
const queryOptions = computed(() => { | ||
const _parameters = cloneDeepUnref(parameters) | ||
|
||
const { to, query = {} } = _parameters | ||
const options = prepareTransactionRequestQueryOptions(config, { | ||
..._parameters, | ||
chainId: _parameters.chainId ?? chainId.value, | ||
}) | ||
const enabled = Boolean(to && (query.enabled ?? true)) | ||
|
||
return { | ||
...query, | ||
...options, | ||
enabled, | ||
} | ||
}) | ||
|
||
return useQuery( | ||
queryOptions as any, | ||
) as UsePrepareTransactionRequestReturnType< | ||
parameterType, | ||
config, | ||
chainId, | ||
selectData | ||
> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use client' | ||
|
||
import { | ||
type Config, | ||
type GetTransactionConfirmationsErrorType, | ||
type ResolvedRegister, | ||
} from '@wagmi/core' | ||
import { | ||
type GetTransactionConfirmationsData, | ||
type GetTransactionConfirmationsOptions, | ||
type GetTransactionConfirmationsQueryFnData, | ||
type GetTransactionConfirmationsQueryKey, | ||
getTransactionConfirmationsQueryOptions, | ||
} from '@wagmi/core/query' | ||
|
||
import { computed } from 'vue-demi' | ||
import { | ||
type ConfigParameter, | ||
type MaybeRefDeep, | ||
type QueryParameter, | ||
} from '../types.js' | ||
import { cloneDeepUnref } from '../utils/cloneDeepUnref.js' | ||
import { type UseQueryReturnType, useQuery } from '../utils/query.js' | ||
import { useChainId } from './useChainId.js' | ||
import { useConfig } from './useConfig.js' | ||
|
||
export type UseTransactionConfirmationsParameters< | ||
config extends Config = Config, | ||
chainId extends config['chains'][number]['id'] | undefined = undefined, | ||
selectData = GetTransactionConfirmationsData, | ||
> = MaybeRefDeep< | ||
GetTransactionConfirmationsOptions<config, chainId> & | ||
ConfigParameter<config> & | ||
QueryParameter< | ||
GetTransactionConfirmationsQueryFnData, | ||
GetTransactionConfirmationsErrorType, | ||
selectData, | ||
GetTransactionConfirmationsQueryKey<config, chainId> | ||
> | ||
> | ||
|
||
export type UseTransactionConfirmationsReturnType< | ||
selectData = GetTransactionConfirmationsData, | ||
> = UseQueryReturnType<selectData, GetTransactionConfirmationsErrorType> | ||
|
||
/** https://wagmi.sh/react/api/hooks/useTransactionConfirmations */ | ||
export function useTransactionConfirmations< | ||
config extends Config = ResolvedRegister['config'], | ||
chainId extends config['chains'][number]['id'] | undefined = undefined, | ||
selectData = GetTransactionConfirmationsData, | ||
>( | ||
parameters: UseTransactionConfirmationsParameters< | ||
config, | ||
chainId, | ||
selectData | ||
> = {} as any, | ||
): UseTransactionConfirmationsReturnType<selectData> { | ||
const config = useConfig(parameters) | ||
const chainId = useChainId() | ||
|
||
const queryOptions = computed(() => { | ||
const _parameters = cloneDeepUnref(parameters) | ||
|
||
const { hash, transactionReceipt, query = {} } = _parameters | ||
const options = getTransactionConfirmationsQueryOptions(config, { | ||
..._parameters, | ||
chainId: _parameters.chainId ?? chainId.value, | ||
}) | ||
const enabled = Boolean( | ||
!(hash && transactionReceipt) && | ||
(hash || transactionReceipt) && | ||
(query.enabled ?? true), | ||
) | ||
|
||
return { ...query, ...options, enabled } | ||
}) | ||
|
||
return useQuery( | ||
queryOptions as any, | ||
) as UseTransactionConfirmationsReturnType<selectData> | ||
} |
Oops, something went wrong.