import type { Config } from '../createConfig.js' import { type GetClientReturnType, getClient } from './getClient.js' export type WatchClientParameters< config extends Config = Config, chainId extends config['chains'][number]['id'] = config['chains'][number]['id'], > = { onChange( publicClient: GetClientReturnType, prevClient: GetClientReturnType, ): void } export type WatchClientReturnType = () => void /** https://wagmi.sh/core/api/actions/watchClient */ export function watchClient< config extends Config, chainId extends config['chains'][number]['id'], >( config: config, parameters: WatchClientParameters, ): WatchClientReturnType { const { onChange } = parameters return config.subscribe( () => getClient(config) as GetClientReturnType, onChange, { equalityFn(a, b) { return a?.uid === b?.uid }, }, ) }