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