mirror of https://github.com/BTCPrivate/copay.git
Adds CSV history
This commit is contained in:
parent
6a94f55dc8
commit
46ff73aa02
|
@ -445,7 +445,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div ng-show="index.txHistory[0]" class="scroll">
|
<div ng-show="index.txHistory[0]" class="scroll oh">
|
||||||
<div ng-repeat="btx in index.txHistory"
|
<div ng-repeat="btx in index.txHistory"
|
||||||
ng-click="home.openTxModal(btx)"
|
ng-click="home.openTxModal(btx)"
|
||||||
class="row collapse last-transactions-content">
|
class="row collapse last-transactions-content">
|
||||||
|
@ -495,6 +495,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="m20t text-center">
|
||||||
|
<a class="text-gray" ng-click="index.csvHistory();">
|
||||||
|
<i class="fi-page-export-csv"></i>
|
||||||
|
<span translate>Download CSV file</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<div class="extra-margin-bottom"></div>
|
<div class="extra-margin-bottom"></div>
|
||||||
</div> <!-- END History -->
|
</div> <!-- END History -->
|
||||||
|
|
||||||
|
|
|
@ -535,6 +535,76 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.csvHistory = function() {
|
||||||
|
|
||||||
|
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 '';
|
||||||
|
|
||||||
|
if (str.indexOf('"') !== -1) {
|
||||||
|
//replace all
|
||||||
|
str = str.replace(new RegExp('"', 'g'), '\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
//escaping commas
|
||||||
|
str = '\"' + str + '\"';
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCordova) {
|
||||||
|
log.info('Not available on mobile');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var fc = profileService.focusedClient;
|
||||||
|
if (!fc.isComplete()) return;
|
||||||
|
var self = this;
|
||||||
|
$log.debug('Generating CSV from History');
|
||||||
|
self.setOngoingProcess('generatingCSV', true);
|
||||||
|
$timeout(function() {
|
||||||
|
fc.getTxHistory({
|
||||||
|
skip: 0,
|
||||||
|
limit: 1000000000
|
||||||
|
}, function(err, txs) {
|
||||||
|
self.setOngoingProcess('generatingCSV', false);
|
||||||
|
if (err) {
|
||||||
|
$log.debug('TxHistory ERROR:', err);
|
||||||
|
} else {
|
||||||
|
$log.debug('Wallet Transaction History:', txs);
|
||||||
|
|
||||||
|
self.satToUnit = 1 / self.unitToSatoshi;
|
||||||
|
var data = txs;
|
||||||
|
var filename = "copay_history.csv";
|
||||||
|
var csvContent = "data:text/csv;charset=utf-8,";
|
||||||
|
csvContent += "Date,Amount (" + self.unitName + "),Action,AddressTo,Comment\n";
|
||||||
|
|
||||||
|
data.forEach(function(it, index) {
|
||||||
|
var dataString = formatDate(it.time * 1000) + ',' + strip(it.amount * self.satToUnit) + ',' + it.action + ',' + formatString(it.addressTo) + ',' + formatString(it.message);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
$rootScope.$apply();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
self.clientError = function(err) {
|
self.clientError = function(err) {
|
||||||
if (isCordova) {
|
if (isCordova) {
|
||||||
|
|
|
@ -1054,7 +1054,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
if (confirmed)
|
if (confirmed)
|
||||||
self._doSendAll(amount);
|
self._doSendAll(amount);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/* Start setup */
|
/* Start setup */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue