Page MenuHomePhabricator

D6429.id21510.diff
No OneTemporary

D6429.id21510.diff

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

Mime Type
text/plain
Expires
Wed, Oct 2, 12:16 PM (20 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2217601
Default Alt Text
D6429.id21510.diff (2 KB)

Event Timeline