Skip to content

Commit

Permalink
Add Notify factory
Browse files Browse the repository at this point in the history
  • Loading branch information
alepop committed May 24, 2017
1 parent 7677d26 commit e944e7b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ app.component('main', {
*/
controller: class main {
constructor($scope, $rootScope, $timeout, $q, $state, Peers,
dialog, SendModal, Account, AccountApi) {
dialog, SendModal, Account, AccountApi, Notify) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.$timeout = $timeout;
Expand All @@ -28,6 +28,7 @@ app.component('main', {
this.$state = $state;
this.account = Account;
this.accountApi = AccountApi;
this.notify = Notify.init();

this.activeTab = this.init();
}
Expand Down Expand Up @@ -110,6 +111,10 @@ app.component('main', {
delete res.publicKey;
}

this.notify.about(
'deposite',
res.balance - this.account.get().balance,
);
this.account.set(res);
})
.catch((res) => {
Expand Down
1 change: 1 addition & 0 deletions src/liskNano.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import './components/delegateRegistration/delegateRegistration';

import './services/api/peers';
import './services/lsk';
import './services/notify';
import './services/dialog';
import './services/passphrase';
import './services/signVerify';
Expand Down
73 changes: 73 additions & 0 deletions src/services/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @description This factory provides methods to call Notification
*
* @module app
* @submodule Notify
*/
app.factory('Notify', ($window, lsk) => {
/**
* The Notify factory constructor class
* @class Notify
* @constructor
*/
class Notify {
constructor() {
this.isFocused = true;
}

/**
* Initialize event listeners
*
* @returns {this}
* @method init
* @memberof Notify
*/
init() {
const { electron } = $window;
if (electron) {
electron.ipcRenderer.on('blur', () => this.isFocused = false);
electron.ipcRenderer.on('focus', () => this.isFocused = true);
}
return this;
}

/**
* Routing to specific Notification creator based on type param
* @param {string} type
* @param {any} data
*
* @method about
* @public
* @memberof Notify
*/
about(type, data) {
if (this.isFocused) return;
switch (type) {
case 'deposite':
this.__deposite(data);
break;
default: break;
}
}

/**
* Creating notification about deposit
*
* @param {number} amount
* @private
* @memberof Notify
*/
__deposite(amount) { // eslint-disable-line
if (amount > 0) {
new $window.Notification( // eslint-disable-line
'LSK received',
{
body: `You've received ${lsk.normalize(amount)} LSK.`,
},
);
}
}
}

return new Notify();
});

0 comments on commit e944e7b

Please sign in to comment.