make unit configurable in settings. update after @cmgustavo comments

This commit is contained in:
Matias Alejo Garcia 2014-06-16 12:44:18 -03:00
commit 00ca9f1c32
14 changed files with 359 additions and 259 deletions

View file

@ -562,20 +562,13 @@ Wallet.prototype.addressIsOwn = function(addrStr, opts) {
return ret;
};
//retunrs values in SATOSHIs
Wallet.prototype.getBalance = function(cb) {
var balance = 0;
var safeBalance = 0;
var balanceByAddr = {};
var BIT = coinUtil.BIT;
var COIN = coinUtil.COIN;
if (!BIT)
throw new Error('BIT not defined. A newer version of bitcore is needed');
console.log('[Wallet.js.574] getBalance'); //TODO
this.getUnspent(function(err, safeUnspent, unspent) {
if (err) {
return cb(err);
@ -590,9 +583,10 @@ Wallet.prototype.getBalance = function(cb) {
// we multiply and divide by BIT to avoid rounding errors when adding
for (var a in balanceByAddr) {
balanceByAddr[a] = balanceByAddr[a].toFixed(0) / BIT;
balanceByAddr[a] = parseInt(balanceByAddr[a].toFixed(0));
}
balance = balance.toFixed(0) / BIT;
balance = parseInt(balance.toFixed(0));
for (var i = 0; i < safeUnspent.length; i++) {
var u = safeUnspent[i];
@ -600,7 +594,7 @@ Wallet.prototype.getBalance = function(cb) {
safeBalance += amt;
}
safeBalance = safeBalance.toFixed(0) / BIT;
safeBalance = parseInt(safeBalance.toFixed(0));
return cb(null, balance, balanceByAddr, safeBalance);
});
};
@ -608,7 +602,6 @@ Wallet.prototype.getBalance = function(cb) {
Wallet.prototype.getUnspent = function(cb) {
var self = this;
this.blockchain.getUnspent(this.getAddressesStr(), function(err, unspentList) {
console.log('[Wallet.js.606:unspentList:]', unspentList); //TODO
if (err) {
return cb(err);
@ -642,7 +635,6 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb)
}
this.getUnspent(function(err, safeUnspent) {
console.log('[Wallet.js.639:safeUnspent:]', safeUnspent); //TODO
var ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts);
if (ntxid) {
self.sendIndexes();