From 706b4b3da81aead3523e444acc1142b37a1d9266 Mon Sep 17 00:00:00 2001 From: Jemiiah <160767568+Jemiiah@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:45:17 +0100 Subject: [PATCH] implemented privacy icon (#926) * implemented privacy icon * removed unused code * delete yern lock * remove unused code * set cursor-pointer --- .../UI/iconsComponents/icons/eyeIcon.tsx | 22 ++++++++++++++++++- components/UI/profileCard/profileCard.tsx | 18 +++++++++------ components/dashboard/PortfolioSummary.tsx | 9 +++++--- hooks/useHidePortfolio.ts | 10 +++++++++ 4 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 hooks/useHidePortfolio.ts diff --git a/components/UI/iconsComponents/icons/eyeIcon.tsx b/components/UI/iconsComponents/icons/eyeIcon.tsx index 89f82e32..dfcbd537 100644 --- a/components/UI/iconsComponents/icons/eyeIcon.tsx +++ b/components/UI/iconsComponents/icons/eyeIcon.tsx @@ -31,4 +31,24 @@ const EyeIcon: FunctionComponent = ({ ); }; -export default EyeIcon; +const EyeIconSlashed: FunctionComponent = ({ + color = "#E1DCEA", + width = 17, +}) => { + return ( + + + + ); +}; + +export { EyeIcon, EyeIconSlashed }; diff --git a/components/UI/profileCard/profileCard.tsx b/components/UI/profileCard/profileCard.tsx index ba5018ca..688dd90a 100644 --- a/components/UI/profileCard/profileCard.tsx +++ b/components/UI/profileCard/profileCard.tsx @@ -14,7 +14,7 @@ import xpIcon from "public/icons/xpBadge.svg"; import useCreationDate from "@hooks/useCreationDate"; import shareSrc from "public/icons/share.svg"; import theme from "@styles/theme"; -import EyeIcon from "../iconsComponents/icons/eyeIcon"; +import { EyeIcon, EyeIconSlashed } from "../iconsComponents/icons/eyeIcon"; import ProfilIcon from "../iconsComponents/icons/profilIcon"; import Link from "next/link"; import SocialMediaActions from "../actions/socialmediaActions"; @@ -23,6 +23,8 @@ import { hexToDecimal } from "@utils/feltService"; import { TEXT_TYPE } from "@constants/typography"; import Typography from "../typography/typography"; import { calculateTotalBalance } from "../../../services/argentPortfolioService"; +import { useHidePortfolio } from "@hooks/useHidePortfolio"; + const MAX_RETRIES = 1000; const RETRY_DELAY = 2000; const controller = new AbortController(); @@ -41,6 +43,7 @@ const ProfileCard: FunctionComponent = ({ leaderboardData, isOwner, }) => { + const { hidePortfolio, setHidePortfolio } = useHidePortfolio(); const [userXp, setUserXp] = useState(); const [totalBalance, setTotalBalance] = useState(null); const sinceDate = useCreationDate(identity); @@ -60,13 +63,13 @@ const ProfileCard: FunctionComponent = ({ let attempts = 0; while (true) { try { - const balance = await calculateTotalBalance(formattedAddress, "USD", {signal}); + const balance = await calculateTotalBalance(formattedAddress, "USD", { signal }); setTotalBalance(balance); return; // Exit if successful } catch (err) { attempts++; console.error(`Attempt ${attempts} - Error fetching total balance:`, err); - + if (attempts >= MAX_RETRIES) { console.error("Failed to fetch total balance after multiple attempts."); } else { @@ -102,8 +105,7 @@ const ProfileCard: FunctionComponent = ({ const tweetShareLink: string = useMemo(() => { return `${getTweetLink( - `Check out${isOwner ? " my " : " "}Starknet Quest Profile at ${ - window.location.href + `Check out${isOwner ? " my " : " "}Starknet Quest Profile at ${window.location.href } #Starknet #StarknetID` )}`; }, [isOwner]); @@ -140,12 +142,14 @@ const ProfileCard: FunctionComponent = ({ className={`${styles.wallet_amount} font-extrabold`} > {totalBalance !== null ? ( - `$${totalBalance.toFixed(2)}` + hidePortfolio ? "******" : `$${totalBalance.toFixed(2)}` ) : ( )} - +
setHidePortfolio(!hidePortfolio)} className="cursor-pointer"> + {hidePortfolio ? : } +
diff --git a/components/dashboard/PortfolioSummary.tsx b/components/dashboard/PortfolioSummary.tsx index ea5daf56..b56bf061 100644 --- a/components/dashboard/PortfolioSummary.tsx +++ b/components/dashboard/PortfolioSummary.tsx @@ -10,6 +10,8 @@ import cursor from '../../public/icons/cursor.png'; import cursorPointer from '../../public/icons/pointer-cursor.png'; import ClaimModal from "../discover/claimModal"; import SuccessModal from "../discover/successModal"; +import { useHidePortfolio } from "@hooks/useHidePortfolio"; + Chart.register(ArcElement, DoughnutController, Tooltip); type PortfolioSummaryProps = { @@ -17,7 +19,7 @@ type PortfolioSummaryProps = { data: ChartItem[], totalBalance: number, isProtocol: boolean, - minSlicePercentage?: number + minSlicePercentage?: number, } @@ -25,8 +27,9 @@ const ChartEntry: FunctionComponent = ({ color, itemLabel, itemValue, - itemValueSymbol + itemValueSymbol, }) => { + const { hidePortfolio } = useHidePortfolio(); const value = itemValueSymbol === '%' ? itemValue + itemValueSymbol : itemValueSymbol + itemValue; return (
@@ -36,7 +39,7 @@ const ChartEntry: FunctionComponent = ({ {itemLabel}
- {value} + {hidePortfolio ? "******" : value}
); }; diff --git a/hooks/useHidePortfolio.ts b/hooks/useHidePortfolio.ts new file mode 100644 index 00000000..1dfd63c0 --- /dev/null +++ b/hooks/useHidePortfolio.ts @@ -0,0 +1,10 @@ +import { useAtom } from "jotai"; +import { atomWithStorage } from "jotai/utils"; + +const hidePortfolioAtom = atomWithStorage("hidePortfolio", false); + +export function useHidePortfolio() { + const [hidePortfolio, setHidePortfolio] = useAtom(hidePortfolioAtom); + + return { hidePortfolio, setHidePortfolio }; +} \ No newline at end of file