import { Flex, Text, Tooltip } from 'components/primitives' import { useAttributes, useCollections, useTokens, } from '@reservoir0x/reservoir-kit-ui' import { formatNumber } from 'utils/numbers' type Props = { token: ReturnType['data'][0] | null collection?: NonNullable['data']>[0] | null collectionAttributes?: ReturnType['data'] } export default ({ token, collection, collectionAttributes }: Props) => { const rarityRank = token?.token?.rarityRank as number const tokenCount = collection?.tokenCount as string const rankPercentile = Math.floor((rarityRank / parseInt(tokenCount)) * 100) const topPercentile = (percentile: number) => { if (percentile <= 1) { return 1 } else if (percentile <= 5) { return 5 } else if (percentile <= 10) { return 10 } else if (percentile <= 15) { return 15 } else if (percentile <= 20) { return 20 } else if (percentile <= 25) { return 25 } else if (percentile <= 30) { return 30 } else if (percentile <= 40) { return 40 } else if (percentile <= 50) { return 50 } else return } let topPercentileText = rankPercentile <= 50 && `Top ${topPercentile(rankPercentile)}%` const rarityEnabledCollection = tokenCount && +tokenCount >= 2 && collectionAttributes && collectionAttributes?.length >= 2 if ( rarityRank === undefined || rarityRank === null || token?.token?.kind === 'erc1155' || !rarityEnabledCollection ) { return null } return ( {topPercentileText} Rarity rank:{' '} {`${formatNumber(rarityRank)}/ ${formatNumber(tokenCount)}`} By Poprank } > Rank {formatNumber(rarityRank)} ) }