Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Merge branch 'development' into 391-forging-tab-fixings
Browse files Browse the repository at this point in the history
  • Loading branch information
reyraa authored Jun 12, 2017
2 parents 3f580e7 + 752dcf4 commit f5c140e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 171 deletions.
84 changes: 0 additions & 84 deletions src/components/delegates/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,90 +253,6 @@ app.component('delegates', {
}, UPDATE_INTERVAL);
}

/**
* Needs summary
*
* @method parseVoteListFromInput
*/
parseVoteListFromInput() {
this._parseListFromInput('voteList');
}

/**
* Needs summary
*
* @method parseUnvoteListFromInput
*/
parseUnvoteListFromInput() {
this._parseListFromInput('unvoteList');
}

/**
* @private
*/
_parseListFromInput(listName) {
const list = this[listName];
this.invalidUsernames = [];
this.pendingRequests = 0;
this.usernameList = this.usernameInput.trim().split(this.usernameSeparator);
this.usernameList.forEach((username) => {
if ((listName === 'voteList' && !this.votedDict[username.trim()]) ||
(listName === 'unvoteList' && this.votedDict[username.trim()])) {
this._setSelected(username.trim(), list);
}
});

if (this.pendingRequests === 0) {
this._selectFinish(true, list);
}
}

/**
* @private
*/
_selectFinish(success, list) {
if (list.length !== 0) {
this.usernameListActive = false;
this.usernameInput = '';
this.openVoteDialog();
} else {
this.dialog.errorToast('No delegate usernames could be parsed from the input');
}
}

/**
* @private
*/
_setSelected(username, list) {
const delegate = this.delegates.filter(d => d.username === username)[0];
if (delegate) {
this._selectDelegate(delegate, list);
} else {
this.pendingRequests++;
this.delegateApi.getDelegate(username,
).then((data) => {
this._selectDelegate(data.delegate, list);
}).catch(() => {
this.invalidUsernames.push(username);
}).finally(() => {
this.pendingRequests--;
if (this.pendingRequests === 0) {
this._selectFinish(this.invalidUsernames.length === 0, list);
}
});
}
}
// eslint-disable-next-line class-methods-use-this
_selectDelegate(delegate, list) {
// eslint-disable-next-line no-param-reassign
delegate.status = delegate.status || {};
// eslint-disable-next-line no-param-reassign
delegate.status.selected = true;
if (list.indexOf(delegate) === -1) {
list.push(delegate);
}
}

/**
* Uses dialog.modal to show vote list directive.
*
Expand Down
3 changes: 3 additions & 0 deletions src/components/delegates/delegates.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ delegates {
.downvote {
background-color: rgb(255, 228, 220);
}
.voted{
background-color: #d6f0ff;
}
.pending {
background-color: #eaeae9;
}
Expand Down
7 changes: 2 additions & 5 deletions src/components/delegates/delegates.pug
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ div.offline-hide
i.material-icons.search-append(ng-click='$ctrl.clearSearch()', ng-if='search') close
i.material-icons.search-append(ng-hide='search') search
span.pull-right.right-action-buttons
md-button(ng-click='$ctrl.usernameListActive = true')
i.material-icons list
span Input Names
md-menu.pull-right.right-action-buttons
md-button.pull-right.my-votes-button(ng-click='$mdOpenMenu()', ng-disabled='$ctrl.votedList.length == 0')
i.material-icons visibility
Expand Down Expand Up @@ -61,9 +58,9 @@ div.offline-hide
tbody(md-body, infinite-scroll='$ctrl.showMore()', infinite-scroll-distance='1')
tr(md-row, ng-if='!$ctrl.filteredDelegates.length && !$ctrl.loading')
td(md-cell, colspan='6') No delegates found
tr(md-row, ng-repeat="delegate in ($ctrl.filteredDelegates = ($ctrl.delegates | filter : {username: search} )) | limitTo : $ctrl.delegatesDisplayedCount", ng-class='{"downvote": delegate.status.voted && !delegate.status.selected, "upvote": !delegate.status.voted && delegate.status.selected, "pending": delegate.status.pending}')
tr(md-row, ng-repeat="delegate in ($ctrl.filteredDelegates = ($ctrl.delegates | filter : {username: search} )) | limitTo : $ctrl.delegatesDisplayedCount", ng-class='{"downvote": delegate.status.voted && !delegate.status.selected, "upvote": !delegate.status.voted && delegate.status.selected, "pending": delegate.status.pending, "voted": delegate.status.voted && delegate.status.selected}')
td(md-cell)
md-checkbox(ng-model='delegate.status.selected', ng-change='$ctrl.selectionChange(delegate)', ng-disabled='delegate.status.pending', aria-label='delegate selected for voting')
md-checkbox.md-primary(ng-model='delegate.status.selected', ng-change='$ctrl.selectionChange(delegate)', ng-disabled='delegate.status.pending', aria-label='delegate selected for voting')
td(md-cell, ng-bind='delegate.rank')
td(md-cell, ng-bind='delegate.username')
td(md-cell, ng-bind='delegate.address')
Expand Down
2 changes: 1 addition & 1 deletion src/components/delegates/vote.pug
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ div.dialog-vote(aria-label='Vote for delegates')
md-dialog-actions(layout='row')
md-button(ng-click="$ctrl.$mdDialog.cancel()") Cancel
span(flex)
md-button.md-primary.md-raised.submit-button(ng-disabled='!$ctrl.canVote()', ng-click="$ctrl.vote()") {{$ctrl.votingInProgress ? 'Voting...' : 'Confirm vote'}}
md-button.md-primary.md-raised.submit-button(ng-disabled='!$ctrl.canVote()', ng-click="$ctrl.vote()") {{$ctrl.votingInProgress ? 'Voting...' : 'Confirm'}}
2 changes: 1 addition & 1 deletion src/components/forging/forging.pug
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ md-card.offline-hide
th(md-column) Reward
tbody(md-body, infinite-scroll='$ctrl.loadMoreBlocks()', infinite-scroll-distance='1')
tr(md-row, ng-repeat='block in $ctrl.blocks')
td(md-cell data-title='tableBlocks.cols.height', sortable="'height'") {{block.height}}
td(md-cell data-title='tableBlocks.cols.height', sortable="'height'") {{block.height | liskNumber}}
td(md-cell data-title='tableBlocks.cols.blockId', ng-show='$ctrl.showAllColumns') {{block.id}}
td(md-cell data-title='tableBlocks.cols.timestamp', sortable="'timestamp'")
span(ng-show='block.timestamp > 0')
Expand Down
2 changes: 1 addition & 1 deletion src/components/lsk/lsk.pug
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
span(ng-bind='$ctrl.amount | lsk')
span(ng-bind='$ctrl.amount | lsk | liskNumber')
span(ng-show='$ctrl.append')= ' LSK'
15 changes: 15 additions & 0 deletions src/filters/liskNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This filter format numbers and add comma sperator to them
*
* @module app
*/
app.filter('liskNumber', ($filter) => {
const numberFilter = $filter('number');
return (input) => {
const temp = input.toString().split('.');
if (temp.length === 1) {
return numberFilter(temp[0]);
}
return `${numberFilter(temp[0])}.${temp[1]}`;
};
});
1 change: 1 addition & 0 deletions src/liskNano.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import './services/sync';
import './services/notification';

import './filters/lsk';
import './filters/liskNumber';

import './run';
import './states';
79 changes: 0 additions & 79 deletions test/components/delegates/delegates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,83 +303,4 @@ describe('delegates component controller', () => {
$scope.$apply();
});
});

describe('parseVoteListFromInput(list)', () => {
let delegateApiMock;

beforeEach(() => {
delegateApiMock = sinon.mock(controller.delegateApi);
});

it('parses this.usernameInput to list of delegates and opens vote dialog if all delegates were immediately resolved', () => {
const spy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = 'genesis_20\ngenesis_42\ngenesis_46\n';
controller.parseVoteListFromInput(controller.unvoteList);
expect(spy).to.have.been.calledWith();
});

it('parses this.usernameInput to list of delegates and opens vote dialog if all delegates were resolved immediately or from server', () => {
const username = 'not_fetched_yet';
const deffered = $q.defer();
delegateApiMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
const spy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = `${username}\ngenesis_42\ngenesis_46`;

controller.parseVoteListFromInput(controller.unvoteList);

deffered.resolve({
success: true,
delegate: {
username,
},
});
$scope.$apply();
expect(spy).to.have.been.calledWith();
});

it('parses this.usernameInput to list of delegates and opens vote dialog if any delegates were resolved', () => {
const username = 'invalid_name';
const deffered = $q.defer();
delegateApiMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
const spy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = `${username}\ngenesis_42\ngenesis_46`;

controller.parseVoteListFromInput(controller.unvoteList);

deffered.reject({ success: false });
$scope.$apply();
expect(spy).to.have.been.calledWith();
});

it('parses this.usernameInput to list of delegates and shows error toast if no delegates were resolved', () => {
const username = 'invalid_name';
const deffered = $q.defer();
delegateApiMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
const toastSpy = sinon.spy(controller.dialog, 'errorToast');
const dialogSpy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = username;
controller.voteList = [];

controller.parseVoteListFromInput(controller.unvoteList);

deffered.reject({ success: false });
$scope.$apply();
expect(toastSpy).to.have.been.calledWith();
expect(dialogSpy).to.not.have.been.calledWith();
});
});

describe('parseUnvoteListFromInput(list)', () => {
it('parses this.usernameInput to list of delegates and opens vote dialog if all delegates were immediately resolved', () => {
const delegate = {
username: 'genesis_20',
status: {},
};
const spy = sinon.spy(controller, 'openVoteDialog');
controller.votedDict[delegate.username] = delegate;
controller.usernameInput = `${delegate.username}\ngenesis_42\ngenesis_46\n`;
controller.parseUnvoteListFromInput(controller.unvoteList);
expect(spy).to.have.been.calledWith();
});
});
});

0 comments on commit f5c140e

Please sign in to comment.