Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev --> Main #409

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 47 additions & 24 deletions src/hooks/useAddressInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
throttledFetchEnsAvatar,
throttledFetchEnsName,
throttledFetchUnsAddress,
throttledFetchUnsName,
} from "../helpers";
import { useXmtpStore } from "../store/xmtp";

Expand Down Expand Up @@ -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");
}
Expand All @@ -92,6 +111,8 @@ export const useAddressInput = () => {
if (address) {
setRecipientAddress(address);
setRecipientName(recipientInput);
} else {
setRecipientState("invalid");
}
} else if (isEnsName(recipientInput)) {
setRecipientState("loading");
Expand All @@ -102,6 +123,8 @@ export const useAddressInput = () => {
if (address) {
setRecipientAddress(address);
setRecipientName(recipientInput);
} else {
setRecipientState("invalid");
}
}
} catch {
Expand Down
Loading