2015-08-28 18:23:24 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-06-10 15:16:02 -03:00
|
|
|
angular.module('copayApp.controllers').controller('preferencesGlideraController',
|
2016-11-22 12:35:51 -03:00
|
|
|
function($scope, $log, $timeout, $state, $ionicHistory, ongoingProcess, glideraService, popupService, gettextCatalog) {
|
2015-08-28 18:23:24 -03:00
|
|
|
|
2016-08-24 11:33:43 -03:00
|
|
|
$scope.update = function(opts) {
|
|
|
|
|
if (!$scope.token || !$scope.permissions) return;
|
|
|
|
|
$log.debug('Updating Glidera Account...');
|
|
|
|
|
var accessToken = $scope.token;
|
|
|
|
|
var permissions = $scope.permissions;
|
|
|
|
|
|
|
|
|
|
opts = opts || {};
|
|
|
|
|
|
|
|
|
|
glideraService.getStatus(accessToken, function(err, data) {
|
|
|
|
|
$scope.status = data;
|
2015-08-28 18:23:24 -03:00
|
|
|
});
|
|
|
|
|
|
2016-08-24 11:33:43 -03:00
|
|
|
glideraService.getLimits(accessToken, function(err, limits) {
|
|
|
|
|
$scope.limits = limits;
|
2015-08-28 18:23:24 -03:00
|
|
|
});
|
|
|
|
|
|
2016-08-24 11:33:43 -03:00
|
|
|
if (permissions.transaction_history) {
|
|
|
|
|
glideraService.getTransactions(accessToken, function(err, data) {
|
|
|
|
|
$scope.txs = data;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (permissions.view_email_address && opts.fullUpdate) {
|
|
|
|
|
glideraService.getEmail(accessToken, function(err, data) {
|
2016-09-06 11:59:05 -03:00
|
|
|
$scope.email = data;
|
2016-08-24 11:33:43 -03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (permissions.personal_info && opts.fullUpdate) {
|
|
|
|
|
glideraService.getPersonalInfo(accessToken, function(err, data) {
|
|
|
|
|
$scope.personalInfo = data;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-06-10 15:16:02 -03:00
|
|
|
|
2016-08-24 11:33:43 -03:00
|
|
|
$scope.revokeToken = function() {
|
2016-09-12 13:58:36 -03:00
|
|
|
popupService.showConfirm('Glidera', 'Are you sure you would like to log out of your Glidera account?', null, null, function(res) {
|
2016-08-31 16:43:52 -03:00
|
|
|
if (res) {
|
|
|
|
|
glideraService.removeToken(function() {
|
2016-11-22 12:35:51 -03:00
|
|
|
$ionicHistory.clearHistory();
|
2016-08-31 16:43:52 -03:00
|
|
|
$timeout(function() {
|
2016-11-22 12:35:51 -03:00
|
|
|
$state.go('tabs.home');
|
2016-08-31 16:43:52 -03:00
|
|
|
}, 100);
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-09-10 14:58:06 -03:00
|
|
|
});
|
2015-08-28 18:23:24 -03:00
|
|
|
};
|
|
|
|
|
|
2016-09-22 11:55:23 -03:00
|
|
|
$scope.$on("$ionicView.enter", function(event, data){
|
|
|
|
|
$scope.network = glideraService.getEnvironment();
|
|
|
|
|
|
|
|
|
|
ongoingProcess.set('connectingGlidera', true);
|
|
|
|
|
glideraService.init($scope.token, function(err, glidera) {
|
|
|
|
|
ongoingProcess.set('connectingGlidera');
|
|
|
|
|
if (err || !glidera) {
|
|
|
|
|
if (err) popupService.showAlert(gettextCatalog.getString('Error'), err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$scope.token = glidera.token;
|
|
|
|
|
$scope.permissions = glidera.permissions;
|
|
|
|
|
$scope.update({
|
|
|
|
|
fullUpdate: true
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-08-28 18:23:24 -03:00
|
|
|
});
|