-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47665e3
commit 08f96d4
Showing
16 changed files
with
486 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
frontend/src/components/molecules/chart-mint-burn/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { | ||
Box, | ||
Container, | ||
Flex, | ||
Skeleton, | ||
Text, | ||
useColorMode, | ||
} from '@chakra-ui/react' | ||
import { Dispatch, SetStateAction } from 'react' | ||
import Chart from 'react-apexcharts' | ||
|
||
import { getChartLabels, isEqualLabel } from 'utils/constants/dashboards' | ||
import { toCrypto } from 'utils/formatter' | ||
|
||
import { ChartPeriod, TChartPeriod } from '../chart-period' | ||
|
||
interface IChartMintBurn { | ||
loadingChart: boolean | ||
mintOperations: Hooks.UseDashboardsTypes.IAsset | ||
burnOperations: Hooks.UseDashboardsTypes.IAsset | ||
chartPeriod: TChartPeriod | ||
setChartPeriod: Dispatch<SetStateAction<TChartPeriod>> | ||
} | ||
|
||
export const ChartMintBurn: React.FC<IChartMintBurn> = ({ | ||
mintOperations, | ||
burnOperations, | ||
chartPeriod, | ||
loadingChart, | ||
setChartPeriod, | ||
}) => { | ||
const { colorMode } = useColorMode() | ||
|
||
const series = [ | ||
{ | ||
name: 'Mint', | ||
data: getChartLabels(chartPeriod).map(label => { | ||
const index = mintOperations.date?.findIndex(date => | ||
isEqualLabel(chartPeriod, date, label) | ||
) | ||
return index > -1 ? mintOperations.amount[index] : 0 | ||
}), | ||
}, | ||
{ | ||
name: 'Burn', | ||
data: getChartLabels(chartPeriod).map(label => { | ||
const index = burnOperations.date?.findIndex(date => | ||
isEqualLabel(chartPeriod, date, label) | ||
) | ||
return index > -1 ? burnOperations.amount[index] : 0 | ||
}), | ||
}, | ||
] | ||
|
||
const options = { | ||
chart: { | ||
id: 'line', | ||
foreColor: colorMode === 'dark' ? 'white' : 'black', | ||
toolbar: { | ||
show: true, | ||
offsetX: 0, | ||
offsetY: 0, | ||
tools: { | ||
download: false, | ||
selection: false, | ||
zoom: true, | ||
zoomin: true, | ||
zoomout: true, | ||
pan: false, | ||
reset: true, | ||
}, | ||
}, | ||
stroke: { | ||
curve: 'smooth', | ||
}, | ||
}, | ||
tooltip: { | ||
theme: colorMode, | ||
}, | ||
xaxis: { | ||
categories: getChartLabels(chartPeriod), | ||
labels: { | ||
show: true, | ||
formatter: function (value: string): string { | ||
return `${chartPeriod === '24h' ? `${value}h` : `${value}`}` | ||
}, | ||
}, | ||
}, | ||
yaxis: { | ||
labels: { | ||
show: true, | ||
formatter: function (value: number): string { | ||
return `${toCrypto(value)}` | ||
}, | ||
}, | ||
}, | ||
dataLabels: { | ||
enabled: false, | ||
}, | ||
} | ||
|
||
return ( | ||
<Container | ||
variant="primary" | ||
justifyContent="center" | ||
py="0.5rem" | ||
px="0.75rem" | ||
w="full" | ||
maxW="full" | ||
mt="1rem" | ||
> | ||
<Flex justifyContent="space-between" mb="1.25rem"> | ||
<Text fontSize="xs" fontWeight="600"> | ||
Mint/Burn timeline | ||
</Text> | ||
<Flex> | ||
<ChartPeriod period={chartPeriod} setPeriod={setChartPeriod} /> | ||
</Flex> | ||
</Flex> | ||
<Box> | ||
{loadingChart ? ( | ||
<Skeleton h="12rem" w="full" /> | ||
) : ( | ||
<Chart | ||
options={options} | ||
series={series} | ||
type="line" | ||
width="100%" | ||
height="320px" | ||
/> | ||
)} | ||
</Box> | ||
</Container> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Button, Container, Flex } from '@chakra-ui/react' | ||
import React, { Dispatch, SetStateAction } from 'react' | ||
|
||
export type TChartPeriod = '24h' | '7d' | '30d' | ||
|
||
interface IChartPeriod { | ||
period: TChartPeriod | ||
setPeriod: Dispatch<SetStateAction<TChartPeriod>> | ||
} | ||
|
||
export const ChartPeriod: React.FC<IChartPeriod> = ({ period, setPeriod }) => { | ||
return ( | ||
<Container variant="primary" p="0" h="2rem"> | ||
<Flex> | ||
<Button | ||
variant={period === '24h' ? 'menuButtonSelected' : 'menuButton'} | ||
borderStartRadius="0.25rem" | ||
h="2rem" | ||
onClick={(): void => { | ||
setPeriod('24h') | ||
}} | ||
> | ||
Last 24h | ||
</Button> | ||
<Button | ||
variant={period === '7d' ? 'menuButtonSelected' : 'menuButton'} | ||
h="2rem" | ||
onClick={(): void => { | ||
setPeriod('7d') | ||
}} | ||
> | ||
7 days | ||
</Button> | ||
<Button | ||
variant={period === '30d' ? 'menuButtonSelected' : 'menuButton'} | ||
h="2rem" | ||
borderEndRadius="0.25rem" | ||
onClick={(): void => { | ||
setPeriod('30d') | ||
}} | ||
> | ||
30 days | ||
</Button> | ||
</Flex> | ||
</Container> | ||
) | ||
} |
Oops, something went wrong.