From 18d28d264b14969aa2d4be3c91dd2a71f834b8bb Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 3 Feb 2017 21:12:22 -0300 Subject: [PATCH] Open wallet on tap notification --- src/js/services/pushNotificationsService.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index a5e99a3a7..b252e4b60 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -1,5 +1,5 @@ 'use strict'; -angular.module('copayApp.services').factory('pushNotificationsService', function pushNotificationsService($log, $state, $ionicHistory, platformInfo, lodash, appConfigService, profileService, configService) { +angular.module('copayApp.services').factory('pushNotificationsService', function pushNotificationsService($log, $state, $ionicHistory, sjcl, platformInfo, lodash, appConfigService, profileService, configService) { var root = {}; var isIOS = platformInfo.isIOS; var isAndroid = platformInfo.isAndroid; @@ -72,17 +72,22 @@ angular.module('copayApp.services').factory('pushNotificationsService', function }); }; - var _openWallet = function(walletId) { - var wallet = profileService.getWallet(walletId); + var _openWallet = function(walletIdHashed) { + var wallets = profileService.getWallets(); + var wallet = lodash.find(wallets, function(w) { + return (lodash.isEqual(walletIdHashed, sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(w.id)))); + }); + if (!wallet) return; + if (!wallet.isComplete()) { return $state.go('tabs.copayers', { - walletId: walletId + walletId: wallet.id }); } $state.go('tabs.wallet', { - walletId: walletId + walletId: wallet.id }); }; @@ -100,15 +105,15 @@ angular.module('copayApp.services').factory('pushNotificationsService', function $log.debug('New Event Push onNotification: ' + JSON.stringify(data)); if(data.wasTapped) { // Notification was received on device tray and tapped by the user. - var walletId = data.walletId; - if (!walletId) return; + var walletIdHashed = data.walletId; + if (!walletIdHashed) return; $ionicHistory.nextViewOptions({ disableAnimate: true, historyRoot: true }); $ionicHistory.clearHistory(); $state.go('tabs.home').then(function() { - _openWallet(walletId); + _openWallet(walletIdHashed); }); } else { // TODO