Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3489652
D6372.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D6372.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D6372: [lib] Introduce ENSCacheProvider
Attached
Detach File
Event Timeline
Log In to Comment