mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
[FIX] from_human 'XRP' with full name
from_human 'XRP - Ripples' should result in native XRP
This commit is contained in:
@@ -71,12 +71,9 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
|
|||||||
switch (typeof j) {
|
switch (typeof j) {
|
||||||
case 'string':
|
case 'string':
|
||||||
|
|
||||||
if (!j || /^(0|XRP)$/.test(j)) {
|
// if an empty string is given, fall back to XRP
|
||||||
if (shouldInterpretXrpAsIou) {
|
if (!j) {
|
||||||
this.parse_hex(Currency.HEX_CURRENCY_BAD);
|
this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO);
|
||||||
} else {
|
|
||||||
this.parse_hex(Currency.HEX_ZERO);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +83,17 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
|
|||||||
if (matches) {
|
if (matches) {
|
||||||
|
|
||||||
var currencyCode = matches[1];
|
var currencyCode = matches[1];
|
||||||
|
|
||||||
|
// for the currency 'XRP' case
|
||||||
|
// we drop everything else that could have been provided
|
||||||
|
// e.g. 'XRP - Ripple'
|
||||||
|
if (!currencyCode || /^(0|XRP)$/.test(currencyCode)) {
|
||||||
|
this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO);
|
||||||
|
|
||||||
|
// early break, we can't have interest on XRP
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// the full currency is matched as it is part of the valid currency format, but not stored
|
// the full currency is matched as it is part of the valid currency format, but not stored
|
||||||
// var full_currency = matches[2] || '';
|
// var full_currency = matches[2] || '';
|
||||||
var interest = matches[3] || '';
|
var interest = matches[3] || '';
|
||||||
|
|||||||
@@ -16,11 +16,22 @@ describe('Currency', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('from_json', function() {
|
describe('from_json', function() {
|
||||||
|
it('from_json().to_json() == "XRP"', function() {
|
||||||
|
var r = currency.from_json();
|
||||||
|
assert(!r.is_valid());
|
||||||
|
assert.strictEqual('XRP', r.to_json());
|
||||||
|
});
|
||||||
it('from_json(NaN).to_json() == "XRP"', function() {
|
it('from_json(NaN).to_json() == "XRP"', function() {
|
||||||
var r = currency.from_json(NaN);
|
var r = currency.from_json(NaN);
|
||||||
assert(!r.is_valid());
|
assert(!r.is_valid());
|
||||||
assert.strictEqual('XRP', r.to_json());
|
assert.strictEqual('XRP', r.to_json());
|
||||||
});
|
});
|
||||||
|
it('from_json().to_json("") == "XRP"', function() {
|
||||||
|
var r = currency.from_json('');
|
||||||
|
assert(r.is_valid());
|
||||||
|
assert(r.is_native());
|
||||||
|
assert.strictEqual('XRP', r.to_json());
|
||||||
|
});
|
||||||
it('from_json("XRP").to_json() == "XRP"', function() {
|
it('from_json("XRP").to_json() == "XRP"', function() {
|
||||||
var r = currency.from_json('XRP');
|
var r = currency.from_json('XRP');
|
||||||
assert(r.is_valid());
|
assert(r.is_valid());
|
||||||
@@ -103,6 +114,16 @@ describe('Currency', function() {
|
|||||||
var cur = currency.from_human('INR - 30 Indian Rupees');
|
var cur = currency.from_human('INR - 30 Indian Rupees');
|
||||||
assert.strictEqual(cur.to_json(), 'INR');
|
assert.strictEqual(cur.to_json(), 'INR');
|
||||||
});
|
});
|
||||||
|
it('From human "XRP"', function() {
|
||||||
|
var cur = currency.from_human('XRP');
|
||||||
|
assert.strictEqual(cur.to_json(), 'XRP');
|
||||||
|
assert(cur.is_native(), true);
|
||||||
|
});
|
||||||
|
it('From human "XRP - Ripples"', function() {
|
||||||
|
var cur = currency.from_human('XRP - Ripples');
|
||||||
|
assert.strictEqual(cur.to_json(), 'XRP');
|
||||||
|
assert(cur.is_native(), true);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user