diff --git a/src/js/ripple/currency.js b/src/js/ripple/currency.js index e5b27fd7..e2521510 100644 --- a/src/js/ripple/currency.js +++ b/src/js/ripple/currency.js @@ -313,16 +313,18 @@ Currency.prototype.to_json = function(opts) { return 'XRP'; } + var opts = opts || {}; + var currency; var fullName = opts && opts.full_name ? " - " + opts.full_name : ""; // Any currency with standard properties and a valid code can be abbreviated // in the JSON wire format as the three character code. - if (/^[A-Z0-9]{3}$/.test(this._iso_code) && !this.has_interest()) { + if (!opts.force_hex && /^[A-Z0-9]{3}$/.test(this._iso_code) && !this.has_interest()) { currency = this._iso_code + fullName; // If there is interest, append the annual interest to the full currency name - } else if (this.has_interest()) { + } else if (!opts.force_hex && this.has_interest()) { var decimals = opts ? opts.decimals : undefined; currency = this._iso_code + fullName + " (" + this.get_interest_percentage_at(this._interest_start + 3600 * 24 * 365, decimals) + "%pa)"; } else { diff --git a/test/currency-test.js b/test/currency-test.js index 65fc7879..e742017c 100644 --- a/test/currency-test.js +++ b/test/currency-test.js @@ -37,6 +37,22 @@ describe('Currency', function() { assert(!r.is_valid()); assert.strictEqual('XRP', r.to_json()); }); + it('from_json("XAU").to_json() hex', function() { + var r = currency.from_json("XAU"); + assert.strictEqual('0000000000000000000000005841550000000000', r.to_json({force_hex: true})); + }); + it('from_json("XAU (0.5%pa").to_json() hex', function() { + var r = currency.from_json("XAU (0.5%pa)"); + assert.strictEqual('015841550000000041F78E0A28CBF19200000000', r.to_json({force_hex: true})); + }); + it('json_rewrite("015841550000000041F78E0A28CBF19200000000").to_json() hex', function() { + var r = currency.json_rewrite('015841550000000041F78E0A28CBF19200000000'); + assert.strictEqual('XAU (0.5%pa)', r); + }); + it('json_rewrite("015841550000000041F78E0A28CBF19200000000") hex', function() { + var r = currency.json_rewrite('015841550000000041F78E0A28CBF19200000000', {force_hex: true}); + assert.strictEqual('015841550000000041F78E0A28CBF19200000000', r); + }); }); describe('from_human', function() {