Refactor Glidera Authorization process
This commit is contained in:
parent
fc52a8cf87
commit
fcae682954
6 changed files with 230 additions and 229 deletions
|
|
@ -1,72 +1,37 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('glideraController',
|
||||
function($scope, $timeout, $ionicModal, $log, storageService, glideraService, ongoingProcess, platformInfo, externalLinkService, popupService, gettextCatalog) {
|
||||
|
||||
$scope.network = glideraService.getEnvironment();
|
||||
function($scope, $timeout, $ionicModal, $log, storageService, glideraService, ongoingProcess, platformInfo, externalLinkService, popupService, lodash) {
|
||||
|
||||
$scope.openExternalLink = function(url) {
|
||||
externalLinkService.open(url);
|
||||
};
|
||||
|
||||
var initGlidera = function(accessToken) {
|
||||
$scope.token = accessToken;
|
||||
$scope.permissions = null;
|
||||
$scope.email = null;
|
||||
$scope.personalInfo = null;
|
||||
$scope.txs = null;
|
||||
$scope.status = null;
|
||||
$scope.limits = null;
|
||||
var init = function() {
|
||||
glideraService.init(function(err, data) {
|
||||
if (err || lodash.isEmpty(data)) return;
|
||||
|
||||
$scope.connectingGlidera = true;
|
||||
ongoingProcess.set('connectingGlidera', true);
|
||||
glideraService.init($scope.token, function(err, glidera) {
|
||||
ongoingProcess.set('connectingGlidera');
|
||||
$scope.connectingGlidera = false;
|
||||
if (err || !glidera) {
|
||||
if (err) popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
return;
|
||||
}
|
||||
$scope.token = glidera.token;
|
||||
$scope.permissions = glidera.permissions;
|
||||
$scope.update({
|
||||
fullUpdate: true
|
||||
$scope.account['token'] = data.token;
|
||||
$scope.account['status'] = data.status;
|
||||
$scope.account['price'] = {};
|
||||
|
||||
glideraService.buyPrice($scope.account.token, {qty: 1}, function(err, buy) {
|
||||
$scope.account.price['buy'] = buy.price;
|
||||
});
|
||||
glideraService.sellPrice($scope.account.token, {qty: 1}, function(err, sell) {
|
||||
$scope.account.price['sell'] = sell.price;
|
||||
});
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
$scope.update();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$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;
|
||||
});
|
||||
|
||||
glideraService.getLimits(accessToken, function(err, limits) {
|
||||
$scope.limits = limits;
|
||||
});
|
||||
|
||||
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) {
|
||||
$scope.email = data.email;
|
||||
});
|
||||
}
|
||||
if (permissions.personal_info && opts.fullUpdate) {
|
||||
glideraService.getPersonalInfo(accessToken, function(err, data) {
|
||||
$scope.personalInfo = data;
|
||||
});
|
||||
}
|
||||
$log.debug('Updating Glidera...');
|
||||
glideraService.updateStatus($scope.account);
|
||||
};
|
||||
|
||||
$scope.getAuthenticateUrl = function() {
|
||||
|
|
@ -75,29 +40,22 @@ angular.module('copayApp.controllers').controller('glideraController',
|
|||
|
||||
$scope.submitOauthCode = function(code) {
|
||||
ongoingProcess.set('connectingGlidera', true);
|
||||
$timeout(function() {
|
||||
glideraService.getToken(code, function(err, data) {
|
||||
ongoingProcess.set('connectingGlidera', false);
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
} else if (data && data.access_token) {
|
||||
storageService.setGlideraToken($scope.network, data.access_token, function() {
|
||||
initGlidera(data.access_token);
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
});
|
||||
}, 100);
|
||||
glideraService.authorize(code, function(err, data) {
|
||||
ongoingProcess.set('connectingGlidera', false);
|
||||
if (err) {
|
||||
popupService.showAlert('Authorisation error', err);
|
||||
return;
|
||||
}
|
||||
init();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openTxModal = function(token, tx) {
|
||||
$scope.openTxModal = function(tx) {
|
||||
$scope.tx = tx;
|
||||
|
||||
glideraService.getTransaction(token, tx.transactionUuid, function(err, tx) {
|
||||
glideraService.getTransaction($scope.account.token, tx.transactionUuid, function(err, tx) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not get transactions'));
|
||||
popupService.showAlert('Error getting transaction', 'Could not get transactions');
|
||||
return;
|
||||
}
|
||||
$scope.tx = tx;
|
||||
|
|
@ -127,10 +85,10 @@ angular.module('copayApp.controllers').controller('glideraController',
|
|||
$scope.openSupportWindow = function() {
|
||||
var url = glideraService.getSupportUrl();
|
||||
var optIn = true;
|
||||
var title = gettextCatalog.getString('Glidera Support');
|
||||
var message = gettextCatalog.getString('You can email glidera at support@glidera.io for direct support, or you can contact Glidera on Twitter.');
|
||||
var okText = gettextCatalog.getString('Tweet @GlideraInc');
|
||||
var cancelText = gettextCatalog.getString('Go Back');
|
||||
var title = 'Glidera Support';
|
||||
var message = 'You can email glidera at support@glidera.io for direct support, or you can contact Glidera on Twitter.';
|
||||
var okText = 'Tweet @GlideraInc';
|
||||
var cancelText = 'Go Back';
|
||||
externalLinkService.open(url, optIn, title, message, okText, cancelText);
|
||||
}
|
||||
|
||||
|
|
@ -147,8 +105,10 @@ angular.module('copayApp.controllers').controller('glideraController',
|
|||
}
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
$scope.network = glideraService.getNetwork();
|
||||
$scope.showOauthForm = false;
|
||||
initGlidera();
|
||||
$scope.account = {};
|
||||
init();
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,46 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesGlideraController',
|
||||
function($scope, $log, $timeout, $state, $ionicHistory, ongoingProcess, glideraService, popupService, gettextCatalog) {
|
||||
|
||||
$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;
|
||||
});
|
||||
|
||||
glideraService.getLimits(accessToken, function(err, limits) {
|
||||
$scope.limits = limits;
|
||||
});
|
||||
|
||||
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) {
|
||||
$scope.email = data;
|
||||
});
|
||||
}
|
||||
if (permissions.personal_info && opts.fullUpdate) {
|
||||
glideraService.getPersonalInfo(accessToken, function(err, data) {
|
||||
$scope.personalInfo = data;
|
||||
});
|
||||
}
|
||||
};
|
||||
function($scope, $timeout, $state, $ionicHistory, glideraService, popupService) {
|
||||
|
||||
$scope.revokeToken = function() {
|
||||
popupService.showConfirm('Glidera', 'Are you sure you would like to log out of your Glidera account?', null, null, function(res) {
|
||||
if (res) {
|
||||
glideraService.removeToken(function() {
|
||||
glideraService.remove(function() {
|
||||
$ionicHistory.clearHistory();
|
||||
$timeout(function() {
|
||||
$state.go('tabs.home');
|
||||
|
|
@ -50,21 +16,20 @@ angular.module('copayApp.controllers').controller('preferencesGlideraController'
|
|||
});
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data){
|
||||
$scope.network = glideraService.getEnvironment();
|
||||
$scope.$on("$ionicView.afterEnter", function(event, data){
|
||||
glideraService.updateStatus($scope.account);
|
||||
});
|
||||
|
||||
ongoingProcess.set('connectingGlidera', true);
|
||||
glideraService.init($scope.token, function(err, glidera) {
|
||||
ongoingProcess.set('connectingGlidera');
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data){
|
||||
$scope.account = {};
|
||||
glideraService.init(function(err, glidera) {
|
||||
if (err || !glidera) {
|
||||
if (err) popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
if (err) popupService.showAlert('Error connecting Glidera', err);
|
||||
return;
|
||||
}
|
||||
$scope.token = glidera.token;
|
||||
$scope.permissions = glidera.permissions;
|
||||
$scope.update({
|
||||
fullUpdate: true
|
||||
});
|
||||
$scope.account['token'] = glidera.token;
|
||||
$scope.account['permissions'] = glidera.permissions;
|
||||
$scope.account['status'] = glidera.status;
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue