From 21ad7534a10c0c238e23262bb681a85bc006a724 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Tue, 21 Nov 2023 16:28:07 -0600 Subject: [PATCH 1/3] Set `invalid` state when name lookups fail --- src/hooks/useAddressInput.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hooks/useAddressInput.ts b/src/hooks/useAddressInput.ts index 3e71ec34..b0eb3082 100644 --- a/src/hooks/useAddressInput.ts +++ b/src/hooks/useAddressInput.ts @@ -92,6 +92,8 @@ export const useAddressInput = () => { if (address) { setRecipientAddress(address); setRecipientName(recipientInput); + } else { + setRecipientState("invalid"); } } else if (isEnsName(recipientInput)) { setRecipientState("loading"); @@ -102,6 +104,8 @@ export const useAddressInput = () => { if (address) { setRecipientAddress(address); setRecipientName(recipientInput); + } else { + setRecipientState("invalid"); } } } catch { From 4296b468b64c04b8cc41ef9fe985dca5929b5c17 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Tue, 21 Nov 2023 16:59:07 -0600 Subject: [PATCH 2/3] Add try/catch blocks to some calls --- src/hooks/useAddressInput.ts | 60 +++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/src/hooks/useAddressInput.ts b/src/hooks/useAddressInput.ts index b0eb3082..120f85c0 100644 --- a/src/hooks/useAddressInput.ts +++ b/src/hooks/useAddressInput.ts @@ -39,33 +39,45 @@ export const useAddressInput = () => { const fetchAddressIdentity = async () => { // must have a valid recipient address if (recipientAddress) { - // no name - if (!recipientName) { - setRecipientState("loading"); - // check for name - const name = await throttledFetchEnsName({ - address: recipientAddress, - }); - setRecipientName(name); + try { + // no name + if (!recipientName) { + setRecipientState("loading"); + // check for name + const name = await throttledFetchEnsName({ + address: recipientAddress, + }); + setRecipientName(name); + } + } catch (e) { + console.error(e); } - // no avatar - if (!recipientAvatar && recipientName) { - setRecipientState("loading"); - // check for avatar - const avatar = await throttledFetchEnsAvatar({ - name: recipientName, - }); - setRecipientAvatar(avatar); + try { + // no avatar + if (!recipientAvatar && recipientName) { + setRecipientState("loading"); + // check for avatar + const avatar = await throttledFetchEnsAvatar({ + name: recipientName, + }); + setRecipientAvatar(avatar); + } + } catch (e) { + console.error(e); } - // make sure we can message the recipient - if (!recipientOnNetwork) { - setRecipientState("loading"); - const validRecipient = await canMessage(recipientAddress); - if (validRecipient) { - setRecipientOnNetwork(true); - } else { - setRecipientOnNetwork(false); + try { + // make sure we can message the recipient + if (!recipientOnNetwork) { + setRecipientState("loading"); + const validRecipient = await canMessage(recipientAddress); + if (validRecipient) { + setRecipientOnNetwork(true); + } else { + setRecipientOnNetwork(false); + } } + } catch (e) { + console.error(e); } setRecipientState("valid"); } From 7e2103b7ee10cba8c9e5258bb96cbff098cd824c Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Tue, 21 Nov 2023 17:26:29 -0600 Subject: [PATCH 3/3] Look for UNS name before ENS --- src/hooks/useAddressInput.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hooks/useAddressInput.ts b/src/hooks/useAddressInput.ts index 120f85c0..ca3fdf9c 100644 --- a/src/hooks/useAddressInput.ts +++ b/src/hooks/useAddressInput.ts @@ -9,6 +9,7 @@ import { throttledFetchEnsAvatar, throttledFetchEnsName, throttledFetchUnsAddress, + throttledFetchUnsName, } from "../helpers"; import { useXmtpStore } from "../store/xmtp"; @@ -43,11 +44,17 @@ export const useAddressInput = () => { // no name if (!recipientName) { setRecipientState("loading"); - // check for name - const name = await throttledFetchEnsName({ - address: recipientAddress, - }); - setRecipientName(name); + // check for UNS name + const unsName = await throttledFetchUnsName(recipientAddress); + if (unsName) { + setRecipientName(unsName); + } else { + // check for ENS name + const ensName = await throttledFetchEnsName({ + address: recipientAddress, + }); + setRecipientName(ensName); + } } } catch (e) { console.error(e);