2015-09-09 14:15:08 -03:00
|
|
|
'use strict';
|
|
|
|
|
angular.module('copayApp.controllers').controller('glideraUriController',
|
2015-11-05 18:57:59 -03:00
|
|
|
function($scope, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) {
|
2015-09-09 14:15:08 -03:00
|
|
|
|
|
|
|
|
this.submitOauthCode = function(code) {
|
|
|
|
|
var self = this;
|
2015-11-05 18:57:59 -03:00
|
|
|
var glideraTestnet = configService.getSync().glidera.testnet;
|
|
|
|
|
var network = glideraTestnet ? 'testnet' : 'livenet';
|
2015-09-09 14:15:08 -03:00
|
|
|
this.loading = true;
|
|
|
|
|
this.error = null;
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
glideraService.getToken(code, function(err, data) {
|
|
|
|
|
self.loading = null;
|
|
|
|
|
if (err) {
|
|
|
|
|
self.error = err;
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
}, 100);
|
|
|
|
|
}
|
|
|
|
|
else if (data && data.access_token) {
|
2015-11-05 18:57:59 -03:00
|
|
|
storageService.setGlideraToken(network, data.access_token, function() {
|
2015-09-11 13:11:41 -03:00
|
|
|
$scope.$emit('Local/GlideraUpdated', data.access_token);
|
2015-09-09 14:15:08 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
go.path('glidera');
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
}, 100);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}, 100);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.checkCode = function() {
|
|
|
|
|
this.code = $stateParams.code;
|
|
|
|
|
this.submitOauthCode(this.code);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
});
|