Skip to content

Commit

Permalink
check staking page manually & fixed render issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hapetherw committed May 5, 2024
1 parent f9b6d05 commit 8c8b57a
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 195 deletions.
5 changes: 2 additions & 3 deletions src/app/app/[tab]/AppTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { AppPreMining } from "@/components/app/pre-mining/AppPreMining";
import { AppAirdrop } from "@/components/app/airdrop/AppAirdrop";
import { SessionProvider } from "next-auth/react";
import { AppStaking } from "@/components/app/staking/AppStaking";

interface Props {
defaultTab: string;
}
Expand All @@ -27,7 +26,6 @@ const AppTabs: FC<Props> = ({ defaultTab }) => {

const _AppTabs: FC = () => {
const { currentTab, switchTab } = useSwitchAppTab();

return (
<Tabs
value={currentTab}
Expand Down Expand Up @@ -60,7 +58,8 @@ const _AppTabs: FC = () => {
>
Pre-Mining
</TabsTrigger>
<TabsTrigger value="staking">Staking</TabsTrigger>

{/* <TabsTrigger value="staking">Staking</TabsTrigger> */}
<TabsTrigger value="dashboard">Dashboard</TabsTrigger>
</TabsList>
<div className="[&_>_*]:animate-fadeAndMoveIn [&_>_*]:[animation-duration:300ms] sm:px-5 max-w-[100vw]">
Expand Down
1 change: 1 addition & 0 deletions src/app/app/[tab]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
airdrop: "Multi-Airdrop",
"get-usdc": "Get USDC",
"pre-mining": "Pre-Mining",
staking: "Staking",
}[params.tab];

const description = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/app/staking/AppStaking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Card } from "@/components/ui";
import { FC, useEffect, useRef } from "react";
import { AppStakingPane } from "./AppStakingPane";
import { AppStakingDescription } from "./AppStakingDescription";
import { AppStakingPool } from "./AppStakingPool";
import { AppStakingPools } from "./AppStakingPools";
import { useContractAddress } from "@/hooks/useContractAddress";
import { useAccount, usePublicClient } from "wagmi";
import { zeroAddress } from "viem";
Expand Down Expand Up @@ -73,7 +73,7 @@ export const AppStaking: FC = () => {
defaultGradient={false}
className="w-full flex flex-col gap-8 col-span-12 before:bg-primary p-2"
>
<AppStakingPool
<AppStakingPools
ldyTokenDecimals={ldyDecimals}
ldyTokenBalanceQuery={ldyBalanceQuery || []}
stakingAprInfo={stakingAprInfo ? stakingAprInfo.stakingAPRInfo || undefined : undefined}
Expand Down
190 changes: 0 additions & 190 deletions src/components/app/staking/AppStakingPool.tsx

This file was deleted.

137 changes: 137 additions & 0 deletions src/components/app/staking/AppStakingPoolPane.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { FC } from "react";

import { CarouselItem } from "@/components/ui/Carousel";
import { TxButton } from "@/components/ui";
import { formatUnits } from "viem";
import { useSimulateLdyStakingGetReward, useSimulateLdyStakingUnstake } from "@/generated";
import dayjs from "dayjs";
import localizedFormat from "dayjs/plugin/localizedFormat";
import relativeTime from "dayjs/plugin/relativeTime";
import utc from "dayjs/plugin/utc";
import { OneMonth } from "@/constants/staking";
import { useAPYCalculation } from "@/hooks/useAPYCalculation";
import { QueryKey } from "@tanstack/react-query";
import { IStakingAPRInfo, IUserStakingInfo } from "@/services/graph/hooks/useStakingEvent";
dayjs.extend(localizedFormat);
dayjs.extend(relativeTime);
dayjs.extend(utc);

export interface IPoolInfo {
stakedAmount: bigint;
unStakeAt: bigint;
duration: bigint;
rewardPerTokenPaid: bigint;
rewards: bigint;
}

export const AppStakingPoolPane: FC<{
poolInfo: IPoolInfo;
poolIndex: number;
ldyTokenDecimals: number;
userStakingInfo: IUserStakingInfo | undefined;
rewardsArray: readonly bigint[] | undefined;
stakingAprInfo: IStakingAPRInfo | undefined;
getUserStakesQuery?: QueryKey;
ldyTokenBalanceQuery?: QueryKey;
rewardsArrayQuery?: QueryKey;
}> = ({
poolInfo,
poolIndex,
ldyTokenDecimals,
userStakingInfo,
rewardsArray,
stakingAprInfo,
getUserStakesQuery,
ldyTokenBalanceQuery,
rewardsArrayQuery,
...props
}) => {
return (
<CarouselItem key={poolIndex} className="px-2 md:basis-1/2 lg:basis-1/3">
<div className="p-3 lg:p-4 rounded-lg bg-card-content-default">
<div className="flex flex-col justify-start">
<span className="font-semibold text-lg">Pool #{poolIndex + 1}</span>
<div className="flex text-sm justify-between">
<span>Staked Amount</span>
<span className="font-semibold">
{formatUnits(poolInfo.stakedAmount, ldyTokenDecimals!)}
</span>
</div>
<div className="flex text-sm justify-between">
<span>Duration</span>
<span className="font-semibold">{Number(poolInfo.duration) / OneMonth} Months</span>
</div>
<div className="flex text-sm justify-between">
<span>Unlock Timestamp</span>
<span className="font-semibold">
{dayjs.utc(Number(poolInfo.unStakeAt) * 1000).format("DD/MM/YYYY")}
</span>
</div>
<div className="flex text-sm justify-between">
<span>Earned</span>
<span className="font-semibold">
{userStakingInfo
? formatUnits(BigInt(userStakingInfo.earnedAmount), ldyTokenDecimals!)
: 0}{" "}
Token
</span>
</div>
<div className="flex text-sm justify-between">
<span>APY</span>
<span className="font-semibold">
{stakingAprInfo
? useAPYCalculation(stakingAprInfo.APR, false, Number(poolInfo.duration))
: "-"}
%
</span>
</div>
<div className="flex text-sm justify-between">
<span>Time Left</span>
<span className="font-semibold">
{dayjs(Number(poolInfo.unStakeAt) * 1000).fromNow(true)}
</span>
</div>
<div className="flex py-1 w-full">
<TxButton
preparation={useSimulateLdyStakingUnstake({
args: [poolInfo.stakedAmount, BigInt(poolIndex)],
})}
variant="primary"
size="tiny"
disabled={dayjs().isBefore(Number(poolInfo.unStakeAt) * 1000)}
className="w-full"
queryKeys={[ldyTokenBalanceQuery, getUserStakesQuery, rewardsArrayQuery]}
>
UNSTAKE
</TxButton>
</div>
<div className="flex py-1 w-full">
<TxButton
preparation={useSimulateLdyStakingGetReward({
args: [BigInt(poolIndex)],
})}
variant="outline"
size="tiny"
disabled={
Number(
formatUnits(
BigInt(rewardsArray ? rewardsArray[poolIndex] : 0),
ldyTokenDecimals!,
),
) < 0.0001
}
className="w-full"
queryKeys={[rewardsArrayQuery, ldyTokenBalanceQuery]}
>
CLAIM{" "}
{Number(
formatUnits(BigInt(rewardsArray ? rewardsArray[poolIndex] : 0), ldyTokenDecimals!),
).toFixed(4)}{" "}
Token
</TxButton>
</div>
</div>
</div>
</CarouselItem>
);
};
Loading

0 comments on commit 8c8b57a

Please sign in to comment.