Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:EjembiEmmanuel/starkfarm-client into…
Browse files Browse the repository at this point in the history
… dev
  • Loading branch information
EjembiEmmanuel committed Sep 20, 2024
2 parents ada3eb0 + b133bd5 commit 3858435
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
31 changes: 14 additions & 17 deletions src/app/community/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useAtomValue } from 'jotai';
import { referralCodeAtom } from '@/store/referral.store';
import { useEffect, useMemo, useState } from 'react';
import toast from 'react-hot-toast';
import { getReferralUrl } from '@/utils';
import {
useContractRead,
useContractWrite,
Expand All @@ -17,6 +16,8 @@ import { Contract } from 'starknet';
import NFTAbi from '../../abi/nft.abi.json';
import { atomWithQuery } from 'jotai-tanstack-query';
import { addressAtom } from '@/store/claims.atoms';
import { copyReferralLink, getReferralUrl } from '@/utils';
import mixpanel from 'mixpanel-browser';

import {
Box,
Expand Down Expand Up @@ -124,17 +125,9 @@ const CommunityPage = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [address]);

function copyReferralLink() {
if (window.location.origin.includes('app.strkfarm.xyz')) {
navigator.clipboard.writeText(`https://strkfarm.xyz/r/${referralCode}`);
} else {
navigator.clipboard.writeText(getReferralUrl(referralCode));
}

toast.success('Referral link copied to clipboard', {
position: 'bottom-right',
});
}
useEffect(() => {
mixpanel.track('Community Page open');
}, []);

async function handleEligibility() {
if (!address) {
Expand Down Expand Up @@ -244,9 +237,11 @@ const CommunityPage = () => {
borderColor="#3B4A3E"
>
<Text color="white" fontSize={{ base: '8px', md: '12px' }}>
{!referralCode
? 'Referral link loading...'
: `https://strkfarm.xyz/r/${referralCode}`}
{!address
? 'Connect wallet for your referral link'
: !referralCode
? 'Referral link loading...'
: `${getReferralUrl(referralCode)}`}
</Text>

<Button
Expand All @@ -257,8 +252,10 @@ const CommunityPage = () => {
_hover={{
bg: 'transparent',
}}
isDisabled={referralCode.length === 0}
onClick={copyReferralLink}
isDisabled={referralCode.length === 0 || !address}
onClick={() => {
copyReferralLink(referralCode);
}}
>
Copy link
</Button>
Expand Down
13 changes: 9 additions & 4 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,11 @@ export default function Navbar(props: NavbarProps) {
bg: 'color2_50p',
}}
display={{ base: 'none !important', md: 'flex !important' }}
onClick={() => {
mixpanel.track('community_program_click');
}}
>
Community
Community Program
</Button>
</Link>

Expand All @@ -310,7 +313,6 @@ export default function Navbar(props: NavbarProps) {
bg: 'color2_50p',
}}
display={{ base: 'none !important', md: 'flex !important' }}
className="glow-button"
>
Join Telegram
</Button>
Expand Down Expand Up @@ -433,10 +435,13 @@ export default function Navbar(props: NavbarProps) {
<Link
href="/community"
color="color1_light"
onClick={onClose}
onClick={() => {
onClose();
mixpanel.track('community_program_click');
}}
mt={4}
>
Community
Community Program
</Link>
</Flex>
</DrawerBody>
Expand Down
26 changes: 10 additions & 16 deletions src/components/TVL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addressAtom } from '@/store/claims.atoms';
import { referralCodeAtom } from '@/store/referral.store';
import { strategiesAtom } from '@/store/strategies.atoms';
import { dAppStatsAtom, userStatsAtom } from '@/store/utils.atoms';
import { getReferralUrl } from '@/utils';
import { copyReferralLink } from '@/utils';
import { CopyIcon } from '@chakra-ui/icons';
import {
Box,
Expand All @@ -18,7 +18,6 @@ import {
import { useAtomValue } from 'jotai';
import Link from 'next/link';
import React from 'react';
import toast from 'react-hot-toast';

const TVL: React.FC = () => {
const _strategies = useAtomValue(strategiesAtom);
Expand All @@ -29,18 +28,6 @@ const TVL: React.FC = () => {
const address = useAtomValue(addressAtom);
const referralCode = useAtomValue(referralCodeAtom);

function copyReferralLink() {
if (window.location.origin.includes('app.strkfarm.xyz')) {
navigator.clipboard.writeText(`https://strkfarm.xyz/r/${referralCode}`);
} else {
navigator.clipboard.writeText(getReferralUrl(referralCode));
}

toast.success('Referral link copied to clipboard', {
position: 'bottom-right',
});
}

return (
<Grid
templateColumns={{ base: 'repeat(1, 1, 1fr)', md: 'repeat(3, 1fr)' }}
Expand Down Expand Up @@ -110,7 +97,9 @@ const TVL: React.FC = () => {
textDecoration="underline"
fontWeight="600"
cursor={'pointer'}
onClick={copyReferralLink}
onClick={() => {
copyReferralLink(referralCode);
}}
>
{referralCode}
</StatNumber>
Expand All @@ -124,7 +113,12 @@ const TVL: React.FC = () => {
)}

{address && (
<CopyIcon cursor="pointer" onClick={copyReferralLink} />
<CopyIcon
cursor="pointer"
onClick={() => {
copyReferralLink(referralCode);
}}
/>
)}
</Box>
</Stat>
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MenuItemProps, MenuListProps } from '@chakra-ui/react';
import { num } from 'starknet';
import { TOKENS } from './constants';
import toast from 'react-hot-toast';

export function getUniqueStrings(arr: Array<string>) {
const _arr: string[] = [];
Expand Down Expand Up @@ -92,6 +93,9 @@ export function generateReferralCode() {
}

export function getReferralUrl(referralCode: string) {
if (window.location.origin.includes('app.strkfarm.xyz')) {
return `https://strkfarm.xyz/r/${referralCode}`;
}
return `${window.location.origin}/r/${referralCode}`;
}

Expand All @@ -101,3 +105,11 @@ export function getDisplayCurrencyAmount(
) {
return Number(Number(amount).toFixed(decimals)).toLocaleString();
}

export function copyReferralLink(refCode: string) {
navigator.clipboard.writeText(getReferralUrl(refCode));

toast.success('Referral link copied to clipboard', {
position: 'bottom-right',
});
}

0 comments on commit 3858435

Please sign in to comment.