Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
refactor: increase coin precision to support msats
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Mar 29, 2020
1 parent ed23de0 commit 62254c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion renderer/components/UI/Value.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Value = ({ value, currency, currentTicker, fiatTicker, style }) => {
let dp
switch (currency) {
case 'btc':
dp = 8
dp = 11
break
case 'bits':
dp = 5
Expand Down
15 changes: 7 additions & 8 deletions utils/coin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import BigNumber from 'bignumber.js'

const PRECISION = 8
const PRECISION = 11
const getCurrencyPrecision = code => {
switch (code) {
case 'CHF':
Expand Down Expand Up @@ -32,16 +32,14 @@ CoinBig.config({

/**
* @param {number|string|Coin|BigNumber} value Value
* @param {number} precision Decimal precision
* @returns {Coin} Coin instance
* @class
*/
function Coin(value, precision) {
function Coin(value) {
if (!(this instanceof Coin)) {
return new Coin(value, precision)
return new Coin(value)
}
const p = precision || PRECISION
const big = CoinBig(value).decimalPlaces(p)
const big = CoinBig(value).decimalPlaces(PRECISION)

/**
*
Expand Down Expand Up @@ -74,15 +72,16 @@ function Coin(value, precision) {
/**
* @returns {string} String representation of value
*/
this.toString = () => big.decimalPlaces(p).toPrecision()
this.toString = () => big.decimalPlaces(PRECISION).toPrecision()

/**
* returns a string that represents value, truncated to the specified precision
*
* @param {number} digits Digits
* @returns {string} String representation of value
*/
this.toPrecision = digits => big.decimalPlaces(Math.min(Math.max(0, digits), p)).toPrecision()
this.toPrecision = digits =>
big.decimalPlaces(Math.min(Math.max(0, digits), PRECISION)).toPrecision()

/**
* returns a string that represents value, truncated to the specified precision per given code of currency
Expand Down

0 comments on commit 62254c2

Please sign in to comment.