2016-04-13 14:08:03 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2017-01-24 18:17:44 -03:00
|
|
|
angular.module('copayApp.controllers').controller('preferencesCoinbaseController', function($scope, $timeout, $log, $state, $ionicHistory, lodash, ongoingProcess, popupService, coinbaseService) {
|
2016-04-13 14:08:03 -03:00
|
|
|
|
2016-12-08 13:06:01 -03:00
|
|
|
$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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2016-04-13 14:08:03 -03:00
|
|
|
|
2016-12-08 13:06:01 -03:00
|
|
|
$scope.$on("$ionicView.enter", function(event, data){
|
|
|
|
|
ongoingProcess.set('connectingCoinbase', true);
|
2017-01-03 12:43:08 -03:00
|
|
|
coinbaseService.init(function(err, data) {
|
2016-12-08 13:06:01 -03:00
|
|
|
if (err || lodash.isEmpty(data)) {
|
|
|
|
|
ongoingProcess.set('connectingCoinbase', false);
|
|
|
|
|
if (err) {
|
2017-01-24 18:17:44 -03:00
|
|
|
$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();
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-12-08 13:06:01 -03:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var accessToken = data.accessToken;
|
|
|
|
|
var accountId = data.accountId;
|
|
|
|
|
coinbaseService.getAccount(accessToken, accountId, function(err, account) {
|
2017-01-03 12:43:08 -03:00
|
|
|
ongoingProcess.set('connectingCoinbase', false);
|
2016-12-08 13:06:01 -03:00
|
|
|
$scope.coinbaseAccount = account.data;
|
2016-04-13 14:08:03 -03:00
|
|
|
});
|
2016-12-08 13:06:01 -03:00
|
|
|
coinbaseService.getCurrentUser(accessToken, function(err, user) {
|
|
|
|
|
$scope.coinbaseUser = user.data;
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-04-13 14:08:03 -03:00
|
|
|
});
|
2016-12-08 13:06:01 -03:00
|
|
|
|
|
|
|
|
});
|