2014-03-26 09:18:42 -03:00
|
|
|
'use strict';
|
2014-06-12 17:42:26 -03:00
|
|
|
var bitcore = require('bitcore');
|
2014-03-26 09:18:42 -03:00
|
|
|
|
2014-10-30 14:13:40 -03:00
|
|
|
angular.module('copayApp.controllers').controller('HistoryController',
|
2014-09-24 02:13:56 -03:00
|
|
|
function($scope, $rootScope, $timeout, controllerUtils, notification, rateService) {
|
2014-10-10 17:58:19 -03:00
|
|
|
controllerUtils.redirIfNotComplete();
|
|
|
|
|
|
2014-09-04 11:12:08 -03:00
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
|
2014-10-30 18:17:41 -03:00
|
|
|
$rootScope.title = 'History';
|
2014-04-24 22:43:19 -03:00
|
|
|
$scope.loading = false;
|
2014-05-17 01:19:52 -03:00
|
|
|
$scope.lastShowed = false;
|
2014-04-25 17:53:19 -03:00
|
|
|
|
2014-11-10 10:40:03 -03:00
|
|
|
$scope.currentPage = 1;
|
|
|
|
|
$scope.itemsPerPage = 10;
|
|
|
|
|
$scope.nbPages = 0;
|
2014-11-10 19:10:24 -03:00
|
|
|
$scope.totalItems = 0;
|
2014-06-03 16:54:09 -03:00
|
|
|
$scope.blockchain_txs = [];
|
2014-09-24 02:13:56 -03:00
|
|
|
$scope.alternativeCurrency = [];
|
2014-05-20 11:14:52 -07:00
|
|
|
|
2014-11-10 19:10:24 -03:00
|
|
|
|
2014-11-10 18:00:43 -03:00
|
|
|
|
2014-11-10 19:10:24 -03:00
|
|
|
$scope.selectPage = function(page) {
|
|
|
|
|
$scope.currentPage = page;
|
|
|
|
|
$scope.update();
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-10 18:00:43 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
$scope.downloadHistory = function() {
|
2014-11-11 11:19:08 -03:00
|
|
|
|
|
|
|
|
if (window.cordova) {
|
|
|
|
|
log.info('Not available on mobile');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-11-11 17:56:12 -03:00
|
|
|
var w = $rootScope.wallet;
|
|
|
|
|
if (!w) return;
|
2014-11-11 11:19:08 -03:00
|
|
|
|
2014-11-11 17:56:12 -03:00
|
|
|
var data = w.getTransactionHistory(null, function(err, res) {
|
|
|
|
|
if (err) throw err;
|
2014-11-10 18:00:43 -03:00
|
|
|
|
2014-11-11 17:56:12 -03:00
|
|
|
if (!res) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-11-10 18:00:43 -03:00
|
|
|
|
2014-11-11 17:56:12 -03:00
|
|
|
var data = res.items;
|
|
|
|
|
var filename = "copay_history.csv";
|
|
|
|
|
var csvContent = "data:text/csv;charset=utf-8,Date,Amount,Action,AddressTo,Comment\n";
|
2014-11-10 18:00:43 -03:00
|
|
|
|
2014-11-11 17:56:12 -03:00
|
|
|
data.forEach(function(it, index) {
|
|
|
|
|
var dataString = formatDate(it.minedTs || it.sentTs) + ',' + it.amount + ',' + it.action + ',' + it.addressTo + ',' + formatString(it.comment);
|
|
|
|
|
csvContent += index < data.length ? dataString + "\n" : dataString;
|
|
|
|
|
});
|
2014-11-11 11:19:08 -03:00
|
|
|
|
2014-11-11 17:56:12 -03:00
|
|
|
var encodedUri = encodeURI(csvContent);
|
|
|
|
|
var link = document.createElement("a");
|
|
|
|
|
link.setAttribute("href", encodedUri);
|
|
|
|
|
link.setAttribute("download", filename);
|
2014-11-11 11:19:08 -03:00
|
|
|
|
2014-11-11 17:56:12 -03:00
|
|
|
link.click();
|
2014-11-11 12:29:10 -03:00
|
|
|
|
|
|
|
|
|
2014-11-11 17:56:12 -03:00
|
|
|
function formatDate(date) {
|
|
|
|
|
var dateObj = new Date(date);
|
|
|
|
|
if (!dateObj) {
|
|
|
|
|
log.error('Error formating a date');
|
|
|
|
|
return 'DateError'
|
|
|
|
|
}
|
|
|
|
|
if (!dateObj.toJSON()) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dateObj.toJSON().substring(0, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatString(str) {
|
|
|
|
|
if (!str) return '';
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-11-11 12:29:10 -03:00
|
|
|
|
2014-11-10 18:00:43 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-16 12:44:18 -03:00
|
|
|
$scope.update = function() {
|
2014-11-07 12:22:05 -03:00
|
|
|
$scope.getTransactions();
|
2014-05-16 18:33:06 -03:00
|
|
|
};
|
|
|
|
|
|
2014-08-06 13:59:33 -03:00
|
|
|
$scope.show = function() {
|
2014-06-16 12:44:18 -03:00
|
|
|
$scope.loading = true;
|
|
|
|
|
setTimeout(function() {
|
2014-05-17 01:19:52 -03:00
|
|
|
$scope.update();
|
2014-11-10 10:40:03 -03:00
|
|
|
}, 1);
|
2014-05-17 01:19:52 -03:00
|
|
|
};
|
|
|
|
|
|
2014-11-10 10:40:03 -03:00
|
|
|
$scope.getTransactions = function() {
|
2014-06-03 16:54:09 -03:00
|
|
|
var w = $rootScope.wallet;
|
2014-10-22 13:10:41 -03:00
|
|
|
if (!w) return;
|
|
|
|
|
|
2014-10-22 16:57:29 -03:00
|
|
|
$scope.blockchain_txs = w.cached_txs || [];
|
2014-06-03 16:54:09 -03:00
|
|
|
$scope.loading = true;
|
2014-10-30 16:20:25 -03:00
|
|
|
|
2014-11-10 10:40:03 -03:00
|
|
|
w.getTransactionHistory({
|
|
|
|
|
currentPage: $scope.currentPage,
|
|
|
|
|
itemsPerPage: $scope.itemsPerPage,
|
|
|
|
|
}, function(err, res) {
|
2014-10-22 13:10:41 -03:00
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
|
$scope.loading = false;
|
|
|
|
|
$scope.lastShowed = false;
|
|
|
|
|
return;
|
2014-04-24 23:13:55 -03:00
|
|
|
}
|
2014-10-22 13:10:41 -03:00
|
|
|
|
2014-11-10 10:40:03 -03:00
|
|
|
var items = res.items;
|
|
|
|
|
|
|
|
|
|
_.each(items, function(r) {
|
2014-10-30 16:46:39 -03:00
|
|
|
r.ts = r.minedTs || r.sentTs;
|
|
|
|
|
});
|
2014-11-10 10:40:03 -03:00
|
|
|
$scope.blockchain_txs = w.cached_txs = items;
|
|
|
|
|
$scope.nbPages = res.nbPages;
|
2014-11-10 19:10:24 -03:00
|
|
|
$scope.totalItems = res.nbItems;
|
2014-11-10 10:40:03 -03:00
|
|
|
|
|
|
|
|
|
2014-10-22 13:10:41 -03:00
|
|
|
$scope.loading = false;
|
2014-10-27 17:16:24 -03:00
|
|
|
setTimeout(function() {
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
}, 1);
|
2014-10-22 13:10:41 -03:00
|
|
|
});
|
2014-04-23 01:55:00 -03:00
|
|
|
};
|
|
|
|
|
|
2014-10-22 13:10:41 -03:00
|
|
|
|
2014-07-31 20:34:21 -03:00
|
|
|
$scope.hasAction = function(actions, action) {
|
|
|
|
|
return actions.hasOwnProperty('create');
|
2014-11-07 12:22:05 -03:00
|
|
|
};
|
2014-07-31 20:34:21 -03:00
|
|
|
|
2014-05-08 18:14:49 -03:00
|
|
|
$scope.getShortNetworkName = function() {
|
2014-10-30 16:38:08 -03:00
|
|
|
var w = $rootScope.wallet;
|
2014-09-11 11:25:32 -07:00
|
|
|
return w.getNetworkName().substring(0, 4);
|
2014-05-08 18:14:49 -03:00
|
|
|
};
|
2014-10-30 16:20:25 -03:00
|
|
|
|
2014-03-26 09:18:42 -03:00
|
|
|
});
|