Skip to content

Commit

Permalink
fix: resolves #2294 (#2301)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom authored May 23, 2024
1 parent 601cb74 commit 36c55da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-news-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed `isAddress` cache.
5 changes: 3 additions & 2 deletions src/utils/address/isAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ export function isAddress(
options?: IsAddressOptions | undefined,
): address is Address {
const { strict = true } = options ?? {}
const cacheKey = `${address}.${strict}`

if (isAddressCache.has(address)) return isAddressCache.get(address)!
if (isAddressCache.has(cacheKey)) return isAddressCache.get(cacheKey)!

const result = (() => {
if (!addressRegex.test(address)) return false
if (address.toLowerCase() === address) return true
if (strict) return checksumAddress(address as Address) === address
return true
})()
isAddressCache.set(address, result)
isAddressCache.set(cacheKey, result)
return result
}

0 comments on commit 36c55da

Please sign in to comment.