copay/js/controllers/history.js

123 lines
3.1 KiB
JavaScript
Raw Normal View History

2014-03-26 05:18:42 -07:00
'use strict';
2014-06-12 13:42:26 -07:00
var bitcore = require('bitcore');
2014-03-26 05:18:42 -07:00
2014-10-30 10:13:40 -07:00
angular.module('copayApp.controllers').controller('HistoryController',
function($scope, $rootScope, $filter, rateService) {
var w = $rootScope.wallet;
2014-10-30 14:17:41 -07:00
$rootScope.title = 'History';
2014-04-24 18:43:19 -07:00
$scope.loading = false;
2014-11-12 12:54:18 -08:00
$scope.generating = false;
$scope.lastShowed = false;
2014-11-10 05:40:03 -08:00
$scope.currentPage = 1;
$scope.itemsPerPage = 10;
$scope.nbPages = 0;
2014-11-10 14:10:24 -08:00
$scope.totalItems = 0;
$scope.blockchain_txs = [];
$scope.alternativeCurrency = [];
2014-11-10 14:10:24 -08:00
$scope.selectPage = function(page) {
$scope.currentPage = page;
$scope.update();
};
2014-11-10 13:00:43 -08:00
$scope.downloadHistory = function() {
var w = $rootScope.wallet;
if (!w) return;
2014-11-11 06:19:08 -08:00
2014-11-12 12:54:18 -08:00
$scope.generating = true;
2014-11-11 06:19:08 -08:00
//getTransactionHistoryCSV
2014-11-11 06:19:08 -08:00
w.getTransactionHistoryCsv(function() {
2014-11-12 12:54:18 -08:00
$scope.generating = false;
$scope.$digest();
2014-11-11 07:29:10 -08:00
2014-11-19 10:47:28 -08:00
})
2014-11-10 13:00:43 -08:00
};
2014-11-19 10:47:28 -08:00
$scope.update = function() {
$scope.getTransactions();
};
$scope.show = function() {
$scope.loading = true;
setTimeout(function() {
$scope.update();
2014-11-10 05:40:03 -08:00
}, 1);
};
2014-11-10 05:40:03 -08:00
$scope.getTransactions = function() {
var w = $rootScope.wallet;
2014-10-22 09:10:41 -07:00
if (!w) return;
2014-10-22 12:57:29 -07:00
$scope.blockchain_txs = w.cached_txs || [];
$scope.loading = true;
2014-10-30 12:20:25 -07:00
2014-11-10 05:40:03 -08:00
w.getTransactionHistory({
currentPage: $scope.currentPage,
itemsPerPage: $scope.itemsPerPage,
}, function(err, res) {
2014-10-22 09:10:41 -07:00
if (err) throw err;
if (!res) {
$scope.loading = false;
$scope.lastShowed = false;
return;
2014-04-24 19:13:55 -07:00
}
2014-10-22 09:10:41 -07:00
2014-11-10 05:40:03 -08:00
var items = res.items;
<<<<<<< HEAD
2014-11-28 06:23:08 -08:00
var now = new Date();
_.each(items, function(tx) {
tx.ts = tx.minedTs || tx.sentTs;
2014-11-28 06:23:08 -08:00
tx.rateTs = Math.floor((tx.ts || now) / 1000);
tx.amount = $filter('noFractionNumber')(tx.amount);
=======
_.each(items, function(r, index) {
r.ts = r.minedTs || r.sentTs;
>>>>>>> Move function getTransactionHistoryCsv to wallet
});
2014-11-10 05:40:03 -08:00
2014-11-28 06:23:08 -08:00
var index = _.indexBy(items, 'rateTs');
rateService.getHistoricRates(w.settings.alternativeIsoCode, _.keys(index), function(err, res) {
if (!err && res) {
_.each(res, function(r) {
var tx = index[r.ts];
var alternativeAmount = (r.rate != null ? tx.amountSat * rateService.SAT_TO_BTC * r.rate : null);
tx.alternativeAmount = alternativeAmount ? $filter('noFractionNumber')(alternativeAmount, 2) : null;
});
setTimeout(function() {
$scope.$digest();
}, 1);
}
2014-10-30 12:46:39 -07:00
});
2014-11-25 10:09:51 -08:00
2014-11-10 05:40:03 -08:00
$scope.blockchain_txs = w.cached_txs = items;
$scope.nbPages = res.nbPages;
2014-11-10 14:10:24 -08:00
$scope.totalItems = res.nbItems;
2014-11-10 05:40:03 -08:00
2014-10-22 09:10:41 -07:00
$scope.loading = false;
2014-10-27 13:16:24 -07:00
setTimeout(function() {
$scope.$digest();
}, 1);
2014-10-22 09:10:41 -07:00
});
};
2014-10-22 09:10:41 -07:00
$scope.hasAction = function(actions, action) {
return actions.hasOwnProperty('create');
};
$scope.getShortNetworkName = function() {
var w = $rootScope.wallet;
2014-09-11 11:25:32 -07:00
return w.getNetworkName().substring(0, 4);
};
2014-10-30 12:20:25 -07:00
2014-03-26 05:18:42 -07:00
});