Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #140 from unicape/1.x
Browse files Browse the repository at this point in the history
chore: Added useBytecode useProof useStorageAt useTransactionReceipt
  • Loading branch information
unicape authored Jan 15, 2024
2 parents b3200ac + 6b4e241 commit a45cae7
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 20 deletions.
6 changes: 6 additions & 0 deletions .changeset/loud-buckets-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@use-wagmi/nuxt": minor
"use-wagmi": minor
---

Added useBytecode useProof useStorageAt useTransactionReceipt
4 changes: 4 additions & 0 deletions packages/nuxt/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const functions = [
'useBlock',
'useBlockNumber',
'useBlockTransactionCount',
'useBytecode',
'useCall',
'useChainId',
'useClient',
Expand All @@ -30,6 +31,7 @@ export const functions = [
'useGasPrice',
'useInfiniteReadContracts',
'useContractInfiniteReads',
'useProof',
'usePublicClient',
'useReadContract',
'useContractRead',
Expand All @@ -40,11 +42,13 @@ export const functions = [
'useSignMessage',
'useSignTypedData',
'useSimulateContract',
'useStorageAt',
'useSwitchAccount',
'useSwitchChain',
'useToken',
'useTransaction',
'useTransactionCount',
'useTransactionReceipt',
'useVerifyMessage',
'useVerifyTypedData',
'useWalletClient',
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
}
},
"dependencies": {
"@wagmi/connectors": "4.1.2",
"@wagmi/core": "2.1.2",
"@wagmi/connectors": "4.1.4",
"@wagmi/core": "2.2.1",
"vue": "3.3.8",
"vue-demi": "^0.14.6"
},
Expand Down
24 changes: 24 additions & 0 deletions packages/vue/src/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export {
useBlockTransactionCount,
} from '../hooks/useBlockTransactionCount.js'

export {
type UseBytecodeParameters,
type UseBytecodeReturnType,
useBytecode,
} from '../hooks/useBytecode.js'

export {
type UseCallParameters,
type UseCallReturnType,
Expand Down Expand Up @@ -176,6 +182,12 @@ export {
useInfiniteReadContracts as useContractInfiniteReads,
} from '../hooks/useInfiniteReadContracts.js'

export {
type UseProofParameters,
type UseProofReturnType,
useProof,
} from '../hooks/useProof.js'

export {
type UsePublicClientParameters,
type UsePublicClientReturnType,
Expand Down Expand Up @@ -228,6 +240,12 @@ export {
useSimulateContract,
} from '../hooks/useSimulateContract.js'

export {
type UseStorageAtParameters,
type UseStorageAtReturnType,
useStorageAt,
} from '../hooks/useStorageAt.js'

export {
type UseSwitchAccountParameters,
type UseSwitchAccountReturnType,
Expand Down Expand Up @@ -259,6 +277,12 @@ export {
useTransactionCount,
} from '../hooks/useTransactionCount.js'

export {
type UseTransactionReceiptParameters,
type UseTransactionReceiptReturnType,
useTransactionReceipt,
} from '../hooks/useTransactionReceipt.js'

export {
type UseVerifyMessageParameters,
type UseVerifyMessageReturnType,
Expand Down
18 changes: 12 additions & 6 deletions packages/vue/src/hooks/useAccount.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use client'

import {
type Config,
type GetAccountReturnType,
type ResolvedRegister,
getAccount,
watchAccount,
} from '@wagmi/core'
Expand All @@ -17,14 +19,18 @@ import type { ConfigParameter, MaybeRefDeep } from '../types.js'
import { updateState } from '../utils/updateState.js'
import { useConfig } from './useConfig.js'

export type UseAccountParameters = MaybeRefDeep<ConfigParameter>
export type UseAccountParameters<config extends Config = Config> = MaybeRefDeep<
ConfigParameter<config>
>

export type UseAccountReturnType = ToRefs<DeepReadonly<GetAccountReturnType>>
export type UseAccountReturnType<config extends Config = Config> = ToRefs<
DeepReadonly<GetAccountReturnType<config>>
>

/** https://wagmi.sh/react/api/hooks/useAccount */
export function useAccount(
parameters: UseAccountParameters = {},
): UseAccountReturnType {
export function useAccount<config extends Config = ResolvedRegister['config']>(
parameters: UseAccountParameters<config> = {},
): UseAccountReturnType<config> {
const config = useConfig(parameters)

const account = reactive(getAccount(config))
Expand All @@ -34,5 +40,5 @@ export function useAccount(
},
})

return toRefs(readonly(account))
return toRefs(readonly(account)) as UseAccountReturnType<config>
}
77 changes: 77 additions & 0 deletions packages/vue/src/hooks/useBytecode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use client'

import {
type Config,
type GetBytecodeErrorType,
type ResolvedRegister,
} from '@wagmi/core'
import type { Evaluate } from '@wagmi/core/internal'
import {
type GetBytecodeData,
type GetBytecodeOptions,
type GetBytecodeQueryKey,
getBytecodeQueryOptions,
} from '@wagmi/core/query'
import { type GetBytecodeQueryFnData } from '@wagmi/core/query'
import { computed } from 'vue-demi'
import {
type ConfigParameter,
type DeepUnwrapRef,
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 UseBytecodeParameters<
config extends Config = Config,
selectData = GetBytecodeData,
> = MaybeRefDeep<
Evaluate<
GetBytecodeOptions<config> &
ConfigParameter<config> &
QueryParameter<
GetBytecodeQueryFnData,
GetBytecodeErrorType,
selectData,
GetBytecodeQueryKey<config>
>
>
>

export type UseBytecodeReturnType<selectData = GetBytecodeData> =
UseQueryReturnType<selectData, GetBytecodeErrorType>

/** https://wagmi.sh/react/api/hooks/useBytecode */
export function useBytecode<
config extends Config = ResolvedRegister['config'],
selectData = GetBytecodeData,
>(
parameters: UseBytecodeParameters<config, selectData> = {},
): UseBytecodeReturnType<selectData> {
const config = useConfig(parameters)
const chainId = useChainId()

const queryOptions = computed(() => {
const _parameters = cloneDeepUnref<
DeepUnwrapRef<UseBytecodeParameters<config, selectData>>
>(parameters as any)

const { address, query = {} } = _parameters
const options = getBytecodeQueryOptions(config, {
..._parameters,
chainId: _parameters.chainId ?? chainId.value,
})
const enabled = Boolean(address && (query.enabled ?? true))

return {
...query,
...options,
enabled,
}
})

return useQuery(queryOptions as any) as UseBytecodeReturnType<selectData>
}
7 changes: 6 additions & 1 deletion packages/vue/src/hooks/useCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ export type UseCallParameters<
Evaluate<
CallOptions<config> &
ConfigParameter<config> &
QueryParameter<CallQueryFnData, CallErrorType, selectData, CallQueryKey>
QueryParameter<
CallQueryFnData,
CallErrorType,
selectData,
CallQueryKey<config>
>
>
>

Expand Down
82 changes: 82 additions & 0 deletions packages/vue/src/hooks/useProof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
'use client'

import {
type Config,
type GetProofErrorType,
type ResolvedRegister,
} from '@wagmi/core'
import type { Evaluate } from '@wagmi/core/internal'
import {
type GetProofData,
type GetProofOptions,
type GetProofQueryKey,
getProofQueryOptions,
} from '@wagmi/core/query'
import { type GetProofQueryFnData } from '@wagmi/core/query'

import { computed } from 'vue-demi'
import {
type ConfigParameter,
type DeepUnwrapRef,
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 UseProofParameters<
config extends Config = Config,
selectData = GetProofData,
> = MaybeRefDeep<
Evaluate<
GetProofOptions<config> &
ConfigParameter<config> &
QueryParameter<
GetProofQueryFnData,
GetProofErrorType,
selectData,
GetProofQueryKey<config>
>
>
>

export type UseProofReturnType<selectData = GetProofData> = UseQueryReturnType<
selectData,
GetProofErrorType
>

/** https://wagmi.sh/react/api/hooks/useProof */
export function useProof<
config extends Config = ResolvedRegister['config'],
selectData = GetProofData,
>(
parameters: UseProofParameters<config, selectData> = {},
): UseProofReturnType<selectData> {
const config = useConfig(parameters)
const chainId = useChainId()

const queryOptions = computed(() => {
const _parameters =
cloneDeepUnref<DeepUnwrapRef<UseProofParameters<config, selectData>>>(
parameters,
)

const { address, storageKeys, query = {} } = _parameters

const options = getProofQueryOptions(config, {
..._parameters,
chainId: _parameters.chainId ?? chainId.value,
})
const enabled = Boolean(address && storageKeys && (query.enabled ?? true))

return {
...query,
...options,
enabled,
}
})

return useQuery(queryOptions as any) as UseProofReturnType<selectData>
}
77 changes: 77 additions & 0 deletions packages/vue/src/hooks/useStorageAt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use client'

import {
type Config,
type GetStorageAtErrorType,
type ResolvedRegister,
} from '@wagmi/core'
import type { Evaluate } from '@wagmi/core/internal'
import {
type GetStorageAtData,
type GetStorageAtOptions,
type GetStorageAtQueryKey,
getStorageAtQueryOptions,
} from '@wagmi/core/query'
import { type GetStorageAtQueryFnData } from '@wagmi/core/query'
import { computed } from 'vue-demi'
import {
type ConfigParameter,
type DeepUnwrapRef,
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 UseStorageAtParameters<
config extends Config = Config,
selectData = GetStorageAtData,
> = MaybeRefDeep<
Evaluate<
GetStorageAtOptions<config> &
ConfigParameter<config> &
QueryParameter<
GetStorageAtQueryFnData,
GetStorageAtErrorType,
selectData,
GetStorageAtQueryKey<config>
>
>
>

export type UseStorageAtReturnType<selectData = GetStorageAtData> =
UseQueryReturnType<selectData, GetStorageAtErrorType>

/** https://wagmi.sh/react/api/hooks/useStorageAt */
export function useStorageAt<
config extends Config = ResolvedRegister['config'],
selectData = GetStorageAtData,
>(
parameters: UseStorageAtParameters<config, selectData> = {},
): UseStorageAtReturnType<selectData> {
const config = useConfig(parameters)
const chainId = useChainId()

const queryOptions = computed(() => {
const _parameters = cloneDeepUnref<
DeepUnwrapRef<UseStorageAtParameters<config, selectData>>
>(parameters as any)

const { address, slot, query = {} } = _parameters
const options = getStorageAtQueryOptions(config, {
..._parameters,
chainId: _parameters.chainId ?? chainId.value,
})
const enabled = Boolean(address && slot && (query.enabled ?? true))

return {
...query,
...options,
enabled,
}
})

return useQuery(queryOptions as any) as UseStorageAtReturnType<selectData>
}
Loading

0 comments on commit a45cae7

Please sign in to comment.