Page MenuHomePhabricator

D6430.id21511.diff
No OneTemporary

D6430.id21511.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
@@ -14,12 +14,12 @@
+normalizedETHAddress: string,
+cacheInsertionTime: number,
// We normalize ENS names using eth-ens-namehash
- +normalizedENSName: ?string,
+ +normalizedENSName: ?string | Promise<?string>,
};
type ENSAddressQueryCacheEntry = {
+normalizedENSName: string,
+cacheInsertionTime: number,
- +normalizedETHAddress: ?string,
+ +normalizedETHAddress: ?string | Promise<?string>,
};
const normalizeETHAddress = (ethAddress: string) => ethAddress.toLowerCase();
@@ -92,7 +92,7 @@
return normalizedENSName;
}
- getCachedNameForAddress(ethAddress: string): ?string {
+ getCachedEntryForAddress(ethAddress: string): ?ENSNameQueryCacheEntry {
const normalizedETHAddress = normalizeETHAddress(ethAddress);
const cacheResult = this.nameQueryCache.get(normalizedETHAddress);
@@ -100,12 +100,26 @@
return undefined;
}
- const { cacheInsertionTime, normalizedENSName } = cacheResult;
+ const { cacheInsertionTime } = cacheResult;
if (cacheInsertionTime + cacheTimeout <= Date.now()) {
this.nameQueryCache.delete(normalizedETHAddress);
return undefined;
}
+ return cacheResult;
+ }
+
+ getCachedNameForAddress(ethAddress: string): ?string {
+ const cacheResult = this.getCachedEntryForAddress(ethAddress);
+ if (!cacheResult) {
+ return undefined;
+ }
+
+ const { normalizedENSName } = cacheResult;
+ if (typeof normalizedENSName !== 'string') {
+ return undefined;
+ }
+
return normalizedENSName;
}
@@ -137,7 +151,7 @@
return normalizedETHAddress;
}
- getCachedAddressForName(ensName: string): ?string {
+ getCachedEntryForName(ensName: string): ?ENSAddressQueryCacheEntry {
const normalizedENSName = normalizeENSName(ensName);
if (normalizedENSName !== ensName) {
return undefined;
@@ -148,12 +162,26 @@
return undefined;
}
- const { cacheInsertionTime, normalizedETHAddress } = cacheResult;
+ const { cacheInsertionTime } = cacheResult;
if (cacheInsertionTime + cacheTimeout <= Date.now()) {
this.addressQueryCache.delete(normalizedENSName);
return undefined;
}
+ return cacheResult;
+ }
+
+ getCachedAddressForName(ensName: string): ?string {
+ const cacheResult = this.getCachedEntryForName(ensName);
+ if (!cacheResult) {
+ return undefined;
+ }
+
+ const { normalizedETHAddress } = cacheResult;
+ if (typeof normalizedETHAddress !== 'string') {
+ return undefined;
+ }
+
return normalizedETHAddress;
}
}

File Metadata

Mime Type
text/plain
Expires
Wed, Oct 2, 10:39 AM (19 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2216354
Default Alt Text
D6430.id21511.diff (2 KB)

Event Timeline