Merge pull request #405 from matiu/feature/optimizations2

Feature/optimizations2
This commit is contained in:
Mario Colque 2014-05-19 10:43:08 -03:00
commit 307e5d27cc
8 changed files with 124 additions and 71 deletions

View File

@ -356,7 +356,12 @@
<div class="transactions" data-ng-controller="TransactionsController"> <div class="transactions" data-ng-controller="TransactionsController">
<div class="row" ng-show='$root.wallet.publicKeyRing.isComplete()'> <div class="row" ng-show='$root.wallet.publicKeyRing.isComplete()'>
<div class="large-12 columns"> <div class="large-12 columns">
<h4>Transaction proposals <small>({{txs.length}})</small></h4> <h4> Transaction proposals <span ng-if="onlyPending">[Pending]</span> <small>({{txs.length}})</small></h4>
<ul class="button-group">
<li> <button ng-click="show(true)" ng-disabled="loading || onlyPending" loading="Updating"> Pending </button>
<li> <button ng-click="show()" ng-disabled="loading || !onlyPending" loading="Updating"> All </button>
</ul>
<div class="panel radius pending" ng-repeat="tx in txs | orderBy: 'createdTs':true"> <div class="panel radius pending" ng-repeat="tx in txs | orderBy: 'createdTs':true">
<div class="txheader"> <div class="txheader">
<div class="row m10"> <div class="row m10">
@ -450,9 +455,15 @@
</div> </div>
</div> </div>
</div> </div>
<div class="large-12 columns" ng-init="getTransactions()" ng-show="blockchain_txs[0].txid"> <div class="large-12 columns">
<h3>Last transactions</h3> <h4>Last transactions</h4>
<div class="btransactions"> <button ng-click="toogleLast()" ng-disabled="loading" loading="Updating">
Show
</button>
<div class="btransactions" ng-if="lastShowed">
<div ng-if="!blockchain_txs[0].txid && !loading">
No transactions yet.
</div>
<div class="panel radius" ng-repeat="btx in blockchain_txs | orderBy: 'firstSeenTs':true"> <div class="panel radius" ng-repeat="btx in blockchain_txs | orderBy: 'firstSeenTs':true">
<div class="m15"> <div class="m15">
<div class="row"> <div class="row">

View File

@ -21,12 +21,6 @@ angular.module('copay.header').controller('HeaderController',
'link': '#/backup' 'link': '#/backup'
}]; }];
$rootScope.$watch('wallet', function(wallet) {
if (wallet) {
controllerUtils.updateTxs();
}
});
// Initialize alert notification (not show when init wallet) // Initialize alert notification (not show when init wallet)
$rootScope.txAlertCount = 0; $rootScope.txAlertCount = 0;
$notification.enableHtml5Mode(); // for chrome: if support, enable it $notification.enableHtml5Mode(); // for chrome: if support, enable it

View File

@ -3,6 +3,7 @@
angular.module('copay.setup').controller('SetupController', angular.module('copay.setup').controller('SetupController',
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase) { function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase) {
$rootScope.videoInfo = {};
$scope.loading = false; $scope.loading = false;
$scope.walletPassword = $rootScope.walletPassword; $scope.walletPassword = $rootScope.walletPassword;
@ -37,8 +38,6 @@ angular.module('copay.setup').controller('SetupController',
$rootScope.flashMessage = { message: 'Please, enter required fields', type: 'error'}; $rootScope.flashMessage = { message: 'Please, enter required fields', type: 'error'};
return; return;
} }
$scope.loading = true; $scope.loading = true;
Passphrase.getBase64Async($scope.walletPassword, function(passphrase){ Passphrase.getBase64Async($scope.walletPassword, function(passphrase){
var opts = { var opts = {

View File

@ -6,9 +6,7 @@ angular.module('copay.signin').controller('SigninController',
var v1 = o1.show.toLowerCase(), v2 = o2.show.toLowerCase(); var v1 = o1.show.toLowerCase(), v2 = o2.show.toLowerCase();
return v1 > v2 ? 1 : ( v1 < v2 ) ? -1 : 0; return v1 > v2 ? 1 : ( v1 < v2 ) ? -1 : 0;
}; };
$rootScope.videoInfo = {}; $rootScope.videoInfo = {};
$scope.loading = $scope.failure = false; $scope.loading = $scope.failure = false;
$scope.wallets = walletFactory.getWallets().sort(cmp); $scope.wallets = walletFactory.getWallets().sort(cmp);
$scope.selectedWalletId = $scope.wallets.length ? $scope.wallets[0].id : null; $scope.selectedWalletId = $scope.wallets.length ? $scope.wallets[0].id : null;
@ -46,7 +44,9 @@ angular.module('copay.signin').controller('SigninController',
$rootScope.$digest(); $rootScope.$digest();
return; return;
} }
console.log('[signin.js.49]'); //TODO
installStartupHandlers(w); installStartupHandlers(w);
console.log('[signin.js.52]'); //TODO
controllerUtils.startNetwork(w); controllerUtils.startNetwork(w);
}); });
}; };

View File

@ -5,13 +5,42 @@ angular.module('copay.transactions').controller('TransactionsController',
$scope.title = 'Transactions'; $scope.title = 'Transactions';
$scope.loading = false; $scope.loading = false;
$scope.onlyPending = true;
$scope.lastShowed = false;
$scope.update = function () { $scope.update = function () {
$scope.loading = false; $scope.loading = false;
controllerUtils.updateTxs(); controllerUtils.updateTxs({onlyPending:$scope.onlyPending});
$rootScope.$digest(); $rootScope.$digest();
}; };
$scope.show = function (onlyPending) {
$scope.loading=true;
$scope.onlyPending = onlyPending;
setTimeout(function(){
$scope.update();
}, 10);
};
$scope.toogleLast = function () {
console.log('[toogleLast]');
$scope.loading=true;
$scope.lastShowed = !$scope.lastShowed;
if ($scope.lastShowed) {
$scope.getTransactions(function(txs){
$scope.loading=false;
$scope.blockchain_txs = txs;
$rootScope.$digest();
});
}
else {
setTimeout(function(){
$scope.loading=false;
$rootScope.$digest();
});
}
};
$scope.send = function (ntxid,cb) { $scope.send = function (ntxid,cb) {
$scope.loading = true; $scope.loading = true;
$rootScope.txAlertCount = 0; $rootScope.txAlertCount = 0;
@ -36,32 +65,31 @@ angular.module('copay.transactions').controller('TransactionsController',
type:'error', type:'error',
message: 'There was an error signing the Transaction', message: 'There was an error signing the Transaction',
}; };
$scope.update(); $scope.update();
} } else {
else {
var p = w.txProposals.getTxProposal(ntxid); var p = w.txProposals.getTxProposal(ntxid);
if (p.builder.isFullySigned()) { if (p.builder.isFullySigned()) {
$scope.send(ntxid, function() { $scope.send(ntxid, function() {
$scope.update(); $scope.update();
}); });
} }
else $scope.update(); else
$scope.update();
} }
}); });
}; };
$scope.getTransactions = function() { $scope.getTransactions = function(cb) {
var w =$rootScope.wallet; var w =$rootScope.wallet;
if (w) { if (w) {
var addresses = w.getAddressesStr();
console.log('### Querying last transactions...'); //TODO
var addresses = w.getAddressesStr();
if (addresses.length > 0) { if (addresses.length > 0) {
w.blockchain.getTransactions(addresses, function(txs) { return w.blockchain.getTransactions(addresses, cb);
$scope.blockchain_txs = txs;
$rootScope.$digest();
});
} }
} }
return cb();
}; };
$scope.getShortNetworkName = function() { $scope.getShortNetworkName = function() {

View File

@ -54,7 +54,11 @@ Wallet.prototype.seedCopayer = function(pubKey) {
}; };
Wallet.prototype.connectToAll = function() { Wallet.prototype.connectToAll = function() {
console.log('[Wallet.js.57]'); //TODO
var all = this.publicKeyRing.getAllCopayerIds(); var all = this.publicKeyRing.getAllCopayerIds();
console.log('[Wallet.js.58] connecting'); //TODO
this.network.connectToCopayers(all); this.network.connectToCopayers(all);
if (this.seededCopayerId) { if (this.seededCopayerId) {
this.sendWalletReady(this.seededCopayerId); this.sendWalletReady(this.seededCopayerId);
@ -106,7 +110,7 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
this.sendTxProposals(recipients, newId); this.sendTxProposals(recipients, newId);
} }
if (data.lastInBatch) { if (data.lastInBatch) {
this.emit('txProposalsUpdated', this.txProposals); this.emit('txProposalsUpdated');
this.store(); this.store();
} }
}; };
@ -225,10 +229,11 @@ Wallet.prototype.netStart = function() {
net.start(startOpts, function() { net.start(startOpts, function() {
self.emit('ready', net.getPeer()); self.emit('ready', net.getPeer());
setTimeout(function(){ setTimeout(function(){
console.log('[EMIT publicKeyRingUpdated:]'); //TODO console.log('[EMIT publicKeyRingUpdated:]'); //TODO
self.emit('publicKeyRingUpdated'); self.emit('publicKeyRingUpdated', true);
console.log('[CONNECT:]'); //TODO console.log('[CONNECT:]'); //TODO
self.connectToAll(); self.connectToAll();
console.log('[EMIT TxProposal]'); //TODO
self.emit('txProposalsUpdated'); self.emit('txProposalsUpdated');
},10); },10);
}); });

View File

@ -48,9 +48,9 @@ WalletFactory.prototype._checkRead = function(walletId) {
}; };
WalletFactory.prototype.fromObj = function(obj) { WalletFactory.prototype.fromObj = function(obj) {
console.log('## Decrypting'); //TODO
var w = Wallet.fromObj(obj, this.storage, this.network, this.blockchain); var w = Wallet.fromObj(obj, this.storage, this.network, this.blockchain);
w.verbose = this.verbose; w.verbose = this.verbose;
// JIC: Add our key // JIC: Add our key
try { try {
w.publicKeyRing.addCopayer( w.publicKeyRing.addCopayer(
@ -60,16 +60,15 @@ WalletFactory.prototype.fromObj = function(obj) {
// No really an error, just to be sure. // No really an error, just to be sure.
} }
this.log('### WALLET OPENED:', w.id); this.log('### WALLET OPENED:', w.id);
// store imported wallet
w.store();
return w; return w;
}; };
WalletFactory.prototype.fromEncryptedObj = function(base64, password) { WalletFactory.prototype.fromEncryptedObj = function(base64, password) {
this.storage._setPassphrase(password); this.storage._setPassphrase(password);
var walletObj = this.storage.import(base64); var walletObj = this.storage.import(base64);
return this.fromObj(walletObj); var w= this.fromObj(walletObj);
w.store();
return w;
}; };
WalletFactory.prototype.read = function(walletId) { WalletFactory.prototype.read = function(walletId) {

View File

@ -3,6 +3,7 @@
angular.module('copay.controllerUtils') angular.module('copay.controllerUtils')
.factory('controllerUtils', function($rootScope, $sce, $location, Socket, video) { .factory('controllerUtils', function($rootScope, $sce, $location, Socket, video) {
var root = {}; var root = {};
var bitcore = require('bitcore');
root.getVideoMutedStatus = function(copayer) { root.getVideoMutedStatus = function(copayer) {
var vi = $rootScope.videoInfo[copayer] var vi = $rootScope.videoInfo[copayer]
@ -58,17 +59,27 @@ angular.module('copay.controllerUtils')
$rootScope.wallet = w; $rootScope.wallet = w;
$location.path('addresses'); $location.path('addresses');
video.setOwnPeer(myPeerID, w, handlePeerVideo); video.setOwnPeer(myPeerID, w, handlePeerVideo);
console.log('# Done ready handler');
}); });
w.on('publicKeyRingUpdated', function() { w.on('publicKeyRingUpdated', function(dontDigest) {
console.log('[start publicKeyRing handler]'); //TODO
root.setSocketHandlers(); root.setSocketHandlers();
root.updateAddressList(); root.updateAddressList();
$rootScope.$digest(); if (!dontDigest) {
}); console.log('[pkr digest]');
w.on('txProposalsUpdated', function() {
root.updateTxs();
root.updateBalance(function(){
$rootScope.$digest(); $rootScope.$digest();
console.log('[done digest]');
}
});
w.on('txProposalsUpdated', function(dontDigest) {
root.updateTxs({onlyPending:true});
root.updateBalance(function(){
if (!dontDigest) {
console.log('[txp digest]');
$rootScope.$digest();
console.log('[done digest]');
}
}); });
}); });
w.on('openError', root.onErrorDigest); w.on('openError', root.onErrorDigest);
@ -76,6 +87,7 @@ angular.module('copay.controllerUtils')
if (peerID) { if (peerID) {
video.callPeer(peerID, handlePeerVideo); video.callPeer(peerID, handlePeerVideo);
} }
console.log('[digest]');
$rootScope.$digest(); $rootScope.$digest();
}); });
w.on('disconnect', function(peerID) { w.on('disconnect', function(peerID) {
@ -94,7 +106,8 @@ angular.module('copay.controllerUtils')
console.log('Updating balance...'); console.log('Updating balance...');
root.updateAddressList(); root.updateAddressList();
var w = $rootScope.wallet; var w = $rootScope.wallet;
if ($rootScope.addrInfos.length === 0) return; if ($rootScope.addrInfos.length === 0)
return cb?cb():null;
$rootScope.balanceByAddr = {}; $rootScope.balanceByAddr = {};
$rootScope.updatingBalance = true; $rootScope.updatingBalance = true;
@ -105,52 +118,56 @@ angular.module('copay.controllerUtils')
$rootScope.availableBalance = safeBalance; $rootScope.availableBalance = safeBalance;
$rootScope.updatingBalance = false; $rootScope.updatingBalance = false;
console.log('Done updating balance.'); //TODO console.log('Done updating balance.'); //TODO
if (cb) cb(); return cb?cb():null;
}); });
}; };
root.updateTxs = function() { root.updateTxs = function(opts) {
var bitcore = require('bitcore');
var w = $rootScope.wallet; var w = $rootScope.wallet;
if (!w) return; if (!w) return;
opts = opts || {};
console.log('## updating tx proposals', opts); //TODO
var myCopayerId = w.getMyCopayerId(); var myCopayerId = w.getMyCopayerId();
var pending = 0; var pendingForUs = 0;
var inT = w.getTxProposals(); var inT = w.getTxProposals();
var txs = []; var txs = [];
console.log('[START LOOP]'); //TODO
inT.forEach(function(i){ 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);
if (myCopayerId != i.creator && !i.finallyRejected && !i.sentTs && !i.rejectedByUs && !i.signedByUs) { if (myCopayerId != i.creator && !i.finallyRejected && !i.sentTs && !i.rejectedByUs && !i.signedByUs) {
pending++; pendingForUs++;
}
if (!i.finallyRejected && !i.sentTs) {
i.isPending=1;
}
if (!opts.onlyPending || i.isPending) {
console.log('tx:',i); //TODO
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; $rootScope.txs = txs; //.some(function(i) {return i.isPending; } );
if ($rootScope.pendingTxCount < pending) { if ($rootScope.pendingTxCount < pendingForUs) {
$rootScope.txAlertCount = pending; $rootScope.txAlertCount = pendingForUs;
} }
$rootScope.pendingTxCount = pending; $rootScope.pendingTxCount = pendingForUs;
w.removeListener('txProposalsUpdated',root.updateTxs) console.log('## Done updating tx proposals'); //TODO
w.once('txProposalsUpdated',root.updateTxs);
}; };
root.setSocketHandlers = function() { root.setSocketHandlers = function() {