glidera service
This commit is contained in:
parent
7cca568c0a
commit
1095b48cd5
4 changed files with 106 additions and 81 deletions
78
old/index.js
78
old/index.js
|
|
@ -564,84 +564,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
$log.debug('Disclaimer not accepted, cannot open menu');
|
||||
});
|
||||
};
|
||||
|
||||
self.initGlidera = function(accessToken) {
|
||||
self.glideraEnabled = configService.getSync().glidera.enabled;
|
||||
self.glideraTestnet = configService.getSync().glidera.testnet;
|
||||
var network = self.glideraTestnet ? 'testnet' : 'livenet';
|
||||
|
||||
self.glideraToken = null;
|
||||
self.glideraError = null;
|
||||
self.glideraPermissions = null;
|
||||
self.glideraEmail = null;
|
||||
self.glideraPersonalInfo = null;
|
||||
self.glideraTxs = null;
|
||||
self.glideraStatus = null;
|
||||
|
||||
if (!self.glideraEnabled) return;
|
||||
|
||||
glideraService.setCredentials(network);
|
||||
|
||||
var getToken = function(cb) {
|
||||
if (accessToken) {
|
||||
cb(null, accessToken);
|
||||
} else {
|
||||
storageService.getGlideraToken(network, cb);
|
||||
}
|
||||
};
|
||||
|
||||
getToken(function(err, accessToken) {
|
||||
if (err || !accessToken) return;
|
||||
else {
|
||||
glideraService.getAccessTokenPermissions(accessToken, function(err, p) {
|
||||
if (err) {
|
||||
self.glideraError = err;
|
||||
} else {
|
||||
self.glideraToken = accessToken;
|
||||
self.glideraPermissions = p;
|
||||
self.updateGlidera({
|
||||
fullUpdate: true
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.updateGlidera = function(opts) {
|
||||
if (!self.glideraToken || !self.glideraPermissions) return;
|
||||
var accessToken = self.glideraToken;
|
||||
var permissions = self.glideraPermissions;
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
glideraService.getStatus(accessToken, function(err, data) {
|
||||
self.glideraStatus = data;
|
||||
});
|
||||
|
||||
glideraService.getLimits(accessToken, function(err, limits) {
|
||||
self.glideraLimits = limits;
|
||||
});
|
||||
|
||||
if (permissions.transaction_history) {
|
||||
glideraService.getTransactions(accessToken, function(err, data) {
|
||||
self.glideraTxs = data;
|
||||
});
|
||||
}
|
||||
|
||||
if (permissions.view_email_address && opts.fullUpdate) {
|
||||
glideraService.getEmail(accessToken, function(err, data) {
|
||||
self.glideraEmail = data.email;
|
||||
});
|
||||
}
|
||||
if (permissions.personal_info && opts.fullUpdate) {
|
||||
glideraService.getPersonalInfo(accessToken, function(err, data) {
|
||||
self.glideraPersonalInfo = data;
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
self.initCoinbase = function(accessToken) {
|
||||
self.coinbaseEnabled = configService.getSync().coinbase.enabled;
|
||||
self.coinbaseTestnet = configService.getSync().coinbase.testnet;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('headController',
|
||||
function($scope, $window, $log) {
|
||||
function($scope, $window, $log, glideraService) {
|
||||
$scope.appConfig = $window.appConfig;
|
||||
$log.info('Running head controller:' + $window.appConfig.nameCase)
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log) {
|
||||
angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log, $timeout) {
|
||||
var root = {};
|
||||
|
||||
var defaultConfig = {
|
||||
|
|
@ -79,6 +79,16 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
return configCache;
|
||||
};
|
||||
|
||||
root._queue = [];
|
||||
root.whenAvailable = function(cb) {
|
||||
if (!configCache) {
|
||||
root._queue.push(cb);
|
||||
return;
|
||||
}
|
||||
return cb(configCache);
|
||||
};
|
||||
|
||||
|
||||
root.get = function(cb) {
|
||||
|
||||
storageService.getConfig(function(err, localConfig) {
|
||||
|
|
@ -118,6 +128,14 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
configCache.coinbase.testnet = false;
|
||||
|
||||
$log.debug('Preferences read:', configCache)
|
||||
|
||||
lodash.each(root._queue, function(x) {
|
||||
$timeout(function() {
|
||||
return x(configCache);
|
||||
}, 1);
|
||||
});
|
||||
root._queue = [];
|
||||
|
||||
return cb(err, configCache);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('glideraService', function($http, $log, platformInfo) {
|
||||
angular.module('copayApp.services').factory('glideraService', function($http, $log, platformInfo, storageService, configService) {
|
||||
var root = {};
|
||||
var credentials = {};
|
||||
var isCordova = platformInfo.isCordova;
|
||||
//
|
||||
//
|
||||
|
||||
root.setCredentials = function(network) {
|
||||
if (network == 'testnet') {
|
||||
|
|
@ -256,6 +258,89 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
});
|
||||
};
|
||||
|
||||
root.init = function(accessToken) {
|
||||
root.glideraEnabled = configService.getSync().glidera.enabled;
|
||||
root.glideraTestnet = configService.getSync().glidera.testnet;
|
||||
var network = root.glideraTestnet ? 'testnet' : 'livenet';
|
||||
|
||||
root.glideraToken = null;
|
||||
root.glideraError = null;
|
||||
root.glideraPermissions = null;
|
||||
root.glideraEmail = null;
|
||||
root.glideraPersonalInfo = null;
|
||||
root.glideraTxs = null;
|
||||
root.glideraStatus = null;
|
||||
|
||||
if (!root.glideraEnabled) return;
|
||||
|
||||
root.setCredentials(network);
|
||||
|
||||
var getToken = function(cb) {
|
||||
if (accessToken) {
|
||||
cb(null, accessToken);
|
||||
} else {
|
||||
storageService.getGlideraToken(network, cb);
|
||||
}
|
||||
};
|
||||
|
||||
getToken(function(err, accessToken) {
|
||||
if (err || !accessToken) return;
|
||||
else {
|
||||
root.getAccessTokenPermissions(accessToken, function(err, p) {
|
||||
if (err) {
|
||||
root.glideraError = err;
|
||||
} else {
|
||||
root.glideraToken = accessToken;
|
||||
root.glideraPermissions = p;
|
||||
root.updateGlidera({
|
||||
fullUpdate: true
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
root.updateGlidera = function(opts) {
|
||||
if (!root.glideraToken || !root.glideraPermissions) return;
|
||||
var accessToken = root.glideraToken;
|
||||
var permissions = root.glideraPermissions;
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
root.getStatus(accessToken, function(err, data) {
|
||||
root.glideraStatus = data;
|
||||
});
|
||||
|
||||
root.getLimits(accessToken, function(err, limits) {
|
||||
root.glideraLimits = limits;
|
||||
});
|
||||
|
||||
if (permissions.transaction_history) {
|
||||
root.getTransactions(accessToken, function(err, data) {
|
||||
root.glideraTxs = data;
|
||||
});
|
||||
}
|
||||
|
||||
if (permissions.view_email_address && opts.fullUpdate) {
|
||||
root.getEmail(accessToken, function(err, data) {
|
||||
root.glideraEmail = data.email;
|
||||
});
|
||||
}
|
||||
if (permissions.personal_info && opts.fullUpdate) {
|
||||
root.getPersonalInfo(accessToken, function(err, data) {
|
||||
root.glideraPersonalInfo = data;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
configService.whenAvailable(function() {
|
||||
$log.debug('Init Glidera Service...');
|
||||
root.init();
|
||||
});
|
||||
|
||||
|
||||
|
||||
return root;
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue