Skip to content

Commit 657eb7f

Browse files
committed
feat(user-name): introduce UserName component for displaying user information
1 parent 28f3b10 commit 657eb7f

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

components/hypercert/contributors.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import { getAddress, isAddress } from "viem";
1515
import { HypercertState } from "@/hypercerts/fragments/hypercert-state.fragment";
1616
import { useGetUser } from "@/users/hooks";
1717
import { UserIcon } from "../user-icon";
18-
import EnsName from "../ens-name";
1918
import { ImageIcon } from "../user-icon/ImageIcon";
2019
import { SvgIcon } from "../user-icon/SvgIcon";
2120
import { Skeleton } from "../ui/skeleton";
21+
import { UserName } from "../user-name";
2222
const MAX_CONTRIBUTORS_DISPLAYED = 10;
2323

2424
function Contributor({ contributor }: { contributor: string }) {
@@ -47,16 +47,17 @@ function Contributor({ contributor }: { contributor: string }) {
4747
<SvgIcon size="tiny" />
4848
)}
4949
<div className="flex flex-col justify-center items-start">
50-
<p>{userData.user.display_name}</p>
51-
<EthAddress address={userData.user.address} />
50+
<UserName
51+
address={userData.user.address}
52+
userName={userData.user.display_name}
53+
/>
5254
</div>
5355
</div>
5456
) : address ? (
5557
<div className="flex gap-2">
5658
<UserIcon address={address} size="tiny" />
5759
<div className="flex flex-col justify-center items-start">
58-
<EnsName address={address} />
59-
<EthAddress address={address} />
60+
<EthAddress address={address} showEnsName={true} />
6061
</div>
6162
</div>
6263
) : (

components/user-name.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from "react";
2+
import { CopyButton } from "./copy-button";
3+
4+
export function UserName({
5+
address,
6+
userName,
7+
}: {
8+
address: string | undefined | null;
9+
userName: string | undefined | null;
10+
}) {
11+
const copyAddress = (event: React.MouseEvent<HTMLDivElement>) => {
12+
event.stopPropagation();
13+
void navigator.clipboard.writeText(address as string);
14+
};
15+
16+
if (!address) {
17+
return <div>Unknown</div>;
18+
}
19+
return (
20+
<div className="flex items-center gap-2 content-center cursor-pointer px-1 py-0.5 bg-slate-100 rounded-md w-max text-sm">
21+
<div onClick={copyAddress}>
22+
<p>{userName}</p>
23+
</div>
24+
<CopyButton
25+
textToCopy={address}
26+
className="w-4 h-4 bg-transparent focus:opacity-70 focus:scale-90"
27+
/>
28+
</div>
29+
);
30+
}

0 commit comments

Comments
 (0)