2016-08-10 15:29:31 -03:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
2016-10-06 19:23:39 -03:00
|
|
|
|
angular.module('copayApp.controllers').controller('bitpayCardController', function($scope, $timeout, $log, $state, lodash, bitpayCardService, configService, profileService, walletService, ongoingProcess, moment, popupService, gettextCatalog, bwcError, $ionicHistory) {
|
2016-08-10 15:29:31 -03:00
|
|
|
|
|
|
|
|
|
|
var self = this;
|
2016-09-28 21:09:41 -03:00
|
|
|
|
$scope.dateRange = 'last30Days';
|
|
|
|
|
|
$scope.network = bitpayCardService.getEnvironment();
|
|
|
|
|
|
|
2016-10-06 19:23:39 -03:00
|
|
|
|
/*
|
2016-09-28 21:09:41 -03:00
|
|
|
|
bitpayCardService.getCacheData(function(err, data) {
|
|
|
|
|
|
if (err || lodash.isEmpty(data)) return;
|
|
|
|
|
|
self.bitpayCardTransactionHistory = data.transactions;
|
|
|
|
|
|
self.bitpayCardCurrentBalance = data.balance;
|
2016-08-29 17:01:34 -03:00
|
|
|
|
});
|
2016-10-06 19:23:39 -03:00
|
|
|
|
*/
|
2016-08-10 15:29:31 -03:00
|
|
|
|
|
|
|
|
|
|
var setDateRange = function(preset) {
|
|
|
|
|
|
var startDate, endDate;
|
|
|
|
|
|
preset = preset || 'last30Days';
|
|
|
|
|
|
switch(preset) {
|
|
|
|
|
|
case 'last30Days':
|
|
|
|
|
|
startDate = moment().subtract(30, 'days').toISOString();
|
|
|
|
|
|
endDate = moment().toISOString();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 'lastMonth':
|
|
|
|
|
|
startDate = moment().startOf('month').subtract(1, 'month').toISOString();
|
|
|
|
|
|
endDate = moment().startOf('month').toISOString();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 'all':
|
|
|
|
|
|
startDate = null;
|
|
|
|
|
|
endDate = null;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
|
|
|
startDate: startDate,
|
|
|
|
|
|
endDate: endDate
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.update = function() {
|
|
|
|
|
|
var dateRange = setDateRange($scope.dateRange);
|
|
|
|
|
|
|
2016-10-06 19:23:39 -03:00
|
|
|
|
$scope.loadingHistory = true;
|
|
|
|
|
|
bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) {
|
|
|
|
|
|
$scope.loadingHistory = false;
|
|
|
|
|
|
if (err || history.error) {
|
|
|
|
|
|
$log.error(err || history.error);
|
|
|
|
|
|
$scope.error = gettextCatalog.getString('Could not get transactions');
|
2016-08-10 15:29:31 -03:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-06 19:23:39 -03:00
|
|
|
|
self.bitpayCardTransactionHistory = history.transactionList;
|
|
|
|
|
|
self.bitpayCardCurrentBalance = history.currentCardBalance;
|
2016-08-10 15:29:31 -03:00
|
|
|
|
|
2016-10-06 19:23:39 -03:00
|
|
|
|
var cacheData = {
|
|
|
|
|
|
balance: self.bitpayCardCurrentBalance,
|
|
|
|
|
|
transactions: self.bitpayCardTransactionHistory
|
|
|
|
|
|
};
|
2016-08-10 15:29:31 -03:00
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.getMerchantInfo = function(tx) {
|
|
|
|
|
|
var bpTranCodes = bitpayCardService.bpTranCodes;
|
|
|
|
|
|
lodash.keys(bpTranCodes).forEach(function(code) {
|
|
|
|
|
|
if (tx.type.indexOf(code) === 0) {
|
|
|
|
|
|
lodash.assign(tx, bpTranCodes[code]);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.getIconName = function(tx) {
|
|
|
|
|
|
var icon = tx.mcc || tx.category || null;
|
|
|
|
|
|
if (!icon) return 'default';
|
|
|
|
|
|
return bitpayCardService.iconMap[icon];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.processDescription = function(tx) {
|
|
|
|
|
|
if (lodash.isArray(tx.description)) {
|
|
|
|
|
|
return tx.description[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
return tx.description;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-10-06 19:23:39 -03:00
|
|
|
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
|
|
|
|
|
$scope.cardId = data.stateParams.id;
|
|
|
|
|
|
if (!$scope.cardId) {
|
|
|
|
|
|
var msg = gettextCatalog.getString('Bad param');
|
|
|
|
|
|
$ionicHistory.nextViewOptions({
|
|
|
|
|
|
disableAnimate: true
|
|
|
|
|
|
});
|
|
|
|
|
|
$state.go('tabs.home');
|
|
|
|
|
|
popupService.showAlert(null, msg);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
self.update();
|
|
|
|
|
|
}
|
2016-09-28 11:08:08 -03:00
|
|
|
|
});
|
|
|
|
|
|
|
2016-08-10 15:29:31 -03:00
|
|
|
|
});
|
|
|
|
|
|
|