import React, { useState, useEffect } from 'react' import { connect } from 'react-redux' import { getChart, getTriggers, getNotifications, getTransactions } from '../../stores/exchange/duck/operations' import '../../styles/indexExchange.scss' const IndexExchange = ({ user, exchange, getChart, getTriggers, getNotifications, getTransactions }) => { useEffect( () => { getChart() }, [] ) const [candleInfo, setCandleInfo] = useState( { Open: 0, Close: 0, Min: 0, Max: 0, Vol: 0 } ) const colorGreen = { background: 'green', } const colorRed = { background: 'red', } const getCandleInformation = (candle) => { setCandleInfo( { Open: candle.Open, Close: candle.Close, Min: candle.Min, Max: candle.Max, Vol: candle.Volume, Date: candle.Date } ) } return (
-1 ? 'exchangeChartUser' : 'exchangeChartGuest' }>
{ exchange.candles.candles.map( (candle, key) => { const color = candle.Open > candle.Close ? colorRed.background : colorGreen.background let highValue = candle.Open > candle.Close ? candle.Open : candle.Close let lowValue = candle.Open < candle.Close ? candle.Open : candle.Close let difference = highValue - lowValue let chartScaleY = (exchange.candles.graphMax - candle.Max) / 8 if ( difference > 0 && difference < 10 ) difference *= 2 else if ( difference > 50 && difference < 100 ) difference /= 2 else if ( difference >= 100 && difference <= 200 ) difference /= 3 else if ( difference > 200 ) difference = difference % 100 return (
getCandleInformation(candle) }>
) } ) }
-1 ? 'exchangeInterface' : 'emptySpaceExchange' }>

Open: { candleInfo.Open }, Close: { candleInfo.Close }

Max: { candleInfo.Max }, Min: { candleInfo.Min }

Volume: { candleInfo.Vol }

Date: { candleInfo.Date }

) } const mapStateToProps = state => ({ user: state.user, exchange: state.exchange }) const mapDispatchToProps = dispatch => ({ getChart: exchange => dispatch( getChart(exchange) ), getTriggers: exchange => dispatch( getTriggers(exchange) ), getNotifications: exchange => dispatch( getNotifications(exchange) ), getTransactions: exchange => dispatch( getTransactions(exchange) ) }) export default connect(mapStateToProps,mapDispatchToProps)(IndexExchange)