UNPKG

@safe-global/safe-react-hooks

Version:

A collection of React Hooks that facilitates the interaction of React apps with Safe Smart Accounts

23 lines 912 B
import { createConfig, useChains } from 'wagmi'; import { useConfig } from '../hooks/useConfig.js'; /** * Hook to get the configured chain depending on the config from the nearest `SafeProvider`. * @param params Parameters to customize the hook behavior. * @param params.config SafeConfig to use instead of the one provided by `SafeProvider`. * @returns Object describing the configured chain. */ export function useChain(params = {}) { const [config] = useConfig({ config: params.config }); const wagmiConfig = config.chain ? createConfig({ chains: [config.chain], transports: { [config.chain.id]: config.transport } }) : undefined; const chains = useChains({ config: wagmiConfig }); if (chains.length === 0) { throw new Error('No chain found for the given config.'); } return chains[0]; } //# sourceMappingURL=useChain.js.map