Use an environment object instead of string.
This commit is contained in:
parent
189117433a
commit
28f9fbc0b6
5 changed files with 22 additions and 17 deletions
|
|
@ -7,7 +7,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
||||||
$scope.dateRange = {
|
$scope.dateRange = {
|
||||||
value: 'last30Days'
|
value: 'last30Days'
|
||||||
};
|
};
|
||||||
$scope.network = bitpayService.getEnvironment();
|
$scope.network = bitpayService.getEnvironment().network;
|
||||||
|
|
||||||
var updateHistoryFromCache = function(cb) {
|
var updateHistoryFromCache = function(cb) {
|
||||||
bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) {
|
bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) {
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,6 @@ angular.module('copayApp.services').factory('appIdentityService', function($log,
|
||||||
var pubkey, sin, isNew;
|
var pubkey, sin, isNew;
|
||||||
storageService.getAppIdentity(network, function(err, data) {
|
storageService.getAppIdentity(network, function(err, data) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (lodash.isString(data)) {
|
|
||||||
data = JSON.parse(data);
|
|
||||||
}
|
|
||||||
var appIdentity = data || {};
|
var appIdentity = data || {};
|
||||||
if (lodash.isEmpty(appIdentity) || (appIdentity && !appIdentity.priv)) {
|
if (lodash.isEmpty(appIdentity) || (appIdentity && !appIdentity.priv)) {
|
||||||
isNew = true;
|
isNew = true;
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
||||||
method: 'getInvoiceHistory',
|
method: 'getInvoiceHistory',
|
||||||
params: JSON.stringify(params)
|
params: JSON.stringify(params)
|
||||||
};
|
};
|
||||||
appIdentityService.getIdentity(bitpayService.getEnvironment(), function(err, appIdentity) {
|
appIdentityService.getIdentity(bitpayService.getEnvironment().network, function(err, appIdentity) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
root.getBitpayDebitCards(function(err, data) {
|
root.getBitpayDebitCards(function(err, data) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
@ -97,7 +97,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
||||||
method: 'generateTopUpInvoice',
|
method: 'generateTopUpInvoice',
|
||||||
params: JSON.stringify(params)
|
params: JSON.stringify(params)
|
||||||
};
|
};
|
||||||
appIdentityService.getIdentity(bitpayService.getEnvironment(), function(err, appIdentity) {
|
appIdentityService.getIdentity(bitpayService.getEnvironment().network, function(err, appIdentity) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
root.getBitpayDebitCards(function(err, data) {
|
root.getBitpayDebitCards(function(err, data) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
@ -127,7 +127,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getBitpayDebitCards = function(cb) {
|
root.getBitpayDebitCards = function(cb) {
|
||||||
storageService.getBitpayDebitCards(bitpayService.getEnvironment(), function(err, data) {
|
storageService.getBitpayDebitCards(bitpayService.getEnvironment().network, function(err, data) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (lodash.isString(data)) {
|
if (lodash.isString(data)) {
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
|
|
@ -139,14 +139,14 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
||||||
|
|
||||||
root.setBitpayDebitCards = function(data, cb) {
|
root.setBitpayDebitCards = function(data, cb) {
|
||||||
data = JSON.stringify(data);
|
data = JSON.stringify(data);
|
||||||
storageService.setBitpayDebitCards(bitpayService.getEnvironment(), data, function(err) {
|
storageService.setBitpayDebitCards(bitpayService.getEnvironment().network, data, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
return cb();
|
return cb();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getBitpayDebitCardsHistory = function(cardId, cb) {
|
root.getBitpayDebitCardsHistory = function(cardId, cb) {
|
||||||
storageService.getBitpayDebitCardsHistory(bitpayService.getEnvironment(), function(err, data) {
|
storageService.getBitpayDebitCardsHistory(bitpayService.getEnvironment().network, function(err, data) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (lodash.isString(data)) {
|
if (lodash.isString(data)) {
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
|
|
@ -158,7 +158,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setBitpayDebitCardsHistory = function(cardId, data, opts, cb) {
|
root.setBitpayDebitCardsHistory = function(cardId, data, opts, cb) {
|
||||||
storageService.getBitpayDebitCardsHistory(bitpayService.getEnvironment(), function(err, oldData) {
|
storageService.getBitpayDebitCardsHistory(bitpayService.getEnvironment().network, function(err, oldData) {
|
||||||
if (lodash.isString(oldData)) {
|
if (lodash.isString(oldData)) {
|
||||||
oldData = JSON.parse(oldData);
|
oldData = JSON.parse(oldData);
|
||||||
}
|
}
|
||||||
|
|
@ -172,19 +172,19 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
||||||
}
|
}
|
||||||
inv = JSON.stringify(inv);
|
inv = JSON.stringify(inv);
|
||||||
|
|
||||||
storageService.setBitpayDebitCardsHistory(bitpayService.getEnvironment(), inv, function(err) {
|
storageService.setBitpayDebitCardsHistory(bitpayService.getEnvironment().network, inv, function(err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.remove = function(card, cb) {
|
root.remove = function(card, cb) {
|
||||||
storageService.removeBitpayDebitCard(bitpayService.getEnvironment(), card, function(err) {
|
storageService.removeBitpayDebitCard(bitpayService.getEnvironment().network, card, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
$log.error('Error removing BitPay debit card: ' + err);
|
$log.error('Error removing BitPay debit card: ' + err);
|
||||||
// Continue, try to remove/cleanup card history
|
// Continue, try to remove/cleanup card history
|
||||||
}
|
}
|
||||||
storageService.removeBitpayDebitCardHistory(bitpayService.getEnvironment(), card, function(err) {
|
storageService.removeBitpayDebitCardHistory(bitpayService.getEnvironment().network, card, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
$log.error('Error removing BitPay debit card transaction history: ' + err);
|
$log.error('Error removing BitPay debit card transaction history: ' + err);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ angular.module('copayApp.services').factory('bitpayService', function($log, $htt
|
||||||
var BITPAY_API_URL = NETWORK == 'livenet' ? 'https://bitpay.com' : 'https://test.bitpay.com';
|
var BITPAY_API_URL = NETWORK == 'livenet' ? 'https://bitpay.com' : 'https://test.bitpay.com';
|
||||||
|
|
||||||
root.getEnvironment = function() {
|
root.getEnvironment = function() {
|
||||||
return NETWORK;
|
return {
|
||||||
|
network: NETWORK
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -58,7 +60,7 @@ angular.module('copayApp.services').factory('bitpayService', function($log, $htt
|
||||||
code: pairData.otp
|
code: pairData.otp
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
appIdentityService.getIdentity(root.getEnvironment(), function(err, appIdentity) {
|
appIdentityService.getIdentity(root.getEnvironment().network, function(err, appIdentity) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
$http(_postAuth('/api/v2/', json, appIdentity)).then(function(data) {
|
$http(_postAuth('/api/v2/', json, appIdentity)).then(function(data) {
|
||||||
if (data && data.data.error) return cb(data.data.error);
|
if (data && data.data.error) return cb(data.data.error);
|
||||||
|
|
@ -132,7 +134,7 @@ angular.module('copayApp.services').factory('bitpayService', function($log, $htt
|
||||||
|
|
||||||
var setBitpayAccount = function(accountData, cb) {
|
var setBitpayAccount = function(accountData, cb) {
|
||||||
var data = JSON.stringify(accountData);
|
var data = JSON.stringify(accountData);
|
||||||
storageService.setBitpayAccount(root.getEnvironment(), data, function(err) {
|
storageService.setBitpayAccount(root.getEnvironment().network, data, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
return cb();
|
return cb();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -728,7 +728,13 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getAppIdentity = function(network, cb) {
|
root.getAppIdentity = function(network, cb) {
|
||||||
storage.get('appIdentity-' + network, cb);
|
storage.get('appIdentity-' + network, function(err, data) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
if (lodash.isString(data)) {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
}
|
||||||
|
cb(err, data);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.removeAppIdentity = function(network, cb) {
|
root.removeAppIdentity = function(network, cb) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue