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

Created a Reusable CopyAddress Component for ProfileCard and WalletButton #864

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
47 changes: 47 additions & 0 deletions components/UI/CopyAddress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useState } from 'react';
import CopyIcon from "@components/UI/iconsComponents/icons/copyIcon";
import VerifiedIcon from "@components/UI/iconsComponents/icons/verifiedIcon";
import Typography from "@components/UI/typography/typography";
import { TEXT_TYPE } from "@constants/typography";

interface CopyAddressProps {
address: string;
className?: string;
iconSize?: string;
wallet:boolean;
}

const CopyAddress: React.FC<CopyAddressProps> = ({ address, className, iconSize = "24",wallet=false }) => {
const [copied, setCopied] = useState(false);


const copyAddress = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
setCopied(true);
navigator.clipboard.writeText(address ?? "");
setTimeout(() => {
setCopied(false);
}, 1500);
};

return (
<button className={className} onClick={copyAddress}>
{!copied ? (
<CopyIcon width={iconSize} color={wallet ? undefined : "#F4FAFF"} />
) : (
<VerifiedIcon width={iconSize} />
)}
{wallet && (
<Typography
color="secondary500"
type={TEXT_TYPE.BUTTON_SMALL}
style={{ textTransform: 'none', }}
>
Copy Address
</Typography>
)}
</button>
);
};

export default CopyAddress;
26 changes: 7 additions & 19 deletions components/UI/profileCard/profileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import useCreationDate from "@hooks/useCreationDate";
import shareSrc from "public/icons/share.svg";
import theme from "@styles/theme";
import { Skeleton, Tooltip } from "@mui/material";
import VerifiedIcon from "../iconsComponents/icons/verifiedIcon";
import CopyAddress from "@components/UI/CopyAddress";
import ProfilIcon from "../iconsComponents/icons/profilIcon";
import Link from "next/link";
import SocialMediaActions from "../actions/socialmediaActions";
Expand All @@ -41,13 +41,6 @@ const ProfileCard: FunctionComponent<ProfileCard> = ({
const [userPercentile, setUserPercentile] = useState("");
const [userXp, setUserXp] = useState<number>();

const copyToClipboard = () => {
setCopied(true);
writeToClipboard(identity?.owner);
setTimeout(() => {
setCopied(false);
}, 1500);
};

const rankFormatter = useCallback((rank: number) => {
if (rank > 10000) return "+10k";
Expand Down Expand Up @@ -111,17 +104,12 @@ const ProfileCard: FunctionComponent<ProfileCard> = ({
</Typography>
<Typography type={TEXT_TYPE.H2} className={styles.profile_name}>{identity.domain.domain}</Typography>
<div className={styles.address_div}>
<div onClick={() => copyToClipboard()}>
{!copied ? (
<Tooltip title="Copy" arrow>
<div onClick={() => copyToClipboard()}>
<CopyIcon width="20" color="#F4FAFF" />
</div>
</Tooltip>
) : (
<VerifiedIcon width="20" />
)}
</div>
<CopyAddress
address={identity?.owner ?? ""}
iconSize="24"
className={styles.copyButton}
wallet={false}
/>
<Typography type={TEXT_TYPE.BODY_SMALL} className={styles.addressText} color="secondary">
{minifyAddress(addressOrDomain ?? identity?.owner, 8)}
</Typography>
Expand Down
26 changes: 9 additions & 17 deletions components/navbar/walletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import TrophyIcon from "@components/UI/iconsComponents/icons/trophyIcon";
import Typography from "@components/UI/typography/typography";
import { TEXT_TYPE } from "@constants/typography";
import { Connector } from "starknetkit";
import CopyAddress from "@components/UI/CopyAddress"; // Import the new CopyAddress component


type WalletButtonProps = {
setShowWallet: (showWallet: boolean) => void;
Expand Down Expand Up @@ -78,15 +80,6 @@ const WalletButton: FunctionComponent<WalletButtonProps> = ({
}
}, [notifications]);

const copyAddress = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
setCopied(true);
navigator.clipboard.writeText(address ?? "");
setTimeout(() => {
setCopied(false);
}, 1500);
};

const handleDisconnect = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
disconnectByClick();
Expand Down Expand Up @@ -156,14 +149,13 @@ const WalletButton: FunctionComponent<WalletButtonProps> = ({
<Typography type={TEXT_TYPE.BUTTON_SMALL} color="secondary500">Leaderboard</Typography>
</button>
</Link>
<button onClick={copyAddress}>
{copied ? (
<VerifiedIcon width="24" />
) : (
<CopyIcon width="24" />
)}
<Typography color="secondary500" type={TEXT_TYPE.BUTTON_SMALL}>Copy Address</Typography>
</button>
<div className="flex items-center">
<CopyAddress
address={address ?? ""}
iconSize="24"
className={styles.copyButton}
wallet={true}/>
</div>
{isWebWallet && (
<button onClick={handleOpenWebWallet}>
<ArgentIcon width="24" />
Expand Down