fix double transactions

This commit is contained in:
Sonata Green 2016-08-20 16:52:31 -05:00
parent d8182c084c
commit 955db5fcfc

View file

@ -131,6 +131,7 @@ var WalletPage = React.createClass({
if (results.length == 0) { if (results.length == 0) {
out = 'No transactions yet.'; out = 'No transactions yet.';
} else { } else {
var condensedTransactions = {};
var rows = []; var rows = [];
rows.push(<tr className="transaction_history"> rows.push(<tr className="transaction_history">
<th className="transaction_history">Amount</th> <th className="transaction_history">Amount</th>
@ -139,18 +140,29 @@ var WalletPage = React.createClass({
<th className="transaction_history">Transaction</th> <th className="transaction_history">Transaction</th>
</tr>); </tr>);
results.forEach(function(tx) { results.forEach(function(tx) {
rows.push(<tr className="transaction_history"> var txid = tx["txid"];
<td className="transaction_history">{ (tx["amount"]>0 ? '+' : '' ) + tx["amount"] }</td> if (!(txid in condensedTransactions)) {
<td className="transaction_history">{ (new Date(parseInt(tx["time"])*1000)).toLocaleTimeString() }</td> condensedTransactions[txid] = 0;
<td className="transaction_history">{ (new Date(parseInt(tx["time"])*1000)).toLocaleDateString() }</td> }
<td className="transaction_history"> condensedTransactions[txid] += parseFloat(tx["amount"]);
<a className="transaction_explorer_link" href={"https://explorer.lbry.io/tx/"+tx["txid"]}>
{ tx["txid"] }
</a>
</td>
</tr>)
}); });
out = <table className="transaction_history">{rows}</table> results.forEach(function(tx) {
var txid = tx["txid"];
var txval = condensedTransactions[txid];
var txdate = new Date(parseInt(tx["time"])*1000);
if (txid in condensedTransactions && txval != 0) {
rows.push(<tr key={txid} className="transaction_history">
<td className="transaction_history">{ (txval>0 ? '+' : '' ) + txval }</td>
<td className="transaction_history">{ txdate.toLocaleTimeString() }</td>
<td className="transaction_history">{ txdate.toLocaleDateString() }</td>
<td className="transaction_history">
<a className="transaction_explorer_link" href={"https://explorer.lbry.io/tx/"+txid}>{txid}</a>
</td>
</tr>);
delete condensedTransactions[tx["txid"]];
}
});
out = <table className="transaction_history"><tbody>{rows}</tbody></table>
} }
this.setState({ this.setState({
txlog: out, txlog: out,