From c2d0b315498316d1cb8eea08cd8872b5a07f098e Mon Sep 17 00:00:00 2001 From: Beardev118 Date: Tue, 24 Oct 2023 15:01:35 +0200 Subject: [PATCH] Added finished tab for farming --- src/App.tsx | 4 + src/config/constants/farmsWithSmartChef.ts | 14 + .../FarmsV2/components/ToggleNew/index.jsx | 7 + .../NewFarms/components/ToggleNew/index.jsx | 7 + src/views/OldFarms/components/BountyCard.tsx | 130 +++ src/views/OldFarms/components/BountyModal.tsx | 133 +++ .../components/CakeVaultCard/FeeSummary.tsx | 49 + .../CakeVaultCard/PercentageButton.tsx | 23 + .../CakeVaultCard/RecentCakeProfitBalance.tsx | 41 + .../CakeVaultCard/RecentCakeProfitRow.tsx | 44 + .../UnstakingFeeCountdownRow.tsx | 64 + .../VaultCardActions/HasSharesActions.tsx | 677 +++++++++++ .../VaultCardActions/VaultApprovalAction.tsx | 69 ++ .../VaultCardActions/VaultStakeActions.tsx | 664 +++++++++++ .../CakeVaultCard/VaultCardActions/index.tsx | 700 +++++++++++ .../CakeVaultCard/VaultStakeModal.tsx | 261 +++++ .../CakeVaultCard/WithdrawalFeeTimer.tsx | 13 + .../components/CakeVaultCard/index.tsx | 97 ++ .../OldFarms/components/PoolCard/AprRow.tsx | 135 +++ .../PoolCard/CardActions/ApprovalAction.tsx | 77 ++ .../PoolCard/CardActions/HarvestActions.tsx | 145 +++ .../PoolCard/CardActions/StakeActions.tsx | 171 +++ .../components/PoolCard/CardActions/index.tsx | 102 ++ .../PoolCard/CardFooter/ExpandedFooter.tsx | 278 +++++ .../components/PoolCard/CardFooter/index.tsx | 97 ++ .../PoolCard/Modals/CollectModal.tsx | 166 +++ .../PoolCard/Modals/NotEnoughTokensModal.tsx | 59 + .../PoolCard/Modals/PercentageButton.tsx | 23 + .../components/PoolCard/Modals/StakeModal.tsx | 250 ++++ .../components/PoolCard/StyledCard.tsx | 56 + .../components/PoolCard/StyledCardHeader.tsx | 87 ++ .../OldFarms/components/PoolCard/index.tsx | 1037 +++++++++++++++++ .../OldFarms/components/PoolTabButtons.tsx | 82 ++ .../OldFarms/components/ToggleNew/index.jsx | 45 + src/views/OldFarms/helpers.tsx | 32 + src/views/OldFarms/index.tsx | 164 +++ 36 files changed, 6003 insertions(+) create mode 100644 src/views/OldFarms/components/BountyCard.tsx create mode 100644 src/views/OldFarms/components/BountyModal.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/FeeSummary.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/PercentageButton.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/RecentCakeProfitBalance.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/RecentCakeProfitRow.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/UnstakingFeeCountdownRow.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/VaultCardActions/HasSharesActions.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/VaultCardActions/VaultApprovalAction.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/VaultCardActions/VaultStakeActions.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/VaultCardActions/index.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/VaultStakeModal.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/WithdrawalFeeTimer.tsx create mode 100644 src/views/OldFarms/components/CakeVaultCard/index.tsx create mode 100644 src/views/OldFarms/components/PoolCard/AprRow.tsx create mode 100644 src/views/OldFarms/components/PoolCard/CardActions/ApprovalAction.tsx create mode 100644 src/views/OldFarms/components/PoolCard/CardActions/HarvestActions.tsx create mode 100644 src/views/OldFarms/components/PoolCard/CardActions/StakeActions.tsx create mode 100644 src/views/OldFarms/components/PoolCard/CardActions/index.tsx create mode 100644 src/views/OldFarms/components/PoolCard/CardFooter/ExpandedFooter.tsx create mode 100644 src/views/OldFarms/components/PoolCard/CardFooter/index.tsx create mode 100644 src/views/OldFarms/components/PoolCard/Modals/CollectModal.tsx create mode 100644 src/views/OldFarms/components/PoolCard/Modals/NotEnoughTokensModal.tsx create mode 100644 src/views/OldFarms/components/PoolCard/Modals/PercentageButton.tsx create mode 100644 src/views/OldFarms/components/PoolCard/Modals/StakeModal.tsx create mode 100644 src/views/OldFarms/components/PoolCard/StyledCard.tsx create mode 100644 src/views/OldFarms/components/PoolCard/StyledCardHeader.tsx create mode 100644 src/views/OldFarms/components/PoolCard/index.tsx create mode 100644 src/views/OldFarms/components/PoolTabButtons.tsx create mode 100644 src/views/OldFarms/components/ToggleNew/index.jsx create mode 100644 src/views/OldFarms/helpers.tsx create mode 100644 src/views/OldFarms/index.tsx diff --git a/src/App.tsx b/src/App.tsx index dfc74c1..f614fbc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -25,6 +25,7 @@ import SlideOutMenu from './components/SlideOutMenu/SlideOutMenu' import ComingSoon from './views/ComingSoon' import NewVersionModal from './components/NewVersionModal' import NewFarms from './views/NewFarms' +import OldFarms from './views/OldFarms' // import 'bootstrap/dist/css/bootstrap.min.css' @@ -123,6 +124,9 @@ const App: React.FC = () => { + + + diff --git a/src/config/constants/farmsWithSmartChef.ts b/src/config/constants/farmsWithSmartChef.ts index d88e300..ed3b2b5 100644 --- a/src/config/constants/farmsWithSmartChef.ts +++ b/src/config/constants/farmsWithSmartChef.ts @@ -43,6 +43,20 @@ const farmsWithSmartChef: FarmsWithSmartChefConfig[] = [ harvest: true, tokenPerBlock: '1', sortOrder: 999, + isFinished: true, + }, + { + sousId: 4, + stakingToken: LpTokens.soku_eth_sushi, + earningToken: tokens.sodatsu, + contractAddress: { + 1: '0x82ccdac1E2Fe6F86F4A2B241dfBe35E67B6E19F7', + 5: '', + }, + poolCategory: FarmsWithSmartChefCategory.CORE, + harvest: true, + tokenPerBlock: '1', + sortOrder: 999, isFinished: false, }, // { diff --git a/src/views/FarmsV2/components/ToggleNew/index.jsx b/src/views/FarmsV2/components/ToggleNew/index.jsx index 197a439..486473f 100644 --- a/src/views/FarmsV2/components/ToggleNew/index.jsx +++ b/src/views/FarmsV2/components/ToggleNew/index.jsx @@ -27,6 +27,13 @@ const ToggleNew = () => { Farm V2 + + Finished + ) diff --git a/src/views/NewFarms/components/ToggleNew/index.jsx b/src/views/NewFarms/components/ToggleNew/index.jsx index 6d68afa..0e1a812 100644 --- a/src/views/NewFarms/components/ToggleNew/index.jsx +++ b/src/views/NewFarms/components/ToggleNew/index.jsx @@ -27,6 +27,13 @@ const ToggleNew = () => { > Farm V2 + + Finished + ) diff --git a/src/views/OldFarms/components/BountyCard.tsx b/src/views/OldFarms/components/BountyCard.tsx new file mode 100644 index 0000000..b8b911f --- /dev/null +++ b/src/views/OldFarms/components/BountyCard.tsx @@ -0,0 +1,130 @@ +import React, { useMemo } from 'react' +// import BigNumber from 'bignumber.js' +// import styled from 'styled-components' +// import { +// Card, +// CardBody, +// Text, +// Flex, +// HelpIcon, +// Button, +// Heading, +// Skeleton, +// useModal, +// Box, +// useTooltip, +// } from '@pancakeswap/uikit' +// import { useTranslation } from 'contexts/Localization' +// import { getBalanceNumber } from 'utils/formatBalance' +// import { useCakeVault } from 'state/hooks' +// import Balance from 'components/Balance' +// import BountyModal from './BountyModal' + +// const StyledCard = styled(Card)` +// width: 100%; +// ${({ theme }) => theme.mediaQueries.sm} { +// min-width: 240px; +// } +// ` + +// const BountyCard = () => { +// const { t } = useTranslation() +// const { +// estimatedCakeBountyReward, +// totalPendingCakeHarvest, +// fees: { callFee }, +// } = useCakeVault() +// const cakePriceBusd = 0 +// const cakePriceBusdAsNumber = cakePriceBusd.toString() + +// const estimatedDollarBountyReward = useMemo(() => { +// return new BigNumber(estimatedCakeBountyReward).multipliedBy(cakePriceBusdAsNumber) +// }, [cakePriceBusdAsNumber, estimatedCakeBountyReward]) + +// const hasFetchedDollarBounty = +// cakePriceBusdAsNumber && estimatedDollarBountyReward ? estimatedDollarBountyReward.gte(0) : false +// const hasFetchedCakeBounty = estimatedCakeBountyReward ? estimatedCakeBountyReward.gte(0) : false +// const dollarBountyToDisplay = hasFetchedDollarBounty ? getBalanceNumber(estimatedDollarBountyReward, 18) : 0 +// const cakeBountyToDisplay = hasFetchedCakeBounty ? getBalanceNumber(estimatedCakeBountyReward, 18) : 0 + +// const TooltipComponent = () => ( +// <> +// {t('This bounty is given as a reward for providing a service to other users.')} +// +// {t( +// 'Whenever you successfully claim the bounty, you’re also helping out by activating the Auto CAKE Pool’s compounding function for everyone.', +// )} +// +// +// {t('Auto-Compound Bounty: %fee%% of all Auto CAKE pool users pending yield', { fee: callFee / 100 })} +// +// +// ) + +// const [onPresentBountyModal] = useModal( +// , +// ) + +// const { targetRef, tooltip, tooltipVisible } = useTooltip(, { +// placement: 'bottom-end', +// tooltipOffset: [20, 10], +// }) + +// return ( +// <> +// {tooltipVisible && tooltip} +// +// +// +// +// +// {t('Auto CAKE Bounty')} +// +// +// +// +// +// +// +// +// +// {hasFetchedCakeBounty ? ( +// +// ) : ( +// +// )} +// +// {hasFetchedDollarBounty ? ( +// +// ) : ( +// +// )} +// +// +// +// +// +// +// ) +// } + +// export default BountyCard diff --git a/src/views/OldFarms/components/BountyModal.tsx b/src/views/OldFarms/components/BountyModal.tsx new file mode 100644 index 0000000..150d06a --- /dev/null +++ b/src/views/OldFarms/components/BountyModal.tsx @@ -0,0 +1,133 @@ +import React, { useState } from 'react' +// import BigNumber from 'bignumber.js' +// import { useWeb3React } from '@web3-react/core' +// import { DEFAULT_GAS } from 'config' +// import styled from 'styled-components' +// import { Modal, Text, Flex, Button, HelpIcon, AutoRenewIcon, useTooltip } from '@pancakeswap/uikit' +// import { getBalanceNumber } from 'utils/formatBalance' +// import { useCakeVaultContract } from 'hooks/useContract' +// import useTheme from 'hooks/useTheme' +// import useToast from 'hooks/useToast' +// import { useTranslation } from 'contexts/Localization' +// import UnlockButton from 'components/UnlockButton' +// import Balance from 'components/Balance' + +// interface BountyModalProps { +// cakeBountyToDisplay: number +// dollarBountyToDisplay: number +// totalPendingCakeHarvest: BigNumber +// callFee: number +// onDismiss?: () => void +// TooltipComponent: React.ElementType +// } + +// const Divider = styled.div` +// background-color: ${({ theme }) => theme.colors.backgroundDisabled}; +// height: 1px; +// margin: 16px auto; +// width: 100%; +// ` + +// const BountyModal: React.FC = ({ +// cakeBountyToDisplay, +// dollarBountyToDisplay, +// totalPendingCakeHarvest, +// callFee, +// onDismiss, +// TooltipComponent, +// }) => { +// const { t } = useTranslation() +// const { account } = useWeb3React() +// const { theme } = useTheme() +// const { toastError, toastSuccess } = useToast() +// const cakeVaultContract = useCakeVaultContract() +// const [pendingTx, setPendingTx] = useState(false) +// const callFeeAsDecimal = callFee / 100 +// const totalYieldToDisplay = getBalanceNumber(totalPendingCakeHarvest, 18) +// const { targetRef, tooltip, tooltipVisible } = useTooltip(, { +// placement: 'bottom', +// tooltipPadding: { right: 15 }, +// }) + +// const handleConfirmClick = async () => { +// cakeVaultContract.methods +// .harvest() +// .send({ from: account, gas: DEFAULT_GAS }) +// .on('sending', () => { +// setPendingTx(true) +// }) +// .on('receipt', () => { +// toastSuccess(t('Bounty collected!'), t('CAKE bounty has been sent to your wallet.')) +// setPendingTx(false) +// onDismiss() +// }) +// .on('error', (error) => { +// console.error(error) +// toastError( +// t('Could not be collected'), +// t('There may be an issue with your transaction, or another user claimed the bounty first.'), +// ) +// setPendingTx(false) +// onDismiss() +// }) +// } + +// return ( +// +// {tooltipVisible && tooltip} +// +// {t('You’ll claim')} +// +// +// +// +// +// +// +// +// +// +// {t('Pool total pending yield')} +// +// +// +// +// +// {t('Bounty')} +// +// +// {callFeeAsDecimal}% +// +// +// {account ? ( +// +// ) : ( +// +// )} +// +// +// {t('What’s this?')} +// +// +// +// +// +// +// ) +// } + +// export default BountyModal diff --git a/src/views/OldFarms/components/CakeVaultCard/FeeSummary.tsx b/src/views/OldFarms/components/CakeVaultCard/FeeSummary.tsx new file mode 100644 index 0000000..1b2a7b9 --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/FeeSummary.tsx @@ -0,0 +1,49 @@ +import React from 'react' +import { Text, Flex, useTooltip, TooltipText } from '@pancakeswap/uikit' +import { useTranslation } from 'contexts/Localization' +import { useCakeVault } from 'state/hooks' +import UnstakingFeeCountdownRow from './UnstakingFeeCountdownRow' + +interface FeeSummaryProps { + stakingTokenSymbol: string + stakeAmount: string +} + +const FeeSummary: React.FC = ({ stakingTokenSymbol, stakeAmount }) => { + const { t } = useTranslation() + const { + fees: { withdrawalFee }, + } = useCakeVault() + const feeAsDecimal = withdrawalFee / 100 + const feeInCake = (parseFloat(stakeAmount) * (feeAsDecimal / 100)).toFixed(4) + const { targetRef, tooltip, tooltipVisible } = useTooltip( + <> + + {t('Unstaking fee: %fee%%', { fee: feeAsDecimal })} + + + {t( + 'Only applies within 3 days of staking. Unstaking after 3 days will not include a fee. Timer resets every time you stake new SOKU in the pool.', + )} + + , + { placement: 'top-start' }, + ) + + return ( + <> + + {tooltipVisible && tooltip} + + {t('Unstaking Fee')} + + + {stakeAmount ? feeInCake : '-'} {stakingTokenSymbol} + + + + + ) +} + +export default FeeSummary diff --git a/src/views/OldFarms/components/CakeVaultCard/PercentageButton.tsx b/src/views/OldFarms/components/CakeVaultCard/PercentageButton.tsx new file mode 100644 index 0000000..6fb72df --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/PercentageButton.tsx @@ -0,0 +1,23 @@ +import React from 'react' +import styled from 'styled-components' +import { Button } from '@pancakeswap/uikit' + +interface PercentageButtonProps { + onClick: () => void +} + +const StyledButton = styled(Button)` + flex-grow: 1; + background: #04bbfb; + color: #fff; +` + +const PercentageButton: React.FC = ({ children, onClick }) => { + return ( + + {children} + + ) +} + +export default PercentageButton diff --git a/src/views/OldFarms/components/CakeVaultCard/RecentCakeProfitBalance.tsx b/src/views/OldFarms/components/CakeVaultCard/RecentCakeProfitBalance.tsx new file mode 100644 index 0000000..1b01acc --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/RecentCakeProfitBalance.tsx @@ -0,0 +1,41 @@ +import React from 'react' +import { Text, TooltipText, useTooltip } from '@pancakeswap/uikit' +import { useTranslation } from 'contexts/Localization' +import Balance from 'components/Balance' + +interface RecentCakeProfitBalanceProps { + cakeToDisplay: number + dollarValueToDisplay: number + dateStringToDisplay: string +} + +const RecentCakeProfitBalance: React.FC = ({ + cakeToDisplay, + dollarValueToDisplay, + dateStringToDisplay, +}) => { + const { t } = useTranslation() + + const { targetRef, tooltip, tooltipVisible } = useTooltip( + <> + + + {t('Earned since your last action')} + {dateStringToDisplay} + , + { + placement: 'bottom-end', + }, + ) + + return ( + <> + {tooltipVisible && tooltip} + + + + + ) +} + +export default RecentCakeProfitBalance diff --git a/src/views/OldFarms/components/CakeVaultCard/RecentCakeProfitRow.tsx b/src/views/OldFarms/components/CakeVaultCard/RecentCakeProfitRow.tsx new file mode 100644 index 0000000..f06b0a2 --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/RecentCakeProfitRow.tsx @@ -0,0 +1,44 @@ +import React from 'react' +import { Flex, Text } from '@pancakeswap/uikit' +import { useWeb3React } from '@web3-react/core' +import { useTranslation } from 'contexts/Localization' +import { useCakeVault } from 'state/hooks' +import { getBalanceNumber } from 'utils/formatBalance' +import { convertSharesToCake } from 'views/Pools/helpers' +import RecentCakeProfitBalance from './RecentCakeProfitBalance' + +const RecentCakeProfitCountdownRow = () => { + const { t } = useTranslation() + const { account } = useWeb3React() + const { + pricePerFullShare, + userData: { cakeAtLastUserAction, userShares, lastUserActionTime }, + } = useCakeVault() + const shouldDisplayCakeProfit = + account && cakeAtLastUserAction && cakeAtLastUserAction.gt(0) && userShares && userShares.gt(0) + const currentSharesAsCake = convertSharesToCake(userShares, pricePerFullShare) + const cakeProfit = currentSharesAsCake.cakeAsBigNumber.minus(cakeAtLastUserAction) + const cakeToDisplay = cakeProfit.gte(0) ? getBalanceNumber(cakeProfit, 18) : 0 + const cakePriceBusd = 0 + const dollarValueOfCake = cakeProfit.times(cakePriceBusd) + const dollarValueToDisplay = dollarValueOfCake.gte(0) ? getBalanceNumber(dollarValueOfCake, 18) : 0 + + const lastActionInMs = lastUserActionTime && parseInt(lastUserActionTime) * 1000 + const dateTimeLastAction = new Date(lastActionInMs) + const dateStringToDisplay = dateTimeLastAction.toLocaleString() + + return ( + + {t('Recent SUTEKU profit:')} + {shouldDisplayCakeProfit && ( + + )} + + ) +} + +export default RecentCakeProfitCountdownRow diff --git a/src/views/OldFarms/components/CakeVaultCard/UnstakingFeeCountdownRow.tsx b/src/views/OldFarms/components/CakeVaultCard/UnstakingFeeCountdownRow.tsx new file mode 100644 index 0000000..9b4d869 --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/UnstakingFeeCountdownRow.tsx @@ -0,0 +1,64 @@ +import React from 'react' +import { Flex, Text, TooltipText, useTooltip } from '@pancakeswap/uikit' +import { useTranslation } from 'contexts/Localization' +import { useWeb3React } from '@web3-react/core' +import useWithdrawalFeeTimer from 'hooks/cakeVault/useWithdrawalFeeTimer' +import { useCakeVault } from 'state/hooks' +import WithdrawalFeeTimer from './WithdrawalFeeTimer' + +const UnstakingFeeCountdownRow = () => { + const { t } = useTranslation() + const { account } = useWeb3React() + const { + userData: { lastDepositedTime, userShares }, + fees: { withdrawalFee, withdrawalFeePeriod }, + } = useCakeVault() + const feeAsDecimal = withdrawalFee / 100 || '-' + const { targetRef, tooltip, tooltipVisible } = useTooltip( + <> + + {t('Unstaking fee: %fee%%', { fee: feeAsDecimal })} + + + {t( + 'Only applies within 3 days of staking. Unstaking after 3 days will not include a fee. Timer resets every time you stake new CAKE in the pool.', + )} + + , + { placement: 'bottom-start' }, + ) + + const { secondsRemaining, hasUnstakingFee } = useWithdrawalFeeTimer( + parseInt(lastDepositedTime, 10), + userShares, + withdrawalFeePeriod, + ) + + // The user has made a deposit, but has no fee + const noFeeToPay = lastDepositedTime && !hasUnstakingFee && userShares.gt(0) + + // Show the timer if a user is connected, has deposited, and has an unstaking fee + const shouldShowTimer = account && lastDepositedTime && hasUnstakingFee + + const getRowText = () => { + if (noFeeToPay) { + return t('Unstaking Fee').toLowerCase() + } + if (shouldShowTimer) { + return t('unstaking fee until') + } + return t('unstaking fee if withdrawn within 72h') + } + + return ( + + {tooltipVisible && tooltip} + + {noFeeToPay ? '0' : feeAsDecimal}% {getRowText()} + + {shouldShowTimer && } + + ) +} + +export default UnstakingFeeCountdownRow diff --git a/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/HasSharesActions.tsx b/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/HasSharesActions.tsx new file mode 100644 index 0000000..db85f33 --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/HasSharesActions.tsx @@ -0,0 +1,677 @@ +import React, { useState, useEffect } from 'react' +// import { Flex, Text, IconButton, AddIcon, MinusIcon, useModal, Skeleton } from '@pancakeswap/uikit' +// import { useWeb3React } from '@web3-react/core' +// import BigNumber from 'bignumber.js' +// import { getBalanceNumber } from 'utils/formatBalance' +// import { getWeb3NoAccount } from 'utils/web3' +// import { AbiItem } from 'web3-utils' +// import { getAddress } from 'utils/addressHelpers' +// import { Pool } from 'state/types' +// import { useCakeVault, useBusdPriceFromToken, useTokenPrice } from 'state/hooks' +// import Balance from 'components/Balance' +// import NotEnoughTokensModal from '../../PoolCard/Modals/NotEnoughTokensModal' +// import { convertSharesToCake } from '../../../helpers' +// import VaultStakeModal from '../VaultStakeModal' + +// interface HasStakeActionProps { +// pool: Pool +// stakingTokenBalance: BigNumber +// } + +// const HasSharesActions: React.FC = ({ pool, stakingTokenBalance }) => { +// const { +// userData: { userShares }, +// pricePerFullShare, +// } = useCakeVault() +// const { stakingToken } = pool +// const { cakeAsBigNumber, cakeAsNumberBalance } = convertSharesToCake(userShares, pricePerFullShare) +// // const cakePriceBusd = usePriceCakeBusd() +// const [balance, setBalance] = useState(new BigNumber(0)) +// const { account } = useWeb3React() +// const web3 = getWeb3NoAccount() +// const sokuPrice = useTokenPrice('sokuswap') +// const sutekuPrice = 0 +// const stakedDollarValue = getBalanceNumber(cakeAsBigNumber.multipliedBy(sutekuPrice), stakingToken.decimals) + +// // console.log(cakeAsBigNumber, 'cakeAsBigNumber') +// // console.log(cakeAsNumberBalance, 'cakeAsNumberBalance') + +// // useEffect(() => { +// // try { +// // const getBalance = async (address) => { +// // // If SUTEKU +// // if (stakingToken.address[56] === '0x198800af50914004a9e9d19ca18c0b24587a50cf') { +// // const abi = [ +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'spender', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Approval', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'previousOwner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'newOwner', type: 'address' }, +// // ], +// // name: 'OwnershipTransferred', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'from', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'to', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Transfer', +// // type: 'event', +// // }, +// // { +// // inputs: [], +// // name: 'DOMAIN_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'owner', type: 'address' }, +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // ], +// // name: 'allowance', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'approve', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'balanceOf', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'decimals', +// // outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'subtractedValue', type: 'uint256' }, +// // ], +// // name: 'decreaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'getOwner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'addedValue', type: 'uint256' }, +// // ], +// // name: 'increaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: '_to', type: 'address' }, +// // { internalType: 'uint256', name: '_amount', type: 'uint256' }, +// // ], +// // name: 'mint', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'uint256', name: 'amount', type: 'uint256' }], +// // name: 'mint', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'name', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'owner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { inputs: [], name: 'renounceOwnership', outputs: [], stateMutability: 'nonpayable', type: 'function' }, +// // { +// // inputs: [], +// // name: 'symbol', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'totalSupply', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transfer', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'sender', type: 'address' }, +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transferFrom', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }], +// // name: 'transferOwnership', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // ] +// // const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) +// // const response = await contract.methods.balanceOf(address).call() +// // const bal = new BigNumber(response) +// // setBalance(bal) +// // } else if (stakingToken.address[56] === '0x0e4b5ea0259eb3d66e6fcb7cc8785817f8490a53') { +// // // If SOKU +// // const abi = [ +// // { inputs: [], stateMutability: 'nonpayable', type: 'constructor' }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'spender', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Approval', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'delegator', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'fromDelegate', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'toDelegate', type: 'address' }, +// // ], +// // name: 'DelegateChanged', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'delegate', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'previousBalance', type: 'uint256' }, +// // { indexed: false, internalType: 'uint256', name: 'newBalance', type: 'uint256' }, +// // ], +// // name: 'DelegateVotesChanged', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'from', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'to', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Transfer', +// // type: 'event', +// // }, +// // { +// // inputs: [], +// // name: 'DELEGATION_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'DOMAIN_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'owner', type: 'address' }, +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // ], +// // name: 'allowance', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'approve', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'balanceOf', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: '', type: 'address' }, +// // { internalType: 'uint32', name: '', type: 'uint32' }, +// // ], +// // name: 'checkpoints', +// // outputs: [ +// // { internalType: 'uint32', name: 'fromBlock', type: 'uint32' }, +// // { internalType: 'uint256', name: 'votes', type: 'uint256' }, +// // ], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'decimals', +// // outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'subtractedValue', type: 'uint256' }, +// // ], +// // name: 'decreaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'delegatee', type: 'address' }], +// // name: 'delegate', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'delegatee', type: 'address' }, +// // { internalType: 'uint256', name: 'nonce', type: 'uint256' }, +// // { internalType: 'uint256', name: 'expiry', type: 'uint256' }, +// // { internalType: 'uint8', name: 'v', type: 'uint8' }, +// // { internalType: 'bytes32', name: 'r', type: 'bytes32' }, +// // { internalType: 'bytes32', name: 's', type: 'bytes32' }, +// // ], +// // name: 'delegateBySig', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'delegator', type: 'address' }], +// // name: 'delegates', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'getCurrentVotes', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'account', type: 'address' }, +// // { internalType: 'uint256', name: 'blockNumber', type: 'uint256' }, +// // ], +// // name: 'getPriorVotes', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'addedValue', type: 'uint256' }, +// // ], +// // name: 'increaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'name', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: '', type: 'address' }], +// // name: 'nonces', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: '', type: 'address' }], +// // name: 'numCheckpoints', +// // outputs: [{ internalType: 'uint32', name: '', type: 'uint32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'symbol', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'totalSupply', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transfer', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'sender', type: 'address' }, +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transferFrom', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // ] +// // const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) +// // const response = await contract.methods.balanceOf(address).call() +// // const bal = new BigNumber(response) + +// // setBalance(bal) +// // } else { +// // const abi = [ +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'spender', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Approval', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'previousOwner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'newOwner', type: 'address' }, +// // ], +// // name: 'OwnershipTransferred', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'from', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'to', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Transfer', +// // type: 'event', +// // }, +// // { +// // inputs: [], +// // name: 'DOMAIN_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'owner', type: 'address' }, +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // ], +// // name: 'allowance', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'approve', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'balanceOf', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'decimals', +// // outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'subtractedValue', type: 'uint256' }, +// // ], +// // name: 'decreaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'getOwner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'addedValue', type: 'uint256' }, +// // ], +// // name: 'increaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: '_to', type: 'address' }, +// // { internalType: 'uint256', name: '_amount', type: 'uint256' }, +// // ], +// // name: 'mint', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'uint256', name: 'amount', type: 'uint256' }], +// // name: 'mint', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'name', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'owner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'renounceOwnership', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'symbol', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'totalSupply', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transfer', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'sender', type: 'address' }, +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transferFrom', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }], +// // name: 'transferOwnership', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // ] +// // const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) +// // const response = await contract.methods.balanceOf(address).call() +// // const bal = new BigNumber(response) +// // setBalance(bal) +// // } +// // } + +// // getBalance(account) +// // } catch (error) { +// // console.log(error, 'getBalance') +// // } +// // // eslint-disable-next-line react-hooks/exhaustive-deps +// // }) + +// // console.log(stakingTokenBalance, 'vault stakingTokenBalance') + +// const [onPresentTokenRequired] = useModal() +// const [onPresentStake] = useModal() +// const [onPresentUnstake] = useModal() + +// return ( +// +// +// +// +// {sutekuPrice > 0 ? ( +// +// ) : ( +// +// )} +// +// +// +// +// +// +// +// +// +// +// +// ) +// } + +// export default HasSharesActions diff --git a/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/VaultApprovalAction.tsx b/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/VaultApprovalAction.tsx new file mode 100644 index 0000000..625cb76 --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/VaultApprovalAction.tsx @@ -0,0 +1,69 @@ +import React, { useState } from 'react' +// import { Button, AutoRenewIcon, Skeleton } from '@pancakeswap/uikit' +// import { useWeb3React } from '@web3-react/core' +// import { ethers } from 'ethers' +// import { useTranslation } from 'contexts/Localization' +// import { useCake, useCakeVaultContract, useSoku, useSuteku } from 'hooks/useContract' +// import useToast from 'hooks/useToast' +// import { Pool } from 'state/types' + +// interface ApprovalActionProps { +// pool: Pool +// setLastUpdated: () => void +// // eslint-disable-next-line react/require-default-props +// isLoading?: boolean +// } + +// const ApprovalAction: React.FC = ({ pool, isLoading = false, setLastUpdated }) => { +// const { account } = useWeb3React() +// const { stakingToken } = pool +// const cakeVaultContract = useCakeVaultContract() +// // const cakeContract = useCake() +// const sokuContract = useSoku() +// const sutekuContract = useSuteku() +// const { t } = useTranslation() +// const [requestedApproval, setRequestedApproval] = useState(false) +// const { toastSuccess, toastError } = useToast() + +// const handleApprove = () => { +// sutekuContract.methods +// .approve(cakeVaultContract.options.address, ethers.constants.MaxUint256) +// .send({ from: account }) +// .on('sending', () => { +// setRequestedApproval(true) +// }) +// .on('receipt', () => { +// toastSuccess( +// t('Contract Enabled'), +// t('You can now stake in the %symbol% vault!', { symbol: stakingToken.symbol }), +// ) +// setLastUpdated() +// setRequestedApproval(false) +// }) +// .on('error', (error) => { +// console.error(error) +// toastError(t('Error'), t('Please try again. Confirm the transaction and make sure you are paying enough gas!')) +// setRequestedApproval(false) +// }) +// } + +// return ( +// <> +// {isLoading ? ( +// +// ) : ( +// +// )} +// +// ) +// } + +// export default ApprovalAction diff --git a/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/VaultStakeActions.tsx b/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/VaultStakeActions.tsx new file mode 100644 index 0000000..588dcb7 --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/VaultStakeActions.tsx @@ -0,0 +1,664 @@ +import React, { useState, useEffect } from 'react' +// import { Flex, Button, useModal, Skeleton } from '@pancakeswap/uikit' +// import { useWeb3React } from '@web3-react/core' +// import { useBusdPriceFromToken, useTokenPrice, usePriceBnbSuteku } from 'state/hooks' +// import BigNumber from 'bignumber.js' +// import { useTranslation } from 'contexts/Localization' +// import { Pool } from 'state/types' +// import { getWeb3NoAccount } from 'utils/web3' +// import { getAddress } from 'utils/addressHelpers' +// import { AbiItem } from 'web3-utils' +// import NotEnoughTokensModal from '../../PoolCard/Modals/NotEnoughTokensModal' +// import VaultStakeModal from '../VaultStakeModal' +// import HasSharesActions from './HasSharesActions' + +// interface VaultStakeActionsProps { +// pool: Pool +// stakingTokenBalance: BigNumber +// accountHasSharesStaked: boolean +// // eslint-disable-next-line react/require-default-props +// isLoading?: boolean +// } + +// const VaultStakeActions: React.FC = ({ +// pool, +// stakingTokenBalance, +// accountHasSharesStaked, +// isLoading = false, +// }) => { +// const { stakingToken } = pool +// const { t } = useTranslation() +// const sokuPrice = useTokenPrice('sokuswap') +// const sutekuPrice = usePriceBnbSuteku() +// const { account } = useWeb3React() +// const [balance, setBalance] = useState(new BigNumber(0)) +// const [onPresentTokenRequired] = useModal() +// const [onPresentStake] = useModal() +// const web3 = getWeb3NoAccount() + +// // useEffect(() => { +// // try { +// // const getBalance = async (address) => { +// // // If SUTEKU +// // if (stakingToken.address[56] === '0x198800af50914004a9e9d19ca18c0b24587a50cf') { +// // const abi = [ +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'spender', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Approval', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'previousOwner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'newOwner', type: 'address' }, +// // ], +// // name: 'OwnershipTransferred', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'from', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'to', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Transfer', +// // type: 'event', +// // }, +// // { +// // inputs: [], +// // name: 'DOMAIN_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'owner', type: 'address' }, +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // ], +// // name: 'allowance', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'approve', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'balanceOf', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'decimals', +// // outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'subtractedValue', type: 'uint256' }, +// // ], +// // name: 'decreaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'getOwner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'addedValue', type: 'uint256' }, +// // ], +// // name: 'increaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: '_to', type: 'address' }, +// // { internalType: 'uint256', name: '_amount', type: 'uint256' }, +// // ], +// // name: 'mint', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'uint256', name: 'amount', type: 'uint256' }], +// // name: 'mint', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'name', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'owner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { inputs: [], name: 'renounceOwnership', outputs: [], stateMutability: 'nonpayable', type: 'function' }, +// // { +// // inputs: [], +// // name: 'symbol', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'totalSupply', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transfer', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'sender', type: 'address' }, +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transferFrom', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }], +// // name: 'transferOwnership', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // ] +// // const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) +// // const response = await contract.methods.balanceOf(address).call() +// // const bal = new BigNumber(response) +// // setBalance(bal) +// // } else if (stakingToken.address[56] === '0x0e4b5ea0259eb3d66e6fcb7cc8785817f8490a53') { +// // // If SOKU +// // const abi = [ +// // { inputs: [], stateMutability: 'nonpayable', type: 'constructor' }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'spender', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Approval', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'delegator', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'fromDelegate', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'toDelegate', type: 'address' }, +// // ], +// // name: 'DelegateChanged', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'delegate', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'previousBalance', type: 'uint256' }, +// // { indexed: false, internalType: 'uint256', name: 'newBalance', type: 'uint256' }, +// // ], +// // name: 'DelegateVotesChanged', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'from', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'to', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Transfer', +// // type: 'event', +// // }, +// // { +// // inputs: [], +// // name: 'DELEGATION_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'DOMAIN_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'owner', type: 'address' }, +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // ], +// // name: 'allowance', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'approve', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'balanceOf', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: '', type: 'address' }, +// // { internalType: 'uint32', name: '', type: 'uint32' }, +// // ], +// // name: 'checkpoints', +// // outputs: [ +// // { internalType: 'uint32', name: 'fromBlock', type: 'uint32' }, +// // { internalType: 'uint256', name: 'votes', type: 'uint256' }, +// // ], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'decimals', +// // outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'subtractedValue', type: 'uint256' }, +// // ], +// // name: 'decreaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'delegatee', type: 'address' }], +// // name: 'delegate', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'delegatee', type: 'address' }, +// // { internalType: 'uint256', name: 'nonce', type: 'uint256' }, +// // { internalType: 'uint256', name: 'expiry', type: 'uint256' }, +// // { internalType: 'uint8', name: 'v', type: 'uint8' }, +// // { internalType: 'bytes32', name: 'r', type: 'bytes32' }, +// // { internalType: 'bytes32', name: 's', type: 'bytes32' }, +// // ], +// // name: 'delegateBySig', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'delegator', type: 'address' }], +// // name: 'delegates', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'getCurrentVotes', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'account', type: 'address' }, +// // { internalType: 'uint256', name: 'blockNumber', type: 'uint256' }, +// // ], +// // name: 'getPriorVotes', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'addedValue', type: 'uint256' }, +// // ], +// // name: 'increaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'name', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: '', type: 'address' }], +// // name: 'nonces', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: '', type: 'address' }], +// // name: 'numCheckpoints', +// // outputs: [{ internalType: 'uint32', name: '', type: 'uint32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'symbol', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'totalSupply', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transfer', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'sender', type: 'address' }, +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transferFrom', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // ] +// // const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) +// // const response = await contract.methods.balanceOf(address).call() +// // const bal = new BigNumber(response) + +// // setBalance(bal) +// // } else { +// // const abi = [ +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'spender', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Approval', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'previousOwner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'newOwner', type: 'address' }, +// // ], +// // name: 'OwnershipTransferred', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'from', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'to', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Transfer', +// // type: 'event', +// // }, +// // { +// // inputs: [], +// // name: 'DOMAIN_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'owner', type: 'address' }, +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // ], +// // name: 'allowance', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'approve', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'balanceOf', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'decimals', +// // outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'subtractedValue', type: 'uint256' }, +// // ], +// // name: 'decreaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'getOwner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'addedValue', type: 'uint256' }, +// // ], +// // name: 'increaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: '_to', type: 'address' }, +// // { internalType: 'uint256', name: '_amount', type: 'uint256' }, +// // ], +// // name: 'mint', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'uint256', name: 'amount', type: 'uint256' }], +// // name: 'mint', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'name', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'owner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'renounceOwnership', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'symbol', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'totalSupply', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transfer', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'sender', type: 'address' }, +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transferFrom', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }], +// // name: 'transferOwnership', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // ] +// // const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) +// // const response = await contract.methods.balanceOf(address).call() +// // const bal = new BigNumber(response) +// // setBalance(bal) +// // } +// // } + +// // getBalance(account) +// // } catch (error) { +// // console.log(error, 'getBalance') +// // } +// // // eslint-disable-next-line react-hooks/exhaustive-deps +// // }) + +// // console.log(balance.toNumber(), 'bal') +// const formattedBal = balance.toString() +// // console.log(parseFloat(formattedBal), 'formatted') + +// const renderStakeAction = () => { +// return accountHasSharesStaked ? ( +// +// ) : ( +// +// ) +// } + +// return {isLoading ? : renderStakeAction()} +// } + +// export default VaultStakeActions diff --git a/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/index.tsx b/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/index.tsx new file mode 100644 index 0000000..2f6b6c6 --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/VaultCardActions/index.tsx @@ -0,0 +1,700 @@ +import React, { useEffect, useState } from 'react' +// import BigNumber from 'bignumber.js' +// import styled from 'styled-components' +// import { Flex, Text, Box } from '@pancakeswap/uikit' +// import { useWeb3React } from '@web3-react/core' +// import { useTranslation } from 'contexts/Localization' +// import { useCake, useCakeVaultContract, useSoku, useSuteku } from 'hooks/useContract' +// import { getWeb3NoAccount } from 'utils/web3' +// import { getAddress } from 'utils/addressHelpers' +// import { AbiItem } from 'web3-utils' +// import useLastUpdated from 'hooks/useLastUpdated' +// import { Pool } from 'state/types' +// import { BIG_ZERO } from 'utils/bigNumber' +// import VaultApprovalAction from './VaultApprovalAction' +// import VaultStakeActions from './VaultStakeActions' + +// const InlineText = styled(Text)` +// display: inline; +// ` + +// const CakeVaultCardActions: React.FC<{ +// pool: Pool +// accountHasSharesStaked: boolean +// isLoading: boolean +// }> = ({ pool, accountHasSharesStaked, isLoading }) => { +// const { account } = useWeb3React() +// const { stakingToken, userData } = pool +// const { lastUpdated, setLastUpdated } = useLastUpdated() +// const [isVaultApproved, setIsVaultApproved] = useState(false) +// const [balance, setBalance] = useState(new BigNumber(0)) + +// const web3 = getWeb3NoAccount() +// // const cakeContract = useCake() +// const sokuContract = useSoku() +// const sutekuContract = useSuteku() +// const cakeVaultContract = useCakeVaultContract() +// // console.log(cakeVaultContract, 'vault contract') +// const { t } = useTranslation() +// // const stakingTokenBalance = userData?.stakingTokenBalance ? new BigNumber(userData.stakingTokenBalance) : BIG_ZERO + +// // useEffect(() => { +// // const checkApprovalStatus = async () => { +// // try { +// // const response = await sutekuContract.methods.allowance(account, cakeVaultContract.options.address).call() +// // const currentAllowance = new BigNumber(response) +// // setIsVaultApproved(currentAllowance.gt(0)) +// // } catch (error) { +// // console.log(error, 'vault card') +// // setIsVaultApproved(false) +// // } +// // } + +// // checkApprovalStatus() +// // }, [account, sutekuContract, cakeVaultContract, lastUpdated]) + +// // useEffect(() => { +// // try { +// // const getBalance = async (address) => { +// // // If SUTEKU +// // if (stakingToken.address[56] === '0x198800af50914004a9e9d19ca18c0b24587a50cf') { +// // const abi = [ +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'spender', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Approval', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'previousOwner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'newOwner', type: 'address' }, +// // ], +// // name: 'OwnershipTransferred', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'from', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'to', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Transfer', +// // type: 'event', +// // }, +// // { +// // inputs: [], +// // name: 'DOMAIN_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'owner', type: 'address' }, +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // ], +// // name: 'allowance', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'approve', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'balanceOf', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'decimals', +// // outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'subtractedValue', type: 'uint256' }, +// // ], +// // name: 'decreaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'getOwner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'addedValue', type: 'uint256' }, +// // ], +// // name: 'increaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: '_to', type: 'address' }, +// // { internalType: 'uint256', name: '_amount', type: 'uint256' }, +// // ], +// // name: 'mint', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'uint256', name: 'amount', type: 'uint256' }], +// // name: 'mint', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'name', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'owner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { inputs: [], name: 'renounceOwnership', outputs: [], stateMutability: 'nonpayable', type: 'function' }, +// // { +// // inputs: [], +// // name: 'symbol', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'totalSupply', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transfer', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'sender', type: 'address' }, +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transferFrom', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }], +// // name: 'transferOwnership', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // ] +// // const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) +// // const response = await contract.methods.balanceOf(address).call() +// // const bal = new BigNumber(response) +// // setBalance(bal) +// // } else if (stakingToken.address[56] === '0x0e4b5ea0259eb3d66e6fcb7cc8785817f8490a53') { +// // // If SOKU +// // const abi = [ +// // { inputs: [], stateMutability: 'nonpayable', type: 'constructor' }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'spender', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Approval', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'delegator', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'fromDelegate', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'toDelegate', type: 'address' }, +// // ], +// // name: 'DelegateChanged', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'delegate', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'previousBalance', type: 'uint256' }, +// // { indexed: false, internalType: 'uint256', name: 'newBalance', type: 'uint256' }, +// // ], +// // name: 'DelegateVotesChanged', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'from', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'to', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Transfer', +// // type: 'event', +// // }, +// // { +// // inputs: [], +// // name: 'DELEGATION_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'DOMAIN_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'owner', type: 'address' }, +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // ], +// // name: 'allowance', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'approve', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'balanceOf', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: '', type: 'address' }, +// // { internalType: 'uint32', name: '', type: 'uint32' }, +// // ], +// // name: 'checkpoints', +// // outputs: [ +// // { internalType: 'uint32', name: 'fromBlock', type: 'uint32' }, +// // { internalType: 'uint256', name: 'votes', type: 'uint256' }, +// // ], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'decimals', +// // outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'subtractedValue', type: 'uint256' }, +// // ], +// // name: 'decreaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'delegatee', type: 'address' }], +// // name: 'delegate', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'delegatee', type: 'address' }, +// // { internalType: 'uint256', name: 'nonce', type: 'uint256' }, +// // { internalType: 'uint256', name: 'expiry', type: 'uint256' }, +// // { internalType: 'uint8', name: 'v', type: 'uint8' }, +// // { internalType: 'bytes32', name: 'r', type: 'bytes32' }, +// // { internalType: 'bytes32', name: 's', type: 'bytes32' }, +// // ], +// // name: 'delegateBySig', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'delegator', type: 'address' }], +// // name: 'delegates', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'getCurrentVotes', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'account', type: 'address' }, +// // { internalType: 'uint256', name: 'blockNumber', type: 'uint256' }, +// // ], +// // name: 'getPriorVotes', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'addedValue', type: 'uint256' }, +// // ], +// // name: 'increaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'name', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: '', type: 'address' }], +// // name: 'nonces', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: '', type: 'address' }], +// // name: 'numCheckpoints', +// // outputs: [{ internalType: 'uint32', name: '', type: 'uint32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'symbol', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'totalSupply', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transfer', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'sender', type: 'address' }, +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transferFrom', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // ] +// // const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) +// // const response = await contract.methods.balanceOf(address).call() +// // const bal = new BigNumber(response) + +// // setBalance(bal) +// // } else { +// // const abi = [ +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'spender', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Approval', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'previousOwner', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'newOwner', type: 'address' }, +// // ], +// // name: 'OwnershipTransferred', +// // type: 'event', +// // }, +// // { +// // anonymous: false, +// // inputs: [ +// // { indexed: true, internalType: 'address', name: 'from', type: 'address' }, +// // { indexed: true, internalType: 'address', name: 'to', type: 'address' }, +// // { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256' }, +// // ], +// // name: 'Transfer', +// // type: 'event', +// // }, +// // { +// // inputs: [], +// // name: 'DOMAIN_TYPEHASH', +// // outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'owner', type: 'address' }, +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // ], +// // name: 'allowance', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'approve', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'account', type: 'address' }], +// // name: 'balanceOf', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'decimals', +// // outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'subtractedValue', type: 'uint256' }, +// // ], +// // name: 'decreaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'getOwner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'spender', type: 'address' }, +// // { internalType: 'uint256', name: 'addedValue', type: 'uint256' }, +// // ], +// // name: 'increaseAllowance', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: '_to', type: 'address' }, +// // { internalType: 'uint256', name: '_amount', type: 'uint256' }, +// // ], +// // name: 'mint', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'uint256', name: 'amount', type: 'uint256' }], +// // name: 'mint', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'name', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'owner', +// // outputs: [{ internalType: 'address', name: '', type: 'address' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'renounceOwnership', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'symbol', +// // outputs: [{ internalType: 'string', name: '', type: 'string' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [], +// // name: 'totalSupply', +// // outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], +// // stateMutability: 'view', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transfer', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [ +// // { internalType: 'address', name: 'sender', type: 'address' }, +// // { internalType: 'address', name: 'recipient', type: 'address' }, +// // { internalType: 'uint256', name: 'amount', type: 'uint256' }, +// // ], +// // name: 'transferFrom', +// // outputs: [{ internalType: 'bool', name: '', type: 'bool' }], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // { +// // inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }], +// // name: 'transferOwnership', +// // outputs: [], +// // stateMutability: 'nonpayable', +// // type: 'function', +// // }, +// // ] +// // const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) +// // const response = await contract.methods.balanceOf(address).call() +// // const bal = new BigNumber(response) +// // setBalance(bal) +// // } +// // } + +// // getBalance(account) +// // } catch (error) { +// // console.log(error, 'getBalance') +// // } +// // // eslint-disable-next-line react-hooks/exhaustive-deps +// // }) + +// return ( +// +// +// +// +// {accountHasSharesStaked ? stakingToken.symbol : t('Stake')}{' '} +// +// +// {accountHasSharesStaked ? t('Staked (compounding)') : `${stakingToken.symbol}`} +// +// +// {isVaultApproved ? ( +// +// ) : ( +// +// )} +// +// +// ) +// } + +// export default CakeVaultCardActions diff --git a/src/views/OldFarms/components/CakeVaultCard/VaultStakeModal.tsx b/src/views/OldFarms/components/CakeVaultCard/VaultStakeModal.tsx new file mode 100644 index 0000000..5f5fc4a --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/VaultStakeModal.tsx @@ -0,0 +1,261 @@ +import React, { useState, useEffect } from 'react' +// import styled from 'styled-components' +// import { Modal, Text, Flex, Image, Button, BalanceInput, AutoRenewIcon, Link } from '@pancakeswap/uikit' +// import { useTranslation } from 'contexts/Localization' +// import { useWeb3React } from '@web3-react/core' +// import { BASE_EXCHANGE_URL } from 'config' +// import { AbiItem } from 'web3-utils' +// import { useAppDispatch } from 'state' +// import { BIG_TEN } from 'utils/bigNumber' +// import Slider from 'components/Slider' +// import { useCakeVault, usePriceCakeBusd, useBusdPriceFromToken, useTokenPrice, usePriceBnbSuteku } from 'state/hooks' +// import { getWeb3NoAccount } from 'utils/web3' +// import { getAddress } from 'utils/addressHelpers' +// import { useCakeVaultContract } from 'hooks/useContract' +// import useTheme from 'hooks/useTheme' +// import useWithdrawalFeeTimer from 'hooks/cakeVault/useWithdrawalFeeTimer' +// import BigNumber from 'bignumber.js' +// import { getFullDisplayBalance, formatNumber, getDecimalAmount } from 'utils/formatBalance' +// import useToast from 'hooks/useToast' +// import { fetchCakeVaultUserData } from 'state/pools' +// import { Pool } from 'state/types' +// import PercentageButton from './PercentageButton' +// import { convertCakeToShares } from '../../helpers' +// import FeeSummary from './FeeSummary' + +// interface VaultStakeModalProps { +// pool: Pool +// stakingMax: BigNumber +// // eslint-disable-next-line react/require-default-props +// isRemovingStake?: boolean +// // eslint-disable-next-line react/require-default-props +// onDismiss?: () => void +// } + +// const StyledButton = styled(Button)` +// flex-grow: 1; +// ` + +// const StyledLink = styled(Link)` +// width: 100%; +// ` + +// const VaultStakeModal: React.FC = ({ pool, stakingMax, isRemovingStake = false, onDismiss }) => { +// const dispatch = useAppDispatch() +// const [balance, setBalance] = useState(new BigNumber(0)) +// const { stakingToken } = pool +// const sokuPrice = useTokenPrice('sokuswap') +// const sutekuPrice = usePriceBnbSuteku() +// const web3 = getWeb3NoAccount() +// const { account } = useWeb3React() +// const cakeVaultContract = useCakeVaultContract() +// const { +// userData: { lastDepositedTime, userShares }, +// pricePerFullShare, +// } = useCakeVault() +// const { t } = useTranslation() +// const { theme } = useTheme() +// const { toastSuccess, toastError } = useToast() +// const [pendingTx, setPendingTx] = useState(false) +// const [stakeAmount, setStakeAmount] = useState('') +// const [staked, setStaked] = useState(0) +// const [percent, setPercent] = useState(0) +// const { hasUnstakingFee } = useWithdrawalFeeTimer(parseInt(lastDepositedTime, 10), userShares) +// const cakePriceBusd = usePriceCakeBusd() +// const stakingTokenPrice = +// stakingToken.address[56] === '0x198800aF50914004A9E9D19cA18C0b24587a50cf' ? sutekuPrice : sokuPrice +// const usdValueStaked = stakeAmount && formatNumber(new BigNumber(stakeAmount).times(stakingTokenPrice).toNumber()) + +// const handleStakeInputChange = (input: string) => { +// if (input) { +// const convertedInput = new BigNumber(input).multipliedBy(BIG_TEN.pow(stakingToken.decimals)) +// const percentage = Math.floor(convertedInput.dividedBy(stakingMax).multipliedBy(100).toNumber()) +// setPercent(percentage > 100 ? 100 : percentage) +// } else { +// setPercent(0) +// } +// setStakeAmount(input) +// } + +// const handleChangePercent = (sliderPercent: number) => { +// if (sliderPercent > 0) { +// const percentageOfStakingMax = stakingMax.dividedBy(100).multipliedBy(sliderPercent) +// const amountToStake = getFullDisplayBalance(percentageOfStakingMax, stakingToken.decimals, stakingToken.decimals) +// setStakeAmount(amountToStake) +// } else { +// setStakeAmount('') +// } +// setPercent(sliderPercent) +// } + +// const handleWithdrawal = async (convertedStakeAmount: BigNumber) => { +// setPendingTx(true) +// const shareStakeToWithdraw = convertCakeToShares(convertedStakeAmount, pricePerFullShare) +// // trigger withdrawAll function if the withdrawal will leave 0.000001 CAKE or less +// const triggerWithdrawAllThreshold = new BigNumber(1000000000000) +// const sharesRemaining = userShares.minus(shareStakeToWithdraw.sharesAsBigNumber) +// const isWithdrawingAll = sharesRemaining.lte(triggerWithdrawAllThreshold) + +// if (isWithdrawingAll) { +// cakeVaultContract.methods +// .withdrawAll() +// .send({ from: account }) +// .on('sending', () => { +// setPendingTx(true) +// }) +// .on('receipt', () => { +// toastSuccess(t('Unstaked!'), t('Your earnings have also been harvested to your wallet')) +// setPendingTx(false) +// onDismiss() +// dispatch(fetchCakeVaultUserData({ account })) +// }) +// .on('error', (error) => { +// console.error(error) +// // Remove message from toast before prod +// toastError(t('Error'), t('%error% - Please try again.', { error: error.message })) +// setPendingTx(false) +// }) +// } else { +// cakeVaultContract.methods +// .withdraw(shareStakeToWithdraw.sharesAsBigNumber.toString()) +// // .toString() being called to fix a BigNumber error in prod +// // as suggested here https://github.com/ChainSafe/web3.js/issues/2077 +// .send({ from: account }) +// .on('sending', () => { +// setPendingTx(true) +// }) +// .on('receipt', () => { +// toastSuccess(t('Unstaked!'), t('Your earnings have also been harvested to your wallet')) +// setPendingTx(false) +// onDismiss() +// dispatch(fetchCakeVaultUserData({ account })) +// }) +// .on('error', (error) => { +// console.error(error) +// // Remove message from toast before prod +// toastError(t('Error'), t('%error% - Please try again.', { error: error.message })) +// setPendingTx(false) +// }) +// } +// } + +// const handleDeposit = async (convertedStakeAmount: BigNumber) => { +// cakeVaultContract.methods +// .deposit(convertedStakeAmount.toString()) +// // .toString() being called to fix a BigNumber error in prod +// // as suggested here https://github.com/ChainSafe/web3.js/issues/2077 +// .send({ from: account }) +// .on('sending', () => { +// setPendingTx(true) +// }) +// .on('receipt', () => { +// toastSuccess(t('Staked!'), t('Your funds have been staked in the pool')) +// setPendingTx(false) +// onDismiss() +// dispatch(fetchCakeVaultUserData({ account })) +// }) +// .on('error', (error) => { +// console.error(error) +// // Remove message from toast before prod +// toastError(t('Error'), t('%error% - Please try again.', { error: error.message })) +// setPendingTx(false) +// }) +// } + +// const handleConfirmClick = async () => { +// const convertedStakeAmount = getDecimalAmount(new BigNumber(stakeAmount), stakingToken.decimals) +// setPendingTx(true) +// // unstaking +// if (isRemovingStake) { +// handleWithdrawal(convertedStakeAmount) +// // staking +// } else { +// handleDeposit(convertedStakeAmount) +// } +// } + +// // console.log(stakingMax, 'stakingMax') + +// return ( +// +// +// {isRemovingStake ? t('Unstake') : t('Stake')}: +// +// {/* {stakingToken.symbol} */} +// {stakingToken.symbol === 'SOKU' ? ( +// {stakingToken.symbol} +// ) : ( +// {stakingToken.symbol} +// )} + +// +// {stakingToken.symbol} +// +// +// +// 0 && `~${usdValueStaked || 0} USD`} +// style={{ background: 'rgb(239 238 238 / 79%)', border: 'none' }} +// /> +// +// {t('Balance: %balance%', { +// balance: getFullDisplayBalance(isRemovingStake ? new BigNumber(staked) : stakingMax, stakingToken.decimals), +// })} +// +// +// +// handleChangePercent(25)}>25% +// handleChangePercent(50)}>50% +// handleChangePercent(75)}>75% +// handleChangePercent(isRemovingStake ? 100 : 99.99)}>MAX +// +// {isRemovingStake && hasUnstakingFee && ( +// +// )} +// +// {!isRemovingStake && ( +// +// +// +// )} +// +// ) +// } + +// export default VaultStakeModal diff --git a/src/views/OldFarms/components/CakeVaultCard/WithdrawalFeeTimer.tsx b/src/views/OldFarms/components/CakeVaultCard/WithdrawalFeeTimer.tsx new file mode 100644 index 0000000..47c42db --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/WithdrawalFeeTimer.tsx @@ -0,0 +1,13 @@ +import React from 'react' +import { Text } from '@pancakeswap/uikit' +import getTimePeriods from 'utils/getTimePeriods' +import { useTranslation } from 'contexts/Localization' + +const WithdrawalFeeTimer: React.FC<{ secondsRemaining: number }> = ({ secondsRemaining }) => { + const { t } = useTranslation() + const { days, hours, minutes } = getTimePeriods(secondsRemaining) + + return {t('%day%d : %hour%h : %minute%m', { day: days, hour: hours, minute: minutes })} +} + +export default WithdrawalFeeTimer diff --git a/src/views/OldFarms/components/CakeVaultCard/index.tsx b/src/views/OldFarms/components/CakeVaultCard/index.tsx new file mode 100644 index 0000000..3355c32 --- /dev/null +++ b/src/views/OldFarms/components/CakeVaultCard/index.tsx @@ -0,0 +1,97 @@ +import React, { useState, useEffect } from 'react' +// import styled from 'styled-components' +// import { Box, CardBody, Flex, Text, useMatchBreakpoints } from '@pancakeswap/uikit' +// import { useTranslation } from 'contexts/Localization' +// import { useWeb3React } from '@web3-react/core' +// import UnlockButton from 'components/UnlockButton' +// import { useCakeVault } from 'state/hooks' +// import { Pool } from 'state/types' +// import { getWeb3NoAccount } from 'utils/web3' +// import { getAddress } from 'utils/addressHelpers' +// import { AbiItem } from 'web3-utils' +// import AprRow from '../PoolCard/AprRow' +// import { StyledCard, StyledCardInner } from '../PoolCard/StyledCard' +// import CardFooter from '../PoolCard/CardFooter' +// import StyledCardHeader from '../PoolCard/StyledCardHeader' +// import VaultCardActions from './VaultCardActions' +// import UnstakingFeeCountdownRow from './UnstakingFeeCountdownRow' +// import RecentCakeProfitRow from './RecentCakeProfitRow' + +// const StyledCardBody = styled(CardBody)<{ isLoading: boolean }>` +// min-height: ${({ isLoading }) => (isLoading ? '0' : '254px')}; +// ` + +// interface CakeVaultProps { +// pool: Pool +// showStakedOnly: boolean +// } + +// const CakeVaultCard: React.FC = ({ pool, showStakedOnly }) => { +// // console.log('pool', pool) +// const [loading, setLoading] = useState(false) +// const [userDetails, setUserDetails] = useState() +// const web3 = getWeb3NoAccount() +// const { t } = useTranslation() +// const { isXl } = useMatchBreakpoints() +// const { account } = useWeb3React() +// const { +// userData: { userShares, isLoading: isVaultUserDataLoading }, +// fees: { performanceFee }, +// } = useCakeVault() + +// // Estimate & manual for now. 288 = once every 5 mins. We can change once we have a better sense of this +// const timesCompoundedDaily = 288 +// const accountHasSharesStaked = userShares && userShares.gt(0) +// // console.log(pool, 'pool') +// const isLoading = !pool.userData || isVaultUserDataLoading +// const isVault = true +// const performanceFeeAsDecimal = performanceFee && performanceFee / 100 + +// if (showStakedOnly && !accountHasSharesStaked) { +// return null +// } + +// return ( +// +// +// +// +// +// +// +// +// +// +// +// +// {account ? ( +// +// ) : ( +// <> +// +// {t('Start earning')} +// +// +// +// )} +// +// +// +// +// +// ) +// } + +// export default CakeVaultCard diff --git a/src/views/OldFarms/components/PoolCard/AprRow.tsx b/src/views/OldFarms/components/PoolCard/AprRow.tsx new file mode 100644 index 0000000..453a749 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/AprRow.tsx @@ -0,0 +1,135 @@ +import React, { useState, useEffect } from 'react' +import { Flex, TooltipText, IconButton, useModal, CalculateIcon, Skeleton, useTooltip } from '@pancakeswap/uikit' +import Web3 from 'web3' +import { useTranslation } from 'contexts/Localization' +import { getBalanceNumber } from 'utils/formatBalance' +import { getPoolApr } from 'utils/apr' +import { AbiItem } from 'web3-utils' +import { tokenEarnedPerThousandDollarsCompounding, getRoi } from 'utils/compoundApyHelpers' +import { useLpTokenPriceV2, usePriceSodatsuEth, usePriceSokuEth } from 'state/hooks' +import Balance from 'components/Balance' +import ApyCalculatorModal from 'components/ApyCalculatorModal' +import AprCalculatorModal from 'components/AprCalculatorModal' +import { Pool } from 'state/types' +import { BASE_EXCHANGE_URL } from 'config' +import { getWeb3NoAccount } from 'utils/web3' +import { BIG_ZERO } from 'utils/bigNumber' +import BigNumber from 'bignumber.js' + +/* eslint-disable react/require-default-props */ +interface AprRowProps { + pool: Pool + isAutoVault?: boolean + compoundFrequency?: number + performanceFee?: number + rewardPerBlock?: string +} + +const AprRow: React.FC = ({ + pool, + isAutoVault = false, + compoundFrequency = 1, + performanceFee = 0, + rewardPerBlock, +}) => { + const { t } = useTranslation() + const { stakingToken, earningToken, totalStaked, isFinished, tokenPerBlock } = pool + + const tooltipContent = isAutoVault + ? t('APY includes compounding, APR doesn’t. This pool’s SOKU is compounded automatically, so we show APY.') + : t('This farm’s rewards aren’t compounded automatically, so we show APR') + + const { targetRef, tooltip, tooltipVisible } = useTooltip(tooltipContent, { placement: 'bottom-start' }) + + const sodatsuPrice = usePriceSodatsuEth() + const sokuPrice = usePriceSokuEth() + + const farmLpToken = pool.stakingToken + const earningTokenPrice = pool.earningToken.symbol === 'SOKU' ? sokuPrice : sodatsuPrice + const earningTokenPriceAsNumber = parseFloat(earningTokenPrice.toString()) ?? 0 + + const stakingLpPrice = useLpTokenPriceV2(`${farmLpToken.symbol} LP`) + const stakingLpPriceAsNumber = parseFloat(stakingLpPrice.toString()) ?? 0 + + const apr = getPoolApr( + stakingLpPriceAsNumber, + earningTokenPriceAsNumber, + getBalanceNumber(totalStaked, stakingToken.decimals), + parseFloat(rewardPerBlock), + ) + + // special handling for tokens like tBTC or BIFI where the daily token rewards for $1000 dollars will be less than 0.001 of that token + const isHighValueToken = Math.round(earningTokenPriceAsNumber / 1000) > 0 + const roundingDecimals = isHighValueToken ? 4 : 2 + + const earningsPercentageToDisplay = () => { + if (isAutoVault) { + const oneThousandDollarsWorthOfToken = 1000 / earningTokenPriceAsNumber + const tokenEarnedPerThousand365D = tokenEarnedPerThousandDollarsCompounding({ + numberOfDays: 365, + farmApr: apr, + tokenPrice: earningTokenPriceAsNumber, + roundingDecimals, + compoundFrequency, + performanceFee, + }) + return getRoi({ + amountEarned: tokenEarnedPerThousand365D, + amountInvested: oneThousandDollarsWorthOfToken, + }) + } + return apr + } + + const apyModalLink = stakingToken.address && `${BASE_EXCHANGE_URL}/#/swap?outputCurrency=${stakingToken.address[1]}` + + const [onPresentApyModal] = useModal( + , + ) + + const [onPresentAprModal] = useModal( + , + ) + + return ( + <> + + {tooltipVisible && tooltip} + {isAutoVault ? `${t('APY')}:` : `${t('APR')}:`} + {isFinished || !apr ? ( + + ) : ( + + + + )} + + + ) +} + +export default AprRow diff --git a/src/views/OldFarms/components/PoolCard/CardActions/ApprovalAction.tsx b/src/views/OldFarms/components/PoolCard/CardActions/ApprovalAction.tsx new file mode 100644 index 0000000..42452a6 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/CardActions/ApprovalAction.tsx @@ -0,0 +1,77 @@ +import React, { useState, useCallback } from 'react' +import { Button, AutoRenewIcon, Skeleton } from '@pancakeswap/uikit' +import { useSousApproveFarms } from 'hooks/useApprove' +import { useTranslation } from 'contexts/Localization' +import { useERC20 } from 'hooks/useContract' +import useToast from 'hooks/useToast' +import { getAddress } from 'utils/addressHelpers' +import { Pool } from 'state/types' +import { ToastSuccess, ToastError } from 'style/Toasts' +import { toast } from 'react-toastify' + +/* eslint-disable react/require-default-props */ +interface ApprovalActionProps { + pool: Pool + isLoading?: boolean + approved: boolean +} + +const ApprovalAction: React.FC = ({ pool, isLoading = false, approved }) => { + const { sousId, stakingToken, earningToken } = pool + const { t } = useTranslation() + const stakingTokenContract = useERC20(stakingToken.address ? getAddress(stakingToken.address) : '') + const [requestedApproval, setRequestedApproval] = useState(false) + const { onApprove } = useSousApproveFarms(stakingTokenContract, sousId) + const { toastSuccess, toastError } = useToast() + + const handleApprove = useCallback(async () => { + try { + setRequestedApproval(true) + const txHash = await onApprove() + if (txHash) { + toast.success( + ToastSuccess( + t('Contract Enabled'), + t('You can now stake in the %symbol% farm!', { symbol: stakingToken.symbol }), + ), + ) + + setRequestedApproval(false) + } else { + // user rejected tx or didn't go thru + toast.error( + ToastError( + t('Error'), + t('Please try again. Confirm the transaction and make sure you are paying enough gas!'), + ), + ) + setRequestedApproval(false) + } + } catch (e) { + console.error(e) + toast.error(ToastError(t('Error'), 'An error has occured')) + } + }, [onApprove, setRequestedApproval, t, stakingToken]) + + return ( + <> + {isLoading ? ( + + ) : ( + + )} + + ) +} + +export default ApprovalAction diff --git a/src/views/OldFarms/components/PoolCard/CardActions/HarvestActions.tsx b/src/views/OldFarms/components/PoolCard/CardActions/HarvestActions.tsx new file mode 100644 index 0000000..0442c20 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/CardActions/HarvestActions.tsx @@ -0,0 +1,145 @@ +import React, { useState, useEffect, useCallback } from 'react' +import { Flex, Text, Button, Heading, useModal, Skeleton } from '@pancakeswap/uikit' +import Web3 from 'web3' +import BigNumber from 'bignumber.js' +import { Token } from 'config/constants/types' +import { Pool } from 'state/types' +import { getWeb3NoAccount } from 'utils/web3' +import { useWeb3React } from '@web3-react/core' +import { AbiItem } from 'web3-utils' +import { toast } from 'react-toastify' +import { ToastError } from 'style/Toasts' +import { getAddress } from 'utils/addressHelpers' +import { useTranslation } from 'contexts/Localization' +import { getFullDisplayBalance, getBalanceNumber, formatNumber } from 'utils/formatBalance' +import { usePriceSutekuEth, usePriceHobiEth } from 'state/hooks' +import useToast from 'hooks/useToast' +import Balance from 'components/Balance' +import CollectModal from '../Modals/CollectModal' +import { BIG_TEN } from '../../../../../utils/bigNumber' + +/* eslint-disable react/require-default-props */ +interface HarvestActionsProps { + pool: Pool + earnings?: BigNumber + earningToken: Token + sousId: number + isBnbPool: boolean + isLoading?: boolean + lockTime?: any +} + +const HarvestActions: React.FC = ({ + earnings, + earningToken, + sousId, + isBnbPool, + pool, + isLoading = false, + lockTime, +}) => { + const { t } = useTranslation() + // const [lockTime, setLockTime] = useState() + const [loading, setLoading] = useState(false) + const earningTokenBalance = getBalanceNumber(earnings, earningToken.decimals) + const formattedBalance = formatNumber(earningTokenBalance, 3, 3) + const web3 = getWeb3NoAccount() + + // const sutekuPrice = usePriceSutekuEth() + // const hobiPrice = usePriceHobiEth() + + const isSuteku = earningToken.symbol === 'SUTEKU' + + const earningTokenPrice = 0 + + const earningTokenPriceAsNumber = parseFloat(earningTokenPrice.toString()) + + const earningTokenDollarBalance = new BigNumber( + parseFloat(earnings.toString()) * earningTokenPriceAsNumber, + ).dividedBy(BIG_TEN.pow(earningToken.decimals)) + + const earningsDollarValue = formatNumber(earningTokenDollarBalance.toNumber()) + const formattedEarnings = web3.utils.fromWei(earnings.toString(), 'ether') + + const fullBalance = getFullDisplayBalance(earnings, earningToken.decimals) + const hasEarnings = parseFloat(earnings.toString()) > 0 + const isCompoundPool = sousId === 0 + + const [onPresentCollect] = useModal( + , + ) + + return ( + + + + {isLoading ? ( + + ) : ( + <> + {hasEarnings ? ( + + ) : ( + 0 + )} + {/* {earningTokenPriceAsNumber && ( + + {hasEarnings ? ( + + ) : ( + '0 USD' + )} + + )} */} + + )} + + + + + + + ) +} + +export default HarvestActions diff --git a/src/views/OldFarms/components/PoolCard/CardActions/StakeActions.tsx b/src/views/OldFarms/components/PoolCard/CardActions/StakeActions.tsx new file mode 100644 index 0000000..9fbdea9 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/CardActions/StakeActions.tsx @@ -0,0 +1,171 @@ +import React, { useState, useEffect, useCallback } from 'react' +import { Flex, Text, Button, IconButton, AddIcon, MinusIcon, useModal, Skeleton, useTooltip } from '@pancakeswap/uikit' +import { useWeb3React } from '@web3-react/core' +import Web3 from 'web3' +import { AbiItem } from 'web3-utils' +import { getAddress } from 'utils/addressHelpers' +import { getWeb3NoAccount } from 'utils/web3' +import BigNumber from 'bignumber.js' +import { useTranslation } from 'contexts/Localization' +import { getBalanceNumber } from 'utils/formatBalance' +import { Pool } from 'state/types' +import { useLpTokenPriceV2 } from 'state/hooks' +import { getUserPoolData } from 'state/pools' +import useRefresh from 'hooks/useRefresh' +import Balance from 'components/Balance' +import NotEnoughTokensModal from '../Modals/NotEnoughTokensModal' +import StakeModal from '../Modals/StakeModal' +import { BIG_TEN, BIG_ZERO } from '../../../../../utils/bigNumber' + +/* eslint-disable react/require-default-props */ +interface StakeActionsProps { + pool: Pool + stakingTokenBalance: BigNumber + stakedBalance: BigNumber + isBnbPool: boolean + isStaked: ConstrainBoolean + isLoading?: boolean + lockTime?: any +} + +const StakeAction: React.FC = ({ + pool, + stakingTokenBalance, + stakedBalance, + isBnbPool, + isStaked, + isLoading = false, + lockTime, +}) => { + const { stakingToken, stakingLimit, isFinished, userData, contractAddress } = pool + // const [lockTime, setLockTime] = useState() + const [userInfo, setUserInfo] = useState({}) + const { account } = useWeb3React() + const { t } = useTranslation() + const web3 = getWeb3NoAccount() + + const stakedTokenBalance = getBalanceNumber(stakedBalance, stakingToken.decimals) + + const farmLpToken = pool.stakingToken + const stakingLpPrice = useLpTokenPriceV2(`${farmLpToken.symbol} LP`) + const stakingLpPriceAsNumber = stakingLpPrice ? Number(stakingLpPrice) : 0 + + const [onPresentTokenRequired] = useModal() + + const [onPresentStake] = useModal( + , + ) + + const [onPresentUnstake] = useModal( + , + ) + + const { targetRef, tooltip, tooltipVisible } = useTooltip( + t('You’ve already staked the maximum amount you can stake in this farm!'), + { placement: 'bottom' }, + ) + + // console.log(tempStakingDollarBalance, 'tempStakingDollarBalance') + + const reachStakingLimit = stakingLimit.gt(0) && userData.stakedBalance.gte(stakingLimit) + + const renderStakeAction = () => { + return isStaked ? ( + + + <> + + {/* {stakingLpPriceAsNumber !== 0 && ( + + + + )} */} + + + + {/* Disable withdraw/unstake if there is still lock time */} + {(pool.poolCategory === '30DayLock' && lockTime !== '0' && !pool.isFinished) || + (pool.poolCategory === '60DayLock' && lockTime !== '0' && !pool.isFinished) || + (pool.poolCategory === '90DayLock' && lockTime !== '0' && !pool.isFinished) ? ( + + + + ) : ( + + + + )} + + {reachStakingLimit ? ( + + + + + + ) : ( + + + + )} + + {tooltipVisible && tooltip} + + ) : ( + + ) + } + + return {isLoading ? : renderStakeAction()} +} + +export default StakeAction diff --git a/src/views/OldFarms/components/PoolCard/CardActions/index.tsx b/src/views/OldFarms/components/PoolCard/CardActions/index.tsx new file mode 100644 index 0000000..5944422 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/CardActions/index.tsx @@ -0,0 +1,102 @@ +import BigNumber from 'bignumber.js' +import React, { useState, useEffect } from 'react' +import Web3 from 'web3' +import styled from 'styled-components' +import { BIG_ZERO } from 'utils/bigNumber' +import { Flex, Text, Box } from '@pancakeswap/uikit' +import { useTranslation } from 'contexts/Localization' +import { PoolCategory } from 'config/constants/types' +import { AbiItem } from 'web3-utils' +import { getWeb3NoAccount } from 'utils/web3' +import { useWeb3React } from '@web3-react/core' +import { getAddress } from 'utils/addressHelpers' +import { Pool } from 'state/types' +import ApprovalAction from './ApprovalAction' +import StakeActions from './StakeActions' +import HarvestActions from './HarvestActions' + +const InlineText = styled(Text)` + display: inline; +` + +interface CardActionsProps { + pool: Pool + stakedAmount: number + reward: BigNumber + stakingTokenBalance: BigNumber + lockTime: any + isApproved: boolean +} + +const CardActions: React.FC = ({ + pool, + stakedAmount, + reward, + stakingTokenBalance, + lockTime, + isApproved, +}) => { + const { sousId, stakingToken, earningToken, harvest, poolCategory, userData } = pool + + const { account } = useWeb3React() + // Pools using native BNB behave differently than pools using a token + const isBnbPool = poolCategory === PoolCategory.BINANCE + const { t } = useTranslation() + const allowance = userData?.allowance ? new BigNumber(userData.allowance) : BIG_ZERO + // const stakingTokenBalance = userData?.stakingTokenBalance ? new BigNumber(userData.stakingTokenBalance) : BIG_ZERO + // const earnings = userData?.pendingReward ? new BigNumber(userData.pendingReward) : BIG_ZERO + const needsApproval = !isApproved && !isBnbPool + const isStaked = stakedAmount > 0 + const isLoading = !userData + + return ( + + + {harvest && ( + <> + + + {`${earningToken.symbol} `} + + + {t('Earned')} + + + + + )} + + + {isStaked ? stakingToken.symbol : t('Stake')}{' '} + + + {isStaked ? t('Staked') : `${stakingToken.symbol} LP`} + + + {needsApproval ? ( + + ) : ( + + )} + + + ) +} + +export default CardActions diff --git a/src/views/OldFarms/components/PoolCard/CardFooter/ExpandedFooter.tsx b/src/views/OldFarms/components/PoolCard/CardFooter/ExpandedFooter.tsx new file mode 100644 index 0000000..0274a20 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/CardFooter/ExpandedFooter.tsx @@ -0,0 +1,278 @@ +import React, { useState, useEffect, useCallback } from 'react' +import Web3 from 'web3' +import BigNumber from 'bignumber.js' +import styled from 'styled-components' +import { getBalanceNumber } from 'utils/formatBalance' +import { useTranslation } from 'contexts/Localization' +import { + Flex, + MetamaskIcon, + Text, + TooltipText, + LinkExternal, + TimerIcon, + Skeleton, + useTooltip, + Button, +} from '@pancakeswap/uikit' +import LockClockIcon from '@mui/icons-material/LockClock' +import { BASE_ETHER_SCAN_URL, BASE_URL } from 'config' +import { useBlock, useCakeVault, useLpTokenPriceV2 } from 'state/hooks' +import { Pool } from 'state/types' +import { getAddress } from 'utils/addressHelpers' +import { registerToken } from 'utils/wallet' +import Balance from 'components/Balance' +import { getWeb3NoAccount } from 'utils/web3' +import { AbiItem } from 'web3-utils' +import { BIG_ZERO } from 'utils/bigNumber' +import useRefresh from 'hooks/useRefresh' + +/* eslint-disable react/require-default-props */ +interface ExpandedFooterProps { + pool: Pool + account: string + isAutoVault?: boolean + lockTime?: any + stakedAmount?: number +} + +const ExpandedWrapper = styled(Flex)` + svg { + height: 14px; + width: 14px; + } +` + +const ExpandedFooter: React.FC = ({ + pool, + account, + isAutoVault = false, + lockTime, + stakedAmount, +}) => { + const { t } = useTranslation() + const web3 = getWeb3NoAccount() + // const newWeb3 = new Web3(Web3.givenProvider) + const { currentBlock } = useBlock() + const { + totalCakeInVault, + fees: { performanceFee }, + } = useCakeVault() + + const { stakingToken, earningToken, totalStaked, startBlock, endBlock, isFinished, contractAddress, sousId } = pool + + const farmLpToken = pool.stakingToken + const stakingLpPrice = useLpTokenPriceV2(`${farmLpToken.symbol} LP`) + + const stakingLpPriceAsNumber = stakingLpPrice ? parseFloat(stakingLpPrice?.toString()) : 0 + + const formattedTotalStaked = totalStaked ? web3.utils.fromWei(totalStaked?.toString(), 'ether') : BIG_ZERO + + const totalStakedAsNumber = parseFloat(formattedTotalStaked.toString()) + + const liquidity = totalStakedAsNumber * stakingLpPriceAsNumber + + const tokenAddress = earningToken.address ? getAddress(earningToken.address) : '' + const poolContractAddress = getAddress(contractAddress) + const cakeVaultContractAddress = '0x0' + const imageSrc = `${BASE_URL}/images/tokens/${earningToken.symbol.toLowerCase()}.png` + const isMetaMaskInScope = !!(window as WindowChain).ethereum?.isMetaMask + const isManualCakePool = sousId === 0 + const shouldShowBlockCountdown = Boolean(!isFinished && startBlock && endBlock) + const blocksUntilStart = Math.max(startBlock - currentBlock, 0) + const blocksRemaining = Math.max(endBlock - currentBlock, 0) + + const remainingLock = () => { + let remaining + if (lockTime) { + remaining = parseInt(currentBlock?.toString()) + parseInt(lockTime?.toString()) + } + + return remaining + } + // console.log(currentBlock) + + const hasPoolStarted = blocksUntilStart === 0 && blocksRemaining > 0 + + const { targetRef, tooltip, tooltipVisible } = useTooltip( + t('Subtracted automatically from each yield harvest and burned.'), + { placement: 'bottom-start' }, + ) + + const getTotalStakedBalance = () => { + if (isAutoVault) { + return getBalanceNumber(totalCakeInVault, stakingToken.decimals) + } + if (isManualCakePool) { + const manualCakeTotalMinusAutoVault = new BigNumber(totalStaked).minus(totalCakeInVault) + return getBalanceNumber(manualCakeTotalMinusAutoVault, stakingToken.decimals) + } + return getBalanceNumber(totalStaked, stakingToken.decimals) + } + + return ( + + + {t('Total Liquidity')}: + + {liquidity ? ( + + $ + + + ) : ( + + )} + + + {/* + {t('Total staked')}: + + {totalStaked ? ( + <> + + + {stakingToken.symbol} LP + + + ) : ( + + )} + + */} + {shouldShowBlockCountdown && ( + <> + + {hasPoolStarted ? t('End') : t('Start')}: + + {blocksRemaining || blocksUntilStart ? ( + + ) : ( + + )} + {hasPoolStarted ? ( + + {t('Blocks')} + + ) : ( + + {t('Blocks')} + + )} + + + + + + )} + {(pool.poolCategory === '30DayLock' || + pool.poolCategory === '60DayLock' || + pool.poolCategory === '90DayLock') && ( + <> + + Lock Time: + + {blocksRemaining || blocksUntilStart ? ( + 0 ? lockTime : 0} decimals={0} /> + ) : ( + + )} + {lockTime > 0 && stakedAmount > 0 ? ( + + {t('Blocks')} + + ) : ( + + {t('Blocks')} + + )} + + + + + )} + + {isAutoVault && ( + + {tooltipVisible && tooltip} + + {t('Performance Fee')} + + + + {performanceFee / 100}% + + + + )} + + + {t('View Project Site')} + + + {poolContractAddress && ( + + + {t('View Contract')} + + + )} + {account && isMetaMaskInScope && tokenAddress && ( + + + + )} + + ) +} + +export default React.memo(ExpandedFooter) diff --git a/src/views/OldFarms/components/PoolCard/CardFooter/index.tsx b/src/views/OldFarms/components/PoolCard/CardFooter/index.tsx new file mode 100644 index 0000000..7106d8f --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/CardFooter/index.tsx @@ -0,0 +1,97 @@ +import React, { useState } from 'react' +import BigNumber from 'bignumber.js' +import styled from 'styled-components' +import { useTranslation } from 'contexts/Localization' +import { Flex, CardFooter, ExpandableLabel, HelpIcon, useTooltip, Text } from '@pancakeswap/uikit' +import { Pool } from 'state/types' +import { + CompoundingPoolTag, + ManualPoolTag, + ThirtyDayLockedTag, + SixtyDayLockedTag, + NinetyDayLockedTag, +} from 'components/Tags' +import ExpandedFooter from './ExpandedFooter' + +/* eslint-disable react/require-default-props */ +/* eslint-disable react/no-unused-prop-types */ + +interface FooterProps { + pool: Pool + account: string + isAutoVault?: boolean + totalCakeInVault?: BigNumber + lockTime?: any + stakedAmount?: number +} + +const ExpandableButtonWrapper = styled(Flex)` + align-items: center; + justify-content: space-between; + button { + padding: 0; + } +` + +const Footer: React.FC = ({ pool, account, isAutoVault = false, lockTime, stakedAmount }) => { + const { t } = useTranslation() + const [isExpanded, setIsExpanded] = useState(false) + + const manualTooltipText = t('You must claim and compound your earnings from this farm manually.') + const lockedVaultToolTip = t( + 'Higher payouts than Manual farms, however your tokens will be locked for a certain amount of days from the time they were staked.', + ) + const autoTooltipText = t( + 'Any funds you stake in this farm will be automagically claimed and restaked (compounded) for you.', + ) + + const poolTags = () => { + let tag + if (pool.poolCategory === '30DayLock') { + tag = + } else if (pool.poolCategory === '60DayLock') { + tag = + } else if (pool.poolCategory === '90DayLock') { + tag = + } else { + tag = + } + return tag + } + + const { targetRef, tooltip, tooltipVisible } = useTooltip( + pool.poolCategory === 'Core' ? manualTooltipText : lockedVaultToolTip, + { + placement: 'bottom', + }, + ) + + return ( + + + + {poolTags()} + {/* {isAutoVault ? : } */} + {tooltipVisible && tooltip} + + + + + setIsExpanded(!isExpanded)}> + {isExpanded ? Hide : Details} + + + {isExpanded && ( + + )} + + ) +} + +export default Footer diff --git a/src/views/OldFarms/components/PoolCard/Modals/CollectModal.tsx b/src/views/OldFarms/components/PoolCard/Modals/CollectModal.tsx new file mode 100644 index 0000000..33c3b89 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/Modals/CollectModal.tsx @@ -0,0 +1,166 @@ +import React, { useState, useEffect } from 'react' +import { + Modal, + Text, + Button, + Heading, + Flex, + AutoRenewIcon, + ButtonMenu, + ButtonMenuItem, + HelpIcon, + useTooltip, +} from '@pancakeswap/uikit' +import { useWeb3React } from '@web3-react/core' +import { useTranslation } from 'contexts/Localization' +import useTheme from 'hooks/useTheme' +import { Pool } from 'state/types' +import { AbiItem } from 'web3-utils' +import { getAddress } from 'utils/addressHelpers' +import { getWeb3NoAccount } from 'utils/web3' +import { useSousHarvestFarms } from 'hooks/useHarvest' +import { useSousStakeFarms } from 'hooks/useStake' +import useToast from 'hooks/useToast' +import { Token } from 'config/constants/types' +import useWeb3 from 'hooks/useWeb3' +import { useSousChefV2Farms } from 'hooks/useContract' +import { useSousUnstakeFarms } from 'hooks/useUnstake' +import { ToastError, ToastSuccess } from 'style/Toasts' +import { toast } from 'react-toastify' +import { SmartChefABI } from '../../../helpers' + +/* eslint-disable react/require-default-props */ +interface CollectModalProps { + formattedBalance: string + pool: Pool + fullBalance: string + earningToken: Token + earningsDollarValue: string + sousId: number + isBnbPool: boolean + isCompoundPool?: boolean + onDismiss?: () => void +} + +const CollectModal: React.FC = ({ + formattedBalance, + fullBalance, + earningToken, + earningsDollarValue, + sousId, + pool, + isBnbPool, + isCompoundPool = false, + onDismiss, +}) => { + const { t } = useTranslation() + const { theme } = useTheme() + const { toastSuccess, toastError } = useToast() + const { onReward, claimRewards } = useSousHarvestFarms(sousId, isBnbPool) + const { onUnstake, unStakeInFarm } = useSousUnstakeFarms(sousId, pool.enableEmergencyWithdraw) + const { account } = useWeb3React() + const { onStake } = useSousStakeFarms(sousId, isBnbPool) + const [pendingTx, setPendingTx] = useState(false) + const [shouldCompound, setShouldCompound] = useState(isCompoundPool) + const web3 = useWeb3() + + const { targetRef, tooltip, tooltipVisible } = useTooltip( + <> + {t('Compound: collect and restake SOKU into pool.')} + {t('Claim: collect SOKU and send to wallet')} + , + { placement: 'bottom-end', tooltipOffset: [20, 10] }, + ) + + const handleHarvestConfirm = async () => { + setPendingTx(true) + // compounding + if (shouldCompound) { + try { + await onStake(fullBalance, earningToken.decimals) + toast.success( + ToastSuccess( + `${t('Compounded')}!`, + t('Your %symbol% earnings have been re-invested into the pool!', { symbol: earningToken.symbol }), + ), + ) + setPendingTx(false) + onDismiss() + } catch (e) { + toast.error(ToastError(t('Canceled'), t('Please try again and confirm the transaction.'))) + setPendingTx(false) + } + } else { + // harvesting + try { + await unStakeInFarm('0', earningToken.decimals) + + toast.success( + ToastSuccess( + `${t('Claimed')}!`, + t('Your %symbol% earnings have been sent to your wallet!', { symbol: earningToken.symbol }), + ), + ) + setPendingTx(false) + onDismiss() + } catch (e) { + console.log(e) + toast.error(ToastError(t('Canceled'), t('Please try again and confirm the transaction.'))) + setPendingTx(false) + } + } + } + + return ( + + {isCompoundPool && ( + + setShouldCompound(!index)} + > + {t('Compound')} + {t('Claim')} + + + + + {tooltipVisible && tooltip} + + )} + + + {shouldCompound ? t('Compounding') : t('Claiming')}: + + + {formattedBalance} {earningToken.symbol} + + {/* {`~${earningsDollarValue || 0} USD`} */} + + + + + + + ) +} + +export default CollectModal diff --git a/src/views/OldFarms/components/PoolCard/Modals/NotEnoughTokensModal.tsx b/src/views/OldFarms/components/PoolCard/Modals/NotEnoughTokensModal.tsx new file mode 100644 index 0000000..8fcf69f --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/Modals/NotEnoughTokensModal.tsx @@ -0,0 +1,59 @@ +import React from 'react' +import { useTranslation } from 'contexts/Localization' +import styled from 'styled-components' +import { Modal, Text, Button, OpenNewIcon, Link } from '@pancakeswap/uikit' +import { BASE_EXCHANGE_URL } from 'config' +import useTheme from 'hooks/useTheme' + +/* eslint-disable react/require-default-props */ +interface NotEnoughTokensModalProps { + tokenSymbol: string + onDismiss?: () => void +} + +const StyledText = styled(Text)` + color: #e74c3c !important; +` + +const NotEnoughTokensModal: React.FC = ({ tokenSymbol, onDismiss }) => { + const { t } = useTranslation() + const { theme } = useTheme() + + return ( + + {t('Insufficient %symbol% LP balance', { symbol: tokenSymbol })} + {t('You’ll need %symbol% LP to stake in this farm!', { symbol: tokenSymbol })} + {/* + {t('Get %symbol% LP, or make sure your %symbol% LP isn’t in another farm or LP.', { + symbol: tokenSymbol, + })} + */} + + {/* + + */} + + + ) +} + +export default NotEnoughTokensModal diff --git a/src/views/OldFarms/components/PoolCard/Modals/PercentageButton.tsx b/src/views/OldFarms/components/PoolCard/Modals/PercentageButton.tsx new file mode 100644 index 0000000..6fb72df --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/Modals/PercentageButton.tsx @@ -0,0 +1,23 @@ +import React from 'react' +import styled from 'styled-components' +import { Button } from '@pancakeswap/uikit' + +interface PercentageButtonProps { + onClick: () => void +} + +const StyledButton = styled(Button)` + flex-grow: 1; + background: #04bbfb; + color: #fff; +` + +const PercentageButton: React.FC = ({ children, onClick }) => { + return ( + + {children} + + ) +} + +export default PercentageButton diff --git a/src/views/OldFarms/components/PoolCard/Modals/StakeModal.tsx b/src/views/OldFarms/components/PoolCard/Modals/StakeModal.tsx new file mode 100644 index 0000000..a554d80 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/Modals/StakeModal.tsx @@ -0,0 +1,250 @@ +import React, { useEffect, useState } from 'react' +import styled from 'styled-components' +import { Modal, Text, Flex, Image, Button, BalanceInput, AutoRenewIcon, Link } from '@pancakeswap/uikit' +import Web3 from 'web3' +import { useTranslation } from 'contexts/Localization' +import { BASE_EXCHANGE_URL } from 'config' +import { useSousStakeFarms } from 'hooks/useStake' +import { useSousUnstakeFarms } from 'hooks/useUnstake' +import { ToastError, ToastSuccess } from 'style/Toasts' +import { toast } from 'react-toastify' +import { AbiItem } from 'web3-utils' +import { getAddress } from 'utils/addressHelpers' +import { useWeb3React } from '@web3-react/core' +import { getWeb3NoAccount } from 'utils/web3' +import useTheme from 'hooks/useTheme' +import useToast from 'hooks/useToast' +import BigNumber from 'bignumber.js' +import { getFullDisplayBalance, formatNumber, getDecimalAmount } from 'utils/formatBalance' +import { Pool } from 'state/types' +import Slider from 'components/Slider' +import PercentageButton from './PercentageButton' + +/* eslint-disable react/require-default-props */ +interface StakeModalProps { + isBnbPool: boolean + pool: Pool + stakingTokenBalance: BigNumber + stakedBalance: BigNumber + stakingTokenPrice: number + isRemovingStake?: boolean + onDismiss?: () => void +} + +const StyledLink = styled(Link)` + width: 100%; +` + +const StakeModal: React.FC = ({ + isBnbPool, + pool, + stakingTokenBalance, + stakedBalance, + stakingTokenPrice, + isRemovingStake = false, + onDismiss, +}) => { + const { sousId, stakingToken, userData, stakingLimit, earningToken } = pool + + const { t } = useTranslation() + const { theme } = useTheme() + const { account } = useWeb3React() + const web3 = getWeb3NoAccount() + // const newWeb3 = new Web3(Web3.givenProvider) + + const { onStake, stakeInFarm } = useSousStakeFarms(sousId, isBnbPool) + const { onUnstake, unStakeInFarm } = useSousUnstakeFarms(sousId, pool.enableEmergencyWithdraw) + const { toastSuccess, toastError } = useToast() + const [pendingTx, setPendingTx] = useState(false) + const [stakeAmount, setStakeAmount] = useState('') + const [hasReachedStakeLimit, setHasReachedStakedLimit] = useState(false) + const [percent, setPercent] = useState(0) + + const getCalculatedStakingLimit = () => { + if (isRemovingStake) { + return stakedBalance + } + return stakingLimit.gt(0) && stakingTokenBalance.gt(stakingLimit) ? stakingLimit : stakingTokenBalance + } + + const usdValueStaked = stakeAmount && formatNumber(new BigNumber(stakeAmount).times(stakingTokenPrice).toNumber()) + + useEffect(() => { + if (stakingLimit.gt(0) && !isRemovingStake) { + const fullDecimalStakeAmount = getDecimalAmount(new BigNumber(stakeAmount), stakingToken.decimals) + setHasReachedStakedLimit(fullDecimalStakeAmount.plus(stakedBalance).gt(stakingLimit)) + } + }, [stakeAmount, stakingLimit, stakedBalance, stakingToken, isRemovingStake, setHasReachedStakedLimit]) + + const handleStakeInputChange = (input: string) => { + if (input) { + const convertedInput = getDecimalAmount(new BigNumber(input), stakingToken.decimals) + const percentage = Math.floor(convertedInput.dividedBy(getCalculatedStakingLimit()).multipliedBy(100).toNumber()) + setPercent(Math.min(percentage, 100)) + } else { + setPercent(0) + } + setStakeAmount(parseInt(input).toString()) + } + + const handleChangePercent = (sliderPercent: number) => { + if (sliderPercent > 0) { + const percentageOfStakingMax = new BigNumber(getCalculatedStakingLimit()).div(100).multipliedBy(sliderPercent) + const amountToStake = getFullDisplayBalance(percentageOfStakingMax, stakingToken.decimals) + setStakeAmount(parseFloat(amountToStake).toString()) + } else { + setStakeAmount('') + } + setPercent(sliderPercent) + } + + const handleConfirmClick = async () => { + setPendingTx(true) + + if (isRemovingStake) { + // unstaking + try { + await unStakeInFarm(stakeAmount, stakingToken.decimals) + toastSuccess( + `${t('Unstaked')}!`, + t('Your %symbol% earnings have been automatically sent to your wallet!', { + symbol: earningToken.symbol, + }), + ) + setPendingTx(false) + onDismiss() + } catch (e) { + toast.error(ToastError('Canceled', 'Please try again and confirm the transaction.')) + setPendingTx(false) + } + } else { + try { + // staking + await stakeInFarm(stakeAmount, stakingToken.decimals) + toast.success(ToastSuccess('Staked!', `Your ${stakingToken.symbol} LP tokens have been staked in the pool!`)) + + setPendingTx(false) + onDismiss() + } catch (e) { + toast.error(ToastError('Canceled', 'Please try again and confirm the transaction.')) + setPendingTx(false) + } + } + } + // console.log(web3.utils.fromWei(stakedBalance.toString()), 'staking balance') + + return ( + + {stakingLimit.gt(0) && !isRemovingStake && ( + + {t('Max stake: %amount% %token% LP', { + amount: getFullDisplayBalance(stakingLimit, stakingToken.decimals, 0), + token: stakingToken.symbol, + })} + + )} + + {isRemovingStake ? t('Unstake') : t('Stake')}: + + {/* {stakingToken.symbol} */} + {stakingToken.symbol} + + + {stakingToken.symbol} LP + + + + + {hasReachedStakeLimit && ( + + {t('Maximum total stake: %amount% %token%', { + amount: getFullDisplayBalance(new BigNumber(stakingLimit), stakingToken.decimals, 0), + token: stakingToken.symbol, + })} + + )} + + {t('Balance: %balance%', { + balance: getFullDisplayBalance(new BigNumber(getCalculatedStakingLimit()), stakingToken.decimals), + })} + + {pool.isFinished ? ( + <> + {' '} + + {/* handleChangePercent(25)}>25% + handleChangePercent(50)}>50% + handleChangePercent(75)}>75% */} + handleChangePercent(99.9999)}>MAX + {' '} + + ) : ( + <> + {' '} + + + handleChangePercent(25)}>25% + handleChangePercent(50)}>50% + handleChangePercent(75)}>75% + handleChangePercent(isRemovingStake ? 100 : 99.99)}>MAX + {' '} + + )} + + {!isRemovingStake && ( + + + + )} + + ) +} + +export default StakeModal diff --git a/src/views/OldFarms/components/PoolCard/StyledCard.tsx b/src/views/OldFarms/components/PoolCard/StyledCard.tsx new file mode 100644 index 0000000..b4bbb86 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/StyledCard.tsx @@ -0,0 +1,56 @@ +import styled, { css, keyframes } from 'styled-components' +import { Card, Box } from '@pancakeswap/uikit' + +const PromotedGradient = keyframes` + 0% { + background-position: 50% 0%; + } + 50% { + background-position: 50% 100%; + } + 100% { + background-position: 50% 0%; + } +` + +interface PromotedStyleCardProps { + isDesktop: boolean +} + +export const StyledCard = styled(Card)<{ isPromoted?: PromotedStyleCardProps; isFinished?: boolean }>` + max-width: 352px; + margin: 0 8px 24px; + display: flex; + flex-direction: column; + align-self: baseline; + position: relative; + color: ${({ isFinished, theme }) => theme.colors[isFinished ? 'textDisabled' : 'secondary']}; + box-shadow: 0px 1px 4px rgba(25, 19, 38, 0.15); + + ${({ isPromoted, theme }) => + isPromoted + ? css` + background: linear-gradient(180deg, ${theme.colors.primaryBright}, ${theme.colors.secondary}); + padding: 1px 1px 3px 1px; + background-size: 400% 400%; + ` + : `background: ${(props) => props.theme.card.background};`} + + ${({ isPromoted }) => + isPromoted && + isPromoted.isDesktop && + css` + animation: ${PromotedGradient} 3s ease infinite; + `} + + ${({ theme }) => theme.mediaQueries.sm} { + margin: 0 12px 46px; + } +` + +export const StyledCardInner = styled(Box)<{ isPromotedPool?: boolean }>` + background: #ecf1f8; + border-radius: ${({ isPromotedPool, theme }) => (isPromotedPool ? '31px' : theme.radii.card)}; +` + +export default StyledCard diff --git a/src/views/OldFarms/components/PoolCard/StyledCardHeader.tsx b/src/views/OldFarms/components/PoolCard/StyledCardHeader.tsx new file mode 100644 index 0000000..25b8957 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/StyledCardHeader.tsx @@ -0,0 +1,87 @@ +import React from 'react' +import { CardHeader, Heading, Text, Flex, Image } from '@pancakeswap/uikit' +import { Pool } from 'state/types' +import styled from 'styled-components' +import { useTranslation } from 'contexts/Localization' + +const Wrapper = styled(CardHeader)<{ isFinished?: boolean; background?: string; isPromotedPool?: boolean }>` + background: ${({ isFinished, background, theme }) => (isFinished ? theme.colors.backgroundDisabled : '#f9f9fa')}; + border-radius: 7px 7px 0 0; +` + +/* eslint-disable react/require-default-props */ +const StyledCardHeader: React.FC<{ + earningTokenSymbol: string + stakingTokenSymbol: string + isAutoVault?: boolean + isFinished?: boolean + isStaking?: boolean + isPromotedPool?: boolean + pool: Pool +}> = ({ + earningTokenSymbol, + stakingTokenSymbol, + pool, + isFinished = false, + isAutoVault = false, + isStaking = false, + isPromotedPool = false, +}) => { + const { t } = useTranslation() + const poolImageSrc = isAutoVault + ? `cake-cakevault.svg` + : `${earningTokenSymbol}-${stakingTokenSymbol}.svg`.toLocaleLowerCase() + const isSokuPool = earningTokenSymbol === 'SOKU' && stakingTokenSymbol === 'SOKU' + const background = isStaking ? 'bubblegum' : 'cardHeader' + const farmImage = `${stakingTokenSymbol}.png`.toLocaleLowerCase() + + const getHeadingPrefix = () => { + if (isAutoVault) { + // vault + return t('Auto') + } + if (isSokuPool) { + // manual soku + return t('Manual') + } + // all other pools + return t('Earn') + } + + const getSubHeading = () => { + if (isAutoVault) { + return t('Automatic restaking') + } + if (isSokuPool) { + return t('Earn SOKU, stake SOKU') + } + return t('%symbol%', { symbol: stakingTokenSymbol }) + } + + return ( + + + + + {getSubHeading()} + + {`${getHeadingPrefix()} ${earningTokenSymbol}`} + + {stakingTokenSymbol} + + + ) +} + +export default StyledCardHeader diff --git a/src/views/OldFarms/components/PoolCard/index.tsx b/src/views/OldFarms/components/PoolCard/index.tsx new file mode 100644 index 0000000..82d1646 --- /dev/null +++ b/src/views/OldFarms/components/PoolCard/index.tsx @@ -0,0 +1,1037 @@ +import BigNumber from 'bignumber.js' +import React, { useState, useEffect } from 'react' +import { CardBody, Flex, Text, CardRibbon } from '@pancakeswap/uikit' +import UnlockButton from 'components/UnlockButton' +import LPTokenABI from 'config/abi/lpToken.json' +import SmartChefABI from 'config/abi/SmartChefInitializable.json' +import erc20ABI from 'config/abi/erc20.json' +import useRefresh from 'hooks/useRefresh' +import { useTranslation } from 'contexts/Localization' +import { BIG_ZERO } from 'utils/bigNumber' +import { AbiItem } from 'web3-utils' +import { getWeb3NoAccount } from 'utils/web3' +import { getAddress } from 'utils/addressHelpers' +import { Pool } from 'state/types' +import AprRow from './AprRow' +import { StyledCard, StyledCardInner } from './StyledCard' +import CardFooter from './CardFooter' +import StyledCardHeader from './StyledCardHeader' +import CardActions from './CardActions' + +const PoolCard: React.FC<{ pool: Pool; account: string }> = ({ pool, account }) => { + const { sousId, stakingToken, earningToken, isFinished, userData } = pool + const [lockTime, setLockTime] = useState() + const [reward, setReward] = useState(new BigNumber(0)) + const [rewardPerBlock, setRewardPerBlock] = useState('') + const [stakingTokenBalance, setStakingTokenBalance] = useState(new BigNumber(0)) + const [isApproved, setIsVaultApproved] = useState(false) + const [stakedAmount, setStakedAmount] = useState(Number) + const web3 = getWeb3NoAccount() + const { fastRefresh } = useRefresh() + + const { t } = useTranslation() + // const stakedBalance = userData?.stakedBalance ? new BigNumber(userData.stakedBalance) : BIG_ZERO + const accountHasStakedBalance = stakedAmount > 0 + + useEffect(() => { + if (account) { + const checkApprovalStatus = async () => { + try { + const abi = erc20ABI + const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) + const response = await contract.methods.allowance(account, getAddress(pool.contractAddress)).call() + const currentAllowance = new BigNumber(response) + setIsVaultApproved(currentAllowance.gt(0)) + } catch (error) { + setIsVaultApproved(false) + // console.log(error, 'approval') + } + } + + const getStakingBalance = async (address) => { + try { + const abi = [ + { inputs: [], stateMutability: 'nonpayable', type: 'constructor' }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: 'address', name: 'tokenRecovered', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'AdminTokenRecovery', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'user', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'Deposit', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'user', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'EmergencyWithdraw', + type: 'event', + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: 'uint256', name: 'poolLimitPerUser', type: 'uint256' }], + name: 'NewPoolLimit', + type: 'event', + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: 'uint256', name: 'rewardPerBlock', type: 'uint256' }], + name: 'NewRewardPerBlock', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: 'uint256', name: 'startBlock', type: 'uint256' }, + { indexed: false, internalType: 'uint256', name: 'endBlock', type: 'uint256' }, + ], + name: 'NewStartAndEndBlocks', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'previousOwner', type: 'address' }, + { indexed: true, internalType: 'address', name: 'newOwner', type: 'address' }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: 'uint256', name: 'blockNumber', type: 'uint256' }], + name: 'RewardsStop', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'user', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'Withdraw', + type: 'event', + }, + { + inputs: [], + name: 'PRECISION_FACTOR', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'SMART_CHEF_FACTORY', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'accTokenPerShare', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'bonusEndBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }], + name: 'deposit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }], + name: 'emergencyRewardWithdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { inputs: [], name: 'emergencyWithdraw', outputs: [], stateMutability: 'nonpayable', type: 'function' }, + { + inputs: [], + name: 'hasUserLimit', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'contract IBEP20', name: '_stakedToken', type: 'address' }, + { internalType: 'contract IBEP20', name: '_rewardToken', type: 'address' }, + { internalType: 'uint256', name: '_rewardPerBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_startBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_bonusEndBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_poolLimitPerUser', type: 'uint256' }, + { internalType: 'address', name: '_admin', type: 'address' }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'isInitialized', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastRewardBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: '_user', type: 'address' }], + name: 'pendingReward', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'poolLimitPerUser', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: '_tokenAddress', type: 'address' }, + { internalType: 'uint256', name: '_tokenAmount', type: 'uint256' }, + ], + name: 'recoverWrongTokens', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { inputs: [], name: 'renounceOwnership', outputs: [], stateMutability: 'nonpayable', type: 'function' }, + { + inputs: [], + name: 'rewardPerBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'rewardToken', + outputs: [{ internalType: 'contract IBEP20', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'stakedToken', + outputs: [{ internalType: 'contract IBEP20', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'startBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { inputs: [], name: 'stopReward', outputs: [], stateMutability: 'nonpayable', type: 'function' }, + { + inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'bool', name: '_hasUserLimit', type: 'bool' }, + { internalType: 'uint256', name: '_poolLimitPerUser', type: 'uint256' }, + ], + name: 'updatePoolLimitPerUser', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_rewardPerBlock', type: 'uint256' }], + name: 'updateRewardPerBlock', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'uint256', name: '_startBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_bonusEndBlock', type: 'uint256' }, + ], + name: 'updateStartAndEndBlocks', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: '', type: 'address' }], + name: 'userInfo', + outputs: [ + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + { internalType: 'uint256', name: 'rewardDebt', type: 'uint256' }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }], + name: 'withdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + ] + const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(pool.contractAddress)) + const stakeAmount = await contract.methods.userInfo(address).call() + const userStaked = await stakeAmount[0] + const parsedBal = parseFloat(userStaked) + + setStakedAmount(parsedBal) + } catch (error) { + // console.log(error, 'get staking bal') + } + } + + const getPendingReward = async (address) => { + try { + const abi = [ + { inputs: [], stateMutability: 'nonpayable', type: 'constructor' }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: 'address', name: 'tokenRecovered', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'AdminTokenRecovery', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'user', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'Deposit', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'user', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'EmergencyWithdraw', + type: 'event', + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: 'uint256', name: 'poolLimitPerUser', type: 'uint256' }], + name: 'NewPoolLimit', + type: 'event', + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: 'uint256', name: 'rewardPerBlock', type: 'uint256' }], + name: 'NewRewardPerBlock', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: 'uint256', name: 'startBlock', type: 'uint256' }, + { indexed: false, internalType: 'uint256', name: 'endBlock', type: 'uint256' }, + ], + name: 'NewStartAndEndBlocks', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'previousOwner', type: 'address' }, + { indexed: true, internalType: 'address', name: 'newOwner', type: 'address' }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: 'uint256', name: 'blockNumber', type: 'uint256' }], + name: 'RewardsStop', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'user', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'Withdraw', + type: 'event', + }, + { + inputs: [], + name: 'PRECISION_FACTOR', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'SMART_CHEF_FACTORY', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'accTokenPerShare', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'bonusEndBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }], + name: 'deposit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }], + name: 'emergencyRewardWithdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { inputs: [], name: 'emergencyWithdraw', outputs: [], stateMutability: 'nonpayable', type: 'function' }, + { + inputs: [], + name: 'hasUserLimit', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'contract IBEP20', name: '_stakedToken', type: 'address' }, + { internalType: 'contract IBEP20', name: '_rewardToken', type: 'address' }, + { internalType: 'uint256', name: '_rewardPerBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_startBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_bonusEndBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_poolLimitPerUser', type: 'uint256' }, + { internalType: 'address', name: '_admin', type: 'address' }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'isInitialized', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastRewardBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: '_user', type: 'address' }], + name: 'pendingReward', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'poolLimitPerUser', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: '_tokenAddress', type: 'address' }, + { internalType: 'uint256', name: '_tokenAmount', type: 'uint256' }, + ], + name: 'recoverWrongTokens', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { inputs: [], name: 'renounceOwnership', outputs: [], stateMutability: 'nonpayable', type: 'function' }, + { + inputs: [], + name: 'rewardPerBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'rewardToken', + outputs: [{ internalType: 'contract IBEP20', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'stakedToken', + outputs: [{ internalType: 'contract IBEP20', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'startBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { inputs: [], name: 'stopReward', outputs: [], stateMutability: 'nonpayable', type: 'function' }, + { + inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'bool', name: '_hasUserLimit', type: 'bool' }, + { internalType: 'uint256', name: '_poolLimitPerUser', type: 'uint256' }, + ], + name: 'updatePoolLimitPerUser', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_rewardPerBlock', type: 'uint256' }], + name: 'updateRewardPerBlock', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'uint256', name: '_startBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_bonusEndBlock', type: 'uint256' }, + ], + name: 'updateStartAndEndBlocks', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: '', type: 'address' }], + name: 'userInfo', + outputs: [ + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + { internalType: 'uint256', name: 'rewardDebt', type: 'uint256' }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }], + name: 'withdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + ] + const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(pool.contractAddress)) + const penReward = await contract.methods.pendingReward(address).call() + setReward(penReward) + } catch (error) { + // console.log(error, 'getPendingReward') + } + } + + const getBalance = async (address) => { + const abi = LPTokenABI + const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(stakingToken.address)) + const response = await contract.methods.balanceOf(address).call() + const bal = new BigNumber(response) + setStakingTokenBalance(bal) + } + + const getLockTime = async (address) => { + try { + const abi = SmartChefABI + if ( + pool.poolCategory === '30DayLock' || + pool.poolCategory === '60DayLock' || + pool.poolCategory === '90DayLock' + ) { + const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(pool.contractAddress)) + const remainingTime = await contract.methods.getRemainingLockTime(address).call() + setLockTime(remainingTime) + } + } catch (error) { + // console.log('lock time error', error) + } + } + + checkApprovalStatus() + getLockTime(account) + getPendingReward(account) + getStakingBalance(account) + getBalance(account) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [account, fastRefresh, isApproved, setIsVaultApproved]) + + const getRewardPerBlock = async () => { + if (pool) { + try { + const abi = [ + { inputs: [], stateMutability: 'nonpayable', type: 'constructor' }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: 'address', name: 'tokenRecovered', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'AdminTokenRecovery', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'user', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'ClaimReward', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'user', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'Deposit', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'user', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'EmergencyWithdraw', + type: 'event', + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: 'uint256', name: 'poolLimitPerUser', type: 'uint256' }], + name: 'NewPoolLimit', + type: 'event', + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: 'uint256', name: 'rewardPerBlock', type: 'uint256' }], + name: 'NewRewardPerBlock', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: 'uint256', name: 'startBlock', type: 'uint256' }, + { indexed: false, internalType: 'uint256', name: 'endBlock', type: 'uint256' }, + ], + name: 'NewStartAndEndBlocks', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'previousOwner', type: 'address' }, + { indexed: true, internalType: 'address', name: 'newOwner', type: 'address' }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { indexed: true, internalType: 'address', name: 'user', type: 'address' }, + { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' }, + ], + name: 'Withdraw', + type: 'event', + }, + { + inputs: [], + name: 'PRECISION_FACTOR', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'SMART_CHEF_FACTORY', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'accTokenPerShare', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: '', type: 'address' }], + name: 'addressEndLockTime', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'bonusEndBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { inputs: [], name: 'claimReward', outputs: [], stateMutability: 'nonpayable', type: 'function' }, + { + inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }], + name: 'deposit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }], + name: 'emergencyRewardWithdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { inputs: [], name: 'emergencyWithdraw', outputs: [], stateMutability: 'nonpayable', type: 'function' }, + { + inputs: [], + name: 'endLockTime', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: '_user', type: 'address' }], + name: 'getRemainingLockTime', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'hasAllRewardDistributedByAdmin', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'hasSavedPendingRewardUpdatedByAdmin', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'hasUserLimit', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'contract IBEP20', name: '_stakedToken', type: 'address' }, + { internalType: 'contract IBEP20', name: '_rewardToken', type: 'address' }, + { internalType: 'uint256', name: '_rewardPerBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_startBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_bonusEndBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_lockTime', type: 'uint256' }, + { internalType: 'uint256', name: '_poolLimitPerUser', type: 'uint256' }, + { internalType: 'address', name: '_admin', type: 'address' }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'isInitialized', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastRewardBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lockTime', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'numberOfClaimCurrentAndTotalPendingReward', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'numberOfClaimSavedPendingReward', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: '_user', type: 'address' }], + name: 'pendingReward', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'poolLimitPerUser', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: '_tokenAddress', type: 'address' }, + { internalType: 'uint256', name: '_tokenAmount', type: 'uint256' }, + ], + name: 'recoverWrongTokens', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { inputs: [], name: 'renounceOwnership', outputs: [], stateMutability: 'nonpayable', type: 'function' }, + { + inputs: [], + name: 'rewardPerBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'rewardToken', + outputs: [{ internalType: 'contract IBEP20', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'stakedToken', + outputs: [{ internalType: 'contract IBEP20', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'startBlock', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { inputs: [], name: 'stopReward', outputs: [], stateMutability: 'nonpayable', type: 'function' }, + { + inputs: [{ internalType: 'address', name: '', type: 'address' }], + name: 'temporaryPendingReward', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'bool', name: '_hasUserLimit', type: 'bool' }, + { internalType: 'uint256', name: '_poolLimitPerUser', type: 'uint256' }, + ], + name: 'updatePoolLimitPerUser', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_rewardPerBlock', type: 'uint256' }], + name: 'updateRewardPerBlock', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'uint256', name: '_startBlock', type: 'uint256' }, + { internalType: 'uint256', name: '_bonusEndBlock', type: 'uint256' }, + ], + name: 'updateStartAndEndBlocks', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: '', type: 'address' }], + name: 'userInfo', + outputs: [ + { internalType: 'uint256', name: 'amount', type: 'uint256' }, + { internalType: 'uint256', name: 'rewardDebt', type: 'uint256' }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }], + name: 'withdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + ] + const contract = new web3.eth.Contract(abi as unknown as AbiItem, getAddress(pool.contractAddress)) + // console.log('reward contract', contract) + + const rpb = await contract.methods.rewardPerBlock().call() + setRewardPerBlock(web3.utils.fromWei(rpb)) + } catch (error) { + // console.log('stake action', error) + } + } + } + + useEffect(() => { + if (pool) { + getRewardPerBlock() + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [pool, account]) + + return ( + } + className="hover_shadow emphasized_swap_layout" + > + + + + + + {account ? ( + + ) : ( + <> + + {t('Start earning')} + + + + )} + + + + + + ) +} + +export default PoolCard diff --git a/src/views/OldFarms/components/PoolTabButtons.tsx b/src/views/OldFarms/components/PoolTabButtons.tsx new file mode 100644 index 0000000..fd1fdad --- /dev/null +++ b/src/views/OldFarms/components/PoolTabButtons.tsx @@ -0,0 +1,82 @@ +import React from 'react' +import styled from 'styled-components' +import ToggleButton from '@mui/material/ToggleButton' +import { useRouteMatch, Link } from 'react-router-dom' +import { + ButtonMenu, + ButtonMenuItem, + Button, + HelpIcon, + Toggle, + Text, + Flex, + NotificationDot, + Link as UiKitLink, +} from '@pancakeswap/uikit' +import { useTranslation } from 'contexts/Localization' +import { ToggleSwitch } from 'components/ToggleSwitch' + +const ButtonText = styled(Text)` + display: none; + ${({ theme }) => theme.mediaQueries.lg} { + display: block; + } +` + +const StyledLink = styled(UiKitLink)` + width: 100%; + + &:hover { + text-decoration: none; + } +` + +const StyledButtonMenu = styled(ButtonMenu)` + border: none; + background: transparent; +` + +const PoolTabButtons = ({ stakedOnly, setStakedOnly, hasStakeInFinishedPools }) => { + const { url, isExact } = useRouteMatch() + const { t } = useTranslation() + + const pathname = window.location.pathname + const newUrl = pathname.replace(/\/?$/, '/') + + const isActive = pathname === newUrl + + return ( + + + {/* + + {t('Live')} + + + + {t('Finished')} + + + */} + + setStakedOnly((prev) => !prev)} /> + + {t('Staked only')} + + + + + ) +} + +export default PoolTabButtons diff --git a/src/views/OldFarms/components/ToggleNew/index.jsx b/src/views/OldFarms/components/ToggleNew/index.jsx new file mode 100644 index 0000000..14a864b --- /dev/null +++ b/src/views/OldFarms/components/ToggleNew/index.jsx @@ -0,0 +1,45 @@ +import React from 'react' +import styled from 'styled-components' +import { useRouteMatch, Link } from 'react-router-dom' +import { ButtonMenu, ButtonMenuItem } from '@pancakeswap/uikit' + +/* eslint-disable */ + +const ToggleNew = () => { + const { isExact } = useRouteMatch() + + return ( + + + + Farm V1 + + + Farm V2 + + + Finished + + + + ) +} + +const Wrapper = styled.div` + display: flex; + justify-content: center; + align-items: center; + padding-bottom: 20px; +` + +export default ToggleNew diff --git a/src/views/OldFarms/helpers.tsx b/src/views/OldFarms/helpers.tsx new file mode 100644 index 0000000..fd67c32 --- /dev/null +++ b/src/views/OldFarms/helpers.tsx @@ -0,0 +1,32 @@ +import BigNumber from 'bignumber.js' +import { getBalanceNumber, getFullDisplayBalance, getDecimalAmount } from 'utils/formatBalance' + +export const convertSharesToCake = ( + shares: BigNumber, + cakePerFullShare: BigNumber, + decimals = 18, + decimalsToRound = 3, +) => { + const sharePriceNumber = getBalanceNumber(cakePerFullShare, decimals) + const amountInCake = new BigNumber(shares.multipliedBy(sharePriceNumber)) + const cakeAsNumberBalance = getBalanceNumber(amountInCake, decimals) + const cakeAsBigNumber = getDecimalAmount(new BigNumber(cakeAsNumberBalance), decimals) + const cakeAsDisplayBalance = getFullDisplayBalance(amountInCake, decimals, decimalsToRound) + return { cakeAsNumberBalance, cakeAsBigNumber, cakeAsDisplayBalance } +} + +export const convertCakeToShares = ( + cake: BigNumber, + cakePerFullShare: BigNumber, + decimals = 18, + decimalsToRound = 3, +) => { + const sharePriceNumber = getBalanceNumber(cakePerFullShare, decimals) + const amountInShares = new BigNumber(cake.dividedBy(sharePriceNumber)) + const sharesAsNumberBalance = getBalanceNumber(amountInShares, decimals) + const sharesAsBigNumber = getDecimalAmount(new BigNumber(sharesAsNumberBalance), decimals) + const sharesAsDisplayBalance = getFullDisplayBalance(amountInShares, decimals, decimalsToRound) + return { sharesAsNumberBalance, sharesAsBigNumber, sharesAsDisplayBalance } +} + +export const SmartChefABI = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"tokenRecovered","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"AdminTokenRecovery","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EmergencyWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"poolLimitPerUser","type":"uint256"}],"name":"NewPoolLimit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rewardPerBlock","type":"uint256"}],"name":"NewRewardPerBlock","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"startBlock","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endBlock","type":"uint256"}],"name":"NewStartAndEndBlocks","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"RewardsStop","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"PRECISION_FACTOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SMART_CHEF_FACTORY","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accTokenPerShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bonusEndBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"emergencyRewardWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emergencyWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"hasUserLimit","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IBEP20","name":"_stakedToken","type":"address"},{"internalType":"contract IBEP20","name":"_rewardToken","type":"address"},{"internalType":"uint256","name":"_rewardPerBlock","type":"uint256"},{"internalType":"uint256","name":"_startBlock","type":"uint256"},{"internalType":"uint256","name":"_bonusEndBlock","type":"uint256"},{"internalType":"uint256","name":"_poolLimitPerUser","type":"uint256"},{"internalType":"address","name":"_admin","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastRewardBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"pendingReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolLimitPerUser","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"uint256","name":"_tokenAmount","type":"uint256"}],"name":"recoverWrongTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardPerBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardToken","outputs":[{"internalType":"contract IBEP20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakedToken","outputs":[{"internalType":"contract IBEP20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"startBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stopReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_hasUserLimit","type":"bool"},{"internalType":"uint256","name":"_poolLimitPerUser","type":"uint256"}],"name":"updatePoolLimitPerUser","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rewardPerBlock","type":"uint256"}],"name":"updateRewardPerBlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_startBlock","type":"uint256"},{"internalType":"uint256","name":"_bonusEndBlock","type":"uint256"}],"name":"updateStartAndEndBlocks","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userInfo","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"rewardDebt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}] diff --git a/src/views/OldFarms/index.tsx b/src/views/OldFarms/index.tsx new file mode 100644 index 0000000..d213546 --- /dev/null +++ b/src/views/OldFarms/index.tsx @@ -0,0 +1,164 @@ +import React, { useEffect, useMemo, useRef, useState } from 'react' +import ModalVideo from 'react-modal-video' + +import { Route, useRouteMatch } from 'react-router-dom' + +import { useWeb3React } from '@web3-react/core' +import { Heading, Flex } from '@pancakeswap/uikit' +import { getWeb3NoAccount } from 'utils/web3' +import { getUserPoolData as getUserFarmData } from 'state/farmsWithSmartChef' +import orderBy from 'lodash/orderBy' +import partition from 'lodash/partition' +import { useTranslation } from 'contexts/Localization' +import usePersistState from 'hooks/usePersistState' +import { useFarmsWithSmartChef, usePriceBnbBusd } from 'state/hooks' +import FlexLayout from 'components/layout/Flex' +import Page from 'components/layout/Page' +import AlertDismissable from 'components/Alerts' +import PageHeader from 'components/PageHeader' +import PoolCard from './components/PoolCard' +// import CakeVaultCard from './components/CakeVaultCard' +import PoolTabButtons from './components/PoolTabButtons' +// import BountyCard from './components/BountyCard' + +import 'react-modal-video/css/modal-video.css' +import ToggleNew from './components/ToggleNew' + +const NUMBER_OF_FARMS_VISIBLE = 12 +// declare let window: any + +const NewFarms: React.FC = () => { + const { path } = useRouteMatch() + const { t } = useTranslation() + const { account } = useWeb3React() + const pools = useFarmsWithSmartChef(account) + + // modal video + const [isOpen, setOpen] = useState(false) + + const web3 = getWeb3NoAccount() + const [stakedOnly, setStakedOnly] = usePersistState(false, 'pancake_pool_staked') + const [staked, setStaked] = useState(0) + const [userDetails, setUserDetails] = useState({}) + const [userInfo, setUserInfo] = useState({}) + const [numberOfPoolsVisible, setNumberOfPoolsVisible] = useState(NUMBER_OF_FARMS_VISIBLE) + const [observerIsSet, setObserverIsSet] = useState(false) + const loadMoreRef = useRef(null) + + const [finishedPools, openPools] = useMemo(() => partition(pools, (pool) => pool.isFinished), [pools]) + + useEffect(() => { + const fetchUserData = async () => { + try { + const test = await getUserFarmData(account) + setUserInfo(test) + } catch (err) { + console.log(err, 'err') + } + } + fetchUserData() + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [account]) + + const stakedOnlyFinishedPools = useMemo( + () => + finishedPools.filter((pool) => + // eslint-disable-next-line dot-notation + userInfo['stakedBalances'] ? userInfo['stakedBalances'][pool.sousId] !== '0' : null, + ), + // eslint-disable-next-line react-hooks/exhaustive-deps + [finishedPools], + ) + const stakedOnlyOpenPools = useMemo( + () => + // eslint-disable-next-line dot-notation + openPools.filter((pool) => (userInfo['stakedBalances'] ? userInfo['stakedBalances'][pool.sousId] !== '0' : null)), + // eslint-disable-next-line react-hooks/exhaustive-deps + [openPools], + ) + + const hasStakeInFinishedPools = stakedOnlyFinishedPools.length > 0 + + // This pool is passed explicitly to the cake vault + const cakePoolData = useMemo(() => openPools.find((pool) => pool.sousId === 0), [openPools]) + + useEffect(() => { + const showMorePools = (entries) => { + const [entry] = entries + if (entry.isIntersecting) { + setNumberOfPoolsVisible((poolsCurrentlyVisible) => poolsCurrentlyVisible + NUMBER_OF_FARMS_VISIBLE) + } + } + + if (!observerIsSet) { + const loadMoreObserver = new IntersectionObserver(showMorePools, { + rootMargin: '0px', + threshold: 1, + }) + loadMoreObserver.observe(loadMoreRef.current) + setObserverIsSet(true) + } + }, [observerIsSet]) + + return ( +
+ + + + + {t('Farms V2')} + + + {t('Stake Liquidity Pool (LP) tokens to earn SODATSU!')} + + + + {/* + + */} + + + + +
+ setOpen(false)} /> +
+ + + {stakedOnly + ? orderBy(stakedOnlyFinishedPools, ['sortOrder']) + .slice(0, numberOfPoolsVisible) + .map((pool) => ) + : orderBy(finishedPools, ['sortOrder']) + .slice(0, numberOfPoolsVisible) + .map((pool) => )} + + +
+ {/* Pancake illustration */} + +
+ ) +} + +export default NewFarms