Skip to content

Commit

Permalink
Showing username on ProfileAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
luloxi committed Sep 29, 2024
1 parent 812a9b8 commit 1251cbc
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/nextjs/app/explore/_components/ProfileAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { hardhat } from "viem/chains";
import { normalize } from "viem/ens";
import { useEnsAvatar, useEnsName } from "wagmi";
import { BlockieAvatar } from "~~/components/scaffold-eth";
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";

type AddressProps = {
Expand All @@ -30,12 +31,19 @@ const blockieSizeMap = {
* Displays an address (or ENS) with a Blockie image and option to copy address.
*/
export const ProfileAddress = ({ address, disableAddressLink, format, size = "base" }: AddressProps) => {
const [ens, setEns] = useState<string | null>();
// const [ens, setEns] = useState<string | null>();
const [ensAvatar, setEnsAvatar] = useState<string | null>();
const checkSumAddress = address ? getAddress(address) : undefined;

const { targetNetwork } = useTargetNetwork();

const { data: profileInfo } = useScaffoldReadContract({
contractName: "ProfileInfo",
functionName: "profiles",
args: [address],
watch: true,
});

const { data: fetchedEns } = useEnsName({
address: checkSumAddress,
chainId: 1,
Expand All @@ -53,9 +61,9 @@ export const ProfileAddress = ({ address, disableAddressLink, format, size = "ba
});

// We need to apply this pattern to avoid Hydration errors.
useEffect(() => {
setEns(fetchedEns);
}, [fetchedEns]);
// useEffect(() => {
// setEns(fetchedEns);
// }, [fetchedEns]);

useEffect(() => {
setEnsAvatar(fetchedEnsAvatar);
Expand All @@ -79,8 +87,12 @@ export const ProfileAddress = ({ address, disableAddressLink, format, size = "ba

let displayAddress = checkSumAddress?.slice(0, 6) + "..." + checkSumAddress?.slice(-4);

if (ens) {
displayAddress = ens;
// else if (ens) {
// displayAddress = ens;
// }

if (profileInfo && profileInfo[0] !== "") {
displayAddress = profileInfo[0];
} else if (format === "long") {
displayAddress = checkSumAddress;
}
Expand Down

0 comments on commit 1251cbc

Please sign in to comment.