Skip to content

Commit

Permalink
chore: finish status details
Browse files Browse the repository at this point in the history
  • Loading branch information
Chef-Yogi committed Jan 16, 2025
1 parent 6c8327e commit 8c808a9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
23 changes: 17 additions & 6 deletions apps/web/src/views/Idos/components/IdoCards/IdoCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { useAccount } from 'wagmi'
import { IdoRibbon } from './IdoRibbon'

import { getBannerUrl } from '../../helpers'
import { useIDOClaimCallback } from '../../hooks/ido/useIDOClaimCallback'
import { useIDODepositCallback } from '../../hooks/ido/useIDODepositCallback'
import { IDOPublicData } from '../../hooks/ido/useIdoPublicData'

Expand Down Expand Up @@ -149,7 +150,9 @@ export const IdoStakeActionCard: React.FC<{ idoPublicData: IDOPublicData }> = ({
<Card background="#FAF9FA">
<CardBody>
<FlexGap flexDirection="column" gap="8px">
{userHasStaked ? (
{idoPublicData.status === 'finished' ? (
<ClaimDisplay idoPublicData={idoPublicData} />
) : userHasStaked ? (
<StakedDisplay idoPublicData={idoPublicData} />
) : (
<FlexGap flexDirection="column" gap="8px">
Expand Down Expand Up @@ -439,13 +442,14 @@ export const StakedDisplay: React.FC<{ idoPublicData: IDOPublicData }> = ({ idoP

export const ClaimDisplay: React.FC<{ idoPublicData: IDOPublicData }> = ({ idoPublicData }) => {
const { t } = useTranslation()
const stakedAmount = idoPublicData?.userStakedAmount
const { claim } = useIDOClaimCallback()
const claimableAmount = idoPublicData?.userClaimableAmount
const amountInDollar = useStablecoinPriceAmount(
idoPublicData?.stakeCurrency ?? undefined,
stakedAmount !== undefined && Number.isFinite(+stakedAmount) ? +stakedAmount : undefined,
claimableAmount !== undefined && Number.isFinite(+claimableAmount) ? +claimableAmount : undefined,
{
hideIfPriceImpactTooHigh: true,
enabled: Boolean(stakedAmount !== undefined && Number.isFinite(+stakedAmount)),
enabled: Boolean(claimableAmount !== undefined && Number.isFinite(+claimableAmount)),
},
)
return (
Expand All @@ -460,7 +464,7 @@ export const ClaimDisplay: React.FC<{ idoPublicData: IDOPublicData }> = ({ idoPu
</FlexGap>
<FlexGap gap="8px" flexDirection="column">
<Text fontSize="20px" bold lineHeight="30px">
{stakedAmount?.toSignificant(6)}
{claimableAmount?.toSignificant(6)}
</Text>
<FlexGap>
{Number.isFinite(amountInDollar) ? (
Expand All @@ -476,7 +480,14 @@ export const ClaimDisplay: React.FC<{ idoPublicData: IDOPublicData }> = ({ idoPu
</FlexGap>
</FlexGap>
</FlexGap>
<IdoDepositButton idoPublicData={idoPublicData} type="add" />
<Button
width="100%"
onClick={() => {
claim()
}}
>
{t('Claim')}
</Button>
</FlexGap>
)
}
8 changes: 7 additions & 1 deletion apps/web/src/views/Idos/hooks/ido/useIDOUserStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type IDOUserStatus = {
export const useIDOUserStatus = () => {
const { data: userInfo } = useIDOUserInfo()
const { data: offeringAndRefundingAmounts } = useViewUserOfferingAndRefundingAmounts()
const { stakeCurrency } = useIDOCurrencies()
const { stakeCurrency, offeringCurrency } = useIDOCurrencies()

const stakedAmount = useMemo(() => {
if (!stakeCurrency || !userInfo) return undefined
Expand All @@ -33,10 +33,16 @@ export const useIDOUserStatus = () => {
return CurrencyAmount.fromRawAmount(stakeCurrency, offeringAndRefundingAmounts?.userRefundingAmount ?? 0n)
}, [stakeCurrency, offeringAndRefundingAmounts])

const claimableAmount = useMemo(() => {
if (!offeringCurrency) return undefined
return CurrencyAmount.fromRawAmount(offeringCurrency, offeringAndRefundingAmounts?.userOfferingAmount ?? 0n)
}, [offeringCurrency, offeringAndRefundingAmounts])

return {
stakedAmount,
stakeTax,
stakeRefund,
claimableAmount,
}
}

Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/views/Idos/hooks/ido/useIdoPublicData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type IDOPublicData = {
offeringCurrency: UnsafeCurrency
raiseAmount: CurrencyAmount<Currency> | undefined
saleAmount: CurrencyAmount<Currency> | undefined
userClaimableAmount?: CurrencyAmount<Currency>
userStakedAmount?: CurrencyAmount<Currency>
userStakedRefund?: CurrencyAmount<Currency>
userStakedTax?: CurrencyAmount<Currency>
Expand All @@ -40,7 +41,12 @@ export const useIdoPublicData = (chainId: ChainId): IDOPublicData => {
const { stakeCurrency, offeringCurrency } = useIDOCurrencies()
const { progress, currentStakedAmount } = useIDOStatus()
const { pricePerToken, raiseAmount, saleAmount } = useIDOConfig()
const { stakedAmount: userStakedAmount, stakeRefund: userStakedRefund, stakeTax: userStakedTax } = useIDOUserStatus()
const {
stakedAmount: userStakedAmount,
stakeRefund: userStakedRefund,
stakeTax: userStakedTax,
claimableAmount: userClaimableAmount,
} = useIDOUserStatus()

const startTime = Number(poolInfo?.startTimestamp) || 0
const endTime = 1737407928 // Number(poolInfo?.endTimestamp) || 0
Expand Down Expand Up @@ -72,5 +78,6 @@ export const useIdoPublicData = (chainId: ChainId): IDOPublicData => {
userStakedAmount,
userStakedRefund,
userStakedTax,
userClaimableAmount,
}
}

0 comments on commit 8c808a9

Please sign in to comment.