import React, { useState, useEffect } from 'react' import { connect } from 'react-redux' import { getChart, getUserTriggers, getUserNotifications, getUserTransactions } from '../../stores/exchange/duck/operations' import { useInterval } from '../useInterval' import ExchangeTriggerAdd from './exchangeTriggerAdd' import ExchangePrognosis from './exchangePrognosis' import ExchangeNotifications from './exchangeNotifications' import '../../styles/indexExchange.scss' const IndexExchange = ({ user, exchange, getChart, getUserTriggers, getUserNotifications, getUserTransactions }) => { let fifteenMinuts = 1500000 useInterval( () => { getChart() }, fifteenMinuts ) const [candleInfo, setCandleInfo] = useState( { Open: 0, Close: 0, Min: 0, Max: 0, Vol: 0 } ) const [mousePosition, setMousePosition] = useState( { x: 0, y: 0 } ) const [triggerValue, setTriggerValue] = useState(0) const colorGreen = { background: 'green'//'rgba(0,93,0,1)', } const colorRed = { background: 'red'//'rgba(136,15,15,1)', } const getCandleInformation = (candle) => { setCandleInfo( { Open: candle.Open, Close: candle.Close, Min: candle.Min, Max: candle.Max, Vol: candle.Volume, Date: candle.Date } ) } let pixelScale = ( exchange.candles.graphMax - exchange.candles.graphMin ) / 590 let cursorValue = exchange.candles.graphMax - ( pixelScale * ( mousePosition.y - 175 ) ) const getMousePosition = (event) => { setMousePosition( { x: event.pageX, y: event.pageY } ) } return (
-1 ? 'exchangeChartUser' : 'exchangeChartGuest' }>
getMousePosition(event) } onClick={ () => setTriggerValue( parseInt(cursorValue) ) } style={ { width: exchange.candles.candlesCount * 15 + 'px' } }> { user.id > -1 ? (

{ parseInt(cursorValue) } PLN

) : (
) } { 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 scaleProperties = 10 let chartScaleY = (exchange.candles.graphMax - candle.Max) / pixelScale let onePercentScaleY = 100 / chartScaleY let difference = ( highValue - lowValue ) / pixelScale if ( parseInt(difference) === 0 ) difference = 1 return (
getCandleInformation(candle) }>
) } ) }
-1 ? 'exchangeInterface' : 'exchangeEmptySpace' }>

Open: { candleInfo.Open } PLN,

Close: { candleInfo.Close } PLN,

Max: { candleInfo.Max } PLN,

Min: { candleInfo.Min } PLN,

Volume: { candleInfo.Vol },

Date: { candleInfo.Date }

{ user.id > -1 ? (
) : (
) }
) } const mapStateToProps = state => ({ user: state.user, exchange: state.exchange }) const mapDispatchToProps = dispatch => ({ getChart: exchange => dispatch( getChart(exchange) ), getUserTriggers: exchange => dispatch( getUserTriggers(exchange) ), getUserNotifications: exchange => dispatch( getUserNotifications(exchange) ), getUserTransactions: exchange => dispatch( getUserTransactions(exchange) ) }) export default connect(mapStateToProps,mapDispatchToProps)(IndexExchange)