diff --git a/lib/components/ens-cache-provider.react.js b/lib/components/ens-cache-provider.react.js new file mode 100644 --- /dev/null +++ b/lib/components/ens-cache-provider.react.js @@ -0,0 +1,35 @@ +// @flow + +import * as React from 'react'; + +import { ENSCache, type EthersProvider } from '../utils/ens-cache'; + +type ENSCacheContextType = { + +ensCache: ?ENSCache, +}; +const ENSCacheContext: React.Context = React.createContext( + { + ensCache: undefined, + }, +); + +type Props = { + +provider: EthersProvider, + +children: React.Node, +}; +function ENSCacheProvider(props: Props): React.Node { + const { provider, children } = props; + const context = React.useMemo( + () => ({ + ensCache: new ENSCache(provider), + }), + [provider], + ); + return ( + + {children} + + ); +} + +export { ENSCacheContext, ENSCacheProvider }; diff --git a/lib/utils/ens-cache.js b/lib/utils/ens-cache.js --- a/lib/utils/ens-cache.js +++ b/lib/utils/ens-cache.js @@ -4,7 +4,7 @@ const cacheTimeout = 24 * 60 * 60 * 1000; // one day -type EthersProvider = { +export type EthersProvider = { +lookupAddress: (address: string) => Promise, +resolveName: (name: string) => Promise, ...