Wallet/src/js/controllers/glidera.js

57 lines
1.7 KiB
JavaScript

'use strict';
angular.module('copayApp.controllers').controller('glideraController',
function($rootScope, $scope, $timeout, $modal, $ionicModal, profileService, configService, storageService, glideraService, lodash) {
this.getAuthenticateUrl = function() {
return glideraService.getOauthCodeUrl();
};
this.submitOauthCode = function(code) {
var self = this;
var glideraTestnet = configService.getSync().glidera.testnet;
var network = glideraTestnet ? 'testnet' : 'livenet';
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) {
storageService.setGlideraToken(network, data.access_token, function() {
$scope.$emit('Local/GlideraUpdated', data.access_token);
$timeout(function() {
$scope.$apply();
}, 100);
});
}
});
}, 100);
};
this.openTxModal = function(token, tx) {
var self = this;
$scope.self = self;
$scope.tx = tx;
glideraService.getTransaction(token, tx.transactionUuid, function(error, tx) {
$scope.tx = tx;
});
$ionicModal.fromTemplateUrl('views/modals/glidera-tx-details.html', {
scope: $scope,
backdropClickToClose: false,
hardwareBackButtonClose: false,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.glideraTxDetailsModal = modal;
$scope.glideraTxDetailsModal.show();
});
};
});