diff --git a/src/app/components/delegate-registration/delegateRegistration.js b/src/app/components/delegate-registration/delegateRegistration.js index d38725928..7f2f5d217 100644 --- a/src/app/components/delegate-registration/delegateRegistration.js +++ b/src/app/components/delegate-registration/delegateRegistration.js @@ -1,27 +1,39 @@ import './delegateRegistration.less'; -app.directive('delegateRegistration', ($mdDialog, delegateService, Account, dialog) => { +app.directive('delegateRegistration', ($mdDialog, delegateService, Account, dialog, $rootScope) => { const DelegateRegistrationLink = function ($scope, $element) { + function checkPendingRegistration() { + delegateService.getDelegate({ + username: $scope.username, + }).then((data) => { + Account.set({ + isDelegate: true, + username: data.delegate.username, + }); + $scope.pendingRegistrationListener(); + }); + } + $scope.form = { name: '', fee: 25, error: '', onSubmit: (form) => { if (form.$valid) { + $scope.username = $scope.form.name.toLowerCase(); delegateService.registerDelegate( - $scope.form.name.toLowerCase(), + $scope.username, Account.get().passphrase, $scope.form.secondPassphrase, ) .then(() => { dialog.successAlert({ title: 'Success', - text: 'Account was successfully registered as delegate.', + text: 'Delegate registration was successfully submitted. It can take several seconds before it is confirmed.', }) .then(() => { - Account.set({ - isDelegate: true, - username: $scope.form.name.toLowerCase(), + $scope.pendingRegistrationListener = $rootScope.$on('syncTick', () => { + checkPendingRegistration(); }); $scope.reset(form); $mdDialog.hide(); diff --git a/src/app/components/delegate-registration/delegateRegistration.pug b/src/app/components/delegate-registration/delegateRegistration.pug index 40f07a72d..c2fe3ead9 100644 --- a/src/app/components/delegate-registration/delegateRegistration.pug +++ b/src/app/components/delegate-registration/delegateRegistration.pug @@ -8,7 +8,7 @@ div.dialog-delegate-registration(aria-label='Vote for delegates') div md-input-container.md-block label Delegate name - input(type='text', name='delegateName', ng-model='$ctrl.form.name', required, ng-disabled='$ctrl.loading') + input(type='text', name='delegateName', ng-model='$ctrl.form.name', required, ng-disabled='$ctrl.loading', md-autofocus) div(ng-messages='delegateRegistrationForm.name.$error') div(ng-message='required') Required md-input-container.md-block(ng-if='$ctrl.account.get().secondSignature') diff --git a/src/app/components/forging/forging.pug b/src/app/components/forging/forging.pug index aad7b552a..ea333561a 100644 --- a/src/app/components/forging/forging.pug +++ b/src/app/components/forging/forging.pug @@ -5,8 +5,7 @@ div.offline-hide md-content div(layout='row', ng-if='$ctrl.delegate && !$ctrl.delegate.username') md-card(flex-100, flex-gt-xs=100, layout-align='center center', layout-padding) - span.title You need to become a delegate to start forging - md-button.md-raised.md-primary(disabled) Become Delegate + span.title You need to become a delegate to start forging. If you already registered to become a delegate, your registration hasn't been processed, yet. div(layout='column', layout-gt-xs='row', ng-if='$ctrl.delegate.username') md-card(flex-gt-xs=100, layout-padding) md-card-title diff --git a/src/app/components/main/main.js b/src/app/components/main/main.js index 0e28f7804..3cb6fd612 100644 --- a/src/app/components/main/main.js +++ b/src/app/components/main/main.js @@ -72,6 +72,12 @@ app.component('main', { update() { return this.accountApi.get(this.account.get().address) .then((res) => { + if (res.publicKey === null) { + // because res.publicKey is null if the account didn't send any transaction yet, + // but we have the publicKey computed from passphrase + delete res.publicKey; + } + this.account.set(res); }) .catch((res) => { diff --git a/src/spec/spec.js b/src/spec/spec.js index a607a4893..38d4e9cec 100644 --- a/src/spec/spec.js +++ b/src/spec/spec.js @@ -271,7 +271,7 @@ function testDelegateRegistration() { waitForElemAndClickIt('md-dialog button.md-primary'); browser.sleep(500); - checkAlertDialog('Success', 'Account was successfully registered as delegate.'); + checkAlertDialog('Success', 'Delegate registration was successfully submitted. It can take several seconds before it is confirmed.'); } function testForgingCenter() {