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

Commit

Permalink
Merge pull request #314 from LiskHQ/309-version-compatibility-check
Browse files Browse the repository at this point in the history
Check version compatibility on login - Closes #309
  • Loading branch information
slaweet authored Jun 6, 2017
2 parents fec2bab + e6ac1d7 commit 4b62fb7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
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 @@ -85,8 +84,6 @@ app.component('login', {
});
this.$cookies.put('network', JSON.stringify(this.network));
this.$state.go(this.$rootScope.landingUrl || 'main.transactions');
} else {
this.dialog.errorToast(`Failed to connect to node ${this.network.address}`);
}
});
}
Expand Down
27 changes: 24 additions & 3 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,6 +64,7 @@ app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope) => {
}

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

Expand Down Expand Up @@ -96,8 +98,27 @@ app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope) => {
*/
check() {
return this.sendRequestPromise('loader/status', {})
.then(() => this.online = true)
.catch(() => this.online = false);
.then(() => {
this.online = true;
if (this.wasOffline) {
dialog.successToast('Connection re-established');
}
this.wasOffline = false;
})
.catch((data) => {
this.online = false;
if (!this.wasOffline) {
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);
}
this.wasOffline = true;
});
}
}

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();
});
});
});

0 comments on commit 4b62fb7

Please sign in to comment.