From beef8569612636e155dc6aaa12455c4b87680d5e Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 4 Dec 2014 02:53:07 -0300 Subject: [PATCH 1/8] fix layout for small devices --- views/includes/transaction.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/views/includes/transaction.html b/views/includes/transaction.html index fd1ac0f25..a440de365 100644 --- a/views/includes/transaction.html +++ b/views/includes/transaction.html @@ -13,14 +13,16 @@
-
+
{{out.value}} {{$root.wallet.settings.unitName}} - + {{out.alternativeAmount}} {{out.alternativeIsoCode}}
-
-
+
+ +
+
From dfaf40b5501bf29cc5ec9c1e218750a90e7019fc Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 4 Dec 2014 02:56:50 -0300 Subject: [PATCH 2/8] updateTxs from SendController is async to avoid delay on mobile. Txps are below. --- js/controllers/send.js | 46 +++++++++++++++++++++++++++++++----------- views/send.html | 28 +++++++++++++------------ 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index f2279fe8a..0cfc93d4e 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -8,7 +8,7 @@ angular.module('copayApp.controllers').controller('SendController', preconditions.checkState(w); preconditions.checkState(w.settings.unitToSatoshi); - $rootScope.title = 'Send'; + $rootScope.title = w.isShared() ? 'Create Transaction Proposal' : 'Send'; $scope.loading = false; $scope.error = $scope.success = null; var satToUnit = 1 / w.settings.unitToSatoshi; @@ -42,9 +42,9 @@ angular.module('copayApp.controllers').controller('SendController', }; - $scope.updateTxs = _.throttle(function() { + $scope.updateTxs = _.throttle(function(cb) { var w = $rootScope.wallet; - if (!w) return; + if (!w || !cb) return; var res = w.getPendingTxProposals(); _.each(res.txs, function(tx) { @@ -61,7 +61,7 @@ angular.module('copayApp.controllers').controller('SendController', }); } }); - $scope.txps = res.txs; + return cb(res.txs); }, 1000); /** @@ -120,14 +120,24 @@ angular.module('copayApp.controllers').controller('SendController', $scope.init = function() { $rootScope.pendingTxCount = 0; - $scope.updateTxs(); + $scope.updateTxs(function(txps) { + $scope.txps = txps; + }); var w = $rootScope.wallet; - w.on('txProposalEvent', $scope.updateTxs); + w.on('txProposalEvent', function() { + $scope.updateTxs(function(txps) { + $scope.txps = txps; + }); + }); }; $scope.$on("$destroy", function(){ var w = $rootScope.wallet; - w.removeListener('txProposalEvent', $scope.updateTxs ); + w.removeListener('txProposalEvent', function() { + $scope.updateTxs(function(txps) { + $scope.txps = txps; + }); + }); }); $scope.showAddressBook = function() { @@ -155,7 +165,9 @@ angular.module('copayApp.controllers').controller('SendController', $scope.error = message; $scope.loading = false; - $scope.updateTxs(); + $scope.updateTxs(function(txps) { + $scope.txps = txps; + }); }; $scope.submitForm = function(form) { @@ -201,7 +213,9 @@ angular.module('copayApp.controllers').controller('SendController', if (err) return $scope._showError(err); $scope.notifyStatus(status); - $scope.updateTxs(); + $scope.updateTxs(function(txps) { + $scope.txps = txps; + }); }); }; @@ -422,7 +436,11 @@ angular.module('copayApp.controllers').controller('SendController', w.issueTx(ntxid, function(err, txid, status) { $scope.notifyStatus(status); if (cb) return cb(); - else $scope.updateTxs(); + else { + $scope.updateTxs(function(txps) { + $scope.txps = txps; + }); + } }); }; @@ -432,14 +450,18 @@ angular.module('copayApp.controllers').controller('SendController', w.signAndSend(ntxid, function(err, id, status) { $scope.loading = false; $scope.notifyStatus(status); - $scope.updateTxs(); + $scope.updateTxs(function(txps) { + $scope.txps = txps; + }); }); }; $scope.reject = function(ntxid) { w.reject(ntxid); notification.warning('Transaction rejected', 'You rejected the transaction successfully'); - $scope.updateTxs(); + $scope.updateTxs(function(txps) { + $scope.txps = txps; + }); }; $scope.clearMerchant = function(callback) { diff --git a/views/send.html b/views/send.html index 432265057..ce1c31090 100644 --- a/views/send.html +++ b/views/send.html @@ -1,23 +1,13 @@ -
+
+
-

{{$root.title}}

-
-
-

Pending Transactions Proposals

-
-
-
-
-

Create Transaction Proposal

+ name="comment" placeholder="{{($root.wallet.isShared() ? 'Leave a private message to your copayers' : 'Add a private comment to identify the transaction')}}" ng-model="commentText" ng-maxlength="100">
@@ -197,6 +187,18 @@
+
+
+
+
+

Pending Transactions Proposals

+
+
+
+
+
From 763646f3a6a15a4ce804b88a1dbdf442482ca172 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 4 Dec 2014 10:15:29 -0300 Subject: [PATCH 3/8] fix karma --- test/unit/controllers/controllersSpec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 7c0314fa1..2e53c6b96 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -53,6 +53,7 @@ describe("Unit: Controllers", function() { var w = {}; w.id = 1234; w.isComplete = sinon.stub().returns(true); + w.isShared = sinon.stub().returns(true); w.privateKey = {}; w.settings = { unitToSatoshi: 100, @@ -218,7 +219,7 @@ describe("Unit: Controllers", function() { }); it('should have a title', function() { - expect(scope.title).equal('Send'); + expect(scope.title).equal('Create Transaction Proposal'); }); it('should return true if wallet has addressBook', function() { From 2bd90f528bf72c68b8e11022f799a2c6e342b4df Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 4 Dec 2014 10:24:54 -0300 Subject: [PATCH 4/8] Fixes total amount using pp --- views/send.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/send.html b/views/send.html index ce1c31090..c45e8d225 100644 --- a/views/send.html +++ b/views/send.html @@ -130,7 +130,7 @@

- {{amount + defaultFee}} {{$root.wallet.settings.unitName}} + {{amount}} {{$root.wallet.settings.unitName}} {{ alternative }} {{ alternativeIsoCode }} From 738995fd80c37bed301c0fcc647eaec7189c1137 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 4 Dec 2014 11:09:11 -0300 Subject: [PATCH 5/8] revert updateTxs sync --- js/controllers/send.js | 44 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 0cfc93d4e..b8996e31e 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -42,9 +42,9 @@ angular.module('copayApp.controllers').controller('SendController', }; - $scope.updateTxs = _.throttle(function(cb) { + $scope.updateTxs = _.throttle(function() { var w = $rootScope.wallet; - if (!w || !cb) return; + if (!w) return; var res = w.getPendingTxProposals(); _.each(res.txs, function(tx) { @@ -61,7 +61,7 @@ angular.module('copayApp.controllers').controller('SendController', }); } }); - return cb(res.txs); + $scope.txps = res.txs; }, 1000); /** @@ -120,24 +120,14 @@ angular.module('copayApp.controllers').controller('SendController', $scope.init = function() { $rootScope.pendingTxCount = 0; - $scope.updateTxs(function(txps) { - $scope.txps = txps; - }); + $scope.updateTxs(); var w = $rootScope.wallet; - w.on('txProposalEvent', function() { - $scope.updateTxs(function(txps) { - $scope.txps = txps; - }); - }); + w.on('txProposalEvent', $scope.updateTxs); }; $scope.$on("$destroy", function(){ var w = $rootScope.wallet; - w.removeListener('txProposalEvent', function() { - $scope.updateTxs(function(txps) { - $scope.txps = txps; - }); - }); + w.removeListener('txProposalEvent', $scope.updateTxs ); }); $scope.showAddressBook = function() { @@ -165,9 +155,7 @@ angular.module('copayApp.controllers').controller('SendController', $scope.error = message; $scope.loading = false; - $scope.updateTxs(function(txps) { - $scope.txps = txps; - }); + $scope.updateTxs(); }; $scope.submitForm = function(form) { @@ -213,9 +201,7 @@ angular.module('copayApp.controllers').controller('SendController', if (err) return $scope._showError(err); $scope.notifyStatus(status); - $scope.updateTxs(function(txps) { - $scope.txps = txps; - }); + $scope.updateTxs(); }); }; @@ -436,11 +422,7 @@ angular.module('copayApp.controllers').controller('SendController', w.issueTx(ntxid, function(err, txid, status) { $scope.notifyStatus(status); if (cb) return cb(); - else { - $scope.updateTxs(function(txps) { - $scope.txps = txps; - }); - } + else $scope.updateTxs(); }); }; @@ -450,18 +432,14 @@ angular.module('copayApp.controllers').controller('SendController', w.signAndSend(ntxid, function(err, id, status) { $scope.loading = false; $scope.notifyStatus(status); - $scope.updateTxs(function(txps) { - $scope.txps = txps; - }); + $scope.updateTxs(); }); }; $scope.reject = function(ntxid) { w.reject(ntxid); notification.warning('Transaction rejected', 'You rejected the transaction successfully'); - $scope.updateTxs(function(txps) { - $scope.txps = txps; - }); + $scope.updateTxs(); }; $scope.clearMerchant = function(callback) { From 615e421014c0ef8f2e7c0c8466939c555ad1f1ba Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 4 Dec 2014 15:06:17 -0300 Subject: [PATCH 6/8] Moved Pending transactions proposals from Send to Home --- js/controllers/homeWallet.js | 92 +++++++++++++++++++++++++++++++++++- js/controllers/send.js | 58 ++--------------------- views/homeWallet.html | 43 ++++++++++------- views/send.html | 14 +----- 4 files changed, 122 insertions(+), 85 deletions(-) diff --git a/js/controllers/homeWallet.js b/js/controllers/homeWallet.js index 2c86559da..6b131e8f0 100644 --- a/js/controllers/homeWallet.js +++ b/js/controllers/homeWallet.js @@ -1,7 +1,95 @@ 'use strict'; -angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope) { +angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope, $timeout, $filter, rateService) { $scope.init = function() { - $rootScope.title = 'Home'; + $rootScope.title = 'Home'; + + $scope.rateService = rateService; + $scope.isRateAvailable = false; + + var w = $rootScope.wallet; + w.on('txProposalEvent', function() { _updateTxs()}); + $timeout(function() { + _updateTxs(); + }, 1); + + rateService.whenAvailable(function() { + $scope.isRateAvailable = true; + $scope.$digest(); + }); + }; + + // This is necesarry, since wallet can change in homeWallet, without running init() again. + var removeWatch = $rootScope.$watch('wallet.id', function(newWallet, oldWallet) { + if ($rootScope.wallet && $rootScope.wallet.isComplete() && newWallet !== oldWallet) { + var w = $rootScope.wallet; + $rootScope.pendingTxCount = 0; + w.on('txProposalEvent', function() { _updateTxs()}); + _updateTxs(); + } + }); + + $scope.$on("$destroy", function(){ + var w = $rootScope.wallet; + removeWatch(); + w.removeListener('txProposalEvent', function() {_updateTxs()} ); + }); + + $scope.setAlternativeAmount = function(w, tx, cb) { + rateService.whenAvailable(function() { + _.each(tx.outs, function(out) { + var valueSat = out.valueSat * w.settings.unitToSatoshi; + out.alternativeAmount = $filter('noFractionNumber')(rateService.toFiat(valueSat, $scope.alternativeIsoCode), 2); + out.alternativeIsoCode = $scope.alternativeIsoCode; + }); + if (cb) return cb(tx); + }); }; + + var _updateTxs = _.throttle(function() { + var w = $rootScope.wallet; + if (!w) return; + + $scope.alternativeIsoCode = w.settings.alternativeIsoCode; + $scope.myId = w.getMyCopayerId(); + + var res = w.getPendingTxProposals(); + _.each(res.txs, function(tx) { + $scope.setAlternativeAmount(w, tx); + if (tx.merchant) { + var url = tx.merchant.request_url; + var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1]; + tx.merchant.domain = domain; + } + if (tx.outs) { + _.each(tx.outs, function(out) { + out.valueSat = out.value; + out.value = $filter('noFractionNumber')(out.value); + }); + } + }); + $scope.txps = res.txs; + console.log('[homeWallet.js:45]',$scope.txps); //TODO + }, 100); + + + + $scope.sign = function(ntxid) { + var w = $rootScope.wallet; + $scope.loading = true; + $scope.error = $scope.success = null; + w.signAndSend(ntxid, function(err, id, status) { + $scope.loading = false; + $scope.notifyStatus(status); + _updateTxs(); + }); + }; + + $scope.reject = function(ntxid) { + var w = $rootScope.wallet; + w.reject(ntxid); + notification.warning('Transaction rejected', 'You rejected the transaction successfully'); + _updateTxs(); + }; + }); diff --git a/js/controllers/send.js b/js/controllers/send.js index b8996e31e..bf52a5be8 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -39,30 +39,7 @@ angular.module('copayApp.controllers').controller('SendController', }); if (cb) return cb(tx); }); - }; - - - $scope.updateTxs = _.throttle(function() { - var w = $rootScope.wallet; - if (!w) return; - - var res = w.getPendingTxProposals(); - _.each(res.txs, function(tx) { - $scope.setAlternativeAmount(w, tx); - if (tx.merchant) { - var url = tx.merchant.request_url; - var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1]; - tx.merchant.domain = domain; - } - if (tx.outs) { - _.each(tx.outs, function(out) { - out.valueSat = out.value; - out.value = $filter('noFractionNumber')(out.value); - }); - } - }); - $scope.txps = res.txs; - }, 1000); + }; /** * Setting the two related amounts as properties prevents an infinite @@ -119,16 +96,8 @@ angular.module('copayApp.controllers').controller('SendController', $scope.init = function() { - $rootScope.pendingTxCount = 0; - $scope.updateTxs(); - var w = $rootScope.wallet; - w.on('txProposalEvent', $scope.updateTxs); - }; - - $scope.$on("$destroy", function(){ - var w = $rootScope.wallet; - w.removeListener('txProposalEvent', $scope.updateTxs ); - }); + // Empty + }; $scope.showAddressBook = function() { return w && _.keys(w.addressBook).length > 0; @@ -155,7 +124,6 @@ angular.module('copayApp.controllers').controller('SendController', $scope.error = message; $scope.loading = false; - $scope.updateTxs(); }; $scope.submitForm = function(form) { @@ -201,7 +169,6 @@ angular.module('copayApp.controllers').controller('SendController', if (err) return $scope._showError(err); $scope.notifyStatus(status); - $scope.updateTxs(); }); }; @@ -422,25 +389,8 @@ angular.module('copayApp.controllers').controller('SendController', w.issueTx(ntxid, function(err, txid, status) { $scope.notifyStatus(status); if (cb) return cb(); - else $scope.updateTxs(); }); - }; - - $scope.sign = function(ntxid) { - $scope.loading = true; - $scope.error = $scope.success = null; - w.signAndSend(ntxid, function(err, id, status) { - $scope.loading = false; - $scope.notifyStatus(status); - $scope.updateTxs(); - }); - }; - - $scope.reject = function(ntxid) { - w.reject(ntxid); - notification.warning('Transaction rejected', 'You rejected the transaction successfully'); - $scope.updateTxs(); - }; + }; $scope.clearMerchant = function(callback) { // TODO: Find a better way of detecting diff --git a/views/homeWallet.html b/views/homeWallet.html index a0c3cff12..68994d632 100644 --- a/views/homeWallet.html +++ b/views/homeWallet.html @@ -16,16 +16,16 @@

- - {{$root.wallet.balanceInfo.totalBalance || 0}} - - {{$root.wallet.settings.unitName}} - + + {{$root.wallet.balanceInfo.totalBalance || 0}} + + {{$root.wallet.settings.unitName}} + - {{$root.wallet.balanceInfo.totalBalanceAlternative}} {{$root.wallet.balanceInfo.alternativeIsoCode}} - N/A - + {{$root.wallet.balanceInfo.totalBalanceAlternative}} {{$root.wallet.balanceInfo.alternativeIsoCode}} + N/A +
@@ -35,23 +35,34 @@
Personal Wallet - Multisignature wallet [{{$root.wallet.requiredCopayers}} of {{$root.wallet.totalCopayers}} ] - + Multisignature wallet [{{$root.wallet.requiredCopayers}} of {{$root.wallet.totalCopayers}} ] + in TESTNET
+
-
- +
+
-
-

Copayers

-
-
+

Pending Transactions Proposals

+
+
+ +
+
+

Copayers

+
+
+
+
+
diff --git a/views/send.html b/views/send.html index c45e8d225..15063e451 100644 --- a/views/send.html +++ b/views/send.html @@ -185,19 +185,7 @@ 1 BTC = {{$root.wallet.balanceInfo.alternativeConversionRate}} {{alternativeIsoCode}}
-
- -
-
-
-
-

Pending Transactions Proposals

-
-
-
-
+
From fbc13c0803841468f1aa0f8cc203ea2174edae74 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 4 Dec 2014 15:06:50 -0300 Subject: [PATCH 7/8] Counter label in Home --- views/includes/bottombar-mobile.html | 2 +- views/includes/sidebar.html | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/views/includes/bottombar-mobile.html b/views/includes/bottombar-mobile.html index 4393bcdcc..70ea38c4a 100644 --- a/views/includes/bottombar-mobile.html +++ b/views/includes/bottombar-mobile.html @@ -4,7 +4,7 @@
{{item.title}} - {{$root.pendingTxCount}} + {{$root.pendingTxCount}}
diff --git a/views/includes/sidebar.html b/views/includes/sidebar.html index d1404b0b7..ec744603f 100644 --- a/views/includes/sidebar.html +++ b/views/includes/sidebar.html @@ -56,7 +56,7 @@
{{(item.name || item.id) | limitTo: 1}}
- +
[ {{item.requiredCopayers}} of {{item.totalCopayers}} ]
{{item.name || item.id}}
@@ -80,7 +80,9 @@
{{item.title|translate}} - {{$root.pendingTxCount}} + + {{$root.pendingTxCount}} + From c5e2a698fc55a6cf89a68c2b646bb193a76ec6df Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 4 Dec 2014 15:13:08 -0300 Subject: [PATCH 8/8] fix karma --- test/unit/controllers/controllersSpec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 2e53c6b96..21dd6dd05 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -255,13 +255,10 @@ describe("Unit: Controllers", function() { sendForm.amount.$setViewValue(anAmount); sendForm.comment.$setViewValue(aComment); - scope.updateTxs = sinon.spy(); - var w = scope.wallet; scope.submitForm(sendForm); sinon.assert.callCount(w.spend, 1); sinon.assert.callCount(w.broadcastTx, 0); - sinon.assert.callCount(scope.updateTxs, 1); var spendArgs = w.spend.getCall(0).args[0]; spendArgs.toAddress.should.equal(anAddr); spendArgs.amountSat.should.equal(anAmount * scope.wallet.settings.unitToSatoshi);