From 222fbe57ff31dbcca1b79589ce4739d0c38c9be3 Mon Sep 17 00:00:00 2001
From: Gustavo Maximiliano Cortez
Date: Fri, 7 Oct 2016 19:21:46 -0300
Subject: [PATCH] Bitpay card config external json
---
package.json | 1 +
src/js/controllers/bitpayCardIntro.js | 7 +++--
src/js/services/bitpayCardService.js | 21 ++++++++++---
src/js/services/incomingData.js | 1 +
util/buildExternalServices.js | 4 +++
www/views/bitpayCardIntro.html | 45 +++++++++++++++++++++++++++
www/views/tab-home.html | 2 +-
7 files changed, 73 insertions(+), 8 deletions(-)
create mode 100644 www/views/bitpayCardIntro.html
diff --git a/package.json b/package.json
index c690d4989..4d770f788 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
"angular-mocks": "1.4.10",
"bezier-easing": "^2.0.3",
"bhttp": "^1.2.1",
+ "bitauth": "^0.3.2",
"bitcore-wallet-client": "4.3.1",
"bower": "^1.7.9",
"chai": "^3.5.0",
diff --git a/src/js/controllers/bitpayCardIntro.js b/src/js/controllers/bitpayCardIntro.js
index 09ea1a96c..fe87e4c4e 100644
--- a/src/js/controllers/bitpayCardIntro.js
+++ b/src/js/controllers/bitpayCardIntro.js
@@ -1,5 +1,5 @@
'use strict';
-angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $state, $timeout, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService) {
+angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $log, $state, $timeout, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService) {
var checkOtp = function(obj, cb) {
if (obj.otp) {
@@ -48,7 +48,10 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
});
});
} else {
- // TODO
+ // TEST TODO
+ bitpayCardService.testSession(function(err, session) {
+ if (err) $log.error(err);
+ });
}
/*
diff --git a/src/js/services/bitpayCardService.js b/src/js/services/bitpayCardService.js
index 7c91bc8a4..3b4c1f7f8 100644
--- a/src/js/services/bitpayCardService.js
+++ b/src/js/services/bitpayCardService.js
@@ -1,24 +1,29 @@
'use strict';
-angular.module('copayApp.services').factory('bitpayCardService', function($http, $log, lodash, storageService, bitauthService, platformInfo) {
+angular.module('copayApp.services').factory('bitpayCardService', function($http, $log, $window, lodash, storageService, bitauthService, platformInfo) {
var root = {};
var credentials = {};
var bpSession = {};
var pubkey, sin;
var _setCredentials = function() {
+ if (!$window.externalServices || !$window.externalServices.bitpayCard) {
+ return;
+ }
+
+ var bitpayCard = $window.externalServices.bitpayCard;
/*
* Development: 'testnet'
* Production: 'livenet'
*/
credentials.NETWORK = 'livenet';
if (credentials.NETWORK == 'testnet') {
- credentials.BITPAY_PRIV_KEY = '';
- credentials.BITPAY_API_URL = 'https://test.bitpay.com';
+ credentials.BITPAY_PRIV_KEY = bitpayCard.sandbox.secret;
+ credentials.BITPAY_API_URL = bitpayCard.sandbox.host;
}
else {
- credentials.BITPAY_PRIV_KEY = '';
- credentials.BITPAY_API_URL = 'https://bitpay.com';
+ credentials.BITPAY_PRIV_KEY = bitpayCard.production.secret;
+ credentials.BITPAY_API_URL = bitpayCard.production.host;
}
try {
pubkey = bitauthService.getPublicKeyFromPrivateKey(credentials.BITPAY_PRIV_KEY);
@@ -87,6 +92,12 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
return credentials.BITPAY_API_URL;
};
+ root.testSession = function(cb) {
+ _getSession(function(err, session) {
+ return cb(err, session);
+ });
+ };
+
var _postBitAuth = function(endpoint, data) {
var dataToSign = credentials.BITPAY_API_URL + endpoint + JSON.stringify(data);
var signedData = bitauthService.sign(dataToSign, credentials.BITPAY_PRIV_KEY);
diff --git a/src/js/services/incomingData.js b/src/js/services/incomingData.js
index 33c2de8a9..53a3c483b 100644
--- a/src/js/services/incomingData.js
+++ b/src/js/services/incomingData.js
@@ -70,6 +70,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
// Plain URL
} else if (/^https?:\/\//.test(data)) {
+ if ($state.current.name == 'tabs.bitpayCardIntro' || $state.current.name == 'tabs.buyandsell.glidera') return false;
$state.go('tabs.send');
$timeout(function() {
$state.transitionTo('tabs.send.confirm', {paypro: data});
diff --git a/util/buildExternalServices.js b/util/buildExternalServices.js
index 630d03609..68a338bad 100755
--- a/util/buildExternalServices.js
+++ b/util/buildExternalServices.js
@@ -24,6 +24,10 @@ if (externalServices.glidera &&
if (externalServices.glidera &&
(externalServices.glidera.sandbox.mobile.client_id || externalServices.glidera.sandbox.desktop.client_id))
console.log('Glidera Sandbox Enabled');
+if (externalServices.bitpayCard && externalServices.bitpayCard.production.secret)
+ console.log('BitPay Card Production Enabled');
+if (externalServices.bitpayCard && externalServices.bitpayCard.sandbox.secret)
+ console.log('BitPay Card Sandbox Enabled');
var content = 'window.externalServices=' + JSON.stringify(externalServices) + ';';
fs.writeFileSync("./src/js/externalServices.js", content);
diff --git a/www/views/bitpayCardIntro.html b/www/views/bitpayCardIntro.html
new file mode 100644
index 000000000..7b42f3611
--- /dev/null
+++ b/www/views/bitpayCardIntro.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Turn bitcoin into dollars, swipe anywhere Visa® is accepted.
+
+
+
+
+ Get local cash anywhere you go, from any Visa®-compatible ATM.
+
+ *ATM bank fees may apply
+
+
+
+
+
+ Pay 0% fees to turn bitcoin into dollars.
+
+
+
+
+
+
+
+
+
diff --git a/www/views/tab-home.html b/www/views/tab-home.html
index a072aa704..e1754c82e 100644
--- a/www/views/tab-home.html
+++ b/www/views/tab-home.html
@@ -104,7 +104,7 @@