From f8fb16563026d66e0c9508cd880423d90a3d53f6 Mon Sep 17 00:00:00 2001 From: Matias Pando Date: Tue, 11 Nov 2014 17:56:12 -0300 Subject: [PATCH] Using getTransactionHistory from wallet --- js/controllers/history.js | 76 +++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/js/controllers/history.js b/js/controllers/history.js index 6cdee8a9f..18c17359b 100644 --- a/js/controllers/history.js +++ b/js/controllers/history.js @@ -33,42 +33,52 @@ angular.module('copayApp.controllers').controller('HistoryController', log.info('Not available on mobile'); return; } + var w = $rootScope.wallet; + if (!w) return; - var data = $scope.blockchain_txs; - var filename = "copay_history.csv"; - var csvContent = "data:text/csv;charset=utf-8,Date,Amount,Action,AddressTo,Comment\n"; + var data = w.getTransactionHistory(null, function(err, res) { + if (err) throw err; - data.forEach(function(it, index) { - var dataString = formatDate(it.ts) + ',' + it.amount + ',' + it.action + ',' + it.addressTo + ',' + formatString(it.comment); - csvContent += index < data.length ? dataString + "\n" : dataString; + if (!res) { + return; + } + + var data = res.items; + var filename = "copay_history.csv"; + var csvContent = "data:text/csv;charset=utf-8,Date,Amount,Action,AddressTo,Comment\n"; + + 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; + }); + + var encodedUri = encodeURI(csvContent); + var link = document.createElement("a"); + link.setAttribute("href", encodedUri); + link.setAttribute("download", filename); + + link.click(); + + + 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; + } }); - var encodedUri = encodeURI(csvContent); - var link = document.createElement("a"); - link.setAttribute("href", encodedUri); - link.setAttribute("download", filename); - - link.click(); - - - 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; - } }; @@ -122,8 +132,6 @@ angular.module('copayApp.controllers').controller('HistoryController', $scope.hasAction = function(actions, action) { - - return actions.hasOwnProperty('create'); };