mirror of https://github.com/BTCPrivate/copay.git
Transactions counter in navbar. Moved updateTx from controller to service.
This commit is contained in:
parent
1b545ea444
commit
cb00a5b629
|
@ -55,7 +55,9 @@
|
||||||
<section class="top-bar-section {{isCollapsed && 'hide_menu' || 'show_menu'}}">
|
<section class="top-bar-section {{isCollapsed && 'hide_menu' || 'show_menu'}}">
|
||||||
<ul>
|
<ul>
|
||||||
<li data-ng-repeat="item in menu" ui-route="/{{item.link}}" class="text-center" data-ng-class="{active: isActive(item)}">
|
<li data-ng-repeat="item in menu" ui-route="/{{item.link}}" class="text-center" data-ng-class="{active: isActive(item)}">
|
||||||
<a href="{{item.link}}"> <i class="{{item.icon}}"></i> {{item.title}}</a>
|
<a href="{{item.link}}"> <i class="{{item.icon}}"></i> {{item.title}}
|
||||||
|
<span ng-if="item.title=='Transactions'">({{$root.txslength}})</span>
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
@ -385,10 +387,10 @@
|
||||||
<div class="row m15">
|
<div class="row m15">
|
||||||
<div class="large-4 columns" ng-show="!tx.sentTs" style="padding-left: 5px;">
|
<div class="large-4 columns" ng-show="!tx.sentTs" style="padding-left: 5px;">
|
||||||
<div ng-show="!tx.signedByUs && !tx.rejectedByUs && !tx.finallyRejected && tx.missingSignatures">
|
<div ng-show="!tx.signedByUs && !tx.rejectedByUs && !tx.finallyRejected && tx.missingSignatures">
|
||||||
<button class="secondary radius m10r" ng-click="sign(tx.ntxid)" ng-disabled="loading" loading="Signing">
|
<button class="secondary radius m10r" ng-click="sign(tx.ntxid)" ng-disabled="loading">
|
||||||
<i class="fi-check"></i> Sign
|
<i class="fi-check"></i> Sign
|
||||||
</button>
|
</button>
|
||||||
<button class="warning radius" ng-click="reject(tx.ntxid)" ng-disabled="loading" loading>
|
<button class="warning radius" ng-click="reject(tx.ntxid)" ng-disabled="loading">
|
||||||
<i class="fi-x" ></i> Reject
|
<i class="fi-x" ></i> Reject
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -23,6 +23,7 @@ angular.module('copay.header').controller('HeaderController',
|
||||||
|
|
||||||
$rootScope.$watch('wallet', function(wallet) {
|
$rootScope.$watch('wallet', function(wallet) {
|
||||||
if (wallet) {
|
if (wallet) {
|
||||||
|
controllerUtils.updateTxs();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,46 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay.transactions').controller('TransactionsController',
|
angular.module('copay.transactions').controller('TransactionsController',
|
||||||
function($scope, $rootScope, $location) {
|
function($scope, $rootScope, controllerUtils) {
|
||||||
var bitcore = require('bitcore');
|
|
||||||
|
|
||||||
$scope.title = 'Transactions';
|
$scope.title = 'Transactions';
|
||||||
$scope.loading = false;
|
$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.send = function (ntxid) {
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
|
@ -50,7 +15,7 @@ angular.module('copay.transactions').controller('TransactionsController',
|
||||||
? {type:'success', message: 'Transaction broadcasted. txid: ' + txid}
|
? {type:'success', message: 'Transaction broadcasted. txid: ' + txid}
|
||||||
: {type:'error', message: 'There was an error sending the Transaction'}
|
: {type:'error', message: 'There was an error sending the Transaction'}
|
||||||
;
|
;
|
||||||
_updateTxs();
|
controllerUtils.updateTxs();
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -62,17 +27,16 @@ angular.module('copay.transactions').controller('TransactionsController',
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
$rootScope.flashMessage = {type:'error', message: 'There was an error signing the Transaction'};
|
$rootScope.flashMessage = {type:'error', message: 'There was an error signing the Transaction'};
|
||||||
_updateTxs();
|
controllerUtils.updateTxs();
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var p = w.txProposals.getTxProposal(ntxid);
|
var p = w.txProposals.getTxProposal(ntxid);
|
||||||
if (p.builder.isFullySigned()) {
|
if (p.builder.isFullySigned()) {
|
||||||
$scope.send(ntxid);
|
$scope.send(ntxid);
|
||||||
_updateTxs();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_updateTxs();
|
controllerUtils.updateTxs();
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -100,18 +64,8 @@ angular.module('copay.transactions').controller('TransactionsController',
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
w.reject(ntxid);
|
w.reject(ntxid);
|
||||||
$rootScope.flashMessage = {type:'warning', message: 'Transaction rejected by you'};
|
$rootScope.flashMessage = {type:'warning', message: 'Transaction rejected by you'};
|
||||||
_updateTxs();
|
controllerUtils.updateTxs();
|
||||||
// $rootScope.$digest();
|
// $rootScope.$digest();
|
||||||
};
|
};
|
||||||
|
|
||||||
_updateTxs();
|
|
||||||
|
|
||||||
var w = $rootScope.wallet;
|
|
||||||
if (w) {
|
|
||||||
w.on('txProposalsUpdated', function() {
|
|
||||||
console.log('[transactions.js.108: txProposalsUpdated:]'); //TODO
|
|
||||||
_updateTxs();
|
|
||||||
$rootScope.$digest();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -82,6 +82,10 @@ angular.module('copay.controllerUtils')
|
||||||
root.updateBalance();
|
root.updateBalance();
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
});
|
});
|
||||||
|
w.on('txProposalsUpdated', function() {
|
||||||
|
console.log('[ txProposalsUpdated ]'); //TODO
|
||||||
|
root.updateTxs();
|
||||||
|
});
|
||||||
w.on('openError', root.onErrorDigest);
|
w.on('openError', root.onErrorDigest);
|
||||||
w.on('connect', function(peerID) {
|
w.on('connect', function(peerID) {
|
||||||
if (peerID) {
|
if (peerID) {
|
||||||
|
@ -116,10 +120,46 @@ angular.module('copay.controllerUtils')
|
||||||
console.log('New available balance:', balance);
|
console.log('New available balance:', balance);
|
||||||
$rootScope.availableBalance = balance;
|
$rootScope.availableBalance = balance;
|
||||||
$rootScope.loading = false;
|
$rootScope.loading = false;
|
||||||
|
$rootScope.$digest();
|
||||||
if (cb) cb();
|
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;
|
||||||
|
console.log('[controllerUtils.js:155]',txs); //TODO
|
||||||
|
$rootScope.txslength = txs.length;
|
||||||
|
w.removeListener('txProposalsUpdated',root.updateTxs)
|
||||||
|
w.once('txProposalsUpdated',root.updateTxs);
|
||||||
|
$rootScope.loading = false;
|
||||||
|
};
|
||||||
|
|
||||||
root.setSocketHandlers = function() {
|
root.setSocketHandlers = function() {
|
||||||
// TODO: optimize this?
|
// TODO: optimize this?
|
||||||
Socket.removeAllListeners();
|
Socket.removeAllListeners();
|
||||||
|
|
Loading…
Reference in New Issue