diff --git a/js/models/Wallet.js b/js/models/Wallet.js index bf8a593fc..c9aa01342 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -2543,85 +2543,6 @@ Wallet.prototype.isComplete = function() { return this.publicKeyRing.isComplete(); }; -/** - * @desc Return a list of transactions on CSV format - * @return {Object} the list of transactions on CSV format - */ -Wallet.prototype.getTransactionHistoryCsv = function(cb) { - var self = this; - self.getTransactionHistory(function(err, res) { - preconditions.checkState(res); - if (err) { - log.warn(err); - return cb(new Error('TXHISTORY: ' + err.toString())); - } - - var unit = self.settings.unitName; - var data = res.items; - - var csvContent = "data:text/csv;charset=utf-8,"; - csvContent += "Date,Amount(" + unit + "),Action,AddressTo,Comment"; - - if (self.isShared()) { - csvContent += ",Signers\n"; - } else { - csvContent += "\n"; - } - - data.forEach(function(it, index) { - if (!it) { - return cb(new Error('TXHISTORY: The item is null')); - } - var dataString = formatDate(it.minedTs || it.sentTs) + ',' + it.amount + ',' + it.action + ',' + formatString(it.addressTo) + ',' + formatString(it.comment); - if (self.isShared() && it.actionList) { - dataString += ',' + formatSigners(it.actionList); - } - csvContent += index < data.length ? dataString + "\n" : dataString; - }); - - - - return cb(csvContent); - - function formatDate(date) { - var dateObj = new Date(date); - if (!dateObj) { - log.warn('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; - } - - function formatSigners(item) { - if (!item) return ''; - var str = ''; - item.forEach(function(it, index) { - str += index == 0 ? self.publicKeyRing.nicknameForCopayer(it.cId) : '|' + self.publicKeyRing.nicknameForCopayer(it.cId); - }); - return str; - } - - }); - -} /** * @desc Sets the version of this wallet object diff --git a/test/Wallet.js b/test/Wallet.js index 74d5be787..39fcb4718 100644 --- a/test/Wallet.js +++ b/test/Wallet.js @@ -2469,76 +2469,6 @@ describe('Wallet model', function() { }); }); - describe('#getTransactionHistoryCsv', function() { - it('should return list of txs', function(done) { - var w = cachedCreateW2(); - var txs = [{ - vin: [{ - addr: 'in_1', - valueSat: 1000 - }], - vout: [{ - scriptPubKey: { - addresses: ['out_1'], - }, - value: '0.00000900', - }], - fees: 0.00000100 - }, { - vin: [{ - addr: 'in_2', - valueSat: 2000 - }], - vout: [{ - scriptPubKey: { - addresses: ['out_2'], - }, - value: '0.00001900', - }], - fees: 0.00000100 - }, { - vin: [{ - addr: 'in_3', - valueSat: 3000 - - }], - vout: [{ - scriptPubKey: { - addresses: ['out_3'], - }, - value: '0.00002900', - - }], - fees: 0.00000100 - }]; - - w.blockchain.getTransactions = sinon.stub().yields(null, { - items: txs, - totalItems: txs.length, - }); - - sinon.stub(w, 'getAddresses').returns(['in_1', 'in_2', 'in_3', 'out_1', 'out_2', 'out_3']); - var s = sinon.stub(w.publicKeyRing, 'addressIsOwn'); - s.withArgs('in_1').returns(true); - s.withArgs('out_1').returns(false); - - s.withArgs('in_2').returns(false); - s.withArgs('out_2').returns(true); - - s.withArgs('in_3').returns(true); - s.withArgs('out_3').returns(true); - - - w.getTransactionHistoryCsv(function(data) { - data.should.exist; - data.should.equal('data:text/csv;charset=utf-8,Date,Amount(bits),Action,AddressTo,Comment,Signers\n,9,sent,"out_1",\n,0,moved,"out_2",\n,29,sent,"out_3",\n'); - done(); - }); - }); - - }); - - describe.skip('#read', function() { var network, blockchain;