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

@ -36,28 +36,33 @@ angular.module('copayApp.services')
root.onError(scope);
if (msg) $rootScope.$flashMessage = {
type: 'error',
message: msg
message: msg
};
$rootScope.$digest();
};
root.installStartupHandlers = function(wallet, $scope) {
wallet.on('serverError', function(msg) {
$rootScope.$flashMessage = {
message: 'There was an error connecting to the PeerJS server.'
+(msg||'Check you settings and Internet connection.'),
type: 'error',
};
root.onErrorDigest($scope);
$location.path('addresses');
$rootScope.$flashMessage = {
message: 'There was an error connecting to the PeerJS server.' + (msg || 'Check you settings and Internet connection.'),
type: 'error',
};
root.onErrorDigest($scope);
$location.path('addresses');
});
wallet.on('connectionError', function() {
var message = "Looks like you are already connected to this wallet, please logout from it and try importing it again.";
$rootScope.$flashMessage = { message: message, type: 'error'};
$rootScope.$flashMessage = {
message: message,
type: 'error'
};
root.onErrorDigest($scope);
});
wallet.on('serverError', function() {
$rootScope.$flashMessage = { message: 'The PeerJS server is not responding, please try again', type: 'error'};
$rootScope.$flashMessage = {
message: 'The PeerJS server is not responding, please try again',
type: 'error'
};
root.onErrorDigest($scope);
});
wallet.on('ready', function() {
@ -105,17 +110,17 @@ angular.module('copayApp.services')
}
});
w.on('txProposalsUpdated', function(dontDigest) {
root.updateTxs({onlyPending:true});
root.updateTxs({
onlyPending: true
});
// give sometime to the tx to propagate.
$timeout(function() {
console.log('[controllerUtils.js.111] UPDATE BALANCE'); //TODO
root.updateBalance(function(){
root.updateBalance(function() {
if (!dontDigest) {
$rootScope.$digest();
}
});
},3000);
}, 3000);
});
w.on('connectionError', function(msg) {
root.onErrorDigest(null, msg);
@ -145,27 +150,30 @@ console.log('[controllerUtils.js.111] UPDATE BALANCE'); //TODO
$rootScope.balanceByAddr = {};
$rootScope.updatingBalance = true;
console.log('[controllerUtils.js.147] GET'); //TODO
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
console.log('[controllerUtils.js.150]', err, balance); //TODO
w.getBalance(function(err, balanceSat, balanceByAddrSat, safeBalanceSat) {
if (err) {
console.error('Error: ' + err.message); //TODO
root._setCommError();
return null;
}
else {
} else {
root._clearCommError();
}
$rootScope.totalBalance = balance;
$rootScope.totalBalanceBTC = (balance / 1e6).toFixed(3) ;
$rootScope.availableBalance = safeBalance;
$rootScope.availableBalanceBTC = (safeBalance / 1e6).toFixed(3);
var satToUnit = 1 / config.unitToSatoshi;
var COIN = bitcore.util.COIN;
$rootScope.totalBalance = balanceSat * satToUnit;
$rootScope.totalBalanceBTC = (balanceSat / COIN).toFixed(4);
$rootScope.availableBalance = safeBalanceSat * satToUnit;
$rootScope.availableBalanceBTC = (safeBalanceSat / COIN).toFixed(4);
var balanceByAddr = {};
for (var ii in balanceByAddrSat) {
balanceByAddr[ii] = balanceByAddrSat[ii] * satToUnit;
}
$rootScope.balanceByAddr = balanceByAddr;
root.updateAddressList();
$rootScope.updatingBalance = false;
return cb?cb():null;
return cb ? cb() : null;
});
};
@ -173,13 +181,16 @@ console.log('[controllerUtils.js.150]', err, balance); //TODO
var w = $rootScope.wallet;
if (!w) return;
opts = opts || {};
var satToUnit = 1 / config.unitToSatoshi;
var myCopayerId = w.getMyCopayerId();
var pendingForUs = 0;
var inT = w.getTxProposals().sort(function(t1, t2) { return t2.createdTs - t1.createdTs });
var txs = [];
var inT = w.getTxProposals().sort(function(t1, t2) {
return t2.createdTs - t1.createdTs
});
var txs = [];
inT.forEach(function(i, index){
inT.forEach(function(i, index) {
if (opts.skip && (index < opts.skip[0] || index >= opts.skip[1])) {
return txs.push(null);
}
@ -188,47 +199,49 @@ console.log('[controllerUtils.js.150]', err, balance); //TODO
pendingForUs++;
}
if (!i.finallyRejected && !i.sentTs) {
i.isPending=1;
i.isPending = 1;
}
if (!opts.onlyPending || i.isPending) {
var tx = i.builder.build();
var tx = i.builder.build();
var outs = [];
tx.outs.forEach(function(o) {
var addr = bitcore.Address.fromScriptPubKey(o.getScript(), config.networkName)[0].toString();
if (!w.addressIsOwn(addr, {excludeMain:true})) {
if (!w.addressIsOwn(addr, {
excludeMain: true
})) {
outs.push({
address: addr,
value: bitcore.util.valueToBigInt(o.getValue())/bitcore.util.BIT,
address: addr,
value: bitcore.util.valueToBigInt(o.getValue()) * satToUnit,
});
}
});
// extra fields
i.outs = outs;
i.fee = i.builder.feeSat/bitcore.util.BIT;
i.fee = i.builder.feeSat * satToUnit;
i.missingSignatures = tx.countInputMissingSignatures(0);
txs.push(i);
}
});
$rootScope.txs = txs; //.some(function(i) {return i.isPending; } );
if ($rootScope.pendingTxCount < pendingForUs) {
$rootScope.txAlertCount = pendingForUs;
}
$rootScope.pendingTxCount = pendingForUs;
};
};
root._setCommError = function(e) {
if ($rootScope.insightError<0)
$rootScope.insightError=0;
if ($rootScope.insightError < 0)
$rootScope.insightError = 0;
$rootScope.insightError++;
};
root._clearCommError = function(e) {
if ($rootScope.insightError>0)
$rootScope.insightError=-1;
if ($rootScope.insightError > 0)
$rootScope.insightError = -1;
else
$rootScope.insightError=0;
$rootScope.insightError = 0;
};
root.setSocketHandlers = function() {
@ -238,16 +251,16 @@ console.log('[controllerUtils.js.150]', err, balance); //TODO
Socket.sysOn('reconnect_failed', root._setCommError);
Socket.sysOn('connect', root._clearCommError);
Socket.sysOn('reconnect', root._clearCommError);
Socket.sysEventsSet=true;
Socket.sysEventsSet = true;
}
if (!$rootScope.wallet) return;
var currentAddrs= Socket.getListeners();
var currentAddrs = Socket.getListeners();
var addrs = $rootScope.wallet.getAddressesStr();
var newAddrs=[];
for(var i in addrs){
var a=addrs[i];
var newAddrs = [];
for (var i in addrs) {
var a = addrs[i];
if (!currentAddrs[a])
newAddrs.push(a);
}
@ -257,7 +270,7 @@ console.log('[controllerUtils.js.150]', err, balance); //TODO
newAddrs.forEach(function(addr) {
Socket.on(addr, function(txid) {
$rootScope.receivedFund = [txid, addr];
root.updateBalance(function(){
root.updateBalance(function() {
$rootScope.$digest();
});
});