Skip to content

Commit

Permalink
Merge branch 'dev' into dj/w3-up
Browse files Browse the repository at this point in the history
  • Loading branch information
daria-github authored Jan 9, 2024
2 parents 9cdda6b + abc8cae commit 0ec7f0a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ export const AddressInput = ({
subtextColor,
)}
data-testid="message-to-subtext">
{resolvedAddress?.walletAddress
? resolvedAddress?.walletAddress
: subtext
{subtext
? t(subtext)
: resolvedAddress?.walletAddress
? resolvedAddress?.walletAddress
: ""}
</div>
</div>
Expand Down
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

0 comments on commit 0ec7f0a

Please sign in to comment.