Skip to content

Commit

Permalink
chore: integrate v2 SC
Browse files Browse the repository at this point in the history
  • Loading branch information
Chef-Yogi committed Jan 17, 2025
1 parent d7a5a06 commit 6bd1665
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 80 deletions.
37 changes: 2 additions & 35 deletions apps/web/src/views/Idos/CurrentIfo.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,20 @@
import { Ifo } from '@pancakeswap/ifos'
import { useMemo } from 'react'

import { useIDOPoolInfo } from './hooks/ido/useIDOPoolInfo'
import { useIDOUserInfo } from './hooks/ido/useIDOUserInfo'
import { useIDOUserStatus } from './hooks/ido/useIDOUserStatus'
import { useIdoPublicData } from './hooks/ido/useIdoPublicData'

import { IDoCurrentCard } from './components/IdoCards/IdoCards'
import IfoContainer from './components/IfoContainer'
import IfoQuestions from './components/IfoQuestions'
import IfoSteps from './components/IfoSteps'
import { SectionBackground } from './components/SectionBackground'

interface TypeProps {
activeIfo: Ifo
}

const CurrentIdo: React.FC<React.PropsWithChildren<TypeProps>> = ({ activeIfo }) => {
const { data: idoPoolInfo } = useIDOPoolInfo()
const idoUserStatus = useIDOUserStatus()
const idoPublicData = useIdoPublicData(activeIfo.chainId)
const idoPublicData = useIdoPublicData(activeIfo.chainId)?.[0]

const isCommitted = useMemo(() => idoUserStatus?.stakedAmount?.greaterThan(0n) ?? false, [idoUserStatus])
const isLive = useMemo(
() =>
idoPoolInfo?.startTimestamp !== undefined &&
idoPoolInfo?.endTimestamp !== undefined &&
Date.now() > idoPoolInfo.startTimestamp &&
Date.now() < idoPoolInfo.endTimestamp,

[idoPoolInfo?.startTimestamp, idoPoolInfo?.endTimestamp],
)
const isFinished = useMemo(
() => idoPoolInfo?.endTimestamp !== undefined && Date.now() > idoPoolInfo.endTimestamp,
[idoPoolInfo?.endTimestamp],
)

const { data: idoUserInfo } = useIDOUserInfo()

const steps = (
<IfoSteps
ifoChainId={activeIfo.chainId}
isLive={isLive}
isFinished={isFinished}
hasClaimed={idoUserInfo?.claimedPool ?? false}
isCommitted={isCommitted}
ifoCurrencyAddress={activeIfo.currency.address}
/>
)
const steps = <></>

const faq = (
<SectionBackground padding="32px 0">
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/views/Idos/components/IdoCards/IdoCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export const IdoDepositButton: React.FC<{ idoPublicData: IDOPublicData; type: 'a
disabled={value === '' || !depositAmount || isUserInsufficientBalance}
width="100%"
onClick={() => {
if (depositAmount) deposit(depositAmount)
if (depositAmount) deposit(0, depositAmount)
}}
>
{t('Confirm Deposit')}
Expand Down Expand Up @@ -537,7 +537,7 @@ export const ClaimDisplay: React.FC<{ idoPublicData: IDOPublicData }> = ({ idoPu
</FlexGap>
<Button
onClick={() => {
if (!userClaimed) claim()
if (!userClaimed) claim(0)
}}
width={userClaimed ? '48px' : undefined}
variant={userClaimed ? 'success' : undefined}
Expand Down
26 changes: 13 additions & 13 deletions apps/web/src/views/Idos/hooks/ido/useIDOUserStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,36 @@ export type IDOUserStatus = {
export const useIDOUserStatus = (): [IDOUserStatus, IDOUserStatus] => {
const { data: userInfo } = useIDOUserInfo()
const { data: offeringAndRefundingAmounts } = useViewUserOfferingAndRefundingAmounts()
const { stakeCurrency, offeringCurrency } = useIDOCurrencies()
const { stakeCurrency0, stakeCurrency1, offeringCurrency } = useIDOCurrencies()

const stakedAmounts = useMemo(() => {
if (!stakeCurrency || !userInfo) return [undefined, undefined]
if (!stakeCurrency0 || !stakeCurrency1 || !userInfo) return [undefined, undefined]
return [
CurrencyAmount.fromRawAmount(stakeCurrency, userInfo[0].amountPool),
CurrencyAmount.fromRawAmount(stakeCurrency, userInfo[1].amountPool),
CurrencyAmount.fromRawAmount(stakeCurrency0, userInfo[0].amountPool),
CurrencyAmount.fromRawAmount(stakeCurrency1, userInfo[1].amountPool),
]
}, [stakeCurrency, userInfo])
}, [stakeCurrency0, stakeCurrency1, userInfo])

const claimed = useMemo(() => {
if (!userInfo) return [undefined, undefined]
return [userInfo[0].claimedPool, userInfo[1].claimedPool]
}, [userInfo])

const stakeTax = useMemo(() => {
if (!stakeCurrency) return [undefined, undefined]
if (!stakeCurrency0 || !stakeCurrency1) return [undefined, undefined]
return [
CurrencyAmount.fromRawAmount(stakeCurrency, offeringAndRefundingAmounts?.[0].userTaxAmount ?? 0n),
CurrencyAmount.fromRawAmount(stakeCurrency, offeringAndRefundingAmounts?.[1].userTaxAmount ?? 0n),
CurrencyAmount.fromRawAmount(stakeCurrency0, offeringAndRefundingAmounts?.[0].userTaxAmount ?? 0n),
CurrencyAmount.fromRawAmount(stakeCurrency1, offeringAndRefundingAmounts?.[1].userTaxAmount ?? 0n),
]
}, [stakeCurrency, offeringAndRefundingAmounts])
}, [stakeCurrency0, stakeCurrency1, offeringAndRefundingAmounts])

const stakeRefund = useMemo(() => {
if (!stakeCurrency) return [undefined, undefined]
if (!stakeCurrency0 || !stakeCurrency1) return [undefined, undefined]
return [
CurrencyAmount.fromRawAmount(stakeCurrency, offeringAndRefundingAmounts?.[0].userRefundingAmount ?? 0n),
CurrencyAmount.fromRawAmount(stakeCurrency, offeringAndRefundingAmounts?.[1].userRefundingAmount ?? 0n),
CurrencyAmount.fromRawAmount(stakeCurrency0, offeringAndRefundingAmounts?.[0].userRefundingAmount ?? 0n),
CurrencyAmount.fromRawAmount(stakeCurrency1, offeringAndRefundingAmounts?.[1].userRefundingAmount ?? 0n),
]
}, [stakeCurrency, offeringAndRefundingAmounts])
}, [stakeCurrency0, stakeCurrency1, offeringAndRefundingAmounts])

const claimableAmount = useMemo(() => {
if (!offeringCurrency) return [undefined, undefined]
Expand Down
85 changes: 55 additions & 30 deletions apps/web/src/views/Idos/hooks/ido/useIdoPublicData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { ChainId } from '@pancakeswap/chains'
import { IfoStatus } from '@pancakeswap/ifos'
import { type Currency, CurrencyAmount, Percent, Price } from '@pancakeswap/swap-sdk-core'
import { CAKE } from '@pancakeswap/tokens'
import { UnsafeCurrency } from 'config/constants/types'
import { useCakePrice } from 'hooks/useCakePrice'
import { useLpTokenPrice } from 'state/farms/hooks'
import { getStatusByTimestamp } from '../helpers'
import { useIDOStatus } from './usdIDOStatus'
import { useIDOConfig } from './useIDOConfig'
Expand All @@ -17,7 +14,7 @@ export type IDOPublicData = {
endTime: number
status: IfoStatus
// currencyPriceInUSD: BigNumber
poolInfo: PoolInfo
poolInfo?: PoolInfo
plannedStartTime: number
progress: Percent
currentStakedAmount?: CurrencyAmount<Currency>
Expand All @@ -43,37 +40,65 @@ export const useIdoPublicData = (chainId: ChainId): [IDOPublicData, IDOPublicDat
const { pricePerTokens, raiseAmounts, saleAmounts } = useIDOConfig()
const [userStatus0, userStatus1] = useIDOUserStatus()

const {
stakedAmount: userStakedAmount,
stakeRefund: userStakedRefund,
stakeTax: userStakedTax,
claimableAmount: userClaimableAmount,
claimed: userClaimed,
} = userStatus0

const startTime = Number(startTimestamp) || 0
const endTime = Number(endTimestamp) || 0 // 1737407928
const now = Math.floor(Date.now() / 1000)
const status = getStatusByTimestamp(now, startTime, endTime)
const lpToken0PriceInUsd = useLpTokenPrice(stakeCurrency0?.symbol ?? 'BNB')
// const lpToken1PriceInUsd = useLpTokenPrice(stakeCurrency1?.symbol ?? 'BNB')
const cakePrice = useCakePrice()

const duration = startTime - endTime
const currencyPriceInUSD = stakeCurrency0 === CAKE[chainId] ? cakePrice : lpToken0PriceInUsd

const timeProgress = status === 'live' ? ((now - startTime) / duration) * 100 : 0

return {
// startTime,
// endTime,
// status,
// // currencyPriceInUSD,
// poolInfo: pool0Info,
// plannedStartTime: poolInfo?.startTimestamp ? poolInfo?.startTimestamp - 432000 : 0, // five days before
// progress,
// currentStakedAmount: status0.currentStakedAmount,
// timeProgress,
// duration,
// pricePerToken,
// stakeCurrency,
// offeringCurrency,
// raiseAmount,
// saleAmount,
// userStakedAmount,
// userStakedRefund,
// userStakedTax,
// userClaimableAmount,
// userClaimed,
}
return [
{
startTime,
endTime,
status,
poolInfo: pool0Info,
plannedStartTime: startTimestamp ? startTimestamp - 432000 : 0, // five days before
progress: status0.progress,
currentStakedAmount: status0.currentStakedAmount,
timeProgress,
duration,
pricePerToken: pricePerTokens[0],
stakeCurrency: stakeCurrency0,
offeringCurrency,
raiseAmount: raiseAmounts[0],
saleAmount: saleAmounts[0],
userStakedAmount,
userStakedRefund,
userStakedTax,
userClaimableAmount,
userClaimed,
},
{
startTime,
endTime,
status,
poolInfo: pool1Info,
plannedStartTime: startTimestamp ? startTimestamp - 432000 : 0, // five days before
progress: status1.progress,
currentStakedAmount: status1.currentStakedAmount,
timeProgress,
duration,
pricePerToken: pricePerTokens[1],
stakeCurrency: stakeCurrency1,
offeringCurrency,
raiseAmount: raiseAmounts[1],
saleAmount: saleAmounts[1],
userStakedAmount: userStatus1.stakedAmount,
userStakedRefund: userStatus1.stakeRefund,
userStakedTax: userStatus1.stakeTax,
userClaimableAmount: userStatus1.claimableAmount,
userClaimed: userStatus1.claimed,
},
]
}

0 comments on commit 6bd1665

Please sign in to comment.