Refactor menu, split transactions tab into send and history

This commit is contained in:
Yemel Jardi 2014-08-06 13:59:33 -03:00
parent a5544d08db
commit ad75265e93
10 changed files with 225 additions and 200 deletions

View File

@ -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();
};
});

View File

@ -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',

View File

@ -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;

View File

@ -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;
}

View File

@ -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);
});
});

View File

@ -42,12 +42,12 @@
<li data-ng-repeat="item in menu" ui-route="{{item.link}}" class="nav-item" data-ng-class="{active: isActive(item)}">
<a href="#!/{{item.link}}" ng-click="toggleCollapse()" class="db p20h">
<i class="size-24 m20r {{item.icon}}"></i> {{item.title}}
<span class="label alert round" ng-if="item.link=='transactions' && $root.pendingTxCount > 0">{{$root.pendingTxCount}}</span>
<span class="label alert round" ng-if="item.link=='send' && $root.pendingTxCount > 0">{{$root.pendingTxCount}}</span>
</a>
</li>
<li>
<a href="#" class="db p20h" title="Signout"
ng-click="signout()"><i class="size-24 m20r fi-power"></i> Signout</a>
<a href="#" class="db p20h" title="Close"
ng-click="signout()"><i class="size-24 m20r fi-power"></i> Close</a>
</li>
</ul>

View File

@ -54,13 +54,13 @@
<a href="#!/{{item.link}}" ng-click="toggleCollapse()" class="db p20h">
<i class="size-21 m20r {{item.icon}}"></i> {{item.title}}
<span class="right">
<span class="label alert" ng-if="item.link=='transactions' && $root.pendingTxCount > 0">{{$root.pendingTxCount}}</span>
<span class="label alert" ng-if="item.link=='send' && $root.pendingTxCount > 0">{{$root.pendingTxCount}}</span>
</span>
</a>
</li>
<li>
<a href="#!/" class="db p20h" title="Signout"
ng-click="signout()"><i class="size-21 m20r fi-power"></i> Signout</a>
<a href="#!/" class="db p20h" title="Close"
ng-click="signout()"><i class="size-21 m20r fi-power"></i> Close</a>
</li>
</ul>

View File

@ -0,0 +1,122 @@
<div class="last-transactions-header">
<div class="hide-for-small-only large-1 medium-1 columns">
<a class="text-black" ng-show="tx.comment">
<i class="fi-comment-quotes size-24" Popover-animation="true" popover="{{$root.wallet.publicKeyRing.nicknameForCopayer(tx.creator)}}" popover-title="{{tx.comment}}" popover-placement="right" popover-trigger="mouseenter"></i>
</a>
<a class="disable" ng-show="!tx.comment">
<i class="fi-comment-quotes size-24 text-gray"></i>
</a>
</div>
<div class="show-for-small-only small-12 columns m10b" ng-show="tx.comment">
<p class="size-14 label" >
{{tx.comment}} -
{{$root.wallet.publicKeyRing.nicknameForCopayer(tx.creator)}}
</p>
</div>
<div class="large-8 medium-8 small-8 columns">
<div ng-repeat="out in tx.outs">
<div class="large-3 medium-3 small-3 columns">
<p class="size-14 hide-for-small-only">{{out.value | noFractionNumber}} {{$root.unitName}}</p>
<p class="size-12 show-for-small-only">{{out.value | noFractionNumber}} {{$root.unitName}}</p>
</div>
<div class="large-1 medium-1 small-2 columns fi-arrow-right"> </div>
<div class="large-8 medium-8 small-7 columns ellipsis">
<contact address="{{out.address}}" tooltip-popup-delay="500" tooltip tooltip-placement="right"/>
</div>
</div>
</div>
<div class="large-3 medium-3 small-4 columns text-right">
<p class="size-12">{{tx.createdTs | amCalendar}}</p>
</div>
</div>
<div class="last-transactions-content">
<div class="box-copayer" ng-repeat="c in tx.actionList">
<a href="#!/transactions" class="has-tip">
<img class="copayer-ico br100" src="./img/satoshi.gif" alt="{{c.cId}}">
</a>
<div class="box-status">
<a ng-if="c.actions.create" tooltip-popup-delay="1000" tooltip="Created {{c.actions.create | amTimeAgo}}">
<i class="fi-crown icon-status icon-active"></i>
</a>
<a ng-if="!c.actions.create"><i class="fi-crown icon-status"></i></a>
<a ng-if="c.actions.seen" tooltip-popup-delay="1000" tooltip="Seen {{c.actions.seen | amTimeAgo}}">
<i class="fi-eye icon-status icon-active"></i>
</a>
<a ng-if="!c.actions.seen"><i class="fi-eye icon-status"></i></a>
<a ng-if="c.actions.rejected" tooltip-popup-delay="1000" tooltip="Rejected {{c.actions.rejected | amTimeAgo}}">
<i class="fi-x icon-status icon-active-x"></i>
</a>
<a ng-if="c.actions.sign" tooltip-popup-delay="1000" tooltip="Signed {{c.actions.sign | amTimeAgo}}">
<i class="fi-check icon-status icon-active-check"></i>
</a>
<a ng-if="!c.actions.sign && !c.actions.rejected" href="#!/transactions" class="icon-status">
<i class="fi-loop icon-rotate"></i>
</a>
</div>
<div class="text-center">
<p class="size-12 text-gray ellipsis">
{{c.cId === $root.wallet.getMyCopayerId() ? 'Me' : $root.wallet.publicKeyRing.nicknameForCopayer(c.cId)}}
</p>
</div>
</div>
</div>
<div class="last-transactions-footer">
<div class="large-5 medium-7 small-12 columns" ng-show="!tx.sentTs">
<div ng-show="!tx.signedByUs && !tx.rejectedByUs && !tx.finallyRejected && tx.missingSignatures">
<div class="hide-for-small-only">
<button class="primary m15r" ng-click="sign(tx.ntxid)" ng-disabled="loading" loading="Signing">
<i class="fi-check"></i> Sign
</button>
<button class="warning" ng-click="reject(tx.ntxid)" ng-disabled="loading" loading="Rejecting">
<i class="fi-x" ></i> Reject
</button>
</div>
<div class="show-for-small-only row m10b">
<button class="primary small-5 columns" ng-click="sign(tx.ntxid)" ng-disabled="loading" loading="Signing">
<i class="fi-check"></i> Sign
</button>
<button class="warning small-5 columns" ng-click="reject(tx.ntxid)" ng-disabled="loading" loading="Rejecting">
<i class="fi-x" ></i> Reject
</button>
</div>
</div>
<div ng-show="!tx.missingSignatures && !tx.sentTs">
<button class="primary" ng-click="send(tx.ntxid)" ng-disabled="loading" loading="Broadcasting"> <i class=".fi-upload-cloud"></i>
Broadcast Transaction
</button>
</div>
</div>
<div class="large-7 medium-5 small-12 columns text-right">
<div ng-show="tx.finallyRejected" class="has-error m10b">
Transaction finally rejected
</div>
<div ng-show="!tx.missingSignatures && tx.sentTs">
<div class="is-valid m10b">
<strong>Sent</strong> <span class="text-gray" am-time-ago="tx.sentTs"></span>
</div>
<div class="ellipsis small">
Transaction ID:
<a href="http://{{getShortNetworkName()}}.insight.is/tx/{{tx.sentTxid}}" target="_blank">
{{tx.sentTxid}}
</a>
</div>
</div>
<p class="text-gray m5b" ng-show="!tx.finallyRejected && tx.missingSignatures==1">
One signature missing
</p>
<p class="text-gray m5b" ng-show="!tx.finallyRejected && tx.missingSignatures>1">
{{tx.missingSignatures}} signatures missing</p>
<div class="ellipsis small text-gray">
<strong>Fee:</strong> {{tx.fee|noFractionNumber}} {{$root.unitName}}
<strong>Proposal ID:</strong> {{tx.ntxid}}
</div>
</div>
</div>

View File

@ -1,5 +1,12 @@
<div class="send" data-ng-controller="SendController">
<div class="send" data-ng-controller="SendController" data-ng-init="loadTxs()">
<div ng-show='$root.wallet.isReady()'>
<h1 ng-show="txs.length != 0">Send Proposals</h1>
<div class="last-transactions" ng-repeat="tx in txs | paged">
<div ng-include="'views/includes/transaction.html'"></div>
</div>
<div ng-show="txs.length != 0" class="large-12 line-dashed" style="padding: 0;"></div>
<h1>{{title}}</h1>
<div class="large-6 columns">
<form name="sendForm" ng-submit="submitForm(sendForm)" novalidate>

View File

@ -1,138 +1,13 @@
<div class="transactions" data-ng-controller="TransactionsController">
<div class="transactions" data-ng-controller="TransactionsController" data-ng-init="update()">
<div ng-show='$root.wallet.isReady()'>
<h1 ng-show="wallet.isShared()"> Transaction proposals <small>({{txs.length}})</small></h1>
<h1 ng-show="wallet.isShared()"> Transaction Proposals <small>({{txs.length}})</small></h1>
<div class="large-12" ng-show="wallet.isShared()">
<ul class="inline-list">
<li> <a class="text-gray size-12" ng-click="show(true)" ng-disabled="loading || onlyPending" loading="Updating" ng-class="{'active' : onlyPending}"> [ Pending ] </a> </li>
<li> <a class="text-gray size-12" ng-click="show()" ng-disabled="loading || !onlyPending" loading="Updating" ng-class="{'active' : !onlyPending}"> [ All ] </a> </li>
</ul>
<div class="last-transactions" ng-repeat="tx in txs | paged">
<div class="last-transactions-header">
<div class="hide-for-small-only large-1 medium-1 columns">
<a class="text-black" ng-show="tx.comment">
<i class="fi-comment-quotes size-24" Popover-animation="true" popover="{{$root.wallet.publicKeyRing.nicknameForCopayer(tx.creator)}}" popover-title="{{tx.comment}}" popover-placement="right" popover-trigger="mouseenter"></i>
</a>
<a class="disable" ng-show="!tx.comment">
<i class="fi-comment-quotes size-24 text-gray"></i>
</a>
</div>
<div class="show-for-small-only small-12 columns m10b" ng-show="tx.comment">
<p class="size-14 label" >
{{tx.comment}} -
{{$root.wallet.publicKeyRing.nicknameForCopayer(tx.creator)}}
</p>
</div>
<div class="large-8 medium-8 small-8 columns">
<div ng-repeat="out in tx.outs">
<div class="large-3 medium-3 small-3 columns">
<p class="size-14 hide-for-small-only">{{out.value | noFractionNumber}} {{$root.unitName}}</p>
<p class="size-12 show-for-small-only">{{out.value | noFractionNumber}} {{$root.unitName}}</p>
</div>
<div class="large-1 medium-1 small-2 columns fi-arrow-right"> </div>
<div class="large-8 medium-8 small-7 columns ellipsis">
<contact address="{{out.address}}" tooltip-popup-delay="500" tooltip tooltip-placement="right"/>
</div>
</div>
</div>
<div class="large-3 medium-3 small-4 columns text-right">
<p class="size-12">{{tx.createdTs | amCalendar}}</p>
</div>
</div>
<div class="last-transactions-content">
<div class="box-copayer" ng-repeat="c in tx.actionList">
<a href="#!/transactions" class="has-tip">
<img class="copayer-ico br100" src="./img/satoshi.gif" alt="{{c.cId}}">
</a>
<div class="box-status">
<a ng-if="c.actions.create" tooltip-popup-delay="1000" tooltip="Created {{c.actions.create | amTimeAgo}}">
<i class="fi-crown icon-status icon-active"></i>
</a>
<a ng-if="!c.actions.create"><i class="fi-crown icon-status"></i></a>
<a ng-if="c.actions.seen" tooltip-popup-delay="1000" tooltip="Seen {{c.actions.seen | amTimeAgo}}">
<i class="fi-eye icon-status icon-active"></i>
</a>
<a ng-if="!c.actions.seen"><i class="fi-eye icon-status"></i></a>
<a ng-if="c.actions.rejected" tooltip-popup-delay="1000" tooltip="Rejected {{c.actions.rejected | amTimeAgo}}">
<i class="fi-x icon-status icon-active-x"></i>
</a>
<a ng-if="c.actions.sign" tooltip-popup-delay="1000" tooltip="Signed {{c.actions.sign | amTimeAgo}}">
<i class="fi-check icon-status icon-active-check"></i>
</a>
<a ng-if="!c.actions.sign && !c.actions.rejected" href="#!/transactions" class="icon-status">
<i class="fi-loop icon-rotate"></i>
</a>
</div>
<div class="text-center">
<p class="size-12 text-gray ellipsis">
{{c.cId === $root.wallet.getMyCopayerId() ? 'Me' : $root.wallet.publicKeyRing.nicknameForCopayer(c.cId)}}
</p>
</div>
</div>
</div>
<div class="last-transactions-footer">
<div class="large-5 medium-7 small-12 columns" ng-show="!tx.sentTs">
<div ng-show="!tx.signedByUs && !tx.rejectedByUs && !tx.finallyRejected && tx.missingSignatures">
<div class="hide-for-small-only">
<button class="primary m15r" ng-click="sign(tx.ntxid)" ng-disabled="loading" loading="Signing">
<i class="fi-check"></i> Sign
</button>
<button class="warning" ng-click="reject(tx.ntxid)" ng-disabled="loading" loading="Rejecting">
<i class="fi-x" ></i> Reject
</button>
</div>
<div class="show-for-small-only row m10b">
<button class="primary small-5 columns" ng-click="sign(tx.ntxid)" ng-disabled="loading" loading="Signing">
<i class="fi-check"></i> Sign
</button>
<button class="warning small-5 columns" ng-click="reject(tx.ntxid)" ng-disabled="loading" loading="Rejecting">
<i class="fi-x" ></i> Reject
</button>
</div>
</div>
<div ng-show="!tx.missingSignatures && !tx.sentTs">
<button class="primary" ng-click="send(tx.ntxid)" ng-disabled="loading" loading="Broadcasting"> <i class=".fi-upload-cloud"></i>
Broadcast Transaction
</button>
</div>
</div>
<div class="large-7 medium-5 small-12 columns text-right">
<div ng-show="tx.finallyRejected" class="has-error m10b">
Transaction finally rejected
</div>
<div ng-show="!tx.missingSignatures && tx.sentTs">
<div class="is-valid m10b">
<strong>Sent</strong> <span class="text-gray" am-time-ago="tx.sentTs"></span>
</div>
<div class="ellipsis small">
Transaction ID:
<a href="http://{{getShortNetworkName()}}.insight.is/tx/{{tx.sentTxid}}" target="_blank">
{{tx.sentTxid}}
</a>
</div>
</div>
<p class="text-gray m5b" ng-show="!tx.finallyRejected && tx.missingSignatures==1">
One signature missing
</p>
<p class="text-gray m5b" ng-show="!tx.finallyRejected && tx.missingSignatures>1">
{{tx.missingSignatures}} signatures missing</p>
<div class="ellipsis small text-gray">
<strong>Fee:</strong> {{tx.fee|noFractionNumber}} {{$root.unitName}}
<strong>Proposal ID:</strong> {{tx.ntxid}}
</div>
</div>
</div>
<div ng-include="'views/includes/transaction.html'"></div>
</div>
<p ng-show="onlyPending && txs.length == 0">No pending transactions proposals.</p>
<p ng-show="!onlyPending && txs.length == 0">No transactions proposals yet.</p>
<pagination ng-show="!onlyPending && txs.length > txpItemsPerPage" total-items="txs.length" items-per-page="txpItemsPerPage" page="txpCurrentPage" on-select-page="show()" class="pagination-small primary"></pagination>
<p ng-show="txs.length == 0">No transactions proposals yet.</p>
<pagination ng-show="txs.length > txpItemsPerPage" total-items="txs.length" items-per-page="txpItemsPerPage" page="txpCurrentPage" on-select-page="show()" class="pagination-small primary"></pagination>
</div>
<h1 ng-class="{'line-dashed': wallet.isShared()}">