Skip to content

Commit

Permalink
Merge branch 'james/acx-1624-update-rewards-page' into james/acx-1625…
Browse files Browse the repository at this point in the history
…-update-referrals-page
  • Loading branch information
james-a-morris committed Nov 20, 2023
2 parents 8c8bd08 + ed5e118 commit 27a4efc
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/hooks/useReferrer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, useEffect } from "react";
import { ethers } from "ethers";
import { useQueryParams } from "./useQueryParams";
import { useConnection } from "hooks";
import { isDefined } from "utils";

export default function useReferrer() {
const { provider } = useConnection();
Expand All @@ -15,32 +16,32 @@ export default function useReferrer() {
const [error, setError] = useState<string>("");
useEffect(() => {
setError("");
if (provider && r) {
if (isDefined(r)) {
if (ethers.utils.isAddress(r)) {
setIsResolved(true);
return setAddress(r);
} else if (isDefined(provider)) {
provider
.resolveName(r)
.then((ra) => {
setAddress(ra || "");
setIsResolved(true);
if (!ra) {
setError("Invalid referral ENS name");
}
})
.catch((e) => {
// Error here would imply an issue with the provider call, not with the ENS name necessarily.
console.warn("error resolving name", e);
setAddress("");
if (!ethers.utils.isAddress(r)) {
setError("Invalid referral address");
}
})
.finally(() => {
setIsResolved(true);
});
}

provider
.resolveName(r)
.then((ra) => {
setAddress(ra || "");
setIsResolved(true);
if (!ra) {
setError("Invalid referral ENS name");
}
})
.catch((e) => {
// Error here would imply an issue with the provider call, not with the ENS name necessarily.
console.warn("error resolving name", e);
setAddress("");
if (!ethers.utils.isAddress(r)) {
setError("Invalid referral address");
}
})
.finally(() => {
setIsResolved(true);
});
} else {
setIsResolved(true);
}
Expand Down

0 comments on commit 27a4efc

Please sign in to comment.