From 539583a2af173d9abccbc6d3e92452fba3ac5eda Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Thu, 8 Dec 2016 13:06:01 -0300 Subject: [PATCH] Coinbase connection issues and logout from tab-setting --- .../modals/coinbaseConfirmation.js | 20 --- src/js/controllers/preferencesCoinbase.js | 48 ++++++-- src/js/controllers/tab-settings.js | 11 +- src/js/routes.js | 29 ++--- src/js/services/coinbaseService.js | 5 +- www/views/coinbase.html | 5 - www/views/modals/coinbase-confirmation.html | 18 --- www/views/preferencesCoinbase.html | 114 +++++++++--------- www/views/tab-settings.html | 7 ++ 9 files changed, 130 insertions(+), 127 deletions(-) delete mode 100644 src/js/controllers/modals/coinbaseConfirmation.js delete mode 100644 www/views/modals/coinbase-confirmation.html diff --git a/src/js/controllers/modals/coinbaseConfirmation.js b/src/js/controllers/modals/coinbaseConfirmation.js deleted file mode 100644 index 729b81945..000000000 --- a/src/js/controllers/modals/coinbaseConfirmation.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -angular.module('copayApp.controllers').controller('coinbaseConfirmationController', function($scope, $timeout, coinbaseService, applicationService) { - - $scope.ok = function() { - - coinbaseService.logout($scope.network, function() { - - $timeout(function() { - applicationService.restart(); - }, 1000); - }); - $scope.cancel(); - }; - - $scope.cancel = function() { - $scope.coinbaseConfirmationModal.hide(); - }; - -}); diff --git a/src/js/controllers/preferencesCoinbase.js b/src/js/controllers/preferencesCoinbase.js index 6bca19de6..b9113cbcd 100644 --- a/src/js/controllers/preferencesCoinbase.js +++ b/src/js/controllers/preferencesCoinbase.js @@ -1,18 +1,42 @@ 'use strict'; -angular.module('copayApp.controllers').controller('preferencesCoinbaseController', - function($scope, $timeout, $ionicModal, applicationService, coinbaseService) { +angular.module('copayApp.controllers').controller('preferencesCoinbaseController', function($scope, $timeout, $state, $ionicHistory, lodash, ongoingProcess, popupService, coinbaseService) { - this.revokeToken = function(testnet) { - $scope.network = testnet ? 'testnet' : 'livenet'; + $scope.revokeToken = function() { + popupService.showConfirm('Coinbase', 'Are you sure you would like to log out of your Coinbase account?', null, null, function(res) { + if (res) { + coinbaseService.logout(function() { + $ionicHistory.clearHistory(); + $timeout(function() { + $state.go('tabs.home'); + }, 100); + }); + } + }); + }; - $ionicModal.fromTemplateUrl('views/modals/coinbase-confirmation.html', { - scope: $scope, - animation: 'slide-in-up' - }).then(function(modal) { - $scope.coinbaseConfirmationModal = modal; - $scope.coinbaseConfirmationModal.show(); + $scope.$on("$ionicView.enter", function(event, data){ + coinbaseService.setCredentials(); + $scope.network = coinbaseService.getEnvironment(); + ongoingProcess.set('connectingCoinbase', true); + coinbaseService.init($scope.accessToken, function(err, data) { + ongoingProcess.set('connectingCoinbase', false); + if (err || lodash.isEmpty(data)) { + ongoingProcess.set('connectingCoinbase', false); + if (err) { + popupService.showAlert(gettextCatalog.getString('Error'), err); + } + return; + } + var accessToken = data.accessToken; + var accountId = data.accountId; + coinbaseService.getAccount(accessToken, accountId, function(err, account) { + $scope.coinbaseAccount = account.data; }); - }; - + coinbaseService.getCurrentUser(accessToken, function(err, user) { + $scope.coinbaseUser = user.data; + }); + }); }); + +}); diff --git a/src/js/controllers/tab-settings.js b/src/js/controllers/tab-settings.js index b5573155e..ab2bf1cff 100644 --- a/src/js/controllers/tab-settings.js +++ b/src/js/controllers/tab-settings.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, appConfigService, $ionicModal, $log, lodash, uxLanguage, platformInfo, profileService, feeService, configService, externalLinkService, bitpayCardService, storageService, glideraService, gettextCatalog) { +angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, appConfigService, $window, $log, lodash, uxLanguage, platformInfo, profileService, feeService, configService, externalLinkService, bitpayCardService, storageService, glideraService, coinbaseService, gettextCatalog) { var updateConfig = function() { var isCordova = platformInfo.isCordova; @@ -26,6 +26,7 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct $scope.bitpayCardEnabled = config.bitpayCard.enabled; $scope.glideraEnabled = config.glidera.enabled && !isWindowsPhoneApp; + $scope.coinbaseEnabled = config.coinbase.enabled && !isWindowsPhoneApp; if ($scope.bitpayCardEnabled) { bitpayCardService.getBitpayDebitCards(function(err, cards) { @@ -41,6 +42,14 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct }); } + if ($scope.coinbaseEnabled) { + coinbaseService.setCredentials(); + storageService.getCoinbaseToken(coinbaseService.getEnvironment(), function(err, token) { + if (err) $log.error(err); + $scope.coinbaseToken = token; + }); + } + }); }; diff --git a/src/js/routes.js b/src/js/routes.js index 786d50f17..4561bc68a 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -926,24 +926,25 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr * */ - .state('tabs.buyandsell.coinbase', { - url: '/coinbase', - views: { - 'tab-home@tabs': { - controller: 'coinbaseController', - controllerAs: 'coinbase', - templateUrl: 'views/coinbase.html' - } - } - }) - .state('tabs.buyandsell.coinbase.preferences', { - url: '/preferences', + .state('tabs.buyandsell.coinbase', { + url: '/coinbase', + views: { 'tab-home@tabs': { - controller: 'preferencesCoinbaseController', + controller: 'coinbaseController', controllerAs: 'coinbase', + templateUrl: 'views/coinbase.html' + } + } + }) + .state('tabs.preferences.coinbase', { + url: '/coinbase', + views: { + 'tab-settings@tabs': { + controller: 'preferencesCoinbaseController', templateUrl: 'views/preferencesCoinbase.html' } - }) + } + }) .state('tabs.buyandsell.coinbase.buy', { url: '/buy', 'tab-home@tabs': { diff --git a/src/js/services/coinbaseService.js b/src/js/services/coinbaseService.js index 4acb37c60..842d1dc50 100644 --- a/src/js/services/coinbaseService.js +++ b/src/js/services/coinbaseService.js @@ -177,7 +177,10 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ if (err) return cb(err); _refreshToken(refreshToken, function(err, newToken) { if (err) return cb(err); - return cb(null, {accessToken: newToken, accountId: accountId}); + _getMainAccountId(newToken, function(err, accountId) { + if (err) return cb(err); + return cb(null, {accessToken: newToken, accountId: accountId}); + }); }); }); } else { diff --git a/www/views/coinbase.html b/www/views/coinbase.html index c92d2c080..82ba63d8c 100644 --- a/www/views/coinbase.html +++ b/www/views/coinbase.html @@ -3,11 +3,6 @@ Coinbase - - - diff --git a/www/views/modals/coinbase-confirmation.html b/www/views/modals/coinbase-confirmation.html deleted file mode 100644 index c243c0f28..000000000 --- a/www/views/modals/coinbase-confirmation.html +++ /dev/null @@ -1,18 +0,0 @@ - -
-
-

Are you sure you would like to log out of your Coinbase account?

-

You will need to log back in to buy or sell bitcoin in Copay.

-
- -
-
- -
-
-
-
diff --git a/www/views/preferencesCoinbase.html b/www/views/preferencesCoinbase.html index fee9ab66f..3b0e0599c 100644 --- a/www/views/preferencesCoinbase.html +++ b/www/views/preferencesCoinbase.html @@ -1,60 +1,62 @@ -
-
+ + + + + Preferences + -
+ -
    -

    Account

    -
  • - ID - - {{index.coinbaseAccount.id}} - -
  • -
  • - Name - - {{index.coinbaseAccount.name}} - -
  • -
  • - Balance - - {{index.coinbaseAccount.balance.amount}} {{index.coinbaseAccount.balance.currency}} - -
  • -
  • - Native Balance - - {{index.coinbaseAccount.native_balance.amount}} {{index.coinbaseAccount.native_balance.currency}} - -
  • +
      +
      + Account +
      +
    • + ID + + {{coinbaseAccount.id}} + +
    • +
    • + Name + + {{coinbaseAccount.name}} + +
    • +
    • + Balance + + {{coinbaseAccount.balance.amount}} {{coinbaseAccount.balance.currency}} + +
    • +
    • + Native Balance + + {{coinbaseAccount.native_balance.amount}} {{coinbaseAccount.native_balance.currency}} + +
    • -

      User Information

      -
    • - ID - - {{index.coinbaseUser.id}} - -
    • -
    • - Email - - {{index.coinbaseUser.email}} - -
    • -
    -
      -

      -
    • - - Log out -
    • -
    -

    +
    + User Information +
    +
  • + ID + + {{coinbaseUser.id}} + +
  • +
  • + Email + + {{coinbaseUser.email}} + +
  • -
-
+
+
  • + Log out +
  • + + +
    + diff --git a/www/views/tab-settings.html b/www/views/tab-settings.html index 9ee416332..868388c56 100644 --- a/www/views/tab-settings.html +++ b/www/views/tab-settings.html @@ -133,6 +133,13 @@ + + + + +