'use client' import { type Config, type GetChainIdReturnType, type ResolvedRegister, getChainId, watchChainId, } from '@wagmi/core' import { type ComputedRef, computed, ref } from 'vue-demi' import type { ConfigParameter, MaybeRefDeep } from '../types.js' import { useConfig } from './useConfig.js' export type UseChainIdParameters = MaybeRefDeep> export type UseChainIdReturnType = ComputedRef< GetChainIdReturnType > /** https://wagmi.sh/react/api/hooks/useChainId */ export function useChainId( parameters: UseChainIdParameters = {}, ): UseChainIdReturnType { const config = useConfig(parameters) const chainId = ref(getChainId(config as ResolvedRegister['config'])) watchChainId(config, { onChange() { chainId.value = getChainId(config) }, }) return computed>(() => chainId.value) }