Skip to content

Commit

Permalink
fix(contributor): added copyAddress component picsoritdidnthappen#353
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieltemtsen committed Nov 24, 2024
1 parent b0870c3 commit bf5c1f9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 30 deletions.
52 changes: 22 additions & 30 deletions src/components/DisplayAddress.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { useState } from 'react';
import { useQuery } from '@tanstack/react-query';
import { getDegenOrEnsName } from '@/utils/web3';
import Link from 'next/link';
import { Chain } from '@/utils/types';
import { toast } from 'react-toastify';
import { CopyDoneIcon, CopyIcon } from '@/components/global/Icons';
import CopyAddressIcon from '@/components/global/CopyAddressIcon';

export default function DisplayAddress({
chain,
address,
showCopyIcon,
}: {
chain: Chain;
address: string;
showCopyIcon?: boolean;
}) {
const [isCopied, setCopied] = useState(false);

const walletDisplayName = useQuery({
queryKey: ['getWalletDisplayName', address, chain.slug],
queryFn: () =>
Expand All @@ -23,33 +21,27 @@ 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 (
<div className='flex items-center lg:w-[29ch] w-[15ch]'>
<Link
href={`/${chain.slug}/account/${address}`}
className=' hover:text-gray-200 max-w-[29ch]'
>
{walletDisplayName.data ?? address}
</Link>
<span
onClick={() => {
setCopied(true);
navigator.clipboard.writeText(address);
toast.success('Address copied to clipboard');
setTimeout(() => {
setCopied(false);
}, 1000);
}}
className='ml-2 cursor-pointer hover:text-gray-200'
>
{isCopied ? (
<CopyDoneIcon width={20} height={20} />
) : (
<CopyIcon width={20} height={20} />
)}
</span>
</div>
<Link
href={`/${chain.slug}/account/${address}`}
className='overflow-hidden lg:w-[25ch] w-[15ch] overflow-ellipsis hover:text-gray-200'
>
{walletDisplayName.data ?? address}
</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;

0 comments on commit bf5c1f9

Please sign in to comment.