Skip to content

Commit

Permalink
feat: add fee burned chart
Browse files Browse the repository at this point in the history
  • Loading branch information
vien.nguyen2-tiki committed Mar 3, 2023
1 parent b211d6d commit 88b813d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pages/charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Head from 'next/head'
import React from 'react'
import Address from 'views/charts/Address'
import Fee from 'views/charts/Fee'
import FeeBurn from 'views/charts/FeeBurn'
import Gas from 'views/charts/Gas'
import Transactions from 'views/charts/Transactions'
import Overview from 'views/homepage/Overview'
Expand All @@ -22,6 +23,7 @@ const Charts: React.FC<NextPage> = _ => {
<Address />
<Gas />
<Fee />
<FeeBurn />
</div>
</Container>
</Layout>
Expand Down
52 changes: 52 additions & 0 deletions views/charts/FeeBurn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Col, Row } from '@astraprotocol/astra-ui'
import API_LIST from 'api/api_list'
import { ethers } from 'ethers'
import { isNumber } from 'lodash'
import useSWR from 'swr'
import { convertBigNumberToString } from 'utils/helper'
import ChartHeader from './components/Header'
import LineChart from './components/LineChart'

function convertFeeToDataSet(history: FeeItem[], convertDecimal?: boolean): [string[], number[]] {
const data = history.map(({ totalTransactionFees }) =>
parseFloat(ethers.utils.formatEther(`${convertBigNumberToString((totalTransactionFees || 0) / 2)}`))
)

const labels = history.map(({ date, year, month }) => (date ? date : `${year}-${month}-01`))
return [labels, data]
}

export default function FeeBurn() {
const { data: feeDailyRes } = useSWR<FeeResponse>(
API_LIST.GET_FEE_DAILY.replace('#YEAR', new Date().getFullYear().toString())
)
const feeDaily = feeDailyRes?.result?.totalFeesHistory || []
const [feeDailyLabels, feeDailyData] = convertFeeToDataSet(feeDaily)

return (
<Col>
<ChartHeader text="Fees Burned" />
<Row className="md-flex-column">
<LineChart
leftTitle="Total fees burned | Daily"
rightTitle={{
title: 'Daily Average',
value: parseFloat(
ethers.utils.formatEther(
`${
isNumber(feeDailyRes?.result?.dailyAverage)
? convertBigNumberToString((feeDailyRes?.result?.dailyAverage || 0) / 2)
: 0
}`
)
)
}}
data={feeDailyData}
labels={feeDailyLabels}
label="Fee Burned"
unitName="ASA"
/>
</Row>
</Col>
)
}

0 comments on commit 88b813d

Please sign in to comment.