Skip to content

Commit

Permalink
chore: display usd value on input
Browse files Browse the repository at this point in the history
  • Loading branch information
Chef-Yogi committed Jan 14, 2025
1 parent a5cc282 commit 7c08fc2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
41 changes: 41 additions & 0 deletions apps/web/src/views/Idos/components/IdoCards/IdoCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
domAnimation,
FlexGap,
LazyAnimatePresence,
Loading,
ModalBody,
ModalContainer,
ModalV2,
Expand All @@ -22,6 +23,7 @@ import getTimePeriods from '@pancakeswap/utils/getTimePeriods'
import { CurrencyLogo, SwapUIV2 } from '@pancakeswap/widgets-internal'
import BigNumber from 'bignumber.js'
import ConnectWalletButton from 'components/ConnectWalletButton'
import { useStablecoinPriceAmount } from 'hooks/useStablecoinPrice'
import { useCallback, useMemo, useState } from 'react'
import { useCurrencyBalance } from 'state/wallet/hooks'
import { styled } from 'styled-components'
Expand Down Expand Up @@ -178,6 +180,13 @@ export const IdoStakeActionCard: React.FC<{ idoPublicData: IDOPublicData }> = ({
)
}

const formatDollarAmount = (amount: number) => {
if (amount > 0 && amount < 0.01) {
return '<0.01'
}
return formatNumber(amount)
}

export const IdoDepositButton: React.FC<{ idoPublicData: IDOPublicData }> = ({ idoPublicData }) => {
const { t } = useTranslation()
const { onDismiss, onOpen, isOpen } = useModalV2()
Expand Down Expand Up @@ -230,6 +239,16 @@ export const IdoDepositButton: React.FC<{ idoPublicData: IDOPublicData }> = ({ i
return false
}, [depositAmount, inputBalance])

const amountInDollar = useStablecoinPriceAmount(
idoPublicData?.stakeCurrency ?? undefined,
value !== undefined && Number.isFinite(+value) ? +value : undefined,
{
hideIfPriceImpactTooHigh: true,
enabled: Boolean(value !== undefined && Number.isFinite(+value)),
},
)
const isInputloading = inputBalance === undefined

return (
<>
<Button width="100%" onClick={onOpen}>
Expand Down Expand Up @@ -266,6 +285,28 @@ export const IdoDepositButton: React.FC<{ idoPublicData: IDOPublicData }> = ({ i
<CurrencyLogo size="40px" currency={idoPublicData?.stakeCurrency} />
</FlexGap>
}
bottom={
isInputloading || Number.isFinite(amountInDollar) ? (
<Box position="absolute" bottom="12px" right="0px">
<FlexGap justifyContent="flex-end" mr="1rem">
<FlexGap maxWidth={['120px', '160px', '200px', '240px']}>
{isInputloading ? (
<Loading width="14px" height="14px" />
) : Number.isFinite(amountInDollar) ? (
<>
<Text fontSize="14px" color="textSubtle" ellipsis>
{`~${amountInDollar && formatDollarAmount(amountInDollar)}`}
</Text>
<Text ml="4px" fontSize="14px" color="textSubtle">
USD
</Text>
</>
) : null}
</FlexGap>
</FlexGap>
</Box>
) : null
}
/>
<FlexGap>
{maxAmountInput?.greaterThan(0) &&
Expand Down
10 changes: 6 additions & 4 deletions apps/web/src/views/Idos/components/IfoContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ interface TypeProps {

const IfoContainer: React.FC<React.PropsWithChildren<TypeProps>> = ({ ifoSection, ifoSteps, faq }) => {
return (
<IfoLayout id="current-ifo">
<Container px="0">
<IfoLayout id="current-ido">
{/* <Container px="0">
<IfoLayoutWrapper>{ifoSection}</IfoLayoutWrapper>
</Container>
</Container> */}
<SectionBackground>
<Container>{ifoSteps}</Container>
<Container px="0">
<IfoLayoutWrapper>{ifoSection}</IfoLayoutWrapper>
</Container>
</SectionBackground>
{/* {faq}
<LinkExternal
Expand Down

0 comments on commit 7c08fc2

Please sign in to comment.