From 3fff14cdd26be01c22a84b7080aa2a482c85d80a Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Thu, 7 Mar 2013 11:38:51 +0100 Subject: [PATCH] JS: Fix for multiple Account instances (which caused multiple subscriptions.) --- src/js/account.js | 2 ++ src/js/remote.js | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/js/account.js b/src/js/account.js index 59eb95c91..2e1121e5d 100644 --- a/src/js/account.js +++ b/src/js/account.js @@ -1,5 +1,7 @@ // Routines for working with an account. // +// You should not instantiate this class yourself, instead use Remote#account. +// // Events: // wallet_clean : True, iff the wallet has been updated. // wallet_dirty : True, iff the wallet needs to be updated. diff --git a/src/js/remote.js b/src/js/remote.js index fa9e4ba51..75622411a 100644 --- a/src/js/remote.js +++ b/src/js/remote.js @@ -1111,11 +1111,17 @@ Remote.prototype.request_owner_count = function (account, current) { }; Remote.prototype.account = function (accountId) { - var account = new Account(this, accountId); + accountId = UInt160.json_rewrite(accountId); - if (!account.is_valid()) return account; + if (!this._accounts[accountId]) { + var account = new Account(this, accountId); - return this._accounts[account.to_json()] = account; + if (!account.is_valid()) return account; + + this._accounts[accountId] = account; + } + + return this._accounts[accountId]; }; Remote.prototype.book = function (currency_out, issuer_out, @@ -1130,7 +1136,7 @@ Remote.prototype.book = function (currency_out, issuer_out, // Return the next account sequence if possible. // <-- undefined or Sequence Remote.prototype.account_seq = function (account, advance) { - var account = UInt160.json_rewrite(account); + account = UInt160.json_rewrite(account); var account_info = this.accounts[account]; var seq;