diff --git a/js/controllers/header.js b/js/controllers/header.js
index 8dd2a0555..4d43919ef 100644
--- a/js/controllers/header.js
+++ b/js/controllers/header.js
@@ -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
diff --git a/js/controllers/setup.js b/js/controllers/setup.js
index 4c7f9402f..a08971cf2 100644
--- a/js/controllers/setup.js
+++ b/js/controllers/setup.js
@@ -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 = {
diff --git a/js/controllers/signin.js b/js/controllers/signin.js
index f05202b42..37a600e32 100644
--- a/js/controllers/signin.js
+++ b/js/controllers/signin.js
@@ -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);
});
};
diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js
index 36f04904c..a8e1062b7 100644
--- a/js/controllers/transactions.js
+++ b/js/controllers/transactions.js
@@ -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;
@@ -36,32 +65,31 @@ angular.module('copay.transactions').controller('TransactionsController',
type:'error',
message: 'There was an error signing the Transaction',
};
- $scope.update();
- }
- else {
+ $scope.update();
+ } 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() {
diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js
index 9a2e07b24..58008ae79 100644
--- a/js/models/core/Wallet.js
+++ b/js/models/core/Wallet.js
@@ -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);
});
diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js
index 24a69bfed..21deb626f 100644
--- a/js/models/core/WalletFactory.js
+++ b/js/models/core/WalletFactory.js
@@ -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) {
diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js
index a176b4191..b7457390a 100644
--- a/js/services/controllerUtils.js
+++ b/js/services/controllerUtils.js
@@ -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();
- $rootScope.$digest();
- });
- w.on('txProposalsUpdated', function() {
- root.updateTxs();
- root.updateBalance(function(){
+ if (!dontDigest) {
+ console.log('[pkr 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);
@@ -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,52 +118,56 @@ 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){
- 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) {
- 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;
- 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() {