diff --git a/src/providers/EthooksProvider.tsx b/src/providers/EthooksProvider.tsx index 8bff838..2fa8c84 100644 --- a/src/providers/EthooksProvider.tsx +++ b/src/providers/EthooksProvider.tsx @@ -4,7 +4,7 @@ import {EthersContext, RootContextProvider, BlockNumberProvider} from '../contex import {useAccountChange} from '../hooks'; import {useMount} from '../hooks/internal'; import useConnect from '../hooks/useConnect'; -import {Chain, EthersProvider} from '../types'; +import {Chain, EthersProvider, Window} from '../types'; export interface EthooksProviderProps extends Partial> { @@ -65,7 +65,8 @@ export const EthooksProvider: React.FC = ({ } const defaultProvider = useMemo(() => { - if ('ethereum' in window) return new providers.Web3Provider(window.ethereum, 'any'); + if ('ethereum' in window) return new providers.Web3Provider((window as Window).ethereum, 'any'); + return null; }, []); diff --git a/src/types.ts b/src/types.ts index 67dfc17..9bd9547 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,10 +1,9 @@ import type {BigNumberish, providers} from 'ethers'; -declare global { - interface Window { +export type Window = globalThis.Window & + typeof globalThis & { ethereum: import('ethers').providers.ExternalProvider; - } -} + }; export type LooseAutoComplete = T | Omit;