Merge branch 'master' of github.com:bitpay/copay into feature/better-buy-and-sell

This commit is contained in:
Jason Dreyzehner 2017-02-01 17:38:57 -05:00
commit aaf9008394
41 changed files with 931 additions and 1016 deletions

View file

@ -1,11 +1,12 @@
'use strict';
angular.module('copayApp.services').factory('glideraService', function($http, $log, $window, platformInfo, storageService) {
angular.module('copayApp.services').factory('glideraService', function($http, $log, $window, platformInfo, storageService, buyAndSellService) {
var root = {};
var credentials = {};
var isCordova = platformInfo.isCordova;
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
var _setCredentials = function() {
var setCredentials = function() {
if (!$window.externalServices || !$window.externalServices.glidera) {
return;
}
@ -17,6 +18,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
* Production: 'livenet'
*/
credentials.NETWORK = 'livenet';
//credentials.NETWORK = 'testnet';
if (credentials.NETWORK == 'testnet') {
credentials.HOST = glidera.sandbox.host;
@ -44,7 +46,6 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
};
root.getEnvironment = function() {
_setCredentials();
return credentials.NETWORK;
};
@ -57,19 +58,17 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
}
root.getOauthCodeUrl = function() {
_setCredentials();
return credentials.HOST + '/oauth2/auth?response_type=code&client_id=' + credentials.CLIENT_ID + '&redirect_uri=' + credentials.REDIRECT_URI;
};
root.removeToken = function(cb) {
_setCredentials();
storageService.removeGlideraToken(credentials.NETWORK, function() {
buyAndSellService.updateLink('glidera', false);
return cb();
});
};
root.getToken = function(code, cb) {
_setCredentials();
var req = {
method: 'POST',
url: credentials.HOST + '/api/v1/oauth/token',
@ -98,7 +97,6 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
};
var _get = function(endpoint, token) {
_setCredentials();
return {
method: 'GET',
url: credentials.HOST + '/api/v1' + endpoint,
@ -216,7 +214,6 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
};
var _post = function(endpoint, token, twoFaCode, data) {
_setCredentials();
return {
method: 'POST',
url: credentials.HOST + '/api/v1' + endpoint,
@ -293,7 +290,6 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
};
root.init = function(accessToken, cb) {
_setCredentials();
$log.debug('Init Glidera...');
var glidera = {
@ -312,6 +308,8 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
getToken(function(err, accessToken) {
if (err || !accessToken) return cb();
else {
buyAndSellService.updateLink('glidera', true);
root.getAccessTokenPermissions(accessToken, function(err, p) {
if (err) {
return cb(err);
@ -325,6 +323,25 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
});
};
return root;
var register = function() {
if (isWindowsPhoneApp) return;
storageService.getGlideraToken(credentials.NETWORK, function(err, token) {
if (err) return cb(err);
buyAndSellService.register({
name: 'glidera',
logo: 'img/glidera-logo.png',
location: 'US Only',
sref: 'tabs.buyandsell.glidera',
configSref: 'tabs.preferences.glidera',
linked: !!token,
});
});
};
setCredentials();
register();
return root;
});