import { type Config, type GetChainIdReturnType, getChainId, type ResolvedRegister, watchChainId, } from '@wagmi/core' import type { ConfigParameter } from '@wagmi/core/internal' import { onScopeDispose, type Ref, readonly, ref } from 'vue' import { useConfig } from './useConfig.js' export type UseChainIdParameters = ConfigParameter export type UseChainIdReturnType = Ref< GetChainIdReturnType > /** https://wagmi.sh/vue/api/composables/useChainId */ export function useChainId( parameters: UseChainIdParameters = {}, ): UseChainIdReturnType { const config = useConfig(parameters) const chainId = ref(getChainId(config)) const unsubscribe = watchChainId(config, { onChange(data) { chainId.value = data }, }) onScopeDispose(() => unsubscribe()) return readonly(chainId) }