Skip to content
Permalink
Browse files

enable desktop notif

  • Loading branch information...
gabrielbazan7 committed Nov 29, 2018
1 parent 63fd9bd commit a0e160812501b2e9540c4499eee5d4ad44f9d66b
Showing with 99 additions and 97 deletions.
  1. +3 −3 electron/main.js
  2. +96 −94 src/providers/profile/profile.ts
@@ -1,4 +1,4 @@
const { app, Menu, BrowserWindow } = require('electron');
const { app, Menu, BrowserWindow, Notification, ipcMain } = require('electron');
const path = require('path');
const url = require('url');
const os = require('os');
@@ -61,11 +61,11 @@ function createWindow() {
win.webContents.send('open-url-event', deeplinkingUrl);
}, 1000);
}
/* if (Notification.isSupported()) {
if (Notification.isSupported()) {
ipcMain.on('new-notification', (event, data) => {
new Notification(data).show();
});
} */
}
});

win.once('ready-to-show', () => {
@@ -16,6 +16,7 @@ import { PersistenceProvider } from '../persistence/persistence';
import { PlatformProvider } from '../platform/platform';
import { PopupProvider } from '../popup/popup';
import { ReplaceParametersProvider } from '../replace-parameters/replace-parameters';
import { TxFormatProvider } from '../tx-format/tx-format';
import { Coin, WalletOptions, WalletProvider } from '../wallet/wallet';

// models
@@ -48,7 +49,8 @@ export class ProfileProvider {
private onGoingProcessProvider: OnGoingProcessProvider,
private translate: TranslateService,
private walletProvider: WalletProvider,
private derivationPathHelperProvider: DerivationPathHelperProvider
private derivationPathHelperProvider: DerivationPathHelperProvider,
private txFormatProvider: TxFormatProvider
) {
this.throttledBwsEvent = _.throttle((n, wallet) => {
this.newBwsEvent(n, wallet);
@@ -201,9 +203,9 @@ export class ProfileProvider {
this.logger.debug('BWC Notification:', JSON.stringify(n));
}

/* if (this.platformProvider.isElectron) {
if (this.platformProvider.isElectron) {
this.showInAppNotification(n, wallet);
} */
}

if (n.type == 'NewBlock' && n.data.network == 'testnet') {
this.throttledBwsEvent(n, wallet);
@@ -228,7 +230,7 @@ export class ProfileProvider {
return;
}
wallet.setNotificationsInterval(this.UPDATE_PERIOD);
wallet.openWallet(() => {});
wallet.openWallet(() => { });
}
);
this.events.subscribe('wallet:updated', (walletId: string) => {
@@ -240,90 +242,90 @@ export class ProfileProvider {
return true;
}

/* private showInAppNotification(n, wallet): void {
if (!this.configProvider.get().desktopNotificationsEnabled) return;
const creatorId = n && n.data && n.data.creatorId;
const amount = n && n.data && n.data.amount;
const walletName = this.wallet.name;
let title: string;
let body: string;
let translatedMsg: string;
switch (n.type) {
case 'NewCopayer':
if (wallet.copayerId != creatorId) {
title = this.translate.instant('New copayer');
translatedMsg = this.translate.instant(
'A new copayer just joined your wallet {{walletName}}.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
walletName
});
}
break;
case 'WalletComplete':
title = this.translate.instant('Wallet complete');
translatedMsg = this.translate.instant(
'Your wallet {{walletName}} is complete.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
walletName
});
break;
case 'NewTxProposal':
if (wallet && wallet.m > 1 && wallet.copayerId != creatorId) {
title = this.translate.instant('New payment proposal');
translatedMsg = this.translate.instant(
'A new payment proposal has been created in your wallet {{walletName}}.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
walletName
});
}
break;
case 'NewIncomingTx':
title = this.translate.instant('New payment received');
const amountStr = this.txFormatProvider.formatAmountStr(
wallet.coin,
amount
);
translatedMsg = this.translate.instant(
'A payment of {{amountStr}} has been received into your wallet {{walletName}}.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
amountStr,
walletName
});
break;
case 'TxProposalFinallyRejected':
title = this.translate.instant('Payment proposal rejected');
translatedMsg = this.translate.instant(
'A payment proposal in your wallet {{walletName}} has been rejected.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
walletName
});
break;
case 'TxConfirmation':
title = this.translate.instant('Transaction confirmed');
translatedMsg = this.translate.instant(
'The transaction from {{walletName}} that you were waiting for has been confirmed.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
walletName
});
break;
}
if (!body) return;
const { ipcRenderer } = (window as any).require('electron');
ipcRenderer.send('new-notification', {
title,
body
});
} */
private showInAppNotification(n, wallet): void {
if (!this.configProvider.get().desktopNotificationsEnabled) return;

const creatorId = n && n.data && n.data.creatorId;
const amount = n && n.data && n.data.amount;
const walletName = this.wallet.name;
let title: string;
let body: string;
let translatedMsg: string;

switch (n.type) {
case 'NewCopayer':
if (wallet.copayerId != creatorId) {
title = this.translate.instant('New copayer');
translatedMsg = this.translate.instant(
'A new copayer just joined your wallet {{walletName}}.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
walletName
});
}
break;
case 'WalletComplete':
title = this.translate.instant('Wallet complete');
translatedMsg = this.translate.instant(
'Your wallet {{walletName}} is complete.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
walletName
});
break;
case 'NewTxProposal':
if (wallet && wallet.m > 1 && wallet.copayerId != creatorId) {
title = this.translate.instant('New payment proposal');
translatedMsg = this.translate.instant(
'A new payment proposal has been created in your wallet {{walletName}}.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
walletName
});
}
break;
case 'NewIncomingTx':
title = this.translate.instant('New payment received');
const amountStr = this.txFormatProvider.formatAmountStr(
wallet.coin,
amount
);
translatedMsg = this.translate.instant(
'A payment of {{amountStr}} has been received into your wallet {{walletName}}.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
amountStr,
walletName
});
break;
case 'TxProposalFinallyRejected':
title = this.translate.instant('Payment proposal rejected');
translatedMsg = this.translate.instant(
'A payment proposal in your wallet {{walletName}} has been rejected.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
walletName
});
break;
case 'TxConfirmation':
title = this.translate.instant('Transaction confirmed');
translatedMsg = this.translate.instant(
'The transaction from {{walletName}} that you were waiting for has been confirmed.'
);
body = this.replaceParametersProvider.replace(translatedMsg, {
walletName
});
break;
}

if (!body) return;

const { ipcRenderer } = (window as any).require('electron');
ipcRenderer.send('new-notification', {
title,
body
});
}

private newBwsEvent(n, wallet): void {
if (wallet.cachedStatus) wallet.cachedStatus.isValid = false;
@@ -420,7 +422,7 @@ export class ProfileProvider {
this.profile.setChecked(this.platformProvider.ua, walletId);
} else {
this.logger.warn('Key Derivation failed for wallet:' + walletId);
this.persistenceProvider.clearLastAddress(walletId).then(() => {});
this.persistenceProvider.clearLastAddress(walletId).then(() => { });
}

this.storeProfileIfDirty();
@@ -727,8 +729,8 @@ export class ProfileProvider {
const mergeAddressBook = _.merge(addressBook, localAddressBook);
this.persistenceProvider
.setAddressBook(
wallet.credentials.network,
JSON.stringify(mergeAddressBook)
wallet.credentials.network,
JSON.stringify(mergeAddressBook)
)
.then(() => {
return resolve();
@@ -1022,9 +1024,9 @@ export class ProfileProvider {

this.logger.debug(
'Binding wallet:' +
credentials.walletId +
' Validating?:' +
!skipKeyValidation
credentials.walletId +
' Validating?:' +
!skipKeyValidation
);
return resolve(this.bindWalletClient(walletClient));
});

0 comments on commit a0e1608

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.