This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into 280-persist-network-on-new-account
- Loading branch information
Showing
11 changed files
with
176 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* Add ipcRenderer to the window object | ||
*/ | ||
const ipcRenderer = window.require('electron').ipcRenderer; | ||
window.ipc = ipcRenderer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* @description This factory provides methods to call Notification | ||
* | ||
* @module app | ||
* @submodule Notify | ||
*/ | ||
app.factory('Notification', ($window, lsk) => { | ||
/** | ||
* The Notify factory constructor class | ||
* @class Notify | ||
* @constructor | ||
*/ | ||
class Notification { | ||
constructor() { | ||
this.isFocused = true; | ||
} | ||
|
||
/** | ||
* Initialize event listeners | ||
* | ||
* @returns {this} | ||
* @method init | ||
* @memberof Notify | ||
*/ | ||
init() { | ||
if (PRODUCTION) { | ||
const { ipc } = $window; | ||
ipc.on('blur', () => this.isFocused = false); | ||
ipc.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 'deposit': | ||
this._deposit(data); | ||
break; | ||
default: break; | ||
} | ||
} | ||
|
||
/** | ||
* Creating notification about deposit | ||
* | ||
* @param {number} amount | ||
* @private | ||
* @memberof Notify | ||
*/ | ||
_deposit(amount) { // eslint-disable-line | ||
const body = `You've received ${lsk.normalize(amount)} LSK.`; | ||
new $window.Notification('LSK received', { body }); // eslint-disable-line | ||
} | ||
} | ||
|
||
return new Notification(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const chai = require('chai'); | ||
const sinon = require('sinon'); | ||
const sinonChai = require('sinon-chai'); | ||
|
||
const expect = chai.expect; | ||
chai.use(sinonChai); | ||
|
||
describe('Factory: Notification', () => { | ||
let lsk; | ||
let $window; | ||
let notify; | ||
|
||
beforeEach(angular.mock.module('app')); | ||
|
||
beforeEach(inject((_Notification_, _lsk_, _$window_) => { | ||
lsk = _lsk_; | ||
$window = _$window_; | ||
notify = _Notification_.init(); | ||
})); | ||
|
||
describe('about(data)', () => { | ||
const amount = 100000000; | ||
const mockNotification = sinon.spy(); | ||
|
||
it('should call this._deposit', () => { | ||
const spy = sinon.spy(notify, '_deposit'); | ||
notify.isFocused = false; | ||
notify.about('deposit', amount); | ||
expect(spy).to.have.been.calledWith(amount); | ||
}); | ||
|
||
it('should call $window.Notification', () => { | ||
$window.Notification = mockNotification; | ||
const msg = `You've received ${lsk.normalize(amount)} LSK.`; | ||
|
||
notify.isFocused = false; | ||
notify.about('deposit', amount); | ||
expect(mockNotification).to.have.been.calledWith( | ||
'LSK received', { body: msg }, | ||
); | ||
mockNotification.reset(); | ||
}); | ||
|
||
it('should not call $window.Notification if app is focused', () => { | ||
notify.about('deposit', amount); | ||
expect(mockNotification).to.have.been.not.calledWith(); | ||
mockNotification.reset(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters