UNPKG

@mojito-inc/connect-wallet

Version:

Connecting wallet via metamask, wallet connect, email

31 lines (28 loc) 1.02 kB
import * as React from 'react'; import { createContext, useContext, useState, useEffect, useMemo } from 'react'; import { getActiveChainId } from '../utils/getChainId.utils.js'; const ThirdWebContext = createContext({}); const useThirdWebClient = () => { return useContext(ThirdWebContext); }; const ThirdWebClientProvider = ({ children, projectId, activeChain }) => { const [clientId, setClientId] = useState(''); const [chainId, setChainId] = useState(11155111); useEffect(() => { if (projectId) setClientId(projectId); }, [projectId]); useEffect(() => { if (activeChain) { setChainId(getActiveChainId(activeChain)); } }, [activeChain]); const value = useMemo(() => { return { clientId, chainId, }; }, [clientId, chainId]); return (React.createElement(ThirdWebContext.Provider, { value: value }, children)); }; export { ThirdWebClientProvider, useThirdWebClient };