Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
Add price charts to Converter and Auction screens
Browse files Browse the repository at this point in the history
Closes #414
  • Loading branch information
Pablo Enrici committed Nov 21, 2018
1 parent 0d6e0fa commit 17e5def
Show file tree
Hide file tree
Showing 10 changed files with 445 additions and 14 deletions.
176 changes: 173 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@
"redux-actions": "2.4.0",
"reselect": "3.0.1",
"safe-buffer": "5.1.2",
"shrink-array": "0.0.2",
"smart-round": "1.0.0",
"socket.io-client": "2.1.1",
"startinterval2": "1.0.1",
"styled-components": "3.3.3",
"supports-color": "5.4.0",
"tough-cookie": "2.4.3",
"universal-analytics": "0.4.17",
"victory": "0.27.0",
"web3": "1.0.0-beta.34"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion public/main/main-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function loadWindow () {
mainWindow = new BrowserWindow({
show: false,
width: 1140,
height: 700,
height: 750,
minWidth: 640,
minHeight: 578,
useContentSize: true
Expand Down
16 changes: 9 additions & 7 deletions src/components/Auction.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CountDownProvider from './providers/CountDownProvider'
import AuctionChartCard from './AuctionChartCard'
import * as selectors from '../selectors'
import BuyMETDrawer from './BuyMETDrawer'
import { connect } from 'react-redux'
Expand Down Expand Up @@ -65,7 +66,7 @@ const Body = styled.div`
align-items: center;
flex-direction: column;
@media (min-width: 1200px) {
@media (min-width: 1140px) {
align-items: flex-start;
margin-top: 4.8rem;
flex-direction: row;
Expand All @@ -78,7 +79,7 @@ const BuyBtn = styled(Btn)`
margin-bottom: 3.2rem;
min-width: 300px;
@media (min-width: 1200px) {
@media (min-width: 1140px) {
margin-bottom: 0;
order: 1;
min-width: auto;
Expand All @@ -92,7 +93,7 @@ const StatsContainer = styled.div`
width: 100%;
margin-right: 0;
@media (min-width: 1200px) {
@media (min-width: 1140px) {
margin-right: 1.6rem;
max-width: 660px;
}
Expand All @@ -117,7 +118,7 @@ const Badge = styled.div`
padding: 0.4rem 0.8rem;
margin-right: 0.4rem;
@media (min-width: 1100px) {
@media (min-width: 1140px) {
font-size: 2rem;
}
`
Expand All @@ -127,7 +128,7 @@ const Price = styled.div`
font-weight: 600;
text-shadow: 0 1px 1px ${p => p.theme.colors.darkShade};
@media (min-width: 1100px) {
@media (min-width: 1140px) {
font-size: 2.4rem;
}
`
Expand All @@ -138,7 +139,7 @@ const USDPrice = styled.div`
font-weight: 600;
text-align: right;
@media (min-width: 1100px) {
@media (min-width: 1140px) {
font-size: 1.6rem;
}
`
Expand All @@ -148,7 +149,7 @@ const AvailableAmount = styled.div`
font-weight: 600;
text-shadow: 0 1px 1px ${p => p.theme.colors.darkShade};
@media (min-width: 1100px) {
@media (min-width: 1140px) {
font-size: 2.4rem;
}
`
Expand Down Expand Up @@ -285,6 +286,7 @@ class Auction extends React.Component {
</AvailableAmount>
</Flex.Row>
</Sp>
<AuctionChartCard />
</StatsContainer>

<BuyMETDrawer
Expand Down
86 changes: 86 additions & 0 deletions src/components/AuctionChartCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React, { Component } from 'react'
import { ChartCard } from './common'
import shrinkArray from 'shrink-array'
import { connect } from 'react-redux'
import config from '../config'
import moment from 'moment'
import last from 'shrink-array/last'

const sevenDaysAgo = () =>
moment()
.subtract({ days: 7 })
.unix()

class AuctionChartCard extends Component {
state = {
chartStatus: 'pending',
chartData: []
}

// eslint-disable-next-line arrow-body-style
retrieveData = () => {
this.setState({ chartStatus: 'pending', chartData: [] })

const from = sevenDaysAgo()
const now = moment().unix()

fetch(`${config.MET_API_URL}/history?from=${from}&to=${now}`)
.then(response => response.json())
.then(chartData => {
if (!this._isMounted) return
this.setState({
chartStatus: 'success',
chartData: chartData.map(point => ({
x: point.timestamp,
y: parseInt(point.currentAuctionPrice, 10)
}))
})
})
.catch(() => {
if (!this._isMounted) return
this.setState({ chartStatus: 'failure', chartData: [] })
})
}

componentDidMount() {
this._isMounted = true
this.retrieveData()
}

componentWillUnmount() {
this._isMounted = false
}

static getDerivedStateFromProps(props, state) {
const point = {
y: parseInt(props.auction.currentPrice, 10),
x: moment().unix()
}
const from = sevenDaysAgo()
const newChartData = state.chartData.concat(point).filter(p => p.x >= from)

return {
chartData:
newChartData.length > 500
? shrinkArray(newChartData, 500, last)
: newChartData
}
}

render() {
return (
<ChartCard
chartStatus={this.state.chartStatus}
chartLabel="Auction Price (last 7 days)"
chartData={this.state.chartData}
onRetry={this.retrieveData}
/>
)
}
}

const mapStateToProps = state => ({
auction: state.auction.status
})

export default connect(mapStateToProps)(AuctionChartCard)
Loading

0 comments on commit 17e5def

Please sign in to comment.