mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
Currency: Behavior change for to_json for demurrage currencies.
Currency#to_json should output a format that can be successfully converted back to a Currency object via from_json. So for demurrage currencies it should output the full hex currency code. Currency#to_human on the other hand should always print something a human will understand. For demurrage currencies we'll print the three-letter code for now.
This commit is contained in:
@@ -193,11 +193,13 @@ Currency.prototype.get_interest_at = function (referenceDate) {
|
||||
|
||||
Currency.prototype.to_json = function () {
|
||||
if (!this.is_valid()) {
|
||||
// XXX This backwards compatible behavior, but probably not very good.
|
||||
// XXX This is backwards compatible behavior, but probably not very good.
|
||||
return "XRP";
|
||||
}
|
||||
|
||||
if (/^[A-Z0-9]{3}$/.test(this._iso_code)) {
|
||||
// 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()) {
|
||||
return this._iso_code;
|
||||
}
|
||||
|
||||
@@ -215,6 +217,11 @@ Currency.prototype.to_json = function () {
|
||||
};
|
||||
|
||||
Currency.prototype.to_human = function () {
|
||||
// to_human() will always print the human-readable currency code if available.
|
||||
if (/^[A-Z0-9]{3}$/.test(this._iso_code)) {
|
||||
return this._iso_code;
|
||||
}
|
||||
|
||||
return this.to_json();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user