This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from LiskHQ/22-support-delegate-registration
Support delegate registration - Closes #22
- Loading branch information
Showing
17 changed files
with
237 additions
and
15 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/app/components/delegate-registration/delegateRegistration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import './delegateRegistration.less'; | ||
|
||
app.directive('delegateRegistration', ($mdDialog, delegateService, Account, dialog) => { | ||
const DelegateRegistrationLink = function ($scope, $element) { | ||
$scope.form = { | ||
name: '', | ||
fee: 25, | ||
error: '', | ||
onSubmit: (form) => { | ||
if (form.$valid) { | ||
delegateService.registerDelegate($scope.form.name.toLowerCase(), Account.get().passphrase) | ||
.then(() => { | ||
dialog.successAlert({ | ||
title: 'Congratulations!', | ||
text: 'Account was successfully registered as delegate.', | ||
}) | ||
.then(() => { | ||
Account.set({ | ||
isDelegate: true, | ||
username: $scope.form.name.toLowerCase(), | ||
}); | ||
$scope.reset(form); | ||
$mdDialog.hide(); | ||
}); | ||
}) | ||
.catch((error) => { | ||
$scope.form.error = error.message ? error.message : ''; | ||
}); | ||
} | ||
}, | ||
}; | ||
|
||
$scope.reset = (form) => { | ||
$scope.form.name = ''; | ||
$scope.form.error = ''; | ||
|
||
form.$setPristine(); | ||
form.$setUntouched(); | ||
}; | ||
|
||
$scope.cancel = (form) => { | ||
$scope.reset(form); | ||
$mdDialog.hide(); | ||
}; | ||
|
||
$element.bind('click', () => { | ||
$mdDialog.show({ | ||
template: require('./delegateRegistration.pug')(), | ||
bindToController: true, | ||
locals: { | ||
form: $scope.form, | ||
cancel: $scope.cancel, | ||
}, | ||
controller: () => {}, | ||
controllerAs: '$ctrl', | ||
}); | ||
}); | ||
}; | ||
|
||
return { | ||
restrict: 'A', | ||
link: DelegateRegistrationLink, | ||
}; | ||
}); |
41 changes: 41 additions & 0 deletions
41
src/app/components/delegate-registration/delegateRegistration.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
.dialog-delegate-registration { | ||
background: transparent; | ||
box-shadow: none; | ||
|
||
& > md-card { | ||
box-shadow: | ||
0px 4px 6px -4px rgba(0, 0, 0, 0.2), | ||
0px 8px 10px 2px rgba(0, 0, 0, 0.14), | ||
0px 3px 12px 4px rgba(0, 0, 0, 0.12); | ||
} | ||
|
||
.fee { | ||
position: absolute; | ||
left: auto; | ||
right: 6px; | ||
bottom: 7px; | ||
font-size: 12px; | ||
line-height: 14px; | ||
transition: all 0.3s cubic-bezier(0.55, 0, 0.55, 0.2); | ||
color: grey; | ||
} | ||
|
||
input { | ||
text-transform: lowercase; | ||
} | ||
|
||
p.error { | ||
font-size:.8em; | ||
width: 100%; | ||
text-align: center; | ||
color: rgb(221,44,0); | ||
} | ||
|
||
md-dialog-actions .md-button { | ||
margin-left: -8px; | ||
} | ||
|
||
.info-icon-wrapper { | ||
margin: 24px 24px 0 0; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/app/components/delegate-registration/delegateRegistration.pug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
div.dialog-delegate-registration(aria-label='Vote for delegates') | ||
form(name='delegateRegistrationForm', ng-submit='$ctrl.form.onSubmit(delegateRegistrationForm)') | ||
md-toolbar | ||
.md-toolbar-tools | ||
h2 Delegate Registration | ||
md-dialog-content | ||
.md-dialog-content | ||
div | ||
md-input-container.md-block | ||
label Delegate name | ||
input(type='text', name='delegateName', ng-model='$ctrl.form.name', required, ng-disabled='$ctrl.loading') | ||
div(ng-messages='delegateRegistrationForm.name.$error') | ||
div(ng-message='required') Required | ||
md-input-container.md-block | ||
div.fee Fee: {{$ctrl.form.fee}} LSK | ||
md-divider | ||
div(layout='row') | ||
p.info-icon-wrapper | ||
i.material-icons info | ||
p | ||
span Becoming a delegate requires registration. You may choose your own delegate name, which can be used to promote your delegate. Only the top 101 delegates are eligible to forge. All fees are shared equally between the top 101 delegates. | ||
md-divider | ||
p.error(ng-bind='$ctrl.form.error', ng-if='$ctrl.form.error') | ||
md-dialog-actions(layout='row') | ||
md-button.md-raised.md-secondary(ng-disabled='$ctrl.loading', ng-click='$ctrl.cancel(delegateRegistrationForm)') {{ 'Cancel' }} | ||
span(flex) | ||
md-button.md-raised.md-primary(ng-disabled='!delegateRegistrationForm.$valid || $ctrl.loading', type='submit') {{ $ctrl.loading ? 'Registering...' : 'Register' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ | |
min-width: 128px; | ||
max-width: 256px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
@in: #73C8A9; | ||
@out: #F45D4C; | ||
@btn: rgb(2,136,209); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/components/delegate-registration/delegateRegistration.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const chai = require('chai'); | ||
const sinon = require('sinon'); | ||
const sinonChai = require('sinon-chai'); | ||
|
||
const expect = chai.expect; | ||
chai.use(sinonChai); | ||
|
||
describe('Delegate registration directive', () => { | ||
let $scope; | ||
let $mdDialog; | ||
let $element; | ||
const template = '<button type="button" data-delegate-registration=""></button>'; | ||
const form = { | ||
$setPristine: () => {}, | ||
$setUntouched: () => {}, | ||
valid: true, | ||
}; | ||
|
||
beforeEach(angular.mock.module('app')); | ||
|
||
beforeEach(inject(($compile, $rootScope, _$mdDialog_) => { | ||
$scope = $rootScope.$new(); | ||
$mdDialog = _$mdDialog_; | ||
$element = $compile(template)($scope); | ||
|
||
$scope.$digest(); | ||
})); | ||
|
||
it('binds click listener to call $mdDialog.show()', () => { | ||
const spy = sinon.spy($mdDialog, 'show'); | ||
$element.triggerHandler('click'); | ||
$scope.$digest(); | ||
|
||
expect(spy).to.have.been.calledWith(); | ||
}); | ||
|
||
it('defines a cancel method to hide modal and reset the form', () => { | ||
const spyReset = sinon.spy($scope, 'reset'); | ||
const spydialog = sinon.spy($mdDialog, 'hide'); | ||
|
||
expect($scope.cancel).to.not.equal(undefined); | ||
$scope.cancel(form); | ||
$scope.$digest(); | ||
|
||
expect(spyReset).to.have.been.calledWith(); | ||
expect(spydialog).to.have.been.calledWith(); | ||
}); | ||
|
||
it('defines a reset method to reset the form and form values', () => { | ||
const spyPristine = sinon.spy(form, '$setPristine'); | ||
const spyUntouched = sinon.spy(form, '$setUntouched'); | ||
|
||
expect($scope.reset).to.not.equal(undefined); | ||
|
||
$scope.form.name = 'TEST_NAME'; | ||
$scope.form.error = 'TEST_ERROR'; | ||
$scope.reset(form); | ||
$scope.$digest(); | ||
|
||
expect($scope.form.name).to.equal(''); | ||
expect($scope.form.error).to.equal(''); | ||
expect(spyPristine).to.have.been.calledWith(); | ||
expect(spyUntouched).to.have.been.calledWith(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters