diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 3ad881565..a7324e2a5 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -49,6 +49,34 @@ angular.module('copayApp.controllers').controller('indexController', function($r ret.tab = 'walletHome'; var vanillaScope = ret; + if (ret.usePushNotifications) { + // Listening for push notifications + var push = PushNotification.init(configService.getDefaults().pushNotifications.config); + + push.on('notification', function(data) { + if (!data.additionalData.foreground) { + window.ignoreMobilePause = true; + // window.plugins.spinnerDialog.show(null, gettextCatalog.getString('LOADING...'), true); + $log.debug('Push notification event: ', data.message); + + $timeout(function() { + var wallets = profileService.getWallets(); + var walletToFind = data.additionalData.walletId; + + var walletFound = lodash.find(wallets, function(w) { + return (lodash.isEqual(walletToFind, sjcl.hash.sha256.hash(w.id))); + }); + + if (!walletFound) return $log.debug('Wallet not found'); + profileService.setAndStoreFocus(walletFound.id, function() { + // $timeout(function() { + // window.plugins.spinnerDialog.hide(); + // }, 200); + }); + }, 100); + } + }); + } function strip(number) { return (parseFloat(number.toPrecision(12)));