From 24e4797900b3d2edf642fdb547bc22357a5b39ad Mon Sep 17 00:00:00 2001 From: jloup Date: Wed, 9 May 2018 19:44:17 +0200 Subject: Refactor Portfolio balance. --- cmd/web/js/balance.jsx | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 cmd/web/js/balance.jsx (limited to 'cmd/web/js/balance.jsx') diff --git a/cmd/web/js/balance.jsx b/cmd/web/js/balance.jsx new file mode 100644 index 0000000..d141aa8 --- /dev/null +++ b/cmd/web/js/balance.jsx @@ -0,0 +1,99 @@ +import React from 'react'; +import moment from 'moment'; + +class CurrencyLogo extends React.Component { + render = () => { + return
+ {this.props.currency} +
; + } + } + + var formatVariation = (variation) => { + var variationAbs = Math.abs(variation); + if (variation === 0.0) { + return {variationAbs}%; + } else if (variation > 0) { + return +{variationAbs}%; + } + return -{variationAbs}%; +}; + + +class CurrencyRateHeader extends React.Component { + render = () => { + return +
+
Asset
+
Position
+
Qty
+
Value (BTC)
+
Weight
+
Perf %
+
+
; + } +} + +class CurrencyRate extends React.Component { + render = () => { + return +
+
{this.props.currency}
+
{this.props.positionType}
+
{this.props.quantity}
+
{this.props.BTCValue}
+
{this.props.weight}%
+
{formatVariation(this.props.positionPerformanceP)}
+
+
; + } +} + +class Assets extends React.Component { + render = () => { + var currencies = Object.keys(this.props.balances).map(function(currency) { + var balance = this.props.balances[currency]; + balance.currency = currency; + return
+
+
; + }.bind(this)); + + return
+ + {currencies} +
; + } +} + +class PFBalance extends React.Component { + render = () => { + var date = moment(this.props.periodStart).format('MMM Do, h:mma'); + return +
+
+
+ Current balance +
+
+ {this.props.balance} +
+
+
+
+ since {date} +
+
+ {formatVariation(this.props.variationP)} +
+
+
+
; + } +} + +export {PFBalance, Assets}; -- cgit v1.2.3