Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #294 from isocolsky/bump/v2.8.0
Browse files Browse the repository at this point in the history
v2.8.0 + bundles
  • Loading branch information
isocolsky committed Jun 23, 2016
2 parents 94b5633 + 3348c99 commit d897024
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
36 changes: 27 additions & 9 deletions bitcore-wallet-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2470,13 +2470,25 @@ Constants.BIP45_SHARED_INDEX = 0x80000000 - 1;
Constants.UNITS = {
btc: {
toSatoshis: 100000000,
maxDecimals: 6,
minDecimals: 2,
full: {
maxDecimals: 8,
minDecimals: 8,
},
short: {
maxDecimals: 6,
minDecimals: 2,
}
},
bit: {
toSatoshis: 100,
maxDecimals: 0,
minDecimals: 0,
full: {
maxDecimals: 2,
minDecimals: 2,
},
short: {
maxDecimals: 0,
minDecimals: 0,
}
},
};

Expand Down Expand Up @@ -2524,8 +2536,7 @@ var Defaults = require('./defaults');

function Utils() {};

Utils.SJCL = {
};
Utils.SJCL = {};

Utils.encryptMessage = function(message, encryptingKey) {
var key = sjcl.codec.base64.toBits(encryptingKey);
Expand Down Expand Up @@ -2650,6 +2661,11 @@ Utils.formatAmount = function(satoshis, unit, opts) {
$.shouldBeNumber(satoshis);
$.checkArgument(_.contains(_.keys(Constants.UNITS), unit));

function roundDown(number, decimals) {
var exp = Math.pow(10, decimals || 0);
return (Math.floor(number * exp) / exp);
}

function addSeparators(nStr, thousands, decimal, minDecimals) {
nStr = nStr.replace('.', decimal);
var x = nStr.split(decimal);
Expand All @@ -2668,8 +2684,10 @@ Utils.formatAmount = function(satoshis, unit, opts) {
opts = opts || {};

var u = Constants.UNITS[unit];
var amount = (satoshis / u.toSatoshis).toFixed(u.maxDecimals);
return addSeparators(amount, opts.thousandsSeparator || ',', opts.decimalSeparator || '.', u.minDecimals);
var precision = opts.fullPrecision ? 'full' : 'short';

var amount = roundDown((satoshis / u.toSatoshis), u[precision].maxDecimals).toFixed(u[precision].maxDecimals);
return addSeparators(amount, opts.thousandsSeparator || ',', opts.decimalSeparator || '.', u[precision].minDecimals);
};

Utils.buildTx = function(txp) {
Expand Down Expand Up @@ -120707,7 +120725,7 @@ module.exports={
"name": "bitcore-wallet-client",
"description": "Client for bitcore-wallet-service",
"author": "BitPay Inc",
"version": "2.7.1",
"version": "2.8.0",
"license": "MIT",
"keywords": [
"bitcoin",
Expand Down
Loading

0 comments on commit d897024

Please sign in to comment.