Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: added copyaddress component and conditional showCopyIcon #402

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/components/DisplayAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { useQuery } from '@tanstack/react-query';
import { getDegenOrEnsName } from '@/utils/web3';
import Link from 'next/link';
import { Chain } from '@/utils/types';
import CopyAddressIcon from '@/components/global/CopyAddressIcon';

export default function DisplayAddress({
chain,
address,
showCopyIcon,
}: {
chain: Chain;
address: string;
showCopyIcon?: boolean;
}) {
const walletDisplayName = useQuery({
queryKey: ['getWalletDisplayName', address, chain.slug],
Expand All @@ -18,6 +21,19 @@ export default function DisplayAddress({
chainName: chain.slug,
}),
});
if (showCopyIcon) {
return (
<div className='flex items-center lg:w-[29ch] w-[15ch]'>
<Link
href={`/${chain.slug}/account/${address}`}
className='hover:text-gray-200 max-w-[29ch] truncate mr-2'
>
{walletDisplayName.data ?? address}
</Link>
<CopyAddressIcon address={address} size={20} />
</div>
);
}

return (
<Link
Expand Down
1 change: 1 addition & 0 deletions src/components/bounty/BountyMultiplayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default function BountyMultiplayer({
<DisplayAddress
address={participant.user_address}
chain={chain}
showCopyIcon={true}
/>
&nbsp;
{`${formatEther(BigInt(participant.amount))} ${
Expand Down
36 changes: 36 additions & 0 deletions src/components/global/CopyAddressIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useState } from 'react';
import { toast } from 'react-toastify';
import { CopyDoneIcon, CopyIcon } from '@/components/global/Icons';

interface CopyAddressIconProps {
address: string;
size?: number;
}

const CopyAddressIcon: React.FC<CopyAddressIconProps> = ({
address,
size = 20,
}) => {
const [isCopied, setCopied] = useState(false);

const handleCopy = () => {
setCopied(true);
navigator.clipboard.writeText(address);
toast.success('Address copied to clipboard');
setTimeout(() => {
setCopied(false);
}, 1000);
};

return (
<span onClick={handleCopy} className='cursor-pointer hover:text-gray-200'>
{isCopied ? (
<CopyDoneIcon width={size} height={size} />
) : (
<CopyIcon width={size} height={size} />
)}
</span>
);
};

export default CopyAddressIcon;
Loading