From 1e3c96b14ff676cf1dbea760f61218a8d8fa6537 Mon Sep 17 00:00:00 2001 From: wltsmrz Date: Tue, 15 Apr 2014 12:27:33 -0700 Subject: [PATCH] Fix transaction finalize --- src/js/ripple/transaction.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/js/ripple/transaction.js b/src/js/ripple/transaction.js index fb00bec3..4a9cc1d6 100644 --- a/src/js/ripple/transaction.js +++ b/src/js/ripple/transaction.js @@ -81,23 +81,16 @@ function Transaction(remote) { // any time it goes on the network this.submittedIDs = [ ]; - function finalize(message) { - if (!self.finalized) { - self.finalized = true; - self.emit('cleanup', message); - } - }; - this.once('success', function(message) { - self.finalized = true; self.setState('validated'); - finalize(message); + self.finalize(message); + self.emit('cleanup', message); }); this.once('error', function(message) { - self.finalized = true; self.setState('failed'); - finalize(message); + self.finalize(message); + self.emit('cleanup', message); }); this.once('submitted', function() { @@ -207,6 +200,20 @@ Transaction.prototype.setState = function(state) { } }; +Transaction.prototype.finalize = function(message) { + this.finalized = true; + + if (this.result) { + this.result.ledger_index = message.ledger_index; + this.result.ledger_hash = message.ledger_hash; + } else { + this.result = message; + this.result.tx_json = this.tx_json; + } + + return this; +}; + Transaction.prototype._accountSecret = function(account) { return this.remote.secrets[account]; };