Minor bug fixes. New bitauth method for getting token
This commit is contained in:
parent
8ee033436f
commit
c916babe25
6 changed files with 104 additions and 68 deletions
|
|
@ -3,7 +3,7 @@
|
|||
angular.module('copayApp.controllers').controller('bitpayCardController', function($scope, $timeout, $log, $state, lodash, bitpayCardService, moment, popupService, gettextCatalog, $ionicHistory) {
|
||||
|
||||
var self = this;
|
||||
$scope.dateRange = 'last30Days';
|
||||
$scope.dateRange = { value: 'last30Days'};
|
||||
$scope.network = bitpayCardService.getEnvironment();
|
||||
|
||||
var getFromCache = function(cb) {
|
||||
|
|
@ -42,7 +42,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
|||
};
|
||||
|
||||
this.update = function() {
|
||||
var dateRange = setDateRange($scope.dateRange);
|
||||
var dateRange = setDateRange($scope.dateRange.value);
|
||||
|
||||
$scope.loadingHistory = true;
|
||||
bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) {
|
||||
|
|
@ -53,39 +53,49 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
|||
return;
|
||||
}
|
||||
|
||||
self.bitpayCardTransactionHistory = history.txs;
|
||||
var txs = lodash.clone(history.txs);
|
||||
for (var i = 0; i < txs.length; i++) {
|
||||
txs[i] = _getMerchantInfo(txs[i]);
|
||||
txs[i].icon = _getIconName(txs[i]);
|
||||
txs[i].desc = _processDescription(txs[i]);
|
||||
}
|
||||
self.bitpayCardTransactionHistory = txs;
|
||||
self.bitpayCardCurrentBalance = history.currentCardBalance;
|
||||
|
||||
var cacheHistory = {
|
||||
balance: self.bitpayCardCurrentBalance,
|
||||
transactions: self.bitpayCardTransactionHistory
|
||||
};
|
||||
bitpayCardService.setBitpayDebitCardsHistory($scope.cardId, cacheHistory, {}, function(err) {
|
||||
if (err) $log.error(err);
|
||||
$scope.historyCached = true;
|
||||
});
|
||||
if ($scope.dateRange.value == 'last30Days') {
|
||||
$log.debug('BitPay Card: store cache history');
|
||||
var cacheHistory = {
|
||||
balance: history.currentCardBalance,
|
||||
transactions: history.txs
|
||||
};
|
||||
bitpayCardService.setBitpayDebitCardsHistory($scope.cardId, cacheHistory, {}, function(err) {
|
||||
if (err) $log.error(err);
|
||||
$scope.historyCached = true;
|
||||
});
|
||||
}
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.getMerchantInfo = function(tx) {
|
||||
var _getMerchantInfo = function(tx) {
|
||||
var bpTranCodes = bitpayCardService.bpTranCodes;
|
||||
lodash.keys(bpTranCodes).forEach(function(code) {
|
||||
if (tx.type.indexOf(code) === 0) {
|
||||
lodash.assign(tx, bpTranCodes[code]);
|
||||
}
|
||||
});
|
||||
return tx;
|
||||
};
|
||||
|
||||
this.getIconName = function(tx) {
|
||||
var _getIconName = function(tx) {
|
||||
var icon = tx.mcc || tx.category || null;
|
||||
if (!icon) return 'default';
|
||||
return bitpayCardService.iconMap[icon];
|
||||
};
|
||||
|
||||
this.processDescription = function(tx) {
|
||||
var _processDescription = function(tx) {
|
||||
if (lodash.isArray(tx.description)) {
|
||||
return tx.description[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -374,11 +374,22 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
};
|
||||
|
||||
$scope.onSuccessConfirm = function() {
|
||||
var previousView = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName;
|
||||
var fromBitPayCard = previousView.match(/tabs.bitpayCard/) ? true : false;
|
||||
|
||||
$ionicHistory.nextViewOptions({
|
||||
disableAnimate: true
|
||||
});
|
||||
$ionicHistory.removeBackView();
|
||||
$scope.sendStatus = '';
|
||||
$state.go('tabs.send');
|
||||
|
||||
if (fromBitPayCard) {
|
||||
$timeout(function() {
|
||||
$state.transitionTo('tabs.bitpayCard', {id: $stateParams.cardId});
|
||||
}, 100);
|
||||
} else {
|
||||
$state.go('tabs.send');
|
||||
}
|
||||
};
|
||||
|
||||
function publishAndSign(wallet, txp, onSendStatusChange) {
|
||||
|
|
|
|||
|
|
@ -203,11 +203,19 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
|||
|
||||
var bitpayCardCache = function() {
|
||||
bitpayCardService.getBitpayDebitCards(function(err, data) {
|
||||
if (err || lodash.isEmpty(data)) return;
|
||||
if (err) return;
|
||||
if (lodash.isEmpty(data)) {
|
||||
$scope.bitpayCards = null;
|
||||
return;
|
||||
}
|
||||
$scope.bitpayCards = data.cards;
|
||||
});
|
||||
bitpayCardService.getBitpayDebitCardsHistory(null, function(err, data) {
|
||||
if (err || lodash.isEmpty(data)) return;
|
||||
if (err) return;
|
||||
if (lodash.isEmpty(data)) {
|
||||
$scope.cardsHistory = null;
|
||||
return;
|
||||
}
|
||||
$scope.cardsHistory = data;
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue