UNPKG

@wagmi/vue

Version:

Vue Composables for Ethereum

38 lines (30 loc) 1.1 kB
import { type Config, type GetAccountReturnType, getAccount, type ResolvedRegister, watchAccount, } from '@wagmi/core' import { onScopeDispose, reactive, readonly, type ToRefs, toRefs } from 'vue' import type { ConfigParameter } from '../types/properties.js' import { updateState } from '../utils/updateState.js' import { useConfig } from './useConfig.js' export type UseAccountParameters<config extends Config = Config> = ConfigParameter<config> export type UseAccountReturnType<config extends Config = Config> = ToRefs< GetAccountReturnType<config> > /** https://wagmi.sh/vue/api/composables/useAccount */ export function useAccount<config extends Config = ResolvedRegister['config']>( parameters: UseAccountParameters<config> = {}, ): UseAccountReturnType<config> { const config = useConfig(parameters) const account = reactive(getAccount(config)) const unsubscribe = watchAccount(config, { onChange(data) { updateState(account, data) }, }) onScopeDispose(() => unsubscribe()) return toRefs(readonly(account)) as UseAccountReturnType<config> }