From 6aad4cc2b93df3a55c300d025ab3e5410da21571 Mon Sep 17 00:00:00 2001 From: Adam Chambers Date: Wed, 11 Oct 2023 20:04:24 -0400 Subject: [PATCH 1/2] fix: prepend mfi.gg url to referral link copy --- apps/marginfi-v2-ui/src/pages/points.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/marginfi-v2-ui/src/pages/points.tsx b/apps/marginfi-v2-ui/src/pages/points.tsx index d9d41f5d55..b540e77c27 100644 --- a/apps/marginfi-v2-ui/src/pages/points.tsx +++ b/apps/marginfi-v2-ui/src/pages/points.tsx @@ -100,7 +100,7 @@ const Points: FC = () => { }} onClick={() => { if (userPointsData.referralLink) { - navigator.clipboard.writeText(userPointsData.referralLink); + navigator.clipboard.writeText(`https://www.mfi.gg/refer/${userPointsData.referralLink}`); } }} > From 7e48de6468f20d58d0597ecd04dd60b178a115f8 Mon Sep 17 00:00:00 2001 From: Adam Chambers Date: Thu, 12 Oct 2023 08:33:43 -0400 Subject: [PATCH 2/2] feat: referral link copy success state --- apps/marginfi-v2-ui/src/pages/points.tsx | 40 ++++++++++++++---------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/apps/marginfi-v2-ui/src/pages/points.tsx b/apps/marginfi-v2-ui/src/pages/points.tsx index b540e77c27..35a1241228 100644 --- a/apps/marginfi-v2-ui/src/pages/points.tsx +++ b/apps/marginfi-v2-ui/src/pages/points.tsx @@ -1,7 +1,8 @@ -import React, { useMemo, FC, useEffect, useState } from "react"; +import React, { useMemo, FC, useEffect, useState, useCallback } from "react"; import Link from "next/link"; import { Button } from "@mui/material"; import FileCopyIcon from "@mui/icons-material/FileCopy"; +import CheckIcon from "@mui/icons-material/Check"; import { useRouter } from "next/router"; import { getFavoriteDomain } from "@bonfida/spl-name-service"; import { Connection, PublicKey } from "@solana/web3.js"; @@ -34,12 +35,15 @@ const Points: FC = () => { const currentUserId = useMemo(() => domain ?? currentFirebaseUser?.uid, [currentFirebaseUser, domain]); const referralCode = useMemo(() => routerQuery.referralCode as string | undefined, [routerQuery.referralCode]); + const [isReferralCopied, setIsReferralCopied] = useState(false); - useEffect(() => { - if (connection && walletAddress) { - resolveDomain(connection, new PublicKey(walletAddress)); + const handleReferralCopy = useCallback(() => { + if (userPointsData.referralLink) { + navigator.clipboard.writeText(`https://www.mfi.gg/refer/${userPointsData.referralLink}`); + setIsReferralCopied(true); + setTimeout(() => setIsReferralCopied(false), 2000); } - }, [connection, walletAddress]); + }, [userPointsData.referralLink]); const resolveDomain = async (connection: Connection, user: PublicKey) => { try { @@ -50,6 +54,12 @@ const Points: FC = () => { } }; + useEffect(() => { + if (connection && walletAddress) { + resolveDomain(connection, new PublicKey(walletAddress)); + } + }, [connection, walletAddress]); + useEffect(() => { fetchLeaderboardData(connection).then(setLeaderboardData); // TODO: cache leaderboard and avoid call }, [connection, connected, walletAddress]); // Dependency array to re-fetch when these variables change @@ -98,18 +108,16 @@ const Points: FC = () => { color: "black", zIndex: 10, }} - onClick={() => { - if (userPointsData.referralLink) { - navigator.clipboard.writeText(`https://www.mfi.gg/refer/${userPointsData.referralLink}`); - } - }} + onClick={handleReferralCopy} > - {`${ - userPointsData.isCustomReferralLink - ? userPointsData.referralLink?.replace("https://", "") - : "Copy referral link" - }`} - + {isReferralCopied + ? "Link copied" + : `${ + userPointsData.isCustomReferralLink + ? userPointsData.referralLink?.replace("https://", "") + : "Copy referral link" + }`} + {isReferralCopied ? : } )}