Skip to content

Commit

Permalink
Merge pull request #192 from TrustlessComputer/daily_reward
Browse files Browse the repository at this point in the history
Daily reward
  • Loading branch information
0xmegalodon authored Feb 1, 2024
2 parents ebc3029 + 1fdcf5b commit 1f7178a
Show file tree
Hide file tree
Showing 18 changed files with 570 additions and 49 deletions.
24 changes: 24 additions & 0 deletions public/public-sale/hourly_bg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions src/Providers/user-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { User } from '@/stores/states/user/types';
import { getReferralByURL } from '@/utils/helpers';
import userServices from '@/services/user';
import ReferralStorage from '@/utils/storage/referral.storage';
import { getCoinPrices } from '@/services/common';
import { setCoinPrices } from '@/stores/states/common/reducer';
import { redirect, useRouter } from 'next/navigation';
import { getCoinPrices, getConfigs } from '@/services/common';
import { setCoinPrices, setConfigs } from '@/stores/states/common/reducer';
import { useRouter } from 'next/navigation';

export interface IUserContext {}

Expand Down Expand Up @@ -50,6 +50,12 @@ export const UserProvider: React.FC<PropsWithChildren> = ({
dispatch(setCoinPrices(coinPrices));
};

const fetchConfigs = async () => {
const configs = await getConfigs();
if (!configs) return;
dispatch(setConfigs(configs));
};

const contextValues = useMemo((): IUserContext => {
return {};
}, []);
Expand All @@ -70,8 +76,10 @@ export const UserProvider: React.FC<PropsWithChildren> = ({

React.useEffect(() => {
fetchCoinPrices();
fetchConfigs();
setInterval(() => {
fetchCoinPrices();
fetchConfigs();
}, 60 * 1000);
}, []);

Expand Down
3 changes: 2 additions & 1 deletion src/modules/PublicSale/aboveTheFold/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { getVCInformation } from '@/services/player-share';
import { VCInfo } from '@/interfaces/vc';
import LeaderBoardVisual from '@/modules/PublicSale/leaderBoardVisual';
import Activities from '@/modules/PublicSale/activities';
import LeaderBoardSwitch from '@/modules/PublicSale/leaderBoardSwitch';
import useWindowSize from '@/hooks/useWindowSize';
import DailyReward from '@/modules/PublicSale/dailyReward';
import HourlyReward from '@/modules/PublicSale/hourlyReward';

const AboveTheFold = () => {
const { setPlay } = useAnimationStore();
Expand Down Expand Up @@ -53,6 +53,7 @@ const AboveTheFold = () => {
<LeaderBoardVisual />
{/*<AddMoreContribution />*/}
<DailyReward />
<HourlyReward />
{/*<LeaderBoardSwitch classNames={s.boardSwitch} />*/}
{mobileScreen && <Activities />}
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/PublicSale/aboveTheFold/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
width: 100%;

:global {
--top-spacing: 24px;
--top-spacing: 20px;
--item-spacing: 12px;
}

Expand Down
17 changes: 11 additions & 6 deletions src/modules/PublicSale/activities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface GameItemProps {
src: string;
ctas?: ICTA[];
type: ActivityType;
startTime?: string;
endTime?: string;
}

const Activities = React.memo(() => {
Expand Down Expand Up @@ -92,8 +94,8 @@ Good luck and have fun!
],
desc:
'NakaChain is a low-cost and lightning-fast Bitcoin Layer 2 blockchain designed for DeFi apps, enabling the payment of gas fees in Bitcoin. It’s powered by BVM with these modules: Bitcoin for security, Polygon for data availability, and Optimism for execution.' +
"<br/><br/>On the second day of awesomeness, challenge yourself to dominate the market by trading futures on BRC-20 tokens' prices. Every two hours, the top gainer will earn $50 in Bitcoin.\n" +
'<br/><br/>Total rewards: <span style="color: #FA4E0E">$1,000</span>',
"<br/><br/>On the second day of awesomeness, challenge yourself to dominate the market by trading futures on BRC-20 tokens' prices. Every four hours, the top gainer will earn $50 in Bitcoin.\n"
// '<br/><br/>Total rewards: <span style="color: #FA4E0E">$1,000</span>',
},
{
key: 2,
Expand Down Expand Up @@ -243,6 +245,8 @@ Good luck and have fun!
const isDisable = item.key > currentDay.diffDay;
const title = isDisable ? item.title : item.title;

const isRunningNaka = expandIndex === item.key && item.key === ActivityType.Day2

return (
<AccordionItem isDisabled={isDisable} className={styles.itemWrapper}>
{({ isExpanded }) => (
Expand All @@ -263,8 +267,11 @@ Good luck and have fun!
>
<Flex direction="column" gap="8px">
<Text>
{item.key < currentDay.diffDay && (
<span className={styles.itemWrapper_happening}>Happening Now</span>
)}
{item.key === currentDay.diffDay && (
<span>Happening Now</span>
<span className={styles.itemWrapper_unlocked}>New unlocked</span>
)}
</Text>
<Text>
Expand Down Expand Up @@ -297,9 +304,7 @@ Good luck and have fun!
className={styles.itemWrapper_desc}
dangerouslySetInnerHTML={{ __html: item.desc }}
/>
{currentDay.diffDay === expandIndex &&
expandIndex === item.key &&
item.key === 1 && <NakaCountDown />}
{isRunningNaka && <NakaCountDown />}
<Flex alignItems="center" gap="8px">
{item.ctas?.map(renderCta)}
</Flex>
Expand Down
31 changes: 20 additions & 11 deletions src/modules/PublicSale/activities/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@
padding-bottom: 0 !important;
}

&_happening {
color: black;
padding: 4px 12px;
font-size: 10px;
font-weight: 400;
border-radius: 100px;
margin-right: 4px;
background: linear-gradient(90deg, #00F5A0 0%, #00D9F5 100%);
}

&_unlocked {
color: black;
padding: 4px 12px;
font-size: 10px;
font-weight: 400;
border-radius: 100px;
margin-right: 4px;
background: linear-gradient(90deg, #FFE259 0%, #FFA751 100%);
}

&_title {
color: #ffffff;
font-size: 14px;
Expand All @@ -59,17 +79,6 @@
max-width: 214px;
}

span {
color: black;
padding: 4px 12px;
font-size: 10px;
font-weight: 400;
border-radius: 100px;
background: #fa4e0e;
margin-right: 4px;
background: linear-gradient(90deg, #00F5A0 0%, #00D9F5 100%);
}

@include is-mobile {
font-size: 14px;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/PublicSale/dailyReward/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
position: absolute;
flex-direction: column;
top: var(--top-spacing);
left: 24px;
left: 20px;
gap: 16px;
min-width: 280px;
max-width: 280px;
Expand Down
73 changes: 73 additions & 0 deletions src/modules/PublicSale/hourlyReward/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import s from './styles.module.scss';
import { Flex, Text } from '@chakra-ui/react';
import dayjs from 'dayjs';
import React, { useEffect, useMemo, useState } from 'react';
import { getPublicSaleProgram, IPublicSalePrograme } from '@/services/public-sale';
import HourlyRewardButton from '@/modules/PublicSale/hourlyRewardButton';
import { useAppSelector } from '@/stores/hooks';
import { commonSelector } from '@/stores/states/common/selector';
import BigNumber from 'bignumber.js';
import { PUBLIC_SALE_START } from '@/modules/Whitelist';
import { formatCurrency } from '@/utils/format';
import { MIN_DECIMAL } from '@/constants/constants';

const HourlyReward = () => {
const [isLoading, setIsLoading] = useState(true);
const [isEnd, setIsEnd] = React.useState(false);
const [programeInfo, setProgrameInfo] = useState<IPublicSalePrograme>();
const configs = useAppSelector(commonSelector).configs;

useEffect(() => {
getProgramInfo();
}, []);

const getProgramInfo = async () => {
try {
const res = await getPublicSaleProgram();
setProgrameInfo(res);
} catch (e) {
} finally {
setIsLoading(false);
}
};

const currentDay = React.useMemo(() => {
const diffDay = new BigNumber(
dayjs.utc(PUBLIC_SALE_START).diff(dayjs.utc(), 'days'),
)
.absoluteValue()
.toNumber();
return {
// step: DAYS.length > diffDay ? DAYS[diffDay] : DAYS[DAYS.length - 1],
diffDay,
};
}, []);

const REWARDS = useMemo(() => {
if(configs) {
if(configs['naka']?.bvm_halvings) {
const res = JSON.parse(configs['naka']?.bvm_halvings);
return Object.values(res);
}
}
return [];
}, [configs]);

const currentHourReward: number = useMemo(() => {
return (REWARDS[currentDay.diffDay] as number) / 24;
}, [currentDay, REWARDS])

return (
<Flex className={s.container}>
<Flex justifyContent={"space-between"} alignItems={"center"} gap={"6px"}>
<Text className={s.title}>Hourly Reward</Text>
<Flex className={s.timeWrapper}>
<Text className={s.time}>{formatCurrency(currentHourReward, 0, 0, 'BTC', false)} BVM</Text>
</Flex>
</Flex>
<HourlyRewardButton />
</Flex>
)
}

export default HourlyReward;
48 changes: 48 additions & 0 deletions src/modules/PublicSale/hourlyReward/styles.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.container {
position: absolute;
flex-direction: column;
top: var(--top-spacing);
right: 20px;
gap: 16px;
//min-width: 280px;
//max-width: 280px;
//border: 1px solid #ffffff1a;
background: linear-gradient(180deg, #FDF6EA 0%, #FCF2DC 27%, #FBECC9 72.17%, #FBECC9 100%);
padding: 12px;
width: fit-content;

.title {
font-size: 12px;
line-height: 100%;
font-weight: 400;
color: #894D1C;
padding-top: 1px;
}

.time {
//margin-top: 10px;
font-size: 14px;
line-height: 100%;
font-weight: 500;
text-transform: uppercase;
background: linear-gradient(180deg, #DF7E2E -12.5%, #894D1C 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;

p {
font-size: inherit !important;
font-weight: inherit !important;
white-space: pre;
}

@include is-mobile {
font-size: 14px;
}
}

@include is-mobile {
max-width: unset;
width: calc(100% - 50px);
}
}
55 changes: 55 additions & 0 deletions src/modules/PublicSale/hourlyRewardButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Center, Flex, Text } from '@chakra-ui/react';
import s from './styles.module.scss';
import React, { useMemo } from 'react';
import cx from 'clsx';
import dayjs from 'dayjs';
import Countdown from '@/modules/Whitelist/stepAirdrop/Countdown';

const HourlyRewardButton = ({ className }: any) => {
const [isEnd, setIsEnd] = React.useState(false);

const hourlyEndTime = useMemo(() => {
let res = dayjs.utc().set('minute', 30);
res = res.set('second', 0);
if (dayjs().utc().isAfter(res)) {
res = res.set('hour', res.get('hour') + 1);
}
if(isEnd) {
setIsEnd(false);
}

return res.toString();
}, [isEnd]);

// console.log('dayjs.utc()', dayjs.utc().toString());
// console.log('hourlyEndTime', hourlyEndTime);

return (
<Flex className={cx(s.container, className)}>
<Flex direction={"column"} justifyContent={"space-between"} flex={1}>
<Center className={s.hourglassWrapper}>
<div className="hourglass">
<div className="top"></div>
<div className="bottom"></div>
</div>
</Center>

<Flex gap={'6px'} className={s.timeWrapper}>
<Text className={s.title}>End in</Text>
<Countdown
className={s.time}
expiredTime={dayjs
.utc(hourlyEndTime, 'YYYY-MM-DD HH:mm:ss')
.toString()}
hideIcon={true}
onRefreshEnd={() => setIsEnd(true)}
type={"column"}
showColon={true}
/>
</Flex>
</Flex>
</Flex>
);
};

export default HourlyRewardButton;
Loading

0 comments on commit 1f7178a

Please sign in to comment.