diff --git a/src/hooks/useAddressInput.ts b/src/hooks/useAddressInput.ts index 3e71ec34..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"; @@ -39,33 +40,51 @@ 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 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); } - // 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"); } @@ -92,6 +111,8 @@ export const useAddressInput = () => { if (address) { setRecipientAddress(address); setRecipientName(recipientInput); + } else { + setRecipientState("invalid"); } } else if (isEnsName(recipientInput)) { setRecipientState("loading"); @@ -102,6 +123,8 @@ export const useAddressInput = () => { if (address) { setRecipientAddress(address); setRecipientName(recipientInput); + } else { + setRecipientState("invalid"); } } } catch {