fix ens name typing bug (#378)

* fix ens typing error handling
This commit is contained in:
Noah Zinsmeister 2019-07-29 18:34:15 -04:00 committed by GitHub
parent 66604cf47e
commit 8d0b8e32a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 21 deletions

@ -93,9 +93,8 @@ export default function AddressInputPanel({ title, initialInput = '', onChange =
let stale = false
if (isAddress(debouncedInput)) {
library
.lookupAddress(debouncedInput)
.then(name => {
try {
library.lookupAddress(debouncedInput).then(name => {
if (!stale) {
// if an ENS name exists, set it as the destination
if (name) {
@ -106,15 +105,14 @@ export default function AddressInputPanel({ title, initialInput = '', onChange =
}
}
})
.catch(() => {
setData({ address: debouncedInput, name: '' })
setError(null)
})
} catch {
setData({ address: debouncedInput, name: '' })
setError(null)
}
} else {
if (debouncedInput !== '') {
library
.resolveName(debouncedInput)
.then(address => {
try {
library.resolveName(debouncedInput).then(address => {
if (!stale) {
// if the debounced input name resolves to an address
if (address) {
@ -125,9 +123,9 @@ export default function AddressInputPanel({ title, initialInput = '', onChange =
}
}
})
.catch(() => {
setError(true)
})
} catch {
setError(true)
}
}
}

@ -58,9 +58,8 @@ export function useENSName(address) {
useEffect(() => {
if (isAddress(address)) {
let stale = false
library
.lookupAddress(address)
.then(name => {
try {
library.lookupAddress(address).then(name => {
if (!stale) {
if (name) {
setENSNname(name)
@ -69,11 +68,11 @@ export function useENSName(address) {
}
}
})
.catch(() => {
if (!stale) {
setENSNname(null)
}
})
} catch {
if (!stale) {
setENSNname(null)
}
}
return () => {
stale = true