From ad75265e9377728425dcd87e5530dd212a92cc5a Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Wed, 6 Aug 2014 13:59:33 -0300 Subject: [PATCH 1/4] Refactor menu, split transactions tab into send and history --- js/controllers/send.js | 63 ++++++++++- js/controllers/sidebar.js | 12 +- js/controllers/transactions.js | 55 +-------- js/services/controllerUtils.js | 10 +- test/unit/controllers/controllersSpec.js | 5 + views/includes/sidebar-mobile.html | 6 +- views/includes/sidebar.html | 6 +- views/includes/transaction.html | 122 ++++++++++++++++++++ views/send.html | 9 +- views/transactions.html | 137 +---------------------- 10 files changed, 225 insertions(+), 200 deletions(-) create mode 100644 views/includes/transaction.html diff --git a/js/controllers/send.js b/js/controllers/send.js index a87e5c256..341b82a58 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -2,13 +2,25 @@ var bitcore = require('bitcore'); angular.module('copayApp.controllers').controller('SendController', - function($scope, $rootScope, $window, $timeout, $anchorScroll, $modal, isMobile, notification) { + function($scope, $rootScope, $window, $timeout, $anchorScroll, $modal, isMobile, notification, controllerUtils) { $scope.title = 'Send'; $scope.loading = false; var satToUnit = 1 / config.unitToSatoshi; $scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit; $scope.unitToBtc = config.unitToSatoshi / bitcore.util.COIN; + $scope.loadTxs = function() { + var opts = { + pending: true, + skip: null + }; + controllerUtils.updateTxs(opts); + setTimeout(function() { + $scope.loading = false; + $rootScope.$digest(); + }, 0); + } + $scope.showAddressBook = function() { var w = $rootScope.wallet; var flag; @@ -54,7 +66,7 @@ angular.module('copayApp.controllers').controller('SendController', $scope.loading = false; var message = 'The transaction proposal has been created'; notification.success('Success!', message); - $rootScope.$digest(); + $scope.loadTxs(); } else { w.sendTx(ntxid, function(txid) { if (txid) { @@ -280,4 +292,51 @@ angular.module('copayApp.controllers').controller('SendController', $scope.amount = $scope.getAvailableAmount(); form.amount.$pristine = false; }; + + + $scope.send = function(ntxid, cb) { + $scope.loading = true; + $rootScope.txAlertCount = 0; + var w = $rootScope.wallet; + w.sendTx(ntxid, function(txid) { + if (!txid) { + notification.error('Error', 'There was an error sending the transaction'); + } else { + notification.success('Transaction broadcast', 'Transaction id: '+txid); + } + + if (cb) return cb(); + else $scope.loadTxs(); + }); + }; + + $scope.sign = function(ntxid) { + $scope.loading = true; + var w = $rootScope.wallet; + w.sign(ntxid, function(ret) { + if (!ret) { + notification.error('Error', 'There was an error signing the transaction'); + $scope.loadTxs(); + } else { + var p = w.txProposals.getTxProposal(ntxid); + if (p.builder.isFullySigned()) { + $scope.send(ntxid, function() { + $scope.loadTxs(); + }); + } else + $scope.loadTxs(); + } + }); + }; + + $scope.reject = function(ntxid) { + $scope.loading = true; + $rootScope.txAlertCount = 0; + var w = $rootScope.wallet; + w.reject(ntxid); + notification.warning('Transaction rejected', 'You rejected the transaction successfully'); + $scope.loading = false; + $scope.loadTxs(); + }; + }); diff --git a/js/controllers/sidebar.js b/js/controllers/sidebar.js index 7606483b9..6935ec03f 100644 --- a/js/controllers/sidebar.js +++ b/js/controllers/sidebar.js @@ -6,17 +6,17 @@ angular.module('copayApp.controllers').controller('SidebarController', $scope.version = copay.version; $scope.networkName = config.networkName; $scope.menu = [{ - 'title': 'Addresses', - 'icon': 'fi-address-book', + 'title': 'Receive', + 'icon': 'fi-arrow-left', 'link': 'addresses' - }, { - 'title': 'Transactions', - 'icon': 'fi-clipboard-pencil', - 'link': 'transactions' }, { 'title': 'Send', 'icon': 'fi-arrow-right', 'link': 'send' + }, { + 'title': 'History', + 'icon': 'fi-clipboard-pencil', + 'link': 'transactions' }, { 'title': 'More', 'icon': 'fi-download', diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index 7a8185d9c..a8fb8f7d8 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -6,7 +6,6 @@ angular.module('copayApp.controllers').controller('TransactionsController', $scope.title = 'Transactions'; $scope.loading = false; - $scope.onlyPending = true; $scope.lastShowed = false; $scope.txpCurrentPage = 1; @@ -19,16 +18,17 @@ angular.module('copayApp.controllers').controller('TransactionsController', $scope.loading = false; var from = ($scope.txpCurrentPage - 1) * $scope.txpItemsPerPage; var opts = { - onlyPending: $scope.onlyPending, - skip: !$scope.onlyPending ? [from, from + $scope.txpItemsPerPage] : null + pending: false, + skip: [from, from + $scope.txpItemsPerPage] }; controllerUtils.updateTxs(opts); - $rootScope.$digest(); + setTimeout(function() { + $rootScope.$digest(); + }, 0); }; - $scope.show = function(onlyPending) { + $scope.show = function() { $scope.loading = true; - $scope.onlyPending = onlyPending; setTimeout(function() { $scope.update(); }, 10); @@ -102,40 +102,6 @@ angular.module('copayApp.controllers').controller('TransactionsController', } }; - $scope.send = function(ntxid, cb) { - $scope.loading = true; - $rootScope.txAlertCount = 0; - var w = $rootScope.wallet; - w.sendTx(ntxid, function(txid) { - if (!txid) { - notification.error('Error', 'There was an error sending the transaction'); - } else { - notification.success('Transaction broadcast', 'Transaction id: '+txid); - } - if (cb) return cb(); - else $scope.update(); - }); - }; - - $scope.sign = function(ntxid) { - $scope.loading = true; - var w = $rootScope.wallet; - w.sign(ntxid, function(ret) { - if (!ret) { - notification.error('Error', 'There was an error signing the transaction'); - $scope.update(); - } else { - var p = w.txProposals.getTxProposal(ntxid); - if (p.builder.isFullySigned()) { - $scope.send(ntxid, function() { - $scope.update(); - }); - } else - $scope.update(); - } - }); - }; - $scope.getTransactions = function() { var w = $rootScope.wallet; $scope.loading = true; @@ -174,15 +140,6 @@ angular.module('copayApp.controllers').controller('TransactionsController', return config.networkName.substring(0, 4); }; - $scope.reject = function(ntxid) { - $scope.loading = true; - $rootScope.txAlertCount = 0; - var w = $rootScope.wallet; - w.reject(ntxid); - notification.warning('Transaction rejected', 'You rejected the transaction successfully'); - $scope.loading = false; - }; - // Autoload transactions on 1-of-1 if ($rootScope.wallet && $rootScope.wallet.totalCopayers == 1) { $scope.lastShowed = true; diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 9480fe74f..fbc5316f9 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -136,9 +136,7 @@ angular.module('copayApp.services') } }); w.on('txProposalsUpdated', function(dontDigest) { - root.updateTxs({ - onlyPending: true - }); + root.updateTxs(); // give sometime to the tx to propagate. $timeout(function() { root.updateBalance(function() { @@ -231,7 +229,7 @@ angular.module('copayApp.services') root.updateTxs = function(opts) { var w = $rootScope.wallet; if (!w) return; - opts = opts || {}; + opts = opts || $rootScope.txsOpts || {}; var satToUnit = 1 / config.unitToSatoshi; var myCopayerId = w.getMyCopayerId(); @@ -252,7 +250,8 @@ angular.module('copayApp.services') if (!i.finallyRejected && !i.sentTs) { i.isPending = 1; } - if (!opts.onlyPending || i.isPending) { + + if (!!opts.pending == !!i.isPending) { var tx = i.builder.build(); var outs = []; tx.outs.forEach(function(o) { @@ -276,6 +275,7 @@ angular.module('copayApp.services') }); $rootScope.txs = txs; + $rootScope.txsOpts = opts; if ($rootScope.pendingTxCount < pendingForUs) { $rootScope.txAlertCount = pendingForUs; } diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index ba9d9e70e..5c6f55faf 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -194,9 +194,12 @@ describe("Unit: Controllers", function() { var spy = sinon.spy(scope.wallet, 'createTx'); var spy2 = sinon.spy(scope.wallet, 'sendTx'); + scope.loadTxs = sinon.spy(); + scope.submitForm(sendForm); sinon.assert.callCount(spy, 1); sinon.assert.callCount(spy2, 0); + sinon.assert.callCount(scope.loadTxs, 1); }); it('should create and send a transaction proposal', function() { @@ -206,10 +209,12 @@ describe("Unit: Controllers", function() { scope.wallet.totalCopayers = scope.wallet.requiredCopayers = 1; var spy = sinon.spy(scope.wallet, 'createTx'); var spy2 = sinon.spy(scope.wallet, 'sendTx'); + scope.loadTxs = sinon.spy(); scope.submitForm(sendForm); sinon.assert.callCount(spy, 1); sinon.assert.callCount(spy2, 1); + sinon.assert.callCount(scope.loadTxs, 0); }); }); diff --git a/views/includes/sidebar-mobile.html b/views/includes/sidebar-mobile.html index 506fcc54a..cc1cb0b53 100644 --- a/views/includes/sidebar-mobile.html +++ b/views/includes/sidebar-mobile.html @@ -42,12 +42,12 @@
  • - Signout + Close
  • diff --git a/views/includes/sidebar.html b/views/includes/sidebar.html index 00e71bcd5..3852fc2f7 100644 --- a/views/includes/sidebar.html +++ b/views/includes/sidebar.html @@ -54,13 +54,13 @@ {{item.title}} - {{$root.pendingTxCount}} + {{$root.pendingTxCount}}
  • - Signout + Close
  • diff --git a/views/includes/transaction.html b/views/includes/transaction.html new file mode 100644 index 000000000..420f84470 --- /dev/null +++ b/views/includes/transaction.html @@ -0,0 +1,122 @@ +
    + +
    +

    + {{tx.comment}} - + {{$root.wallet.publicKeyRing.nicknameForCopayer(tx.creator)}} +

    +
    +
    +
    +
    +

    {{out.value | noFractionNumber}} {{$root.unitName}}

    +

    {{out.value | noFractionNumber}} {{$root.unitName}}

    +
    +
    +
    + +
    +
    +
    +
    +

    {{tx.createdTs | amCalendar}}

    +
    +
    + +
    +
    + + {{c.cId}} + +
    + + + + + + + + + + + + + + + + + + + + + +
    + +
    +

    + {{c.cId === $root.wallet.getMyCopayerId() ? 'Me' : $root.wallet.publicKeyRing.nicknameForCopayer(c.cId)}} +

    +
    +
    +
    + + diff --git a/views/send.html b/views/send.html index 816b02e3f..a3c719162 100644 --- a/views/send.html +++ b/views/send.html @@ -1,5 +1,12 @@ -
    +
    + +

    Send Proposals

    +
    +
    +
    +
    +

    {{title}}

    diff --git a/views/transactions.html b/views/transactions.html index 4fa9d2eb8..020ea96f9 100644 --- a/views/transactions.html +++ b/views/transactions.html @@ -1,138 +1,13 @@ -
    +
    -

    Transaction proposals ({{txs.length}})

    +

    Transaction Proposals ({{txs.length}})

    - +
    -
    - -
    -

    - {{tx.comment}} - - {{$root.wallet.publicKeyRing.nicknameForCopayer(tx.creator)}} -

    -
    -
    -
    -
    -

    {{out.value | noFractionNumber}} {{$root.unitName}}

    -

    {{out.value | noFractionNumber}} {{$root.unitName}}

    -
    -
    -
    - -
    -
    -
    -
    -

    {{tx.createdTs | amCalendar}}

    -
    -
    - -
    -
    - - {{c.cId}} - -
    - - - - - - - - - - - - - - - - - - - - - -
    - -
    -

    - {{c.cId === $root.wallet.getMyCopayerId() ? 'Me' : $root.wallet.publicKeyRing.nicknameForCopayer(c.cId)}} -

    -
    -
    -
    - - +
    -

    No pending transactions proposals.

    -

    No transactions proposals yet.

    - +

    No transactions proposals yet.

    +

    From 2ba794fc479007243ca45f684c454fd5c0e3aa63 Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Wed, 6 Aug 2014 15:34:56 -0300 Subject: [PATCH 2/4] Change url to /receive and /history --- js/controllers/copayers.js | 2 +- js/controllers/sidebar.js | 4 ++-- js/routes.js | 4 ++-- js/services/controllerUtils.js | 4 ++-- views/includes/sidebar-mobile.html | 2 +- views/includes/sidebar.html | 4 ++-- views/includes/transaction.html | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/js/controllers/copayers.js b/js/controllers/copayers.js index c6a9c2c54..5e18c6366 100644 --- a/js/controllers/copayers.js +++ b/js/controllers/copayers.js @@ -15,7 +15,7 @@ angular.module('copayApp.controllers').controller('CopayersController', } $scope.goToWallet = function() { - $location.path('/addresses'); + $location.path('/receive'); }; }); diff --git a/js/controllers/sidebar.js b/js/controllers/sidebar.js index 6935ec03f..54b236cee 100644 --- a/js/controllers/sidebar.js +++ b/js/controllers/sidebar.js @@ -8,7 +8,7 @@ angular.module('copayApp.controllers').controller('SidebarController', $scope.menu = [{ 'title': 'Receive', 'icon': 'fi-arrow-left', - 'link': 'addresses' + 'link': 'receive' }, { 'title': 'Send', 'icon': 'fi-arrow-right', @@ -16,7 +16,7 @@ angular.module('copayApp.controllers').controller('SidebarController', }, { 'title': 'History', 'icon': 'fi-clipboard-pencil', - 'link': 'transactions' + 'link': 'history' }, { 'title': 'More', 'icon': 'fi-download', diff --git a/js/routes.js b/js/routes.js index 00ab8b185..712bbda17 100644 --- a/js/routes.js +++ b/js/routes.js @@ -30,11 +30,11 @@ angular templateUrl: 'views/copayers.html', validate: true }) - .when('/addresses', { + .when('/receive', { templateUrl: 'views/addresses.html', validate: true }) - .when('/transactions', { + .when('/history', { templateUrl: 'views/transactions.html', validate: true }) diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index fbc5316f9..6b1587ad8 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -51,7 +51,7 @@ angular.module('copayApp.services') }); wallet.on('serverError', function(m) { var message = m || 'The PeerJS server is not responding, please try again'; - $location.path('addresses'); + $location.path('receive'); root.onErrorDigest($scope, message); }); wallet.on('ready', function() { @@ -123,7 +123,7 @@ angular.module('copayApp.services') if ($rootScope.pendingPayment) { $location.path('send'); } else { - $location.path('addresses'); + $location.path('receive'); } if (!config.disableVideo) video.setOwnPeer(myPeerID, w, handlePeerVideo); diff --git a/views/includes/sidebar-mobile.html b/views/includes/sidebar-mobile.html index cc1cb0b53..6c5b43d47 100644 --- a/views/includes/sidebar-mobile.html +++ b/views/includes/sidebar-mobile.html @@ -1,7 +1,7 @@
    - + v{{version}} diff --git a/views/includes/sidebar.html b/views/includes/sidebar.html index 3852fc2f7..b6014468a 100644 --- a/views/includes/sidebar.html +++ b/views/includes/sidebar.html @@ -1,7 +1,7 @@
    - +
    @@ -12,7 +12,7 @@
    - + {{$root.wallet.getName()}}
    - + {{c.cId}}
    @@ -54,7 +54,7 @@ - +
    From 09e60b2f705ad935b209cf8971482c3ce465a77e Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Thu, 7 Aug 2014 09:53:20 -0300 Subject: [PATCH 3/4] Refresh tx list after send on 1-of-1 --- js/controllers/send.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/controllers/send.js b/js/controllers/send.js index 341b82a58..dbf98b6aa 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -75,6 +75,7 @@ angular.module('copayApp.controllers').controller('SendController', notification.error('Error', 'There was an error sending the transaction.'); } $scope.loading = false; + $scope.loadTxs(); }); } $rootScope.pendingPayment = null; From 17a66f7ad70c99f166ae9ad92b0efd1ad8caacb9 Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Thu, 7 Aug 2014 10:20:24 -0300 Subject: [PATCH 4/4] update karma tests --- test/unit/controllers/controllersSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 5c6f55faf..8a630b0dd 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -214,7 +214,7 @@ describe("Unit: Controllers", function() { scope.submitForm(sendForm); sinon.assert.callCount(spy, 1); sinon.assert.callCount(spy2, 1); - sinon.assert.callCount(scope.loadTxs, 0); + sinon.assert.callCount(scope.loadTxs, 1); }); });