Transactions counter in navbar. Moved updateTx from controller to service.
This commit is contained in:
parent
1b545ea444
commit
cb00a5b629
4 changed files with 51 additions and 54 deletions
|
|
@ -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,7 @@ 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();
|
||||
$rootScope.$digest();
|
||||
});
|
||||
};
|
||||
|
|
@ -62,17 +27,16 @@ angular.module('copay.transactions').controller('TransactionsController',
|
|||
|
||||
if (!ret) {
|
||||
$rootScope.flashMessage = {type:'error', message: 'There was an error signing the Transaction'};
|
||||
_updateTxs();
|
||||
controllerUtils.updateTxs();
|
||||
$rootScope.$digest();
|
||||
return;
|
||||
}
|
||||
var p = w.txProposals.getTxProposal(ntxid);
|
||||
if (p.builder.isFullySigned()) {
|
||||
$scope.send(ntxid);
|
||||
_updateTxs();
|
||||
}
|
||||
else {
|
||||
_updateTxs();
|
||||
controllerUtils.updateTxs();
|
||||
$rootScope.$digest();
|
||||
}
|
||||
};
|
||||
|
|
@ -100,18 +64,8 @@ angular.module('copay.transactions').controller('TransactionsController',
|
|||
var w = $rootScope.wallet;
|
||||
w.reject(ntxid);
|
||||
$rootScope.flashMessage = {type:'warning', message: 'Transaction rejected by you'};
|
||||
_updateTxs();
|
||||
controllerUtils.updateTxs();
|
||||
// $rootScope.$digest();
|
||||
};
|
||||
|
||||
_updateTxs();
|
||||
|
||||
var w = $rootScope.wallet;
|
||||
if (w) {
|
||||
w.on('txProposalsUpdated', function() {
|
||||
console.log('[transactions.js.108: txProposalsUpdated:]'); //TODO
|
||||
_updateTxs();
|
||||
$rootScope.$digest();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue