diff --git a/src/js/controllers/bitpayCard.js b/src/js/controllers/bitpayCard.js index a0357c77a..4c154bd9b 100644 --- a/src/js/controllers/bitpayCard.js +++ b/src/js/controllers/bitpayCard.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('bitpayCardController', function($scope, $timeout, $log, $state, lodash, bitpayCardService, moment, popupService, gettextCatalog, $ionicHistory, bitpayService) { +angular.module('copayApp.controllers').controller('bitpayCardController', function($scope, $timeout, $log, $state, lodash, bitpayCardService, moment, popupService, gettextCatalog, $ionicHistory, bitpayService, externalLinkService) { var self = this; var runningBalance; @@ -37,15 +37,15 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi var setGetStarted = function(history, cb) { // Is the card new? - if (!lodash.isEmpty(history.transactionList)) + if (!lodash.isEmpty(history.transactionList)) return cb(); var dateRange = setDateRange('all'); bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) { - if (!err && lodash.isEmpty(history.transactionList)) - self.getStated=true; - + if (!err && lodash.isEmpty(history.transactionList)) + self.getStarted = true; + return cb(); }); }; @@ -60,7 +60,11 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi if (err) { $log.error(err); - self.bitpayCardTransactionHistory = null; + self.bitpayCardTransactionHistoryCompleted = null; + self.bitpayCardTransactionHistoryConfirming = null; + self.bitpayCardTransactionHistoryPreAuth = null; + self.underpaidInvoiceInList = null; + self.delayedInvoiceInList = null; self.balance = null; popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not get transactions')); return; @@ -84,7 +88,26 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi txs[i].merchant.location = txs[i].merchant.city || txs[i].merchant.state || ''; } } - self.bitpayCardTransactionHistory = txs; + self.bitpayCardTransactionHistoryCompleted = lodash.filter(txs, function(tx) { + return !tx.pending && tx.type.indexOf('93') == -1; + }); + self.bitpayCardTransactionHistoryConfirming = lodash.filter(txs, function(tx) { + return tx.pending; + }); + self.bitpayCardTransactionHistoryPreAuth = lodash.includes(txs, function(tx) { + return tx.type.indexOf('93') > -1; + }); + + lodash.forEach(self.bitpayCardTransactionHistoryConfirming, function(tx) { + if (lodash.includes(tx, 'paidPartial')) + self.underpaidInvoiceInList = true; + }); + + lodash.forEach(self.bitpayCardTransactionHistoryConfirming, function(tx) { + if (lodash.includes(tx, 'paid') || lodash.includes(tx, 'invalid')) + self.delayedInvoiceInList = true; + }); + self.balance = history.currentCardBalance; self.updatedOn = null; @@ -132,13 +155,33 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi }; var _price = function(tx) { - return parseFloat(tx.amount) + parseFloat(tx.fee) + var price = tx.fee ? parseFloat(tx.amount) + parseFloat(tx.fee) : parseFloat(tx.amount); + return price; }; var _runningBalance = function(tx) { runningBalance -= parseFloat(tx.amount); }; + this.openExternalLink = function(url) { + var optIn = true; + var title = null; + var message = gettextCatalog.getString('Help and support information is available at the website.'); + var okText = gettextCatalog.getString('Open'); + var cancelText = gettextCatalog.getString('Go Back'); + externalLinkService.open(url, optIn, title, message, okText, cancelText); + }; + + this.viewOnBlockchain = function(transactionId) { + var url = 'https://insight.bitpay.com/tx/' + transactionId; + var optIn = true; + var title = null; + var message = gettextCatalog.getString('View Transaction on Insight'); + var okText = gettextCatalog.getString('Open Insight'); + var cancelText = gettextCatalog.getString('Go Back'); + externalLinkService.open(url, optIn, title, message, okText, cancelText); + }; + $scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.cardId = data.stateParams.id; @@ -149,7 +192,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi $state.go('tabs.home'); } - + bitpayCardService.get({ cardId: $scope.cardId, noRefresh: true, diff --git a/src/js/services/bitpayCardService.js b/src/js/services/bitpayCardService.js index 7858513a7..2c22ffe53 100644 --- a/src/js/services/bitpayCardService.js +++ b/src/js/services/bitpayCardService.js @@ -31,7 +31,9 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log, amount: invoices[i].price, type: '00611 = Client Funded Deposit', pending: true, - status: invoices[i].status + status: invoices[i].status, + transactionId: invoices[i].transactions && invoices[i].transactions[0] ? invoices[i].transactions[0].txid : '', + exceptionStatus: invoices[i].exceptionStatus }); } } diff --git a/src/sass/views/bitpayCard.scss b/src/sass/views/bitpayCard.scss index 81414d66f..7db9296dd 100644 --- a/src/sass/views/bitpayCard.scss +++ b/src/sass/views/bitpayCard.scss @@ -7,6 +7,23 @@ @extend .deflash-blue; background: white; + .status-label { + font-size: 14px; + font-weight: 300; + color: #727272; + padding: 2px 1rem; + background: #f8f8f9; + } + + .comment { + padding: 15px; + background: #f8f8f9; + font-weight: bold; + font-size:0.9em; + color: $v-mid-gray; + display: inline-block; + } + .spinner svg { stroke: #0067c8; fill: #0067c8; diff --git a/www/views/bitpayCard.html b/www/views/bitpayCard.html index 69a45028f..f3c2ead30 100644 --- a/www/views/bitpayCard.html +++ b/www/views/bitpayCard.html @@ -46,12 +46,23 @@ class="text-center padding get-started" ng-show="bitpayCard.getStarted"> -