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

Commit

Permalink
Show Online/offline toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Jun 3, 2017
1 parent 01e2e8b commit 02ac40a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/services/api/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope, dialog) =>
}

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

/**
Expand Down Expand Up @@ -94,14 +95,19 @@ app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope, dialog) =>
* @private
* @memberOf Peer
* @method check
* @isOnLogin {bool} - Should an error toast be displayed on error?
*/
check(isOnLogin) {
check() {
return this.sendRequestPromise('loader/status', {})
.then(() => this.online = true)
.then(() => {
this.online = true;
if (this.wasOffline) {
dialog.successToast('Connection rerestablished');
}
this.wasOffline = false;
})
.catch((data) => {
this.online = false;
if (isOnLogin) {
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') {
Expand All @@ -110,8 +116,8 @@ app.factory('Peers', ($timeout, $cookies, $location, $q, $rootScope, dialog) =>
message += ' Make sure that you are using the latest version of Lisk Nano.';
}
dialog.errorToast(message);
this.active = undefined;
}
this.wasOffline = true;
});
}
}
Expand Down

0 comments on commit 02ac40a

Please sign in to comment.