Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F2859021
D6429.id21497.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6429.id21497.diff
View Options
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
@@ -68,27 +68,28 @@
return cacheResult;
}
- const cacheAndReturnResult = (result: ?string) => {
- this.nameQueryCache.set(normalizedETHAddress, {
- normalizedETHAddress,
- cacheInsertionTime: Date.now(),
- normalizedENSName: result,
- });
- return result;
- };
-
- // ethers.js handles checking forward resolution (point 1 above) for us
- const ensName = await this.provider.lookupAddress(normalizedETHAddress);
- if (!ensName) {
- return cacheAndReturnResult(undefined);
- }
-
- const normalizedENSName = normalizeENSName(ensName);
- if (normalizedENSName !== ensName) {
- return cacheAndReturnResult(undefined);
- }
-
- return cacheAndReturnResult(normalizedENSName);
+ const fetchENSNamePromise = (async () => {
+ // ethers.js handles checking forward resolution (point 1 above) for us
+ const ensName = await this.provider.lookupAddress(normalizedETHAddress);
+ if (!ensName) {
+ return undefined;
+ }
+
+ const normalizedENSName = normalizeENSName(ensName);
+ if (normalizedENSName !== ensName) {
+ return undefined;
+ }
+
+ return normalizedENSName;
+ })();
+
+ const normalizedENSName = await fetchENSNamePromise;
+ this.nameQueryCache.set(normalizedETHAddress, {
+ normalizedETHAddress,
+ cacheInsertionTime: Date.now(),
+ normalizedENSName,
+ });
+ return normalizedENSName;
}
getCachedNameForAddress(ethAddress: string): ?string {
@@ -119,20 +120,21 @@
return cacheResult;
}
- const cacheAndReturnResult = (result: ?string) => {
- this.addressQueryCache.set(normalizedENSName, {
- normalizedENSName,
- cacheInsertionTime: Date.now(),
- normalizedETHAddress: result,
- });
- return result;
- };
-
- const ethAddress = await this.provider.resolveName(normalizedENSName);
- if (!ethAddress) {
- return cacheAndReturnResult(undefined);
- }
- return cacheAndReturnResult(normalizeETHAddress(ethAddress));
+ const fetchETHAddressPromise = (async () => {
+ const ethAddress = await this.provider.resolveName(normalizedENSName);
+ if (!ethAddress) {
+ return undefined;
+ }
+ return normalizeETHAddress(ethAddress);
+ })();
+
+ const normalizedETHAddress = await fetchETHAddressPromise;
+ this.addressQueryCache.set(normalizedENSName, {
+ normalizedENSName,
+ cacheInsertionTime: Date.now(),
+ normalizedETHAddress,
+ });
+ return normalizedETHAddress;
}
getCachedAddressForName(ensName: string): ?string {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Oct 2, 12:17 PM (20 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2217601
Default Alt Text
D6429.id21497.diff (2 KB)
Attached To
Mode
D6429: [lib] Refactor ENSCache lambdas a little bit
Attached
Detach File
Event Timeline
Log In to Comment