From 8d0b8e32a4eb7a4d1fb3858f32c35472a1880f61 Mon Sep 17 00:00:00 2001 From: Noah Zinsmeister Date: Mon, 29 Jul 2019 18:34:15 -0400 Subject: [PATCH] fix ens name typing bug (#378) * fix ens typing error handling --- src/components/AddressInputPanel/index.js | 24 +++++++++++------------ src/hooks/index.js | 15 +++++++------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/components/AddressInputPanel/index.js b/src/components/AddressInputPanel/index.js index 85016d308c..f1561638da 100644 --- a/src/components/AddressInputPanel/index.js +++ b/src/components/AddressInputPanel/index.js @@ -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) + } } } diff --git a/src/hooks/index.js b/src/hooks/index.js index 7ba2fb6a21..06f6c42e82 100644 --- a/src/hooks/index.js +++ b/src/hooks/index.js @@ -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