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

Check version compatibility on login - Closes #309 #314

Merged
merged 6 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/components/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ app.component('login', {
/* eslint no-param-reassign: ["error", { "props": false }] */

constructor($scope, $rootScope, $timeout, $document, $mdMedia,
$cookies, $location, Passphrase, $state, Account, Peers, dialog) {
$cookies, $location, Passphrase, $state, Account, Peers) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.$timeout = $timeout;
Expand All @@ -18,7 +18,6 @@ app.component('login', {
this.$state = $state;
this.account = Account;
this.peers = Peers;
this.dialog = dialog;

this.Passphrase = Passphrase;
this.generatingNewPassphrase = false;
Expand Down Expand Up @@ -69,8 +68,6 @@ app.component('login', {
network: this.network,
});
this.$state.go(this.$rootScope.landingUrl || 'main.transactions');
} else {
this.dialog.errorToast(`Failed to connect to node ${this.network.address}`);
}
});
}
Expand Down
22 changes: 18 additions & 4 deletions src/services/api/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import lisk from 'lisk-js';
* @module app
* @submodule Peers
*/
app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope) => {
app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope, dialog) => {
/**
* The Peers factory constructor class
*
Expand Down Expand Up @@ -49,6 +49,7 @@ app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope) => {
* @method setActive
*/
setActive(network) {
this.network = network;
let conf = { };
if (network) {
conf = network;
Expand All @@ -63,7 +64,7 @@ app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope) => {
}

this.active = lisk.api(conf);
return this.check();
return this.check(true);
}

/**
Expand Down Expand Up @@ -93,11 +94,24 @@ app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope) => {
* @private
* @memberOf Peer
* @method check
* @notifyUser {bool} - Should an error toast be displayed on error?
*/
check() {
check(notifyUser) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes perfect sense to notify the user of any error which happens during connections. so this parameter seems to be redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that this should be only on login. After login when this fails, the whole ui get's grey and loading spinner is displayed, so the user is notified in either case. I changed the param name accordingly.

return this.sendRequestPromise('loader/status', {})
.then(() => this.online = true)
.catch(() => this.online = false);
.catch((data) => {
this.online = false;
if (notifyUser) {
const address = `${this.active.currentPeer}:${this.active.port}`;
let message = `Failed to connect to node ${address}. `;
if (data && data.error && data.error.code === 'EUNAVAILABLE') {
message = `Failed to connect: Node ${address} is not active`;
} else if (!(data && data.error && data.error.code)) {
message += ' Make sure that you are using the latest version of Lisk Nano.';
}
dialog.errorToast(message);
}
});
}
}

Expand Down
9 changes: 0 additions & 9 deletions test/components/login/login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,6 @@ describe('Login controller', () => {
$scope.$apply();
expect(spy).to.have.been.calledWith();
});

it('shows error toast if peers.setActive sets peers.online = false', () => {
const spy = sinon.spy(controller.dialog, 'errorToast');
controller.peers.online = false;
controller.passConfirmSubmit();
deferred.resolve();
$scope.$apply();
expect(spy).to.have.been.calledWith(`Failed to connect to node ${controller.network.address}`);
});
});

describe('devTestAccount()', () => {
Expand Down
14 changes: 12 additions & 2 deletions test/services/api/peers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ describe('Factory: Peers', () => {
let Peers;
let $q;
let $rootScope;
let dialog;

beforeEach(angular.mock.module('app'));

beforeEach(inject((_Peers_, _$q_, _$rootScope_) => {
beforeEach(inject((_Peers_, _$q_, _$rootScope_, _dialog_) => {
Peers = _Peers_;
$q = _$q_;
$rootScope = _$rootScope_;
dialog = _dialog_;
}));

describe('setActive(account)', () => {
Expand All @@ -32,7 +34,7 @@ describe('Factory: Peers', () => {
});
});

describe('check()', () => {
describe('check(notifyUser)', () => {
let deffered;
let mock;

Expand Down Expand Up @@ -61,5 +63,13 @@ describe('Factory: Peers', () => {
$rootScope.$apply();
expect(Peers.online).to.equal(false);
});

it('shows error toast if notifyUser is true', () => {
const spy = sinon.spy(dialog, 'errorToast');
Peers.check(true);
deffered.reject();
$rootScope.$apply();
expect(spy).to.have.been.calledWith();
});
});
});