diff --git a/src/js/controllers/coinbase.js b/src/js/controllers/coinbase.js index 3005e07bb..a038e6546 100644 --- a/src/js/controllers/coinbase.js +++ b/src/js/controllers/coinbase.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('coinbaseController', function($scope, $timeout, $ionicModal, $log, coinbaseService, lodash, platformInfo, ongoingProcess, popupService, externalLinkService) { +angular.module('copayApp.controllers').controller('coinbaseController', function($scope, $timeout, $ionicModal, $ionicHistory, $log, coinbaseService, lodash, platformInfo, ongoingProcess, popupService, externalLinkService) { var isNW = platformInfo.isNW; var isCordova = platformInfo.isCordova; @@ -17,8 +17,14 @@ angular.module('copayApp.controllers').controller('coinbaseController', function if (err || lodash.isEmpty(data)) { if (err) { $log.error(err); + var errorId = err.errors ? err.errors[0].id : null; err = err.errors ? err.errors[0].message : err; - popupService.showAlert('Error connecting to Coinbase', err); + popupService.showAlert('Error connecting to Coinbase', err, function() { + if (errorId == 'revoked_token') { + coinbaseService.logout(function() {}); + } + $ionicHistory.goBack(); + }); } return; } diff --git a/src/js/controllers/preferencesCoinbase.js b/src/js/controllers/preferencesCoinbase.js index c55e996ef..eea526bad 100644 --- a/src/js/controllers/preferencesCoinbase.js +++ b/src/js/controllers/preferencesCoinbase.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('preferencesCoinbaseController', function($scope, $timeout, $state, $ionicHistory, lodash, ongoingProcess, popupService, coinbaseService) { +angular.module('copayApp.controllers').controller('preferencesCoinbaseController', function($scope, $timeout, $log, $state, $ionicHistory, lodash, ongoingProcess, popupService, coinbaseService) { $scope.revokeToken = function() { popupService.showConfirm('Coinbase', 'Are you sure you would like to log out of your Coinbase account?', null, null, function(res) { @@ -22,7 +22,15 @@ angular.module('copayApp.controllers').controller('preferencesCoinbaseController if (err || lodash.isEmpty(data)) { ongoingProcess.set('connectingCoinbase', false); if (err) { - popupService.showAlert(gettextCatalog.getString('Error'), err); + $log.error(err); + var errorId = err.errors ? err.errors[0].id : null; + err = err.errors ? err.errors[0].message : err; + popupService.showAlert('Error connecting to Coinbase', err, function() { + if (errorId == 'revoked_token') { + coinbaseService.logout(function() {}); + $ionicHistory.goBack(); + } + }); } return; } diff --git a/src/js/services/coinbaseService.js b/src/js/services/coinbaseService.js index d9ba38963..9057ae729 100644 --- a/src/js/services/coinbaseService.js +++ b/src/js/services/coinbaseService.js @@ -211,7 +211,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }); }; - root.init = function(cb) { + root.init = lodash.throttle(function(cb) { if (lodash.isEmpty(credentials.CLIENT_ID)) { return cb('Coinbase is Disabled'); } @@ -243,7 +243,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }); } }); - }; + }, 10000); var _get = function(endpoint, token) { return { diff --git a/www/views/preferencesCoinbase.html b/www/views/preferencesCoinbase.html index 68050e9af..4676b742e 100644 --- a/www/views/preferencesCoinbase.html +++ b/www/views/preferencesCoinbase.html @@ -51,7 +51,9 @@ {{coinbaseUser.email}} + +