import React, {Component} from "react" import {PositionProp} from "../types"; export class PositionsTable extends Component<{ positions: Array }> { constructor(props) { super(props); } stateColor(state: string): string { const lower_state = state.toLowerCase() let res: string if (lower_state.includes("profit")) { res = "green" } else if (lower_state.includes("break")) { res = "yellow" } else { res = "red" } return res } renderTableHead() { return ["status", "currency pair", "base price", "amount", "Profit/Loss", "actions"].map((entry) => { return ( {entry} ) } ) } 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) return ( {/* Status */} {position.state}
{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 (
{this.renderTableHead()} {this.renderTableRows()}
) } }