Skip to content

Commit

Permalink
fix: overriding marketcap
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Dec 17, 2024
1 parent 3de8dc6 commit de94b08
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
19 changes: 16 additions & 3 deletions src/app/token/[tokenId]/TokenInfo/MarketCap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@ export const MarketCap: FC<
marketCap: number | null | undefined;
tradingVolume24h: number | null | undefined;
tradingVolumeChangePercentage24h: number | null | undefined;
marketCapOverride?: number | null | undefined;
}
> = ({ marketCap, tradingVolumeChangePercentage24h, tradingVolume24h, ...gridProps }) => {
> = ({

Check warning on line 16 in src/app/token/[tokenId]/TokenInfo/MarketCap.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/token/[tokenId]/TokenInfo/MarketCap.tsx#L16

Added line #L16 was not covered by tests
marketCap,
tradingVolumeChangePercentage24h,
tradingVolume24h,
marketCapOverride,
...gridProps
}) => {

Check warning on line 22 in src/app/token/[tokenId]/TokenInfo/MarketCap.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/token/[tokenId]/TokenInfo/MarketCap.tsx#L22

Added line #L22 was not covered by tests
return (
<StatSection
title="Market Cap"
bodyMainText={marketCap ? `$${abbreviateNumber(marketCap)}` : 'N/A'}
bodyMainText={
marketCapOverride
? `$${abbreviateNumber(marketCapOverride, 2)}`

Check warning on line 28 in src/app/token/[tokenId]/TokenInfo/MarketCap.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/token/[tokenId]/TokenInfo/MarketCap.tsx#L28

Added line #L28 was not covered by tests
: marketCap
? `$${abbreviateNumber(marketCap, 2)}`
: 'N/A'

Check warning on line 31 in src/app/token/[tokenId]/TokenInfo/MarketCap.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/token/[tokenId]/TokenInfo/MarketCap.tsx#L30-L31

Added lines #L30 - L31 were not covered by tests
}
bodySecondaryText={null}
caption={
<Flex fontSize={'12px'} fontWeight="500" alignItems={'center'} gap={'6px'}>
Trading Volume: ${tradingVolume24h ? abbreviateNumber(tradingVolume24h) : 'N/A'}
Trading Volume: ${tradingVolume24h ? abbreviateNumber(tradingVolume24h, 2) : 'N/A'}
{tradingVolumeChangePercentage24h ? (
<TrendArrow change={tradingVolumeChangePercentage24h} size={'11px'} />
) : null}
Expand Down
12 changes: 9 additions & 3 deletions src/app/token/[tokenId]/TokenInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC } from 'react';
import { ErrorBoundary } from 'react-error-boundary';

import { getIsSBTC } from '../../../../app/tokens/utils';

Check warning on line 4 in src/app/token/[tokenId]/TokenInfo/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/token/[tokenId]/TokenInfo/index.tsx#L4

Added line #L4 was not covered by tests
import { Wrapper } from '../../../_components/Stats/Wrapper';
import { TokenInfoProps } from '../types';
import { MarketCap } from './MarketCap';
Expand All @@ -12,14 +13,18 @@ export const TokenInfo: FC<{ tokenInfo: TokenInfoProps; tokenId: string }> = ({
tokenInfo,
tokenId,
}) => {
const circulatingSupply =
tokenInfo?.extended?.circulatingSupply || tokenInfo?.basic?.circulatingSupply;
const currentPrice = tokenInfo?.extended?.currentPrice;
const isSBTC = getIsSBTC(tokenId);

Check warning on line 19 in src/app/token/[tokenId]/TokenInfo/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/token/[tokenId]/TokenInfo/index.tsx#L18-L19

Added lines #L18 - L19 were not covered by tests
const sBTCMarketCapOverride = // LunarCrush is returning an incorrect circulating supply for SBTC, resulting in an incorrect market cap. Manually overriding it here.
circulatingSupply && currentPrice ? circulatingSupply * currentPrice : undefined;
return (
<ErrorBoundary fallbackRender={() => null}>
<Wrapper>
<Supply
borderRightWidth={['0px', '0px', '1px', '1px']}
circulatingSupply={
tokenInfo.basic?.circulatingSupply || tokenInfo.extended?.circulatingSupply
}
circulatingSupply={circulatingSupply}
totalSupply={tokenInfo.basic?.totalSupply}
/>
<Price
Expand All @@ -34,6 +39,7 @@ export const TokenInfo: FC<{ tokenInfo: TokenInfoProps; tokenId: string }> = ({
tradingVolume24h={tokenInfo.extended?.tradingVolume24h}
tradingVolumeChangePercentage24h={tokenInfo.extended?.tradingVolumeChangePercentage24h}
borderRightWidth={['0px', '0px', '1px', '1px']}
marketCapOverride={isSBTC ? sBTCMarketCapOverride : undefined}
/>
<Transaction txId={tokenId} marketCapRank={tokenInfo.extended?.marketCapRank} />
</Wrapper>
Expand Down

0 comments on commit de94b08

Please sign in to comment.