Skip to content

Commit

Permalink
Sync token UI with API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Aug 30, 2024
1 parent fec06ac commit d76285b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
26 changes: 26 additions & 0 deletions src/app/components/FiatValue/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { FC } from 'react'
import { useTranslation } from 'react-i18next'

type FiatValueProps = {
isLoading: boolean
value: number | undefined
}

export const FiatValue: FC<FiatValueProps> = ({ isLoading, value }) => {
const { t } = useTranslation()

return (
<>
{!isLoading && value
? t('common.fiatValueInUSD', {
value: value,
formatParams: {
value: {
currency: 'USD',
} satisfies Intl.NumberFormatOptions,
},
})
: t('common.missing')}
</>
)
}
12 changes: 4 additions & 8 deletions src/app/components/Tokens/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RoundedBalance } from '../RoundedBalance'
import { getTokenMarketCap } from '../../utils/tokens'
import { useTokenPrice } from '../../../coin-gecko/api'
import { Ticker } from '../../../types/ticker'
import { FiatValue } from '../FiatValue'
import { MarketCapTitle } from './MarketCapTitle'

type TokensProps = {
Expand Down Expand Up @@ -86,6 +87,8 @@ export const TokenList = (props: TokensProps) => {
]

const tableRows = tokens?.map((token, index) => {
const marketCapValue = getTokenMarketCap(token?.relative_total_value, priceQuery.price)

return {
key: token.contract_addr,
data: [
Expand Down Expand Up @@ -148,14 +151,7 @@ export const TokenList = (props: TokensProps) => {
),
},
{
content: t('common.fiatValueInUSD', {
value: getTokenMarketCap(8.01909111301725e22, priceQuery.price), // provide relative_total_value
formatParams: {
value: {
currency: 'USD',
} satisfies Intl.NumberFormatOptions,
},
}),
content: <FiatValue isLoading={priceQuery.isLoading} value={marketCapValue} />,
key: 'marketCap',
align: TableCellAlign.Right,
},
Expand Down
31 changes: 14 additions & 17 deletions src/app/pages/TokenDashboardPage/TokenMarketCapCard.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import Skeleton from '@mui/material/Skeleton'
import { SearchScope } from '../../../types/searchScope'
import { MarketCapTitle } from '../../components/Tokens/MarketCapTitle'
import { SnapshotTextCard } from '../../components/Snapshots/SnapshotCard'
import { FiatValue } from '../../components/FiatValue'
import { getTokenMarketCap } from '../../utils/tokens'
import { useTokenInfo } from './hook'

type TokenMarketCapCardProps = {
isLoading: boolean
address: string
isPriceLoading: boolean
rosePriceInUsd: number | undefined
scope: SearchScope
}

export const TokenMarketCapCard: FC<TokenMarketCapCardProps> = ({ isLoading, rosePriceInUsd, scope }) => {
const { t } = useTranslation()
export const TokenMarketCapCard: FC<TokenMarketCapCardProps> = ({
address,
isPriceLoading,
rosePriceInUsd,
scope,
}) => {
const { isLoading, token } = useTokenInfo(scope, address)
const marketCapValue = getTokenMarketCap(token?.relative_total_value, rosePriceInUsd)

return (
<SnapshotTextCard title={<MarketCapTitle scope={scope} />} withConstantHeight>
{isLoading ? (
{isLoading && isPriceLoading ? (
<Skeleton variant="text" />
) : (
rosePriceInUsd && (
<>
{t('common.fiatValueInUSD', {
value: getTokenMarketCap(8.01909111301725e22, rosePriceInUsd), // provide relative_total_value
formatParams: {
value: {
currency: 'USD',
} satisfies Intl.NumberFormatOptions,
},
})}
</>
)
<FiatValue isLoading={isPriceLoading} value={marketCapValue} />
)}
</SnapshotTextCard>
)
Expand Down
3 changes: 2 additions & 1 deletion src/app/pages/TokenDashboardPage/TokenSnapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export const TokenSnapshot: FC<TokenSnapshotProps> = ({
</StyledGrid>
<StyledGrid item xs={22} md={6}>
<TokenMarketCapCard
isLoading={isRosePriceInUsdLoading}
address={address}
isPriceLoading={isRosePriceInUsdLoading}
rosePriceInUsd={rosePriceInUsd}
scope={scope}
/>
Expand Down

0 comments on commit d76285b

Please sign in to comment.