From 894223a47f444c8cc0b7d0ae58d06d6d79f41b80 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Mon, 22 Aug 2016 17:43:31 -0300 Subject: [PATCH] BitPay card. Fix initial wallet home --- public/views/bitpayCard.html | 246 ++++++++---------- .../modals/bitpay-card-confirmation.html | 34 +-- public/views/preferencesBitpayCard.html | 34 +-- public/views/tab-home.html | 17 +- src/js/controllers/bitpayCard.js | 16 +- .../modals/bitpayCardConfirmation.js | 4 +- src/js/controllers/tab-home.js | 15 +- src/js/routes.js | 27 +- src/js/services/bitpayCardService.js | 21 +- 9 files changed, 208 insertions(+), 206 deletions(-) diff --git a/public/views/bitpayCard.html b/public/views/bitpayCard.html index d760655e7..b52acfb2d 100644 --- a/public/views/bitpayCard.html +++ b/public/views/bitpayCard.html @@ -1,32 +1,21 @@ -
-
- -
- -
- -
- +
Sandbox version. Only for testing purpose
@@ -34,16 +23,15 @@ Loading...
-
-
-
+
+
-

+

Login to your account 2-Step Verification -

-
+
{{bitpayCard.error}} @@ -55,37 +43,30 @@ ng-submit="bitpayCard.authenticate()" novalidate> - +
+ - - -
- +
+ +

@@ -98,27 +79,22 @@ ng-submit="bitpayCard.authenticate2FA()" novalidate> -

- -
- - -
- +
+
+ + -
@@ -134,7 +110,7 @@
@@ -158,19 +134,19 @@
- +
-
+
-
+
{{tx.merchant.name}}
@@ -180,14 +156,14 @@
+ class="col"> {{desc}}
-
+
-
+
-
+
@@ -211,41 +186,38 @@ ng-submit="bitpayCard.sendFunds()" novalidate> -

Next steps

    -
  • +
  • BitPay Card
  • diff --git a/src/js/controllers/bitpayCard.js b/src/js/controllers/bitpayCard.js index e4d35f8f0..4e1897d28 100644 --- a/src/js/controllers/bitpayCard.js +++ b/src/js/controllers/bitpayCard.js @@ -5,8 +5,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi var self = this; var client; - var network = 'livenet'; - self.sandbox = network == 'testnet' ? true : false; + self.sandbox = bitpayCardService.getEnvironment() == 'testnet' ? true : false; if (platformInfo.isCordova && StatusBar.isVisible) { StatusBar.backgroundColorByHexString("#293C92"); @@ -71,7 +70,6 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi this.update = function() { var dateRange = setDateRange($scope.dateRange); self.loadingSession = true; - bitpayCardService.setCredentials(network); bitpayCardService.isAuthenticated(function(err, bpSession) { self.loadingSession = false; if (err) { @@ -110,14 +108,16 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi $scope.dateRange = 'last30Days'; self.update(); - self.allWallets = profileService.getWallets(network); - client = profileService.focusedClient; - - if (!client) return; + var network = bitpayCardService.getEnvironment(); + self.allWallets = profileService.getWallets({ + network: network, + n: 1, + onlyComplete: true + }); if (lodash.isEmpty(self.allWallets)) return; - if (client.credentials.network != network) return; + client = self.allWallets[0]; if (client.credentials.n > 1) self.isMultisigWallet = true; diff --git a/src/js/controllers/modals/bitpayCardConfirmation.js b/src/js/controllers/modals/bitpayCardConfirmation.js index 2ac75c25f..6dafd872d 100644 --- a/src/js/controllers/modals/bitpayCardConfirmation.js +++ b/src/js/controllers/modals/bitpayCardConfirmation.js @@ -1,10 +1,10 @@ 'use strict'; -angular.module('copayApp.controllers').controller('bitpayCardConfirmationController', function($scope, $timeout, go, bitpayCardService) { +angular.module('copayApp.controllers').controller('bitpayCardConfirmationController', function($scope, $timeout, $location, bitpayCardService) { $scope.ok = function() { bitpayCardService.logout(function() { - go.path('bitpayCard'); + $location.path('/bitpayCard/main'); }); $scope.cancel(); }; diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index eefe6259f..fe3687958 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -4,7 +4,9 @@ angular.module('copayApp.controllers').controller('tabHomeController', function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo) { var self = this; - self.glideraEnabled = configService.getSync().glidera.enabled; + self.setWallets = function() { + $scope.wallets = profileService.getWallets(); + }; var setPendingTxps = function(txps) { @@ -108,7 +110,7 @@ angular.module('copayApp.controllers').controller('tabHomeController', if (err) { console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO return; - } + } if (status.pendingTxps && status.pendingTxps[0]) { var txps = lodash.filter($scope.txps, function(x) { return x.walletId != wallet.id; @@ -136,14 +138,13 @@ angular.module('copayApp.controllers').controller('tabHomeController', c1(); }); - var config = configService.getSync().wallet; - var GLIDERA_LOCK_TIME = 6 * 60 * 60; var glideraActive = true; // TODO TODO TODO // isGlidera flag is a security measure so glidera status is not // only determined by the tx.message $scope.openTxpModal = function(tx) { + var config = configService.getSync().wallet; var scope = $rootScope.$new(true); scope.tx = tx; scope.wallet = tx.wallet; @@ -159,12 +160,12 @@ angular.module('copayApp.controllers').controller('tabHomeController', }); }; - $scope.init = function() { + configService.whenAvailable(function() { var config = configService.getSync(); - var isWindowsPhoneApp = platformInfo.isWP && isCordova; var glideraEnabled = config.glidera.enabled; var coinbaseEnabled = config.coinbase.enabled; + var isWindowsPhoneApp = platformInfo.isWP && isCordova; $scope.buyAndSellEnabled = !isWindowsPhoneApp && (glideraEnabled || coinbaseEnabled); - } + }); }); diff --git a/src/js/routes.js b/src/js/routes.js index eea2d4994..5c1e95d18 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -85,7 +85,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr * */ - .state('disclaimer', { + .state('disclaimer', { url: '/disclaimer', templateUrl: 'views/disclaimer.html', }) @@ -557,13 +557,26 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr * */ - .state('bitpayCard', { - url: '/bitpay-card', - templateUrl: 'views/bitpayCard.html' + .state('bitpayCard', { + url: '/bitpayCard', + abstract: true, + template: '' }) - .state('preferencesBitpayCard', { - url: '/preferences-bitpay-card', - templateUrl: 'views/preferencesBitpayCard.html' + .state('bitpayCard.main', { + url: '/main', + views: { + 'bitpayCard': { + templateUrl: 'views/bitpayCard.html' + } + } + }) + .state('bitpayCard.preferences', { + url: '/preferences', + views: { + 'bitpayCard': { + templateUrl: 'views/preferencesBitpayCard.html' + } + } }) /* diff --git a/src/js/services/bitpayCardService.js b/src/js/services/bitpayCardService.js index 6abbb1fcc..7a0368cb5 100644 --- a/src/js/services/bitpayCardService.js +++ b/src/js/services/bitpayCardService.js @@ -5,9 +5,13 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http, var credentials = {}; var bpSession = {}; - root.setCredentials = function(network) { - credentials.NETWORK = network; - if (network == 'testnet') { + var _setCredentials = function() { + /* + * Development: 'testnet' + * Production: 'livenet' + */ + credentials.NETWORK = 'livenet'; + if (credentials.NETWORK == 'testnet') { credentials.BITPAY_API_URL = 'https://test.bitpay.com'; } else { @@ -16,6 +20,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http, }; var _getUser = function(cb) { + _setCredentials(); storageService.getBitpayCard(credentials.NETWORK, function(err, user) { if (err) return cb(err); if (lodash.isString(user)) { @@ -26,6 +31,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http, }; var _setUser = function(user, cb) { + _setCredentials(); user = JSON.stringify(user); storageService.setBitpayCard(credentials.NETWORK, user, function(err) { return cb(err); @@ -33,6 +39,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http, }; var _getSession = function(cb) { + _setCredentials(); $http({ method: 'GET', url: credentials.BITPAY_API_URL + '/visa-api/session', @@ -50,6 +57,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http, }; var _getBitPay = function(endpoint) { + _setCredentials(); return { method: 'GET', url: credentials.BITPAY_API_URL + endpoint, @@ -61,6 +69,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http, }; var _postBitPay = function(endpoint, data) { + _setCredentials(); return { method: 'POST', url: credentials.BITPAY_API_URL + endpoint, @@ -72,6 +81,11 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http, }; }; + root.getEnvironment = function() { + _setCredentials(); + return credentials.NETWORK; + }; + root.topUp = function(data, cb) { var dataSrc = { amount: data.amount, @@ -173,6 +187,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http, }; root.logout = function(cb) { + _setCredentials(); storageService.removeBitpayCard(credentials.NETWORK, function(err) { $http(_getBitPay('/visa-api/logout')).then(function(data) { $log.info('BitPay Logout: SUCCESS');