Skip to content

Commit

Permalink
Add try/catch blocks to some calls
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Nov 21, 2023
1 parent 21ad753 commit 4296b46
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions src/hooks/useAddressInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 4296b46

Please sign in to comment.