From f70b9dca8a6a6ae6fa88ab28ba0fe592871ec504 Mon Sep 17 00:00:00 2001 From: Matias Pando Date: Tue, 25 Nov 2014 09:51:57 -0300 Subject: [PATCH] Checking for null values --- js/controllers/history.js | 17 +++++++++++++++-- js/models/Wallet.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/js/controllers/history.js b/js/controllers/history.js index af6bacbe1..34fba24a4 100644 --- a/js/controllers/history.js +++ b/js/controllers/history.js @@ -28,9 +28,15 @@ angular.module('copayApp.controllers').controller('HistoryController', $scope.generating = true; w.getTransactionHistory(function(err, res) { - if (err) throw err; + if (err) { + $scope.generating = false; + throw err; + } - if (!res) return; + if (!res) { + $scope.generating = false; + return; + } var unit = w.settings.unitName; var data = res.items; @@ -45,6 +51,13 @@ angular.module('copayApp.controllers').controller('HistoryController', } data.forEach(function(it, index) { + if (!it) { + console.log('Error on tx with index ', index); + return; + } else { + console.log('Txid with index ', it.txid, index); + + } var dataString = formatDate(it.minedTs || it.sentTs) + ',' + it.amount + ',' + it.action + ',' + formatString(it.addressTo) + ',' + formatString(it.comment); if (it.actionList) { dataString += ',' + formatSigners(it.actionList); diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 1414ddf8f..a4d604ff4 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -1368,7 +1368,31 @@ Wallet.prototype.generateAddress = function(isChange) { }; /** - * TODO: get this out of here + * @desc Retrieve all the Transaction proposals (see {@link TxProposals}) + * @return {Object[]} each object returned represents a transaction proposal, with two additional + * booleans: signedByUs and rejectedByUs. An optional third boolean signals + * whether the transaction was finally rejected (finallyRejected set to true). + */ +Wallet.prototype.getTxProposals = function() { + var ret = []; + var self = this; + var copayers = self.getRegisteredCopayerIds(); + var myId = self.getMyCopayerId(); + + _.each(self.txProposals.txps, function(txp, ntxid) { + txp.signedByUs = txp.signedBy[myId] ? true : false; + txp.rejectedByUs = txp.rejectedBy[self.getMyCopayerId()] ? true : false; + txp.finallyRejected = self.totalCopayers - txp.rejectCount < self.requiredCopayers; + txp.isPending = !txp.finallyRejected && !txp.sentTxid; + + if (!txp.readonly || txp.finallyRejected || txp.sentTs) { + ret.push(txp); + } + }); + return ret; +}; + +/** * @desc get list of actions (see {@link getPendingTxProposals}) */ Wallet.prototype._getActionList = function(txp) { @@ -2568,6 +2592,7 @@ Wallet.prototype.getTransactionHistory = function(opts, cb) { function extractInsOuts(tx) { // Inputs + console.log('extractInsOuts'); var inputs = _.map(tx.vin, function(item) { return { type: 'in', @@ -2690,8 +2715,11 @@ Wallet.prototype.getTransactionHistory = function(opts, cb) { self.blockchain.getTransactions(addresses, from, to, function(err, res) { if (err) return cb(err); + console.log(res.items); _.each(res.items, function(tx) { - decorateTx(tx); + if (tx) { + decorateTx(tx); + } }); return cb(null, paginate(res, opts.currentPage, opts.itemsPerPage));