-
diff --git a/js/controllers/header.js b/js/controllers/header.js
index e97010e1e..3ceb1d865 100644
--- a/js/controllers/header.js
+++ b/js/controllers/header.js
@@ -23,6 +23,7 @@ angular.module('copay.header').controller('HeaderController',
$rootScope.$watch('wallet', function(wallet) {
if (wallet) {
+ controllerUtils.updateTxs();
}
});
diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js
index f1ea1952e..26f948cbc 100644
--- a/js/controllers/transactions.js
+++ b/js/controllers/transactions.js
@@ -1,46 +1,11 @@
'use strict';
angular.module('copay.transactions').controller('TransactionsController',
- function($scope, $rootScope, $location) {
- var bitcore = require('bitcore');
+ function($scope, $rootScope, controllerUtils) {
$scope.title = 'Transactions';
$scope.loading = false;
-
-
- var _updateTxs = function() {
- var w =$rootScope.wallet;
- if (!w) return;
-
- var inT = w.getTxProposals();
- var txs = [];
-
- inT.forEach(function(i){
- 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})) {
- outs.push({
- address: addr,
- value: bitcore.util.valueToBigInt(o.getValue())/bitcore.util.COIN,
- });
- }
- });
- // extra fields
- i.outs = outs;
- i.fee = i.builder.feeSat/bitcore.util.COIN;
- i.missingSignatures = tx.countInputMissingSignatures(0);
- txs.push(i);
- });
- $scope.txs = txs;
- w.removeListener('txProposalsUpdated',_updateTxs)
- w.once('txProposalsUpdated',_updateTxs);
- $scope.loading = false;
- };
-
$scope.send = function (ntxid) {
$scope.loading = true;
var w = $rootScope.wallet;
@@ -50,7 +15,8 @@ angular.module('copay.transactions').controller('TransactionsController',
? {type:'success', message: 'Transaction broadcasted. txid: ' + txid}
: {type:'error', message: 'There was an error sending the Transaction'}
;
- _updateTxs();
+ controllerUtils.updateTxs();
+ $scope.loading = false;
$rootScope.$digest();
});
};
@@ -62,17 +28,19 @@ angular.module('copay.transactions').controller('TransactionsController',
if (!ret) {
$rootScope.flashMessage = {type:'error', message: 'There was an error signing the Transaction'};
- _updateTxs();
- $rootScope.$digest();
+ controllerUtils.updateTxs();
+ $scope.loading = false;
+ $rootScope.$digest();
return;
}
var p = w.txProposals.getTxProposal(ntxid);
if (p.builder.isFullySigned()) {
$scope.send(ntxid);
- _updateTxs();
+ controllerUtils.updateTxs();
}
else {
- _updateTxs();
+ controllerUtils.updateTxs();
+ $scope.loading = false;
$rootScope.$digest();
}
};
@@ -100,18 +68,7 @@ angular.module('copay.transactions').controller('TransactionsController',
var w = $rootScope.wallet;
w.reject(ntxid);
$rootScope.flashMessage = {type:'warning', message: 'Transaction rejected by you'};
- _updateTxs();
-// $rootScope.$digest();
+ $scope.loading = false;
};
- _updateTxs();
-
- var w = $rootScope.wallet;
- if (w) {
- w.on('txProposalsUpdated', function() {
- console.log('[transactions.js.108: txProposalsUpdated:]'); //TODO
- _updateTxs();
- $rootScope.$digest();
- });
- }
});
diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js
index 27225bb8a..3eda3de05 100644
--- a/js/models/core/Wallet.js
+++ b/js/models/core/Wallet.js
@@ -346,7 +346,7 @@ Wallet.prototype.reject = function(ntxid) {
txp.rejectedBy[myId] = Date.now();
this.sendTxProposals();
this.store();
- this.emit('refresh');
+ this.emit('txProposalsUpdated');
};
@@ -367,7 +367,7 @@ Wallet.prototype.sign = function(ntxid) {
txp.signedBy[myId] = Date.now();
this.sendTxProposals();
this.store();
- this.emit('refresh');
+ this.emit('txProposalsUpdated');
return true;
}
return false;
@@ -505,6 +505,7 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
self.sendPublicKeyRing(); // Change Address
self.sendTxProposals();
self.store();
+ self.emit('txProposalsUpdated');
}
return cb();
});
diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js
index 30d90a1be..299d021dd 100644
--- a/js/services/controllerUtils.js
+++ b/js/services/controllerUtils.js
@@ -82,6 +82,10 @@ angular.module('copay.controllerUtils')
root.updateBalance();
$rootScope.$digest();
});
+ w.on('txProposalsUpdated', function() {
+ root.updateTxs();
+ root.updateBalance();
+ });
w.on('openError', root.onErrorDigest);
w.on('connect', function(peerID) {
if (peerID) {
@@ -104,7 +108,6 @@ angular.module('copay.controllerUtils')
if ($rootScope.addrInfos.length === 0) return;
$rootScope.loading = true;
w.getBalance(false, function(balance, balanceByAddr) {
- console.log('New total balance:', balance);
$rootScope.totalBalance = balance;
$rootScope.balanceByAddr = balanceByAddr;
$rootScope.selectedAddr = $rootScope.addrInfos[0].address.toString();
@@ -113,13 +116,53 @@ angular.module('copay.controllerUtils')
if (cb) cb();
});
w.getBalance(true, function(balance) {
- console.log('New available balance:', balance);
$rootScope.availableBalance = balance;
$rootScope.loading = false;
+ $rootScope.$digest();
if (cb) cb();
});
};
+ root.updateTxs = function() {
+ var bitcore = require('bitcore');
+ var w = $rootScope.wallet;
+ if (!w) return;
+
+ var inT = w.getTxProposals();
+ var txs = [];
+
+ inT.forEach(function(i){
+ 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})) {
+ outs.push({
+ address: addr,
+ value: bitcore.util.valueToBigInt(o.getValue())/bitcore.util.COIN,
+ });
+ }
+ });
+ // extra fields
+ i.outs = outs;
+ i.fee = i.builder.feeSat/bitcore.util.COIN;
+ i.missingSignatures = tx.countInputMissingSignatures(0);
+ txs.push(i);
+ });
+ $rootScope.txs = txs;
+ var pending = 0;
+ for(var i=0; i