2020-12-12 20:18:25 +00:00
|
|
|
import React, { Component } from "react";
|
2020-12-13 19:32:33 +00:00
|
|
|
import { Col, Container, Navbar, Row } from "react-bootstrap";
|
2020-12-12 20:18:25 +00:00
|
|
|
import Plot from "react-plotly.js";
|
2020-12-13 11:27:50 +00:00
|
|
|
import HCard from "./HCard";
|
2020-12-13 19:32:33 +00:00
|
|
|
import RPlot from "./RPlot";
|
|
|
|
import { RToast } from "./RToast";
|
|
|
|
import { NewTickData, socket } from "../";
|
|
|
|
|
|
|
|
type AppState = {
|
|
|
|
current_price: number,
|
|
|
|
current_tick: number,
|
|
|
|
last_update: Date
|
|
|
|
}
|
2020-12-12 20:18:25 +00:00
|
|
|
|
|
|
|
class App extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
|
|
|
|
2020-12-13 19:32:33 +00:00
|
|
|
state = {
|
|
|
|
current_price: 0,
|
|
|
|
current_tick: 0,
|
|
|
|
last_update: new Date()
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
socket.on("new_tick", (data: NewTickData) => {
|
|
|
|
this.setState({ current_price: data.price, current_tick: data.tick, last_update: new Date() })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-12 20:18:25 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2020-12-13 19:32:33 +00:00
|
|
|
<Container className="flex-fill border d-flex flex-column">
|
|
|
|
<Row className="justify-content-center my-2">
|
|
|
|
<HCard title="Current tick:" content={String(this.state.current_tick)} update={this.state.last_update}></HCard>
|
|
|
|
<HCard title="Current price:" content={String(this.state.current_price)} update={this.state.last_update}></HCard>
|
|
|
|
</Row>
|
2020-12-12 20:18:25 +00:00
|
|
|
|
2020-12-13 19:32:33 +00:00
|
|
|
<Row className="flex-grow-1 border-top border-bottom">
|
|
|
|
<RPlot />
|
|
|
|
</Row>
|
|
|
|
</Container >
|
2020-12-12 20:18:25 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|