-
Notifications
You must be signed in to change notification settings - Fork 0
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
vien.nguyen2-tiki
committed
Mar 3, 2023
1 parent
b211d6d
commit 88b813d
Showing
2 changed files
with
54 additions
and
0 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
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> | ||
) | ||
} |