Refactor network environment
This commit is contained in:
parent
03965b6e3a
commit
e466405769
4 changed files with 20 additions and 22 deletions
|
|
@ -1,13 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('amazonController',
|
angular.module('copayApp.controllers').controller('amazonController',
|
||||||
function($scope, $timeout, $ionicModal, $log, lodash, bwcError, configService, amazonService) {
|
function($scope, $timeout, $ionicModal, $log, lodash, bwcError, amazonService) {
|
||||||
|
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
self.sandbox = amazonService.getEnvironment() == 'testnet' ? true : false;
|
||||||
self.sandbox = network == 'testnet' ? true : false;
|
|
||||||
amazonService.setCredentials(network);
|
|
||||||
amazonService.getPendingGiftCards(function(err, gcds) {
|
amazonService.getPendingGiftCards(function(err, gcds) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err;
|
self.error = err;
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
|
||||||
};
|
};
|
||||||
|
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
var network = amazonService.getEnvironment();
|
||||||
amazonService.setCredentials(network);
|
|
||||||
self.allWallets = profileService.getWallets(network, 1);
|
self.allWallets = profileService.getWallets(network, 1);
|
||||||
client = profileService.focusedClient;
|
client = profileService.focusedClient;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,14 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
var root = {};
|
var root = {};
|
||||||
var credentials = {};
|
var credentials = {};
|
||||||
|
|
||||||
root.setCredentials = function(network) {
|
var _setCredentials = function() {
|
||||||
if (network == 'testnet') {
|
/*
|
||||||
|
* Development: 'testnet'
|
||||||
|
* Production: 'livenet'
|
||||||
|
*/
|
||||||
|
credentials.NETWORK = 'livenet';
|
||||||
|
|
||||||
|
if (credentials.NETWORK == 'testnet') {
|
||||||
credentials.BITPAY_API_URL = "https://test.bitpay.com";
|
credentials.BITPAY_API_URL = "https://test.bitpay.com";
|
||||||
} else {
|
} else {
|
||||||
credentials.BITPAY_API_URL = "https://bitpay.com";
|
credentials.BITPAY_API_URL = "https://bitpay.com";
|
||||||
|
|
@ -12,6 +18,7 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
};
|
};
|
||||||
|
|
||||||
var _getBitPay = function(endpoint) {
|
var _getBitPay = function(endpoint) {
|
||||||
|
_setCredentials();
|
||||||
return {
|
return {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: credentials.BITPAY_API_URL + endpoint,
|
url: credentials.BITPAY_API_URL + endpoint,
|
||||||
|
|
@ -22,6 +29,7 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
};
|
};
|
||||||
|
|
||||||
var _postBitPay = function(endpoint, data) {
|
var _postBitPay = function(endpoint, data) {
|
||||||
|
_setCredentials();
|
||||||
return {
|
return {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: credentials.BITPAY_API_URL + endpoint,
|
url: credentials.BITPAY_API_URL + endpoint,
|
||||||
|
|
@ -32,8 +40,13 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root.getEnvironment = function() {
|
||||||
|
_setCredentials();
|
||||||
|
return credentials.NETWORK;
|
||||||
|
};
|
||||||
|
|
||||||
root.savePendingGiftCard = function(gc, opts, cb) {
|
root.savePendingGiftCard = function(gc, opts, cb) {
|
||||||
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
var network = root.getEnvironment();
|
||||||
storageService.getAmazonGiftCards(network, function(err, oldGiftCards) {
|
storageService.getAmazonGiftCards(network, function(err, oldGiftCards) {
|
||||||
if (lodash.isString(oldGiftCards)) {
|
if (lodash.isString(oldGiftCards)) {
|
||||||
oldGiftCards = JSON.parse(oldGiftCards);
|
oldGiftCards = JSON.parse(oldGiftCards);
|
||||||
|
|
@ -58,7 +71,7 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getPendingGiftCards = function(cb) {
|
root.getPendingGiftCards = function(cb) {
|
||||||
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
var network = root.getEnvironment();
|
||||||
storageService.getAmazonGiftCards(network, function(err, giftCards) {
|
storageService.getAmazonGiftCards(network, function(err, giftCards) {
|
||||||
var _gcds = giftCards ? JSON.parse(giftCards) : null;
|
var _gcds = giftCards ? JSON.parse(giftCards) : null;
|
||||||
return cb(err, _gcds);
|
return cb(err, _gcds);
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,6 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
||||||
testnet: false
|
testnet: false
|
||||||
},
|
},
|
||||||
|
|
||||||
amazon: {
|
|
||||||
enabled: true,
|
|
||||||
testnet: false
|
|
||||||
},
|
|
||||||
|
|
||||||
rates: {
|
rates: {
|
||||||
url: 'https://insight.bitpay.com:443/api/rates',
|
url: 'https://insight.bitpay.com:443/api/rates',
|
||||||
},
|
},
|
||||||
|
|
@ -106,9 +101,6 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
||||||
if (!configCache.coinbase) {
|
if (!configCache.coinbase) {
|
||||||
configCache.coinbase = defaultConfig.coinbase;
|
configCache.coinbase = defaultConfig.coinbase;
|
||||||
}
|
}
|
||||||
if (!configCache.amazon) {
|
|
||||||
configCache.amazon = defaultConfig.amazon;
|
|
||||||
}
|
|
||||||
if (!configCache.pushNotifications) {
|
if (!configCache.pushNotifications) {
|
||||||
configCache.pushNotifications = defaultConfig.pushNotifications;
|
configCache.pushNotifications = defaultConfig.pushNotifications;
|
||||||
}
|
}
|
||||||
|
|
@ -125,10 +117,6 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
||||||
// Disabled for testnet
|
// Disabled for testnet
|
||||||
configCache.coinbase.testnet = false;
|
configCache.coinbase.testnet = false;
|
||||||
|
|
||||||
// Amazon
|
|
||||||
// Disabled for testnet
|
|
||||||
configCache.amazon.testnet = false;
|
|
||||||
|
|
||||||
$log.debug('Preferences read:', configCache)
|
$log.debug('Preferences read:', configCache)
|
||||||
return cb(err, configCache);
|
return cb(err, configCache);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue