diff --git a/apps/web/src/views/FixedStaking/components/FixedStakingPosition.tsx b/apps/web/src/views/FixedStaking/components/FixedStakingActions.tsx similarity index 97% rename from apps/web/src/views/FixedStaking/components/FixedStakingPosition.tsx rename to apps/web/src/views/FixedStaking/components/FixedStakingActions.tsx index 3d0fbb2653ad57..f544439b4379c3 100644 --- a/apps/web/src/views/FixedStaking/components/FixedStakingPosition.tsx +++ b/apps/web/src/views/FixedStaking/components/FixedStakingActions.tsx @@ -36,7 +36,7 @@ import { StakePositionUserInfo } from '../type' import { UnlockedFixedTag } from './UnlockedFixedTag' import { FixedStakingModal } from './FixedStakingModal' -export function FixedStakingPosition({ +export function FixedStakingActions({ token, stakePositionUserInfo, unlockTime, @@ -168,7 +168,7 @@ export function FixedStakingPosition({ APR - 36% + 0% @@ -180,7 +180,7 @@ export function FixedStakingPosition({ Projected Return - 2.055 {token.symbol} + 0 {token.symbol} @@ -196,13 +196,13 @@ export function FixedStakingPosition({ Withdrawal Commission - 1.2507 {token.symbol} + 0 {token.symbol} You Will Get - 1,1410 {token.symbol} + 0 {token.symbol} } + + )} + + + + ) +} diff --git a/apps/web/src/views/FixedStaking/components/FixedStakingCardBody.tsx b/apps/web/src/views/FixedStaking/components/FixedStakingCardBody.tsx index b9a5e73adcf56e..1f42e5374bf206 100644 --- a/apps/web/src/views/FixedStaking/components/FixedStakingCardBody.tsx +++ b/apps/web/src/views/FixedStaking/components/FixedStakingCardBody.tsx @@ -3,8 +3,10 @@ import { useTranslation } from '@pancakeswap/localization' import { useStablecoinPriceAmount } from 'hooks/useBUSDPrice' import { getBalanceAmount } from '@pancakeswap/utils/formatBalance' +import { ReactNode } from 'react' import { LockedFixedTag } from './LockedFixedTag' +import { FixedStakingPool } from '../type' function OverviewDataRow({ title, detail }) { return ( @@ -17,7 +19,7 @@ function OverviewDataRow({ title, detail }) { ) } -export function FixedStakingCardBody({ children, pool }) { +export function FixedStakingCardBody({ children, pool }: { pool: FixedStakingPool; children: ReactNode }) { const { t } = useTranslation() const totalStakedAmount = getBalanceAmount(pool.totalDeposited, pool.token.decimals) @@ -27,7 +29,7 @@ export function FixedStakingCardBody({ children, pool }) { <> } + detail={} /> {pool.lockPeriod}D} /> diff --git a/apps/web/src/views/FixedStaking/components/FixedStakingModal.tsx b/apps/web/src/views/FixedStaking/components/FixedStakingModal.tsx index 8687bc811ede90..d5160fbc226916 100644 --- a/apps/web/src/views/FixedStaking/components/FixedStakingModal.tsx +++ b/apps/web/src/views/FixedStaking/components/FixedStakingModal.tsx @@ -32,6 +32,7 @@ import toNumber from 'lodash/toNumber' import { CurrencyLogo } from 'components/Logo' import ConnectWalletButton from 'components/ConnectWalletButton' import useAccountActiveChain from 'hooks/useAccountActiveChain' +import { format, add } from 'date-fns' export function FixedStakingModal({ stakingToken, @@ -188,19 +189,19 @@ export function FixedStakingModal({ {t('APR')} - 36% + 0% Unlock On - Sep 16 2023 21:45 + {format(add(new Date(), { days: lockPeriod }), 'MMM d, yyyy hh:mm')} Projected Return - 0.23 BNB + 0 {stakingToken.symbol} @@ -212,7 +213,7 @@ export function FixedStakingModal({ }} onClick={handleSubmission} > - {pendingTx ? t('Confirming') : t('Confirm')} + {pendingTx ? t('Staking') : t('Stake')} ) : ( } + + + )} + + + + } + > + + + + + {pool.token.symbol} + + {isBoost ? ( + isMobile || isTablet ? ( + <> + + {pool.lockPeriod}D + + {isBoost ? ( + } + > + + vCAKE + + + ) : null} + + ) : isBoost ? ( + } + > + + vCAKE Boost + + + ) : null + ) : null} + + + {isMobile || isTablet ? null : ( + + + + Lock Periods + + {pool.lockPeriod}D + + + )} + + + + {t('APR')} + + + + + + + + {t('Total Staked:')} + + + + + {isMobile || isTablet ? null : ( + + + + {t('Ends in')} + + + {remainingDays > 0 ? remainingDays : 0} {t('days')} + + + + )} + + ) +} + +export default memo(FixedStakingRow) diff --git a/apps/web/src/views/FixedStaking/components/HarvestFixedStaking.tsx b/apps/web/src/views/FixedStaking/components/HarvestFixedStaking.tsx index 763a2fcdd12c10..cad478ec4b0def 100644 --- a/apps/web/src/views/FixedStaking/components/HarvestFixedStaking.tsx +++ b/apps/web/src/views/FixedStaking/components/HarvestFixedStaking.tsx @@ -8,8 +8,6 @@ import { PreTitle, Text, useModalV2, - Message, - MessageText, useToast, Balance, } from '@pancakeswap/uikit' @@ -36,11 +34,13 @@ export function HarvestFixedStaking({ stakePositionUserInfo, unlockTime, lockPeriod, + poolIndex, }: { unlockTime: number token: Token stakePositionUserInfo: StakePositionUserInfo lockPeriod: number + poolIndex: number }) { const { t } = useTranslation() const stakeModal = useModalV2() @@ -49,26 +49,26 @@ export function HarvestFixedStaking({ const { callWithGasPrice } = useCallWithGasPrice() const { toastSuccess } = useToast() - const totalStakedAmount = getBalanceAmount(stakePositionUserInfo.userDeposit, token.decimals) + const earnedAmount = getBalanceAmount(stakePositionUserInfo.accrueInterest, token.decimals) - const formattedUsdValueStaked = useStablecoinPriceAmount(token, totalStakedAmount.toNumber()) + const formattedUsdEarnedAmount = useStablecoinPriceAmount(token, earnedAmount.toNumber()) const handleSubmission = useCallback(async () => { const receipt = await fetchWithCatchTxError(() => { - const methodArgs = [0] - return callWithGasPrice(fixedStakingContract, 'withdraw', methodArgs) + const methodArgs = [poolIndex] + return callWithGasPrice(fixedStakingContract, 'harvest', methodArgs) }) if (receipt?.status) { toastSuccess( t('Successfully submitted!'), - {t('Your withdrawn request has been submitted.')} + {t('Your harvest request has been submitted.')} , ) stakeModal.onDismiss() } - }, [callWithGasPrice, fetchWithCatchTxError, fixedStakingContract, stakeModal, t, toastSuccess]) + }, [callWithGasPrice, fetchWithCatchTxError, fixedStakingContract, poolIndex, stakeModal, t, toastSuccess]) const shouldUnlock = differenceInMilliseconds(unlockTime * 1_000, new Date()) @@ -79,27 +79,28 @@ export function HarvestFixedStaking({ - + {token.symbol} - + - {shouldUnlock ? {t('End')} : {t('90D')}} + {shouldUnlock ? ( + {t('Ended')} + ) : ( + {unlockTime}D + )} - APR: 35% + APR: 0% Unlock on {format(unlockTime * 1_000, 'MMM d, yyyy')} - - Est. Reward: 2.155 {token.symbol} - diff --git a/apps/web/src/views/FixedStaking/components/InlineText.tsx b/apps/web/src/views/FixedStaking/components/InlineText.tsx new file mode 100644 index 00000000000000..ead7783987323a --- /dev/null +++ b/apps/web/src/views/FixedStaking/components/InlineText.tsx @@ -0,0 +1,6 @@ +import { Text } from '@pancakeswap/uikit' +import styled from 'styled-components' + +export const InlineText = styled(Text)` + display: inline; +` diff --git a/apps/web/src/views/FixedStaking/components/LockedFixedTag.tsx b/apps/web/src/views/FixedStaking/components/LockedFixedTag.tsx index 11c3b3a88a08af..0d41d5b839f0b3 100644 --- a/apps/web/src/views/FixedStaking/components/LockedFixedTag.tsx +++ b/apps/web/src/views/FixedStaking/components/LockedFixedTag.tsx @@ -1,8 +1,9 @@ import { Tag, LockIcon } from '@pancakeswap/uikit' +import { ReactNode, CSSProperties } from 'react' -export function LockedFixedTag({ children }) { +export function LockedFixedTag({ children, style }: { children: ReactNode; style?: CSSProperties }) { return ( - }> + }> {children} ) diff --git a/apps/web/src/views/FixedStaking/hooks/useStakedPools.ts b/apps/web/src/views/FixedStaking/hooks/useStakedPools.ts index 6eb83999cf879a..7cb2375be9d0fc 100644 --- a/apps/web/src/views/FixedStaking/hooks/useStakedPools.ts +++ b/apps/web/src/views/FixedStaking/hooks/useStakedPools.ts @@ -6,8 +6,26 @@ import { useContractRead } from 'wagmi' import toNumber from 'lodash/toNumber' import { useMemo } from 'react' import { useSingleContractMultipleData } from 'state/multicall/hooks' +import BigNumber from 'bignumber.js' import { FixedStakingPool, StakedPosition } from '../type' +export function useCurrenDay(): number { + const fixedStakingContract = useFixedStakingContract() + + const { chainId } = useActiveWeb3React() + + const { data } = useContractRead({ + abi: fixedStakingContract.abi, + address: fixedStakingContract.address as `0x${string}`, + functionName: 'getCurrentDay', + enabled: true, + watch: true, + chainId, + }) + + return (data || 0) as number +} + export function useStakedPositionsByUser(): StakedPosition[] { const fixedStakingContract = useFixedStakingContract() const { account, chainId } = useActiveWeb3React() @@ -80,7 +98,7 @@ export function useStakedPools(): FixedStakingPool[] { depositEnabled: fixedStakePool[7], maxDeposit: fixedStakePool[8], minDeposit: fixedStakePool[9], - totalDeposited: fixedStakePool[10], + totalDeposited: new BigNumber(fixedStakePool[10]), maxPoolAmount: fixedStakePool[11], minBoostAmount: fixedStakePool[12], } diff --git a/apps/web/src/views/FixedStaking/index.tsx b/apps/web/src/views/FixedStaking/index.tsx index 9c1e46fa046809..b6225a628b2f57 100644 --- a/apps/web/src/views/FixedStaking/index.tsx +++ b/apps/web/src/views/FixedStaking/index.tsx @@ -1,110 +1,42 @@ import { useTranslation } from '@pancakeswap/localization' import { - CardBody, Flex, FlexLayout, Heading, - StarFillIcon, PageHeader, - Tag, - Box, - Text, - Button, + Pool, + ToggleView, + ViewMode, + ButtonMenu, + ButtonMenuItem, } from '@pancakeswap/uikit' -import { StyledCard } from '@pancakeswap/uikit/src/widgets/Pool' import Page from 'components/Layout/Page' -import CurrencyLogo from 'components/Logo/CurrencyLogo' -import BigNumber from 'bignumber.js' -import styled from 'styled-components' +import { useState } from 'react' +import { useCurrenDay, useStakedPools, useStakedPositionsByUser } from './hooks/useStakedPools' +import { FixedStakingCard } from './components/FixedStakingCard' +import FixedStakingRow from './components/FixedStakingRow' -import { FixedStakingCardBody } from './components/FixedStakingCardBody' -import { FixedStakingPosition } from './components/FixedStakingPosition' -import { useStakedPools, useStakedPositionsByUser } from './hooks/useStakedPools' -import { FixedStakingPool, StakedPosition } from './type' -import { HarvestFixedStaking } from './components/HarvestFixedStaking' -import { FixedStakingModal } from './components/FixedStakingModal' - -const InlineText = styled(Text)` - display: inline; -` - -function FixedStakingCard({ pool, stakedPositions }: { pool: FixedStakingPool; stakedPositions: StakedPosition[] }) { - const { t } = useTranslation() - - const stakePosition = stakedPositions.find((position) => position.pool.token.address === pool.token.address) - - return ( - - - <> - - - - {pool.token.symbol} - - {new BigNumber(pool.boostDayPercent).gt(0) ? ( - }> - vCAKE Boost - - ) : null} - - - - - - {stakePosition ? ( - <> - - - {`${pool.token.symbol} `} - - - {t('Earned')} - - - - - ) : null} - {stakePosition ? ( - <> - - - {`${pool.token.symbol} `} - - - {t('Staked')} - - - - - ) : ( - - {(openModal) => } - - )} - - - - ) +enum POOL_STATUS { + Finished = 1, + Live = 0, } const FixedStaking = () => { const { t } = useTranslation() + const [viewMode, setViewMode] = useState(ViewMode.TABLE) + + const [poolStatus, togglePoolStatus] = useState(POOL_STATUS.Live) + const stakingPools = useStakedPools() const stakedPositions = useStakedPositionsByUser() + const currentDate = useCurrenDay() + + const displayPools = + poolStatus === POOL_STATUS.Live + ? stakingPools.filter((pool) => pool.endDay > currentDate) + : stakingPools.filter((pool) => pool.endDay <= currentDate) return ( <> @@ -121,19 +53,44 @@ const FixedStaking = () => { - - {stakingPools.map( - (pool) => - pool?.token && ( - stakedPool.token.address === pool.token.address, - )} - /> - ), - )} - + + + + + {t('Live')} + {t('Finished')} + + + + {viewMode === ViewMode.TABLE ? ( + + {displayPools.map( + (pool) => + pool && ( + stakedPool.token.address === pool.token.address, + )} + pool={pool} + /> + ), + )} + + ) : ( + + {displayPools.map( + (pool) => + pool?.token && ( + stakedPool.token.address === pool.token.address, + )} + /> + ), + )} + + )} ) diff --git a/apps/web/src/views/FixedStaking/type.ts b/apps/web/src/views/FixedStaking/type.ts index a9cd322abfd38b..00a7d2afd2bda3 100644 --- a/apps/web/src/views/FixedStaking/type.ts +++ b/apps/web/src/views/FixedStaking/type.ts @@ -19,7 +19,7 @@ export interface FixedStakingPool { depositEnabled: boolean maxDeposit: number minDeposit: number - totalDeposited: number + totalDeposited: BigNumber maxPoolAmount: number minBoostAmount: number } diff --git a/apps/web/src/views/Pools/components/PoolsTable/ActionPanel/ActionPanel.tsx b/apps/web/src/views/Pools/components/PoolsTable/ActionPanel/ActionPanel.tsx index 5b64805d54955c..566660513b22ef 100644 --- a/apps/web/src/views/Pools/components/PoolsTable/ActionPanel/ActionPanel.tsx +++ b/apps/web/src/views/Pools/components/PoolsTable/ActionPanel/ActionPanel.tsx @@ -37,7 +37,7 @@ const collapseAnimation = keyframes` } ` -const StyledActionPanel = styled.div<{ expanded: boolean }>` +export const StyledActionPanel = styled.div<{ expanded: boolean }>` animation: ${({ expanded }) => expanded ? css` @@ -59,7 +59,7 @@ const StyledActionPanel = styled.div<{ expanded: boolean }>` } ` -const ActionContainer = styled.div<{ isAutoVault?: boolean; hasBalance?: boolean }>` +export const ActionContainer = styled(Box)<{ isAutoVault?: boolean; hasBalance?: boolean }>` display: flex; flex-direction: column; flex: 1; @@ -81,7 +81,7 @@ interface ActionPanelProps { expanded: boolean } -const InfoSection = styled(Box)` +export const InfoSection = styled(Box)` flex-grow: 0; flex-shrink: 0; flex-basis: auto; diff --git a/apps/web/src/views/Pools/components/PoolsTable/Cells/NameCell.tsx b/apps/web/src/views/Pools/components/PoolsTable/Cells/NameCell.tsx index 57fa806f82f6ea..565571ae82ef91 100644 --- a/apps/web/src/views/Pools/components/PoolsTable/Cells/NameCell.tsx +++ b/apps/web/src/views/Pools/components/PoolsTable/Cells/NameCell.tsx @@ -15,7 +15,7 @@ interface NameCellProps { pool: Pool.DeserializedPool } -const StyledCell = styled(Pool.BaseCell)` +export const StyledCell = styled(Pool.BaseCell)` flex: 5; flex-direction: row; padding-left: 12px;