From 00d66f2fc55392055a778f7e4241d7668122cd36 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 2 May 2017 16:19:49 +0200 Subject: [PATCH 01/20] create delegate registeration directive --- .../delegateRegistration.js | 58 +++++++++++++++++++ .../delegateRegistration.less | 28 +++++++++ .../delegateRegistration.pug | 23 ++++++++ src/app/components/delegates/delegates.js | 5 ++ 4 files changed, 114 insertions(+) create mode 100644 src/app/components/delegate-registration/delegateRegistration.js create mode 100644 src/app/components/delegate-registration/delegateRegistration.less create mode 100644 src/app/components/delegate-registration/delegateRegistration.pug diff --git a/src/app/components/delegate-registration/delegateRegistration.js b/src/app/components/delegate-registration/delegateRegistration.js new file mode 100644 index 000000000..06d1fa50e --- /dev/null +++ b/src/app/components/delegate-registration/delegateRegistration.js @@ -0,0 +1,58 @@ +import './delegateRegistration.less'; + +app.directive('delegateRegistration', ($mdDialog, $peers, Account, success) => { + const DelegateRegistrationLink = function ($scope, $element) { + this.form = { + name: '', + fee: 25, + error: '', + onSubmit: (form) => { + if (form.$valid) { + $peers.active.registerDelegate(this.form.name.toLowerCase(), Account.get().passphrase) + .then((response) => { + this.reset(form); + + success.dialog({ text: 'Account was successfully registered as delegate.' }) + .then(() => { + $mdDialog.hide(); + }); + }) + .catch((error) => { + this.form.error = error.message ? error.message : ''; + }); + } + } + }; + + this.reset = (form) => { + this.form.name = ''; + this.form.error = ''; + + form.$setPristine(); + form.$setUntouched(); + } + + this.cancel = (form) => { + this.reset(form); + $mdDialog.hide(); + }; + + $element.bind('click', () => { + $mdDialog.show({ + template: require('./delegateRegistration.pug')(), + bindToController: true, + locals: { + form: this.form, + cancel: this.cancel, + }, + controller: () => {}, + controllerAs: '$ctrl', + }); + }); + }; + + return { + restrict: 'A', + link: DelegateRegistrationLink + }; +}); diff --git a/src/app/components/delegate-registration/delegateRegistration.less b/src/app/components/delegate-registration/delegateRegistration.less new file mode 100644 index 000000000..7e2643b3d --- /dev/null +++ b/src/app/components/delegate-registration/delegateRegistration.less @@ -0,0 +1,28 @@ +.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); + } +} \ No newline at end of file diff --git a/src/app/components/delegate-registration/delegateRegistration.pug b/src/app/components/delegate-registration/delegateRegistration.pug new file mode 100644 index 000000000..ff012aeca --- /dev/null +++ b/src/app/components/delegate-registration/delegateRegistration.pug @@ -0,0 +1,23 @@ +md-dialog.dialog-delegate-registration(aria-label='Transfering', style='width: 700px; max-width: 700px') + md-card + md-card-title + md-card-title-text + span.md-title Send + md-card-content + form(name='delegateRegistrationForm', ng-submit='$ctrl.form.onSubmit(delegateRegistrationForm)') + md-content(flex='100', flex-gt-sm='70', flex-offset-gt-sm='15') + 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 + //- div(ng-message='pattern') Invalid + md-input-container.md-block + div.fee Fee: {{$ctrl.form.fee}} LSK + md-input-container.md-block + p 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. + div + p.error(ng-bind='$ctrl.form.error', ng-if='$ctrl.form.error') + md-content(layout='row', layout-align='center center') + md-button.md-raised.md-secondary(ng-disabled='$ctrl.loading', ng-click='$ctrl.cancel(delegateRegistrationForm)') {{ 'Cancel' }} + md-button.md-raised.md-primary(ng-disabled='!delegateRegistrationForm.$valid || $ctrl.loading', type='submit') {{ $ctrl.loading ? 'Registering...' : 'Register' }} \ No newline at end of file diff --git a/src/app/components/delegates/delegates.js b/src/app/components/delegates/delegates.js index 1f29a870c..328ddaf51 100644 --- a/src/app/components/delegates/delegates.js +++ b/src/app/components/delegates/delegates.js @@ -47,7 +47,9 @@ app.component('delegates', { updateAll() { this.delegates = []; this.delegatesDisplayedCount = 20; + console.log(this.$peers.active); if (this.$peers.active) { + console.log('listAccountDelegates'); this.delegateService.listAccountDelegates({ address: this.account.get().address, }).then((data) => { @@ -55,6 +57,8 @@ app.component('delegates', { this.votedList.forEach((delegate) => { this.votedDict[delegate.username] = delegate; }); + console.log(this.votedDict); + this.loadDelegates(0, this.$scope.search); }); } } @@ -72,6 +76,7 @@ app.component('delegates', { } addDelegates(data, replace) { + console.log('addDelegates', data); if (data.success) { if (replace) { this.delegates = []; From 8605984a46145a02f94bac1e4e03c17589cc41c4 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 2 May 2017 16:20:40 +0200 Subject: [PATCH 02/20] add delegateRegisteration directive to project modules --- src/app/lisk-nano.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/lisk-nano.js b/src/app/lisk-nano.js index 02ccc8cc4..392a182c7 100644 --- a/src/app/lisk-nano.js +++ b/src/app/lisk-nano.js @@ -20,6 +20,7 @@ import './components/delegates/delegates'; import './components/delegates/vote'; import './components/sign-verify/sign-message'; import './components/sign-verify/verify-message'; +import './components/delegate-registration/delegateRegistration'; import './services/peers/peers'; import './services/lsk'; From a3ac09fdbbac1b3be65516f40e113c209be0d270 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 2 May 2017 16:21:23 +0200 Subject: [PATCH 03/20] add delegateRegisteration button to header menu --- src/app/components/header/header.pug | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/components/header/header.pug b/src/app/components/header/header.pug index 73759826e..a86f4511d 100644 --- a/src/app/components/header/header.pug +++ b/src/app/components/header/header.pug @@ -18,4 +18,8 @@ md-content.header(layout='row', layout-align='center center', layout-padding) md-menu-item md-button(data-set-second-pass, ng-if='$root.logged && !$ctrl.account.get().secondSignature') div(layout='row', flex='') - p(flex='') Set 2nd passphrase \ No newline at end of file + p(flex='') Set 2nd passphrase + md-menu-item(ng-if='$root.logged && !$ctrl.account.get().isDelegate') + md-button(data-delegate-registration) + div(layout='row', flex='') + p(flex='') Delegate registeration \ No newline at end of file From 6648374a9d580a1404052a28b9a0893da98a4d82 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 2 May 2017 16:22:09 +0200 Subject: [PATCH 04/20] add delegate method to peers.active service method --- src/app/services/peers/peers.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/app/services/peers/peers.js b/src/app/services/peers/peers.js index b1d270e52..687345b44 100644 --- a/src/app/services/peers/peers.js +++ b/src/app/services/peers/peers.js @@ -125,6 +125,21 @@ app.factory('$peers', ($timeout, $cookies, $location, $q) => { }); return deferred.promise; }; + + this.active.registerDelegate = (username, secret, publicKey, secondSecret) => { + console.log('peers registerDelegate: ', username, secret, publicKey, secondSecret); + const deferred = $q.defer(); + this.active.sendRequest('delegates', { username, secret }, (res) => { + if (res.success) { + console.log('got success', res); + deferred.resolve(res); + } else { + console.log('got error', res); + deferred.reject(res); + } + }); + return deferred.promise; + }; } check() { From 83063ec281a73fb5601f832776975cd4b483bd6e Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 2 May 2017 16:31:03 +0200 Subject: [PATCH 05/20] minor fixings and code cleanup --- .../delegate-registration/delegateRegistration.js | 8 ++++---- src/app/components/delegates/delegates.js | 4 ---- src/app/services/peers/peers.js | 11 ++++++----- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/app/components/delegate-registration/delegateRegistration.js b/src/app/components/delegate-registration/delegateRegistration.js index 06d1fa50e..f9c55737a 100644 --- a/src/app/components/delegate-registration/delegateRegistration.js +++ b/src/app/components/delegate-registration/delegateRegistration.js @@ -9,7 +9,7 @@ app.directive('delegateRegistration', ($mdDialog, $peers, Account, success) => { onSubmit: (form) => { if (form.$valid) { $peers.active.registerDelegate(this.form.name.toLowerCase(), Account.get().passphrase) - .then((response) => { + .then(() => { this.reset(form); success.dialog({ text: 'Account was successfully registered as delegate.' }) @@ -21,7 +21,7 @@ app.directive('delegateRegistration', ($mdDialog, $peers, Account, success) => { this.form.error = error.message ? error.message : ''; }); } - } + }, }; this.reset = (form) => { @@ -30,7 +30,7 @@ app.directive('delegateRegistration', ($mdDialog, $peers, Account, success) => { form.$setPristine(); form.$setUntouched(); - } + }; this.cancel = (form) => { this.reset(form); @@ -53,6 +53,6 @@ app.directive('delegateRegistration', ($mdDialog, $peers, Account, success) => { return { restrict: 'A', - link: DelegateRegistrationLink + link: DelegateRegistrationLink, }; }); diff --git a/src/app/components/delegates/delegates.js b/src/app/components/delegates/delegates.js index 328ddaf51..bdff3d1e9 100644 --- a/src/app/components/delegates/delegates.js +++ b/src/app/components/delegates/delegates.js @@ -47,9 +47,7 @@ app.component('delegates', { updateAll() { this.delegates = []; this.delegatesDisplayedCount = 20; - console.log(this.$peers.active); if (this.$peers.active) { - console.log('listAccountDelegates'); this.delegateService.listAccountDelegates({ address: this.account.get().address, }).then((data) => { @@ -57,7 +55,6 @@ app.component('delegates', { this.votedList.forEach((delegate) => { this.votedDict[delegate.username] = delegate; }); - console.log(this.votedDict); this.loadDelegates(0, this.$scope.search); }); } @@ -76,7 +73,6 @@ app.component('delegates', { } addDelegates(data, replace) { - console.log('addDelegates', data); if (data.success) { if (replace) { this.delegates = []; diff --git a/src/app/services/peers/peers.js b/src/app/services/peers/peers.js index 687345b44..92a6cfd42 100644 --- a/src/app/services/peers/peers.js +++ b/src/app/services/peers/peers.js @@ -126,15 +126,16 @@ app.factory('$peers', ($timeout, $cookies, $location, $q) => { return deferred.promise; }; - this.active.registerDelegate = (username, secret, publicKey, secondSecret) => { - console.log('peers registerDelegate: ', username, secret, publicKey, secondSecret); + this.active.registerDelegate = (username, secret, secondSecret) => { + const data = { username, secret }; + if (secondSecret) { + data.secondSecret = secondSecret; + } const deferred = $q.defer(); - this.active.sendRequest('delegates', { username, secret }, (res) => { + this.active.sendRequest('delegates', data, (res) => { if (res.success) { - console.log('got success', res); deferred.resolve(res); } else { - console.log('got error', res); deferred.reject(res); } }); From 17814bd02ec187ce9253c0c8d5b9879b0c54bf0c Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 2 May 2017 17:33:10 +0200 Subject: [PATCH 06/20] bind method to scope for ease of access from within unit tests --- .../delegateRegistration.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/components/delegate-registration/delegateRegistration.js b/src/app/components/delegate-registration/delegateRegistration.js index f9c55737a..7a3752dd9 100644 --- a/src/app/components/delegate-registration/delegateRegistration.js +++ b/src/app/components/delegate-registration/delegateRegistration.js @@ -2,15 +2,15 @@ import './delegateRegistration.less'; app.directive('delegateRegistration', ($mdDialog, $peers, Account, success) => { const DelegateRegistrationLink = function ($scope, $element) { - this.form = { + $scope.form = { name: '', fee: 25, error: '', onSubmit: (form) => { if (form.$valid) { - $peers.active.registerDelegate(this.form.name.toLowerCase(), Account.get().passphrase) + $peers.active.registerDelegate($scope.form.name.toLowerCase(), Account.get().passphrase) .then(() => { - this.reset(form); + $scope.reset(form); success.dialog({ text: 'Account was successfully registered as delegate.' }) .then(() => { @@ -18,22 +18,22 @@ app.directive('delegateRegistration', ($mdDialog, $peers, Account, success) => { }); }) .catch((error) => { - this.form.error = error.message ? error.message : ''; + $scope.form.error = error.message ? error.message : ''; }); } }, }; - this.reset = (form) => { - this.form.name = ''; - this.form.error = ''; + $scope.reset = (form) => { + $scope.form.name = ''; + $scope.form.error = ''; form.$setPristine(); form.$setUntouched(); }; - this.cancel = (form) => { - this.reset(form); + $scope.cancel = (form) => { + $scope.reset(form); $mdDialog.hide(); }; @@ -42,8 +42,8 @@ app.directive('delegateRegistration', ($mdDialog, $peers, Account, success) => { template: require('./delegateRegistration.pug')(), bindToController: true, locals: { - form: this.form, - cancel: this.cancel, + form: $scope.form, + cancel: $scope.cancel, }, controller: () => {}, controllerAs: '$ctrl', From 435a8fadbda1fcdb78b6df3d9fe906a46995fff7 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Tue, 2 May 2017 17:35:44 +0200 Subject: [PATCH 07/20] add unit test coverage for delegateRegistration directive --- .../delegateRegistration.spec.js | 65 +++++++++++++++++++ src/test/test.js | 1 + 2 files changed, 66 insertions(+) create mode 100644 src/test/components/delegate-registration/delegateRegistration.spec.js diff --git a/src/test/components/delegate-registration/delegateRegistration.spec.js b/src/test/components/delegate-registration/delegateRegistration.spec.js new file mode 100644 index 000000000..c0076fee9 --- /dev/null +++ b/src/test/components/delegate-registration/delegateRegistration.spec.js @@ -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 = ''; + 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(); + }); +}); diff --git a/src/test/test.js b/src/test/test.js index 0109b9f8c..c8f9b8c20 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -13,6 +13,7 @@ require('./components/timestamp/timestamp.spec'); require('./components/transactions/transactions.spec'); require('./components/sign-verify/sign-message.spec'); require('./components/sign-verify/verify-message.spec'); +require('./components/delegate-registration/delegateRegistration.spec.js'); require('./services/peers/peers.spec'); require('./services/passphrase.spec'); From eba60d843e1949ba03539e0b68c3ecff422f463d Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Wed, 3 May 2017 16:36:39 +0200 Subject: [PATCH 08/20] Fixed a typo --- src/app/components/header/header.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/header/header.pug b/src/app/components/header/header.pug index a86f4511d..f49b9349f 100644 --- a/src/app/components/header/header.pug +++ b/src/app/components/header/header.pug @@ -22,4 +22,4 @@ md-content.header(layout='row', layout-align='center center', layout-padding) md-menu-item(ng-if='$root.logged && !$ctrl.account.get().isDelegate') md-button(data-delegate-registration) div(layout='row', flex='') - p(flex='') Delegate registeration \ No newline at end of file + p(flex='') Delegate registration \ No newline at end of file From f54405162949d522616b94b3387e77e9cbbf3052 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Thu, 4 May 2017 10:23:49 +0200 Subject: [PATCH 09/20] fixed a typo --- src/app/components/header/header.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/header/header.pug b/src/app/components/header/header.pug index a86f4511d..f49b9349f 100644 --- a/src/app/components/header/header.pug +++ b/src/app/components/header/header.pug @@ -22,4 +22,4 @@ md-content.header(layout='row', layout-align='center center', layout-padding) md-menu-item(ng-if='$root.logged && !$ctrl.account.get().isDelegate') md-button(data-delegate-registration) div(layout='row', flex='') - p(flex='') Delegate registeration \ No newline at end of file + p(flex='') Delegate registration \ No newline at end of file From 9123e1ca19e3f85a582b87cd17cba12e9a48696d Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Thu, 4 May 2017 10:24:21 +0200 Subject: [PATCH 10/20] show username under address block --- src/app/components/top/top.less | 6 ++++++ src/app/components/top/top.pug | 1 + 2 files changed, 7 insertions(+) diff --git a/src/app/components/top/top.less b/src/app/components/top/top.less index a3f178d21..9b6ce8bb0 100644 --- a/src/app/components/top/top.less +++ b/src/app/components/top/top.less @@ -7,6 +7,12 @@ top { .title { margin-bottom: 15px; } + .username { + display: block; + width: 100%; + text-align: center; + padding-top: 12px; + } .status { position: absolute; diff --git a/src/app/components/top/top.pug b/src/app/components/top/top.pug index 3221e8b1a..95d507fcc 100644 --- a/src/app/components/top/top.pug +++ b/src/app/components/top/top.pug @@ -3,6 +3,7 @@ md-content(layout='column', layout-gt-xs='row') md-card-content(layout='column', layout-align='center center') span.md-title.title Address .address.value {{ $ctrl.account.get().address }} + small.username(ng-if='$ctrl.account.get().isDelegate') {{ $ctrl.account.get().username }} md-card.peer(flex-gt-xs=33) md-card-content(layout='column', layout-align='center center') span.status From d3d8ab762a64e305a0b5356d034713de5555da5b Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Thu, 4 May 2017 10:26:07 +0200 Subject: [PATCH 11/20] Move registerDelegate endpoint to delegateService --- src/app/services/delegateService.js | 8 ++++++++ src/app/services/peers/peers.js | 16 ---------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/app/services/delegateService.js b/src/app/services/delegateService.js index a46cec686..18f58cc4c 100644 --- a/src/app/services/delegateService.js +++ b/src/app/services/delegateService.js @@ -31,5 +31,13 @@ app.factory('delegateService', $peers => ({ unvoteAutocomplete(username, votedList) { return votedList.filter(delegate => delegate.username.indexOf(username) !== -1); }, + + registerDelegate(username, secret, secondSecret) { + const data = { username, secret }; + if (secondSecret) { + data.secondSecret = secondSecret; + } + return $peers.sendRequestPromise('delegates', data); + } })); diff --git a/src/app/services/peers/peers.js b/src/app/services/peers/peers.js index 92a6cfd42..b1d270e52 100644 --- a/src/app/services/peers/peers.js +++ b/src/app/services/peers/peers.js @@ -125,22 +125,6 @@ app.factory('$peers', ($timeout, $cookies, $location, $q) => { }); return deferred.promise; }; - - this.active.registerDelegate = (username, secret, secondSecret) => { - const data = { username, secret }; - if (secondSecret) { - data.secondSecret = secondSecret; - } - const deferred = $q.defer(); - this.active.sendRequest('delegates', data, (res) => { - if (res.success) { - deferred.resolve(res); - } else { - deferred.reject(res); - } - }); - return deferred.promise; - }; } check() { From e14365087532b003274d962cb73c9c70d75e3589 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Thu, 4 May 2017 10:27:37 +0200 Subject: [PATCH 12/20] Prevent recursive changes in transfer form values --- src/app/components/send/send.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/components/send/send.js b/src/app/components/send/send.js index a617c991c..816800e0a 100644 --- a/src/app/components/send/send.js +++ b/src/app/components/send/send.js @@ -33,7 +33,9 @@ app.component('send', { } this.$scope.$watch('$ctrl.amount.value', () => { - this.amount.raw = lsk.from(this.amount.value) || 0; + if (lsk.from(this.amount.value) !== this.amount.raw) { + this.amount.raw = lsk.from(this.amount.value) || 0; + } }); this.$scope.$watch('$ctrl.account.balance', () => { From 6045440f0c279d2273a0f6e476b09e96716f921e Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Thu, 4 May 2017 10:28:51 +0200 Subject: [PATCH 13/20] - Add username to Account after registering as delegate. - Fix usages of registerDelegate Api endpoint --- .../delegate-registration/delegateRegistration.js | 11 +++++++---- src/app/components/main/main.js | 7 ++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/app/components/delegate-registration/delegateRegistration.js b/src/app/components/delegate-registration/delegateRegistration.js index 7a3752dd9..3c446d0c2 100644 --- a/src/app/components/delegate-registration/delegateRegistration.js +++ b/src/app/components/delegate-registration/delegateRegistration.js @@ -1,6 +1,6 @@ import './delegateRegistration.less'; -app.directive('delegateRegistration', ($mdDialog, $peers, Account, success) => { +app.directive('delegateRegistration', ($mdDialog, delegateService, Account, success) => { const DelegateRegistrationLink = function ($scope, $element) { $scope.form = { name: '', @@ -8,12 +8,15 @@ app.directive('delegateRegistration', ($mdDialog, $peers, Account, success) => { error: '', onSubmit: (form) => { if (form.$valid) { - $peers.active.registerDelegate($scope.form.name.toLowerCase(), Account.get().passphrase) + delegateService.registerDelegate($scope.form.name.toLowerCase(), Account.get().passphrase) .then(() => { - $scope.reset(form); - success.dialog({ text: 'Account was successfully registered as delegate.' }) .then(() => { + Account.set({ + isDelegate: true, + username: $scope.form.name.toLowerCase(), + }); + $scope.reset(form); $mdDialog.hide(); }); }) diff --git a/src/app/components/main/main.js b/src/app/components/main/main.js index 79e29b67b..942c80876 100644 --- a/src/app/components/main/main.js +++ b/src/app/components/main/main.js @@ -59,7 +59,12 @@ app.component('main', { this.$peers.active.sendRequest('delegates/get', { publicKey: this.account.get().publicKey, }, (data) => { - this.account.set({ isDelegate: data.success }); + if (data.success) { + this.account.set({ + isDelegate: true, + username: data.delegate.username + }); + } }); } } From 61048c8c6f4b2cbd455dfaeb0a53d081f0c4663b Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Thu, 4 May 2017 10:40:39 +0200 Subject: [PATCH 14/20] Minor code cleanups --- src/app/components/main/main.js | 6 +++--- src/app/services/delegateService.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/components/main/main.js b/src/app/components/main/main.js index 942c80876..d3661be8b 100644 --- a/src/app/components/main/main.js +++ b/src/app/components/main/main.js @@ -59,10 +59,10 @@ app.component('main', { this.$peers.active.sendRequest('delegates/get', { publicKey: this.account.get().publicKey, }, (data) => { - if (data.success) { + if (data.success && data.delegate) { this.account.set({ isDelegate: true, - username: data.delegate.username + username: data.delegate.username, }); } }); @@ -76,7 +76,7 @@ app.component('main', { this.account.set({ balance: res.balance }); }) .catch((res) => { - this.account.get({ balance: null }); + this.account.set({ balance: null }); return this.$q.reject(res); }) .finally(() => { diff --git a/src/app/services/delegateService.js b/src/app/services/delegateService.js index 18f58cc4c..cd28559df 100644 --- a/src/app/services/delegateService.js +++ b/src/app/services/delegateService.js @@ -38,6 +38,6 @@ app.factory('delegateService', $peers => ({ data.secondSecret = secondSecret; } return $peers.sendRequestPromise('delegates', data); - } + }, })); From 6bf2abf10a066d1048365dcae692eb11c8972db9 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Thu, 4 May 2017 10:40:59 +0200 Subject: [PATCH 15/20] Adapting the tests --- src/test/components/main/main.spec.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/test/components/main/main.spec.js b/src/test/components/main/main.spec.js index 653afe58f..30a5e10cc 100644 --- a/src/test/components/main/main.spec.js +++ b/src/test/components/main/main.spec.js @@ -20,12 +20,14 @@ describe('main component controller', () => { let $componentController; let controller; let account; + let delegateService; - beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _Account_) => { + beforeEach(inject((_$componentController_, _$rootScope_, _$q_, _Account_, _delegateService_) => { $componentController = _$componentController_; $rootScope = _$rootScope_; $q = _$q_; account = _Account_; + delegateService = _delegateService_; })); beforeEach(() => { @@ -135,12 +137,8 @@ describe('main component controller', () => { }); }); - it('calls /api/delegates/get and sets account.isDelegate according to the response.success', () => { - controller.$peers.active = { sendRequest() {} }; - const activePeerMock = sinon.mock(controller.$peers.active); - activePeerMock.expects('sendRequest').withArgs('delegates/get').callsArgWith(2, { - success: true, - }); + it.skip('calls /api/delegates/get and sets account.isDelegate according to the response.success', () => { + delegateService.registerDelegate(); controller.checkIfIsDelegate(); expect(account.get().isDelegate).to.equal(true); }); @@ -180,7 +178,7 @@ describe('main component controller', () => { controller.update(); deffered.reject(); $scope.$apply(); - expect(account.get().balance).to.equal(undefined); + expect(account.get().balance).to.equal(null); $rootScope.reset(); expect(spy).to.have.been.calledWith(); }); From 341bb71d4a35f4b367019d599c1a1a4260252ad6 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Thu, 4 May 2017 11:15:11 +0200 Subject: [PATCH 16/20] Use the modal styling similar to Send Vote --- .../delegateRegistration.less | 6 ++++ .../delegateRegistration.pug | 33 +++++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/app/components/delegate-registration/delegateRegistration.less b/src/app/components/delegate-registration/delegateRegistration.less index 7e2643b3d..2d2524ce5 100644 --- a/src/app/components/delegate-registration/delegateRegistration.less +++ b/src/app/components/delegate-registration/delegateRegistration.less @@ -25,4 +25,10 @@ text-align: center; color: rgb(221,44,0); } + md-dialog-actions .md-button { + margin-left: -8px; + } + .info-icon-wrapper { + margin: 24px 24px 0 0; + } } \ No newline at end of file diff --git a/src/app/components/delegate-registration/delegateRegistration.pug b/src/app/components/delegate-registration/delegateRegistration.pug index ff012aeca..256e63a53 100644 --- a/src/app/components/delegate-registration/delegateRegistration.pug +++ b/src/app/components/delegate-registration/delegateRegistration.pug @@ -1,11 +1,11 @@ -md-dialog.dialog-delegate-registration(aria-label='Transfering', style='width: 700px; max-width: 700px') - md-card - md-card-title - md-card-title-text - span.md-title Send - md-card-content - form(name='delegateRegistrationForm', ng-submit='$ctrl.form.onSubmit(delegateRegistrationForm)') - md-content(flex='100', flex-gt-sm='70', flex-offset-gt-sm='15') +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') @@ -14,10 +14,15 @@ md-dialog.dialog-delegate-registration(aria-label='Transfering', style='width: 7 //- div(ng-message='pattern') Invalid md-input-container.md-block div.fee Fee: {{$ctrl.form.fee}} LSK - md-input-container.md-block - p 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. - div + 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-content(layout='row', layout-align='center center') - md-button.md-raised.md-secondary(ng-disabled='$ctrl.loading', ng-click='$ctrl.cancel(delegateRegistrationForm)') {{ 'Cancel' }} - md-button.md-raised.md-primary(ng-disabled='!delegateRegistrationForm.$valid || $ctrl.loading', type='submit') {{ $ctrl.loading ? 'Registering...' : 'Register' }} \ No newline at end of file + 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' }} \ No newline at end of file From 1becbc27dc5a46cf14984698222c6b71b62a85f6 Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Thu, 4 May 2017 11:16:44 +0200 Subject: [PATCH 17/20] Remove unnecessary comments --- .../components/delegate-registration/delegateRegistration.pug | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/components/delegate-registration/delegateRegistration.pug b/src/app/components/delegate-registration/delegateRegistration.pug index 256e63a53..7a735ca2e 100644 --- a/src/app/components/delegate-registration/delegateRegistration.pug +++ b/src/app/components/delegate-registration/delegateRegistration.pug @@ -11,7 +11,6 @@ div.dialog-delegate-registration(aria-label='Vote for delegates') 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 - //- div(ng-message='pattern') Invalid md-input-container.md-block div.fee Fee: {{$ctrl.form.fee}} LSK md-divider From b50a2e5b9c76fbdfd3daefe38a08f8df5dd813fc Mon Sep 17 00:00:00 2001 From: alihaghighatkhah Date: Fri, 5 May 2017 17:16:08 +0200 Subject: [PATCH 18/20] Since success factory is removed, use dialog instead --- .../delegate-registration/delegateRegistration.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/components/delegate-registration/delegateRegistration.js b/src/app/components/delegate-registration/delegateRegistration.js index 3c446d0c2..ec3f40553 100644 --- a/src/app/components/delegate-registration/delegateRegistration.js +++ b/src/app/components/delegate-registration/delegateRegistration.js @@ -1,6 +1,6 @@ import './delegateRegistration.less'; -app.directive('delegateRegistration', ($mdDialog, delegateService, Account, success) => { +app.directive('delegateRegistration', ($mdDialog, delegateService, Account, dialog) => { const DelegateRegistrationLink = function ($scope, $element) { $scope.form = { name: '', @@ -10,7 +10,10 @@ app.directive('delegateRegistration', ($mdDialog, delegateService, Account, succ if (form.$valid) { delegateService.registerDelegate($scope.form.name.toLowerCase(), Account.get().passphrase) .then(() => { - success.dialog({ text: 'Account was successfully registered as delegate.' }) + dialog.successAlert({ + title: 'Congratulations!', + text: 'Account was successfully registered as delegate.', + }) .then(() => { Account.set({ isDelegate: true, From cdb3c880841e342defedfed4f6629076ae12d2a6 Mon Sep 17 00:00:00 2001 From: Oliver Beddows Date: Fri, 5 May 2017 17:33:41 +0200 Subject: [PATCH 19/20] Beautifying less --- .../delegateRegistration.less | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/app/components/delegate-registration/delegateRegistration.less b/src/app/components/delegate-registration/delegateRegistration.less index 2d2524ce5..db6489d32 100644 --- a/src/app/components/delegate-registration/delegateRegistration.less +++ b/src/app/components/delegate-registration/delegateRegistration.less @@ -1,12 +1,15 @@ .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 { + 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; @@ -16,19 +19,23 @@ 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; } -} \ No newline at end of file +} From ba2ba4cb470301dec3cd59acf973d71ecda13eef Mon Sep 17 00:00:00 2001 From: Oliver Beddows Date: Fri, 5 May 2017 17:34:18 +0200 Subject: [PATCH 20/20] Normalising space --- src/app/components/delegates/delegates.less | 3 +-- src/app/components/header/header.less | 2 +- src/app/components/top/top.less | 2 +- src/app/components/transactions/transactions.less | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/app/components/delegates/delegates.less b/src/app/components/delegates/delegates.less index 6714e9901..e15bd4f6e 100644 --- a/src/app/components/delegates/delegates.less +++ b/src/app/components/delegates/delegates.less @@ -36,7 +36,7 @@ delegates { .pending { background-color: #eaeae9; } - + md-card-title { md-input-container { margin: 0; @@ -83,4 +83,3 @@ delegates { vertical-align: inherit; } } - diff --git a/src/app/components/header/header.less b/src/app/components/header/header.less index 60ad86267..fe98ca38a 100644 --- a/src/app/components/header/header.less +++ b/src/app/components/header/header.less @@ -10,4 +10,4 @@ min-width: 128px; max-width: 256px; } -} \ No newline at end of file +} diff --git a/src/app/components/top/top.less b/src/app/components/top/top.less index 9b6ce8bb0..5aecee13b 100644 --- a/src/app/components/top/top.less +++ b/src/app/components/top/top.less @@ -1,4 +1,3 @@ - top { .peer { position: relative; @@ -7,6 +6,7 @@ top { .title { margin-bottom: 15px; } + .username { display: block; width: 100%; diff --git a/src/app/components/transactions/transactions.less b/src/app/components/transactions/transactions.less index 998b18ff4..c799dddfb 100644 --- a/src/app/components/transactions/transactions.less +++ b/src/app/components/transactions/transactions.less @@ -1,4 +1,3 @@ - @in: #73C8A9; @out: #F45D4C; @btn: rgb(2,136,209);