mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #405 from matiu/feature/optimizations2
Feature/optimizations2
This commit is contained in:
commit
307e5d27cc
19
index.html
19
index.html
|
@ -356,7 +356,12 @@
|
|||
<div class="transactions" data-ng-controller="TransactionsController">
|
||||
<div class="row" ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
||||
<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="txheader">
|
||||
<div class="row m10">
|
||||
|
@ -450,9 +455,15 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="large-12 columns" ng-init="getTransactions()" ng-show="blockchain_txs[0].txid">
|
||||
<h3>Last transactions</h3>
|
||||
<div class="btransactions">
|
||||
<div class="large-12 columns">
|
||||
<h4>Last transactions</h4>
|
||||
<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="m15">
|
||||
<div class="row">
|
||||
|
|
|
@ -21,12 +21,6 @@ angular.module('copay.header').controller('HeaderController',
|
|||
'link': '#/backup'
|
||||
}];
|
||||
|
||||
$rootScope.$watch('wallet', function(wallet) {
|
||||
if (wallet) {
|
||||
controllerUtils.updateTxs();
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize alert notification (not show when init wallet)
|
||||
$rootScope.txAlertCount = 0;
|
||||
$notification.enableHtml5Mode(); // for chrome: if support, enable it
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
angular.module('copay.setup').controller('SetupController',
|
||||
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase) {
|
||||
|
||||
$rootScope.videoInfo = {};
|
||||
$scope.loading = false;
|
||||
$scope.walletPassword = $rootScope.walletPassword;
|
||||
|
||||
|
@ -37,8 +38,6 @@ angular.module('copay.setup').controller('SetupController',
|
|||
$rootScope.flashMessage = { message: 'Please, enter required fields', type: 'error'};
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$scope.loading = true;
|
||||
Passphrase.getBase64Async($scope.walletPassword, function(passphrase){
|
||||
var opts = {
|
||||
|
|
|
@ -6,9 +6,7 @@ angular.module('copay.signin').controller('SigninController',
|
|||
var v1 = o1.show.toLowerCase(), v2 = o2.show.toLowerCase();
|
||||
return v1 > v2 ? 1 : ( v1 < v2 ) ? -1 : 0;
|
||||
};
|
||||
|
||||
$rootScope.videoInfo = {};
|
||||
|
||||
$scope.loading = $scope.failure = false;
|
||||
$scope.wallets = walletFactory.getWallets().sort(cmp);
|
||||
$scope.selectedWalletId = $scope.wallets.length ? $scope.wallets[0].id : null;
|
||||
|
@ -46,7 +44,9 @@ angular.module('copay.signin').controller('SigninController',
|
|||
$rootScope.$digest();
|
||||
return;
|
||||
}
|
||||
console.log('[signin.js.49]'); //TODO
|
||||
installStartupHandlers(w);
|
||||
console.log('[signin.js.52]'); //TODO
|
||||
controllerUtils.startNetwork(w);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -5,13 +5,42 @@ angular.module('copay.transactions').controller('TransactionsController',
|
|||
|
||||
$scope.title = 'Transactions';
|
||||
$scope.loading = false;
|
||||
$scope.onlyPending = true;
|
||||
$scope.lastShowed = false;
|
||||
|
||||
$scope.update = function () {
|
||||
$scope.loading = false;
|
||||
controllerUtils.updateTxs();
|
||||
controllerUtils.updateTxs({onlyPending:$scope.onlyPending});
|
||||
$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.loading = true;
|
||||
$rootScope.txAlertCount = 0;
|
||||
|
@ -37,31 +66,30 @@ angular.module('copay.transactions').controller('TransactionsController',
|
|||
message: 'There was an error signing the Transaction',
|
||||
};
|
||||
$scope.update();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var p = w.txProposals.getTxProposal(ntxid);
|
||||
if (p.builder.isFullySigned()) {
|
||||
$scope.send(ntxid, function() {
|
||||
$scope.update();
|
||||
});
|
||||
}
|
||||
else $scope.update();
|
||||
else
|
||||
$scope.update();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.getTransactions = function() {
|
||||
$scope.getTransactions = function(cb) {
|
||||
var w =$rootScope.wallet;
|
||||
if (w) {
|
||||
var addresses = w.getAddressesStr();
|
||||
|
||||
console.log('### Querying last transactions...'); //TODO
|
||||
var addresses = w.getAddressesStr();
|
||||
if (addresses.length > 0) {
|
||||
w.blockchain.getTransactions(addresses, function(txs) {
|
||||
$scope.blockchain_txs = txs;
|
||||
$rootScope.$digest();
|
||||
});
|
||||
return w.blockchain.getTransactions(addresses, cb);
|
||||
}
|
||||
}
|
||||
return cb();
|
||||
};
|
||||
|
||||
$scope.getShortNetworkName = function() {
|
||||
|
|
|
@ -54,7 +54,11 @@ Wallet.prototype.seedCopayer = function(pubKey) {
|
|||
};
|
||||
|
||||
Wallet.prototype.connectToAll = function() {
|
||||
|
||||
console.log('[Wallet.js.57]'); //TODO
|
||||
var all = this.publicKeyRing.getAllCopayerIds();
|
||||
|
||||
console.log('[Wallet.js.58] connecting'); //TODO
|
||||
this.network.connectToCopayers(all);
|
||||
if (this.seededCopayerId) {
|
||||
this.sendWalletReady(this.seededCopayerId);
|
||||
|
@ -106,7 +110,7 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
|
|||
this.sendTxProposals(recipients, newId);
|
||||
}
|
||||
if (data.lastInBatch) {
|
||||
this.emit('txProposalsUpdated', this.txProposals);
|
||||
this.emit('txProposalsUpdated');
|
||||
this.store();
|
||||
}
|
||||
};
|
||||
|
@ -225,10 +229,11 @@ Wallet.prototype.netStart = function() {
|
|||
net.start(startOpts, function() {
|
||||
self.emit('ready', net.getPeer());
|
||||
setTimeout(function(){
|
||||
console.log('[EMIT publicKeyRingUpdated:]'); //TODO
|
||||
self.emit('publicKeyRingUpdated');
|
||||
console.log('[CONNECT:]'); //TODO
|
||||
console.log('[EMIT publicKeyRingUpdated:]'); //TODO
|
||||
self.emit('publicKeyRingUpdated', true);
|
||||
console.log('[CONNECT:]'); //TODO
|
||||
self.connectToAll();
|
||||
console.log('[EMIT TxProposal]'); //TODO
|
||||
self.emit('txProposalsUpdated');
|
||||
},10);
|
||||
});
|
||||
|
|
|
@ -48,9 +48,9 @@ WalletFactory.prototype._checkRead = function(walletId) {
|
|||
};
|
||||
|
||||
WalletFactory.prototype.fromObj = function(obj) {
|
||||
console.log('## Decrypting'); //TODO
|
||||
var w = Wallet.fromObj(obj, this.storage, this.network, this.blockchain);
|
||||
w.verbose = this.verbose;
|
||||
|
||||
// JIC: Add our key
|
||||
try {
|
||||
w.publicKeyRing.addCopayer(
|
||||
|
@ -60,16 +60,15 @@ WalletFactory.prototype.fromObj = function(obj) {
|
|||
// No really an error, just to be sure.
|
||||
}
|
||||
this.log('### WALLET OPENED:', w.id);
|
||||
|
||||
// store imported wallet
|
||||
w.store();
|
||||
return w;
|
||||
};
|
||||
|
||||
WalletFactory.prototype.fromEncryptedObj = function(base64, password) {
|
||||
this.storage._setPassphrase(password);
|
||||
var walletObj = this.storage.import(base64);
|
||||
return this.fromObj(walletObj);
|
||||
var w= this.fromObj(walletObj);
|
||||
w.store();
|
||||
return w;
|
||||
};
|
||||
|
||||
WalletFactory.prototype.read = function(walletId) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
angular.module('copay.controllerUtils')
|
||||
.factory('controllerUtils', function($rootScope, $sce, $location, Socket, video) {
|
||||
var root = {};
|
||||
var bitcore = require('bitcore');
|
||||
|
||||
root.getVideoMutedStatus = function(copayer) {
|
||||
var vi = $rootScope.videoInfo[copayer]
|
||||
|
@ -58,17 +59,27 @@ angular.module('copay.controllerUtils')
|
|||
$rootScope.wallet = w;
|
||||
$location.path('addresses');
|
||||
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.updateAddressList();
|
||||
if (!dontDigest) {
|
||||
console.log('[pkr digest]');
|
||||
$rootScope.$digest();
|
||||
console.log('[done digest]');
|
||||
}
|
||||
});
|
||||
w.on('txProposalsUpdated', function() {
|
||||
root.updateTxs();
|
||||
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);
|
||||
|
@ -76,6 +87,7 @@ angular.module('copay.controllerUtils')
|
|||
if (peerID) {
|
||||
video.callPeer(peerID, handlePeerVideo);
|
||||
}
|
||||
console.log('[digest]');
|
||||
$rootScope.$digest();
|
||||
});
|
||||
w.on('disconnect', function(peerID) {
|
||||
|
@ -94,7 +106,8 @@ angular.module('copay.controllerUtils')
|
|||
console.log('Updating balance...');
|
||||
root.updateAddressList();
|
||||
var w = $rootScope.wallet;
|
||||
if ($rootScope.addrInfos.length === 0) return;
|
||||
if ($rootScope.addrInfos.length === 0)
|
||||
return cb?cb():null;
|
||||
|
||||
$rootScope.balanceByAddr = {};
|
||||
$rootScope.updatingBalance = true;
|
||||
|
@ -105,24 +118,33 @@ angular.module('copay.controllerUtils')
|
|||
$rootScope.availableBalance = safeBalance;
|
||||
$rootScope.updatingBalance = false;
|
||||
console.log('Done updating balance.'); //TODO
|
||||
if (cb) cb();
|
||||
return cb?cb():null;
|
||||
});
|
||||
};
|
||||
|
||||
root.updateTxs = function() {
|
||||
var bitcore = require('bitcore');
|
||||
root.updateTxs = function(opts) {
|
||||
var w = $rootScope.wallet;
|
||||
if (!w) return;
|
||||
opts = opts || {};
|
||||
|
||||
console.log('## updating tx proposals', opts); //TODO
|
||||
var myCopayerId = w.getMyCopayerId();
|
||||
var pending = 0;
|
||||
var pendingForUs = 0;
|
||||
var inT = w.getTxProposals();
|
||||
var txs = [];
|
||||
|
||||
console.log('[START LOOP]'); //TODO
|
||||
inT.forEach(function(i){
|
||||
if (myCopayerId != i.creator && !i.finallyRejected && !i.sentTs && !i.rejectedByUs && !i.signedByUs) {
|
||||
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})) {
|
||||
|
@ -137,20 +159,15 @@ angular.module('copay.controllerUtils')
|
|||
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) {
|
||||
pending++;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$rootScope.txs = txs;
|
||||
if ($rootScope.pendingTxCount < pending) {
|
||||
$rootScope.txAlertCount = pending;
|
||||
$rootScope.txs = txs; //.some(function(i) {return i.isPending; } );
|
||||
if ($rootScope.pendingTxCount < pendingForUs) {
|
||||
$rootScope.txAlertCount = pendingForUs;
|
||||
}
|
||||
$rootScope.pendingTxCount = pending;
|
||||
w.removeListener('txProposalsUpdated',root.updateTxs)
|
||||
w.once('txProposalsUpdated',root.updateTxs);
|
||||
$rootScope.pendingTxCount = pendingForUs;
|
||||
console.log('## Done updating tx proposals'); //TODO
|
||||
};
|
||||
|
||||
root.setSocketHandlers = function() {
|
||||
|
|
Loading…
Reference in New Issue