Page MenuHomePhabricator

D6372.diff
No OneTemporary

D6372.diff

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<ENSCacheContextType> = React.createContext<ENSCacheContextType>(
+ {
+ 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 (
+ <ENSCacheContext.Provider value={context}>
+ {children}
+ </ENSCacheContext.Provider>
+ );
+}
+
+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<?string>,
+resolveName: (name: string) => Promise<?string>,
...

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 1:18 PM (20 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2677485
Default Alt Text
D6372.diff (1 KB)

Event Timeline