Skip to content

Commit

Permalink
Prevent caching addresses without ens or uns data
Browse files Browse the repository at this point in the history
  • Loading branch information
xpaczka committed Oct 24, 2023
1 parent f2c3145 commit 1047c4b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/shared/utils/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const getCachedNames = () => {
const addCachedName = ({ name, avatar, address, type }: NameWithProvider) => {
const cachedNames = getCachedNames()
const normalizedAddress = normalizeAddress(address)
const newCachedData = name ? { [type]: { name, avatar } } : {}
const newData = name ? { [type]: { name, avatar } } : {}

const newCache = JSON.stringify({
...cachedNames,
[normalizedAddress]: {
...(cachedNames[normalizedAddress] ?? {}),
...newCachedData,
...newData,
lastUpdate: Date.now(),
},
})
Expand All @@ -45,10 +45,7 @@ const addCachedName = ({ name, avatar, address, type }: NameWithProvider) => {

const resolveENSPromise = (address: string) =>
resolveAddressToENS(address).then((data): WalletData | null => {
if (!data) {
addCachedName({ type: "ens", address })
return null
}
if (!data) return null

addCachedName({ type: "ens", address, ...data })
return data
Expand Down

0 comments on commit 1047c4b

Please sign in to comment.