Browse Source

formatValue negative num fix; balance placeholders rounding fix

all-modes
pbca26 8 years ago
parent
commit
cd89b254d5
  1. 31
      react/src/components/dashboard/walletsBalance/walletsBalance.js
  2. 35
      react/src/components/dashboard/walletsBalance/walletsBalance.render.js
  3. 13
      react/src/util/formatValue.js

31
react/src/components/dashboard/walletsBalance/walletsBalance.js

@ -70,14 +70,13 @@ class WalletsBalance extends React.Component {
if (_mode === 'full') {
_balance = this.props.ActiveCoin.balance || 0;
} else {
} else if (_mode === 'basilisk') {
if (this.props.ActiveCoin.cache) {
const _cache = this.props.ActiveCoin.cache;
const _coin = this.props.ActiveCoin.coin;
const _address = this.props.ActiveCoin.activeAddress;
if (type === 'main' &&
_mode === 'basilisk' &&
if (type === 'transparent' &&
_address &&
_cache[_coin] &&
_cache[_coin][_address] &&
@ -88,7 +87,6 @@ class WalletsBalance extends React.Component {
}
if (type === 'interest' &&
_mode === 'basilisk' &&
_address &&
_cache[_coin] &&
_cache[_coin][_address] &&
@ -99,7 +97,6 @@ class WalletsBalance extends React.Component {
}
if (type === 'total' &&
_mode === 'basilisk' &&
_address &&
_cache[_coin] &&
_cache[_coin][_address] &&
@ -113,6 +110,30 @@ class WalletsBalance extends React.Component {
_balance = _regBalance + _regInterest;
}
}
} else if (_mode === 'native') {
if (type === 'total' &&
this.props.ActiveCoin.balance &&
this.props.ActiveCoin.balance.total) {
_balance = this.props.ActiveCoin.balance.total;
}
if (type === 'interest' &&
this.props.Dashboard.progress &&
this.props.Dashboard.progress.interest) {
_balance = this.props.Dashboard.progress.interest;
}
if (type === 'private' &&
this.props.ActiveCoin.balance &&
this.props.ActiveCoin.balance.private) {
_balance = this.props.ActiveCoin.balance.private;
}
if (type === 'transparent' &&
this.props.ActiveCoin.balance &&
this.props.ActiveCoin.balance.transparent) {
_balance = this.props.ActiveCoin.balance.transparent;
}
}
return _balance;

35
react/src/components/dashboard/walletsBalance/walletsBalance.render.js

@ -37,14 +37,8 @@ const WalletsBalanceRender = function() {
</div>
<span
className="pull-right padding-top-10 font-size-22"
title={ Config.roundValues ? this.renderBalance('main') : null }>
{ this.isNativeMode() ?
this.props.ActiveCoin.balance.transparent ? this.props.ActiveCoin.balance.transparent : '-'
:
<span>
{ Config.roundValues ? formatValue('round', this.renderBalance('main'), -6) : this.renderBalance('main') } { this.props.ActiveCoin.coin }
</span>
}
title={ Config.roundValues ? formatValue('round', this.renderBalance('transparent'), -6) : this.renderBalance('transparent') }>
{ Config.roundValues ? formatValue('round', this.renderBalance('transparent'), -6) : this.renderBalance('transparent') } { this.props.ActiveCoin.coin }
</span>
</div>
</div>
@ -63,8 +57,8 @@ const WalletsBalanceRender = function() {
</div>
<span
className="pull-right padding-top-10 font-size-22"
title={ Config.roundValues ? this.props.ActiveCoin.balance.private : null }>
{ this.props.ActiveCoin.balance.private ? (Config.roundValues ? formatValue('round', this.props.ActiveCoin.balance.private, -6) : this.props.ActiveCoin.balance.private) : '-' }
title={ Config.roundValues ? formatValue('round', this.renderBalance('private'), -6) : this.renderBalance('private') }>
{ Config.roundValues ? formatValue('round', this.renderBalance('private'), -6) : this.renderBalance('private') }
</span>
</div>
</div>
@ -84,15 +78,8 @@ const WalletsBalanceRender = function() {
</div>
<span
className="pull-right padding-top-10 font-size-22"
title={ Config.roundValues ? this.renderBalance('interest') : null }>
{ this.isNativeMode() ?
this.props.Dashboard.progress
&& this.props.Dashboard.progress.interest ? this.props.Dashboard.progress.interest : '-'
:
<span>
{ Config.roundValues ? formatValue('round', this.renderBalance('interest'), -6) : this.renderBalance('interest') } { this.props.ActiveCoin.coin }
</span>
}
title={ Config.roundValues ? formatValue('round', this.renderBalance('interest'), -6) : this.renderBalance('interest') }>
{ Config.roundValues ? formatValue('round', this.renderBalance('interest'), -6) : this.renderBalance('interest') }
</span>
</div>
</div>
@ -112,14 +99,8 @@ const WalletsBalanceRender = function() {
</div>
<span
className="pull-right padding-top-10 font-size-22"
title={ Config.roundValues ? this.renderBalance('total') : null }>
{ this.isNativeMode() ?
this.props.ActiveCoin.balance.total ? this.props.ActiveCoin.balance.total : '-'
:
<span>
{ Config.roundValues ? formatValue('round', this.renderBalance('total'), -6) : this.renderBalance('total') } { this.props.ActiveCoin.coin }
</span>
}
title={ Config.roundValues ? formatValue('round', this.renderBalance('total'), -6) : this.renderBalance('total') }>
{ Config.roundValues ? formatValue('round', this.renderBalance('total'), -6) : this.renderBalance('total') }
</span>
</div>
</div>

13
react/src/util/formatValue.js

@ -1,5 +1,6 @@
// ref: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math/round#Decimal_rounding
export function formatValue(formatType, formatValue, formatExp) {
let _formatExp;
/**
* Decimal adjustment of a number.
*
@ -31,19 +32,21 @@ export function formatValue(formatType, formatValue, formatExp) {
return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
}
if (formatValue >= 1) {
formatExp = -3;
if (Math.abs(Number(formatValue)) >= 1) {
_formatExp = -3;
} else {
_formatExp = formatExp;
}
switch (formatType) {
case 'round':
return decimalAdjust('round', formatValue, formatExp);
return decimalAdjust('round', formatValue, _formatExp);
break;
case 'floor':
return decimalAdjust('floor', formatValue, formatExp);
return decimalAdjust('floor', formatValue, _formatExp);
break;
case 'ceil':
return decimalAdjust('ceil', formatValue, formatExp);
return decimalAdjust('ceil', formatValue, _formatExp);
break;
}
}
Loading…
Cancel
Save