From ecf16d61ea8c3bdc5dfafd84b7b3a86d34bfb809 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 11 Jun 2016 18:28:31 -0300 Subject: [PATCH] Glidera working again. Rm ignoreMobilePause! --- public/views/uri.html | 11 +++++ src/js/controllers/glideraUri.js | 73 ++++++++++++++++--------------- src/js/controllers/index.js | 6 +-- src/js/controllers/uri.js | 12 +++++ src/js/routes.js | 32 +++++--------- src/js/services/openURL.js | 71 ++++++++++++++++++++++-------- src/js/services/profileService.js | 1 - src/js/services/uriHandler.js | 14 ------ 8 files changed, 128 insertions(+), 92 deletions(-) create mode 100644 public/views/uri.html create mode 100644 src/js/controllers/uri.js delete mode 100644 src/js/services/uriHandler.js diff --git a/public/views/uri.html b/public/views/uri.html new file mode 100644 index 000000000..e16b42d1c --- /dev/null +++ b/public/views/uri.html @@ -0,0 +1,11 @@ + +
+
+ +
+
+

+ Please wait to be redirected... +

+
+ diff --git a/src/js/controllers/glideraUri.js b/src/js/controllers/glideraUri.js index 32f13ee6d..c4bbdd5e9 100644 --- a/src/js/controllers/glideraUri.js +++ b/src/js/controllers/glideraUri.js @@ -1,40 +1,43 @@ 'use strict'; angular.module('copayApp.controllers').controller('glideraUriController', - function($scope, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) { +function($scope, $log, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) { - this.submitOauthCode = function(code) { -console.log('[glideraUri.js.5:code:]'+code); //TODO - var self = this; - var glideraTestnet = configService.getSync().glidera.testnet; - var network = glideraTestnet ? 'testnet' : 'livenet'; - this.loading = true; - this.error = null; - $timeout(function() { - glideraService.getToken(code, function(err, data) { - self.loading = null; - if (err) { - self.error = err; + this.submitOauthCode = function(code) { + $log.debug('Glidera Oauth Code:' + code); + var self = this; + var glideraTestnet = configService.getSync().glidera.testnet; + var network = glideraTestnet ? 'testnet' : 'livenet'; + this.loading = true; + this.error = null; + $timeout(function() { + glideraService.getToken(code, function(err, data) { + self.loading = null; + if (err) { + self.error = err; + $timeout(function() { + $scope.$apply(); + }, 100); + } else if (data && data.access_token) { + storageService.setGlideraToken(network, data.access_token, function() { + $scope.$emit('Local/GlideraUpdated', data.access_token); $timeout(function() { - $scope.$apply(); - }, 100); - } - else if (data && data.access_token) { - storageService.setGlideraToken(network, data.access_token, function() { - $scope.$emit('Local/GlideraUpdated', data.access_token); - $timeout(function() { - go.path('glidera'); - $scope.$apply(); - }, 100); - }); - } - }); - }, 100); - }; + go.path('glidera'); + $scope.$apply(); + }, 100); + }); + } + }); + }, 100); + }; - this.checkCode = function() { -console.log('[glideraUri.js.35:$stateParams:]' + JSON.stringify($stateParams)); //TODO - this.code = $stateParams.code; - this.submitOauthCode(this.code); - }; - - }); + this.checkCode = function() { + if ($stateParams.url) { + var match = $stateParams.url.match(/code=(.+)/); + if (match && match[1]) { + this.code = match[1]; + return this.submitOauthCode(this.code); + } + } + $log.error('Bad state: ' + JSON.stringify($stateParams)); + } +}); diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 734105396..05f3e4077 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1500,11 +1500,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r if (!self.lastUpdate || (now - self.lastUpdate) > oneHr) { self.updateAll({ - quiet: true - triggerTxUpdate: true, + quiet: true, + triggerTxUpdate: true }); } - }); + }; $rootScope.$on('Local/Resume', function(event) { $log.debug('### Resume event'); diff --git a/src/js/controllers/uri.js b/src/js/controllers/uri.js new file mode 100644 index 000000000..bf6c91120 --- /dev/null +++ b/src/js/controllers/uri.js @@ -0,0 +1,12 @@ +'use strict'; +angular.module('copayApp.controllers').controller('uriController', + function($rootScope, $stateParams, $log, openURLService) { + + + /* This is only for BROWSER links, it is not excecuted on mobile devices */ + + $log.info('DEEP LINK from Browser:' + $stateParams.url); + openURLService.handleURL({ + url: $stateParams.url + }); + }); diff --git a/src/js/routes.js b/src/js/routes.js index d9400b67e..299def8a4 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -112,6 +112,15 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } } }) + .state('uri', { + url: '/uri/:url', + needProfile: true, + views: { + 'main': { + templateUrl: 'views/uri.html' + } + } + }) .state('uripayment', { url: '/uri-payment/:url', templateUrl: 'views/paymentUri.html', @@ -122,11 +131,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }, needProfile: true }) - .state('selectWalletForPayment', { - url: '/selectWalletForPayment', - controller: 'walletForPaymentController', - needProfile: true - }) .state('join', { url: '/join', needProfile: true, @@ -215,7 +219,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) .state('uriglidera', { - url: '/uri-glidera/:code', + url: '/uri-glidera/:url', needProfile: true, views: { 'main': { @@ -284,7 +288,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) .state('uricoinbase', { - url: '/uri-coinbase/:code', + url: '/uri-coinbase/:url', needProfile: true, views: { 'main': { @@ -504,12 +508,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }, } }) - .state('warning', { - url: '/warning', - controller: 'warningController', - templateUrl: 'views/warning.html', - needProfile: false - }) .state('add', { url: '/add', needProfile: true, @@ -520,7 +518,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); }) - .run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, uriHandler, platformInfo, profileService, uxLanguage, animationService, go, gettextCatalog) { + .run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, platformInfo, profileService, uxLanguage, animationService, go, gettextCatalog) { $ionicPlatform.ready(function() { if (platformInfo.isCordova) { @@ -539,7 +537,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }); $ionicPlatform.on('resume', function() { - // Nothing to do $rootScope.$emit('Local/Resume'); }); @@ -583,11 +580,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr uxLanguage.init(); - // Register URI handler, not for mobileApp - if (!platformInfo.isMobile) { - uriHandler.register(); - } - if (platformInfo.isNW) { var gui = require('nw.gui'); var win = gui.Window.get(); diff --git a/src/js/services/openURL.js b/src/js/services/openURL.js index a7f219a40..07cd8935d 100644 --- a/src/js/services/openURL.js +++ b/src/js/services/openURL.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.services').factory('openURLService', function($ionicHistory, $document, $log, $state, go) { +angular.module('copayApp.services').factory('openURLService', function($ionicHistory, $document, $log, $state, go, platformInfo, lodash) { var root = {}; root.registeredUriHandlers = [{ @@ -9,11 +9,11 @@ angular.module('copayApp.services').factory('openURLService', function($ionicHis transitionTo: 'uripayment', }, { name: 'Glidera Authentication Callback', - startsWith: 'copay://glidera', + startsWith: 'copay:glidera', transitionTo: 'uriglidera', }, { name: 'Coinbase Authentication Callback', - startsWith: 'copay://coinbase', + startsWith: 'copay:coinbase', transitionTo: 'uricoinbase', }]; @@ -27,43 +27,76 @@ angular.module('copayApp.services').factory('openURLService', function($ionicHis disableBack: true, disableAnimation: true }); + var url = args.url; + if (!url) { + $log.error('No url provided'); + return; + }; if (url) { - window.cordova.removeDocumentEventHandler('handleopenurl'); - window.cordova.addStickyDocumentEventHandler('handleopenurl'); - document.removeEventListener('handleopenurl', root.handleOpenUrl); + if ('cordova' in window) { + window.cordova.removeDocumentEventHandler('handleopenurl'); + window.cordova.addStickyDocumentEventHandler('handleopenurl'); + } + document.removeEventListener('handleopenurl', handleOpenURL); } + document.addEventListener('handleopenurl', handleOpenURL, false); - var url = args.url; - - lodash.each(root.registeredUriHandlers, function(x) { - if (url.indexOf(x.startWith) == 0) { - $log.debug('openURL GOT ' + x.name + ' URL'); - return $state.transitionTo(x.transitionTo, { - url: url - }); - } + var x = lodash.find(root.registeredUriHandlers, function(x) { + return url.indexOf(x.startsWith) == 0 || + url.indexOf('web+' + x.startsWith) == 0 || // web protocols + url.indexOf(x.startsWith.replace(':','://')) == 0 // from mobile devices + ; }); - $log.warn('Unknown URL! : ' + url); + + if (x) { + $log.debug('openURL GOT ' + x.name + ' URL'); + return $state.transitionTo(x.transitionTo, { + url: url + }); + } else { + $log.warn('Unknown URL! : ' + url); + } }; var handleResume = function() { $log.debug('Handle Resume @ openURL...'); - document.addEventListener('handleopenurl', handleOpenUrl, false); + document.addEventListener('handleopenurl', handleOpenURL, false); }; root.init = function() { - console.log('[openURL.js.29]'); //TODO + $log.debug('Initializing openURL'); document.addEventListener('handleopenurl', handleOpenURL, false); document.addEventListener('resume', handleResume, false); - }; + if (platformInfo.isChromeApp) { + $log.debug('Registering Chrome message listener'); + chrome.runtime.onMessage.addListener( + function(request, sender, sendResponse) { + if (request.url) { + handleOpenURL(request.url); + } + }); + } else if (platformInfo.isDevel) { + + var base = window.location.origin + '/'; + var url = base + '#/uri/%s'; + + if (navigator.registerProtocolHandler) { + $log.debug('Registering Browser handlers base:' + base); + navigator.registerProtocolHandler('bitcoin', url, 'Copay Bitcoin Handler'); + navigator.registerProtocolHandler('web+copay', url, 'Copay Wallet Handler'); + } + } + }; root.registerHandler = function(x) { $log.debug('Registering URL Handler: ' + x.name); root.registeredUriHandlers.push(x); }; + root.handleURL = handleOpenURL; + return root; }); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 1ed664bd0..5e69bb8c4 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -293,7 +293,6 @@ angular.module('copayApp.services') var name = opts.name || gettextCatalog.getString('Personal Wallet'); var myName = opts.myName || gettextCatalog.getString('me'); -console.log('[profileService.js.303]', opts); //TODO walletClient.createWallet(name, myName, opts.m, opts.n, { network: opts.networkName, singleAddress: opts.singleAddress, diff --git a/src/js/services/uriHandler.js b/src/js/services/uriHandler.js deleted file mode 100644 index da67ab4be..000000000 --- a/src/js/services/uriHandler.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -var UriHandler = function() {}; - -UriHandler.prototype.register = function() { - var base = window.location.origin + '/'; - var url = base + '#/uri-payment/%s'; - - if(navigator.registerProtocolHandler) { - navigator.registerProtocolHandler('bitcoin', url, 'Copay'); - } -}; - -angular.module('copayApp.services').value('uriHandler', new UriHandler());