Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚦 CRT Token status widget #4731

Merged
merged 7 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Meta } from '@storybook/react'

import { CrtStatusWidgetProps, CrtStatusWidget as _CrtStatusWidget } from './CrtStatusWidget'

export default {
title: 'crt/CrtStatusWidget',
component: _CrtStatusWidget,
args: {
name: 'CRT',
creationDate: new Date(),
supply: 20_000_000,
marketCap: 2_222_000,
revenue: 234_000,
revenueShare: 200_000,
transactionVolume: 2_222_222,
},
} as Meta<CrtStatusWidgetProps>

export const CrtStatusWidget = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import styled from '@emotion/styled'

import { Text } from '@/components/Text'
import { WidgetTile } from '@/components/WidgetTile'
import { cVar, sizes } from '@/styles'

export const DetailsBox = styled.div`
display: flex;
flex-direction: column;
gap: ${sizes(6)};
margin-top: ${sizes(6)};
`
export const ExpandableContainer = styled.div`
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
margin-top: ${sizes(4)};
cursor: pointer;

button {
grid-row-end: span 2;
}

p {
color: ${cVar('colorText')};
}
`
export const StatisticsContainer = styled.div`
::before {
content: '';
display: block;
position: absolute;
border-top: solid 1px ${cVar('colorBorderMutedAlpha')};
left: 0;
right: 0;
}
`

export const SupplyLine = styled.div`
display: flex;
align-items: center;
gap: ${sizes(1)};
`

export const LabelText = styled(Text)`
color: ${cVar('colorText')};
`

export const Widget = styled(WidgetTile)`
position: relative;

> :first-child {
margin-bottom: ${sizes(1)};
}

> :last-child {
grid-template-columns: 1fr;
}
`
121 changes: 121 additions & 0 deletions packages/atlas/src/components/_crt/CrtStatusWidget/CrtStatusWidget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { FC, useState } from 'react'

import { Information } from '@/components/Information'
import { JoyTokenIcon } from '@/components/JoyTokenIcon'
import { NumberFormat, NumberFormatProps } from '@/components/NumberFormat'
import { Text } from '@/components/Text'
import { ExpandButton } from '@/components/_buttons/ExpandButton'
import { DetailsContent } from '@/components/_nft/NftTile'
import { useMediaMatch } from '@/hooks/useMediaMatch'
import { formatDate } from '@/utils/time'

import {
DetailsBox,
ExpandableContainer,
LabelText,
StatisticsContainer,
SupplyLine,
Widget,
} from './CrtStatusWidget.styles'

type Amount = NumberFormatProps['value']
export type CrtStatusWidgetProps = {
name: string
creationDate: Date
supply: Amount
marketCap: Amount
revenue: Amount
revenueShare: Amount
transactionVolume: Amount
}

export const CrtStatusWidget: FC<CrtStatusWidgetProps> = ({
name,
creationDate,
supply,
marketCap,
revenue,
revenueShare,
transactionVolume,
}) => {
const [isExpanded, expand] = useState(true)
const smMatch = useMediaMatch('sm')

const ticker = `$${name}`

return (
<Widget
title="Status"
customNode={
<>
<Text as="h4" variant="h500">
No active sale
</Text>

<SupplyLine>
<LabelText as="span" variant="t100">
Total supply:
</LabelText>
<NumberFormat as="span" variant="t100" format="short" value={supply} customTicker={ticker} withToken />
<Information />
</SupplyLine>

<StatisticsContainer onClick={() => expand(!isExpanded)}>
attemka marked this conversation as resolved.
Show resolved Hide resolved
<ExpandableContainer>
<Text as="h3" variant="h500">
Statistics
</Text>
<ExpandButton expanded={isExpanded} />
<Text as="p" variant="t100">
Token creation date, Revenue, Volume, Vesting
</Text>
</ExpandableContainer>

{isExpanded && (
<DetailsBox>
attemka marked this conversation as resolved.
Show resolved Hide resolved
<DetailsContent
avoidIconStyling
tileSize={smMatch ? 'big' : 'bigSmall'}
caption="Token creation date"
content={formatDate(creationDate)}
/>
<DetailsContent
avoidIconStyling
tileSize={smMatch ? 'big' : 'bigSmall'}
caption="Market cap"
content={marketCap}
icon={<JoyTokenIcon size={smMatch ? 24 : 16} variant="silver" />}
withDenomination
/>
<DetailsContent
avoidIconStyling
tileSize={smMatch ? 'big' : 'bigSmall'}
caption="Total revenue"
content={revenue}
icon={<JoyTokenIcon size={smMatch ? 24 : 16} variant="silver" />}
withDenomination
/>
<DetailsContent
avoidIconStyling
tileSize={smMatch ? 'big' : 'bigSmall'}
caption="Total revenue Shares"
content={revenueShare}
icon={<JoyTokenIcon size={smMatch ? 24 : 16} variant="silver" />}
withDenomination
/>
<DetailsContent
avoidIconStyling
tileSize={smMatch ? 'big' : 'bigSmall'}
caption="Total Transaction volume"
content={transactionVolume}
icon={<JoyTokenIcon size={smMatch ? 24 : 16} variant="silver" />}
withDenomination
/>
</DetailsBox>
)}
</StatisticsContainer>
</>
}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CrtStatusWidget'
5 changes: 3 additions & 2 deletions packages/atlas/src/components/_nft/NftTile/NftTileDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BN from 'bn.js'
import { FC, ReactElement, ReactNode, memo, useEffect, useId, useMemo, useRef, useState } from 'react'
import useResizeObserver from 'use-resize-observer'

Expand Down Expand Up @@ -256,7 +257,7 @@ type DetailsContentProps = {
caption: string
icon?: ReactNode
avoidIconStyling?: boolean
content: number | string | ReactElement | ReactElement[]
content: number | BN | string | ReactElement | ReactElement[]
secondary?: boolean
tileSize: TileSize | undefined
withDenomination?: boolean
Expand Down Expand Up @@ -288,7 +289,7 @@ export const DetailsContent: FC<DetailsContentProps> = memo(
<Text as="span" variant={getSize().content} color={secondary ? 'colorText' : undefined}>
{content}
</Text>
) : typeof content === 'number' ? (
) : BN.isBN(content) || typeof content === 'number' ? (
<NumberFormat
as="span"
icon={icon}
Expand Down
Loading