From edbe6002df0f2baf6b35ec92fd36708a7d030332 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Sat, 19 Dec 2020 21:52:40 +0000 Subject: [PATCH] revamped position table --- websrc/components/Tables.tsx | 142 ++++++++++++++++++++--------------- 1 file changed, 83 insertions(+), 59 deletions(-) diff --git a/websrc/components/Tables.tsx b/websrc/components/Tables.tsx index 8987a2b..09786b4 100644 --- a/websrc/components/Tables.tsx +++ b/websrc/components/Tables.tsx @@ -1,87 +1,111 @@ import React, {Component} from "react" -import {Badge, Button, Container, Table} from "react-bootstrap" -import {socket} from '../'; -import {PositionCloseMessage, PositionProp} from "../types"; +import {PositionProp} from "../types"; - -export class PositionTable extends Component<{ positions: Array }> { +export class PositionsTable extends Component<{ positions: Array }> { constructor(props) { - super(props) + super(props); } - stateVariantFromStr(state: string): string { + stateColor(state: string): string { const lower_state = state.toLowerCase() - let res: string; + let res: string if (lower_state.includes("profit")) { - res = "success" + res = "green" } else if (lower_state.includes("break")) { - res = "primary" + res = "yellow" } else { - res = "danger" + res = "red" } return res } - plColorFromStr(amount: number): string { - if (amount > 0) { - return "success" - } else { - return "danger" - } + + renderTableHead() { + return ["status", "currency pair", "base price", "amount", "Profit/Loss", "actions"].map((entry) => { + return ( + + {entry} + + ) + } + ) } - tableData() { - return this.props.positions.map((position: PositionProp) => { - let row_bg = ""; + renderTableRows() { + return this.props.positions.map((position) => { + const stateBg = "bg-".concat(this.stateColor(position.state)).concat("-100 ") + const stateText = "text-".concat(this.stateColor(position.state)).concat("-800 ") + const stateClass = "px-2 inline-flex text-xs leading-5 font-semibold rounded-full ".concat(stateBg).concat(stateText) - if (!position.state.toLowerCase().includes("break")) { - row_bg = "table-" + this.plColorFromStr(position.profit_loss) - } + return ( + + {/* Status */} + + + {position.state} + + - return ( - {position.state} - {position.symbol} - {position.base_price.toFixed(2)} - {position.amount.toFixed(5)} - {position.profit_loss.toFixed(2)} - {position.profit_loss_percentage.toFixed(2)} % - - ) + +
{position.symbol}
+ {/*
{position.}
*/} + + + +
{position.base_price.toLocaleString()} USD/BTC
+ {/*
Insert total % here?
*/} + + + +
{position.amount.toFixed(5)} BTC
+
Insert total % here?
+ + + +
{position.profit_loss.toLocaleString()} USD
+
{position.profit_loss_percentage.toFixed(2)}%
+ + + +
+
+ Close +
+
+ + + ) }) } render() { return ( - -
-

Open positions

+
+
+
+
+ + + + + {this.renderTableHead()} + + + + + {this.renderTableRows()} + +
+
+
- - - - - - - - - - - - - - {this.tableData()} - -
StateSymbolBase priceAmountP/LP/L %Action
- +
+ ) } } \ No newline at end of file