This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
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
beee9f9
commit 9031bc5
Showing
3 changed files
with
32 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Line } from 'react-chartjs-2'; | ||
import Title from './Title'; | ||
|
||
const TokenDaily = { | ||
date: PropTypes.instanceOf(Date).isRequired, | ||
price_usd: PropTypes.number.isRequired, | ||
}; | ||
|
||
const PoolPropTypes = { | ||
pairDailyList: PropTypes.arrayOf(TokenDaily).isRequired, | ||
}; | ||
|
||
const LineChart = ({ pairDailyList }) => { | ||
const sortedPairDailyList = pairDailyList.sort( | ||
(a, b) => new Date(b.date) - new Date(a.date), | ||
); | ||
const labels = sortedPairDailyList.map((pairDaily) => pairDaily.date); | ||
const datasetsData = sortedPairDailyList.map((pairDaily) => pairDaily.price_usd); | ||
const data = { | ||
labels, | ||
datasets: [{ | ||
label: 'Price USD', | ||
data: datasetsData, | ||
}], | ||
}; | ||
return <Line data={data} />; | ||
}; | ||
LineChart.propTypes = PoolPropTypes; | ||
|
||
const Pool = ({ pairDailyList }) => ( | ||
<> | ||
<p>Pool page</p> | ||
<pre> | ||
{JSON.stringify(pairDailyList, null, 2)} | ||
</pre> | ||
<Title title="Pair" /> | ||
<LineChart pairDailyList={pairDailyList} /> | ||
</> | ||
); | ||
Pool.propTypes = { | ||
pairDailyList: PropTypes.arrayOf(TokenDaily).isRequired, | ||
}; | ||
Pool.propTypes = PoolPropTypes; | ||
|
||
export default Pool; |