diff --git a/src/js/controllers/coinbaseUri.js b/src/js/controllers/coinbaseUri.js index 24c48280b..2aff6d1fd 100644 --- a/src/js/controllers/coinbaseUri.js +++ b/src/js/controllers/coinbaseUri.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.controllers').controller('coinbaseUriController', - function($scope, $stateParams, $timeout, profileService, configService, coinbaseService, storageService, go) { + function($scope, $stateParams, $timeout, profileService, configService, coinbaseService, storageService, go) { this.submitOauthCode = function(code) { var self = this; @@ -14,10 +14,9 @@ angular.module('copayApp.controllers').controller('coinbaseUriController', if (err) { self.error = err; $timeout(function() { - $scope.$apply(); - }, 100); - } - else if (data && data.access_token && data.refresh_token) { + $scope.$apply(); + }, 100); + } else if (data && data.access_token && data.refresh_token) { storageService.setCoinbaseToken(network, data.access_token, function() { storageService.setCoinbaseRefreshToken(network, data.refresh_token, function() { $scope.$emit('Local/CoinbaseUpdated', data.access_token); @@ -33,8 +32,13 @@ angular.module('copayApp.controllers').controller('coinbaseUriController', }; this.checkCode = function() { - this.code = $stateParams.code; - this.submitOauthCode(this.code); - }; - + 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/glideraUri.js b/src/js/controllers/glideraUri.js index c4bbdd5e9..d7c27f832 100644 --- a/src/js/controllers/glideraUri.js +++ b/src/js/controllers/glideraUri.js @@ -1,43 +1,43 @@ 'use strict'; angular.module('copayApp.controllers').controller('glideraUriController', -function($scope, $log, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) { + function($scope, $log, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) { - 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); + 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() { - go.path('glidera'); $scope.$apply(); }, 100); - }); - } - }); - }, 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); + }; - 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); + 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)); } - $log.error('Bad state: ' + JSON.stringify($stateParams)); - } -}); + });