import { type Config, type GetChainsReturnType, getChains, type ResolvedRegister, } from '@wagmi/core' import type { ConfigParameter } from '@wagmi/core/internal' import { watchChains } from '@wagmi/core/internal' import { onScopeDispose, type Ref, readonly, ref } from 'vue' import { useConfig } from './useConfig.js' export type UseChainsParameters = ConfigParameter export type UseChainsReturnType = Ref< GetChainsReturnType > /** https://wagmi.sh/vue/api/composables/useChains */ export function useChains( parameters: UseChainsParameters = {}, ): UseChainsReturnType { const config = useConfig(parameters) const chains = ref>(getChains(config)) const unsubscribe = watchChains(config, { onChange(data) { chains.value = data as any }, }) onScopeDispose(() => unsubscribe()) return readonly(chains) as UseChainsReturnType }