mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
Use new Amount(NaN) rather than Amount.NaN()
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
/*eslint-disable new-cap*/
|
||||
|
||||
// Represent Ripple amounts and currencies.
|
||||
// - Numbers in hex are big-endian.
|
||||
|
||||
@@ -137,7 +135,7 @@ Amount.prototype.add = function(addend) {
|
||||
var addendAmount = Amount.from_json(addend);
|
||||
|
||||
if (!this.is_comparable(addendAmount)) {
|
||||
return Amount.NaN();
|
||||
return new Amount(NaN);
|
||||
}
|
||||
|
||||
return this._copy(this._value.plus(addendAmount._value));
|
||||
@@ -207,11 +205,11 @@ Amount.prototype.ratio_human = function(denominator, opts) {
|
||||
|
||||
// If either operand is NaN, the result is NaN.
|
||||
if (!numerator.is_valid() || !denominator.is_valid()) {
|
||||
return Amount.NaN();
|
||||
return new Amount(NaN);
|
||||
}
|
||||
|
||||
if (denominator.is_zero()) {
|
||||
return Amount.NaN();
|
||||
return new Amount(NaN);
|
||||
}
|
||||
|
||||
// Apply interest/demurrage
|
||||
@@ -267,7 +265,7 @@ Amount.prototype.product_human = function(factor, opts) {
|
||||
|
||||
// If either operand is NaN, the result is NaN.
|
||||
if (!this.is_valid() || !factor.is_valid()) {
|
||||
return Amount.NaN();
|
||||
return new Amount(NaN);
|
||||
}
|
||||
|
||||
// Apply interest/demurrage
|
||||
@@ -388,7 +386,7 @@ Amount.prototype._copy = function(value) {
|
||||
Amount.prototype.compareTo = function(to) {
|
||||
var toAmount = Amount.from_json(to);
|
||||
if (!this.is_comparable(toAmount)) {
|
||||
return Amount.NaN();
|
||||
return new Amount(NaN);
|
||||
}
|
||||
return this._value.comparedTo(toAmount._value);
|
||||
};
|
||||
@@ -507,7 +505,7 @@ Amount.prototype.parse_human = function(j, opts) {
|
||||
value = words[0].slice(0, -3);
|
||||
currency = words[0].slice(-3);
|
||||
if (!(isNumber(value) && currency.match(currency_RE))) {
|
||||
return Amount.NaN();
|
||||
return new Amount(NaN);
|
||||
}
|
||||
}
|
||||
} else if (words.length === 2) {
|
||||
@@ -521,10 +519,10 @@ Amount.prototype.parse_human = function(j, opts) {
|
||||
value = words[0];
|
||||
currency = words[1];
|
||||
} else {
|
||||
return Amount.NaN();
|
||||
return new Amount(NaN);
|
||||
}
|
||||
} else {
|
||||
return Amount.NaN();
|
||||
return new Amount(NaN);
|
||||
}
|
||||
|
||||
currency = currency.toUpperCase();
|
||||
|
||||
@@ -242,6 +242,37 @@ function serialize(so, field_name, value) {
|
||||
|
||||
exports.serialize = exports.serialize_whatever = serialize;
|
||||
|
||||
// Take the serialized object, figure out what type/field it is, and return the
|
||||
// parsing of that.
|
||||
|
||||
function parse(so) {
|
||||
var tag_byte = so.read(1)[0];
|
||||
var type_bits = tag_byte >> 4;
|
||||
|
||||
if (type_bits === 0) {
|
||||
type_bits = so.read(1)[0];
|
||||
}
|
||||
|
||||
var field_bits = tag_byte & 0x0f;
|
||||
var field_name = (field_bits === 0)
|
||||
? field_name = binformat.fields[type_bits][so.read(1)[0]]
|
||||
: field_name = binformat.fields[type_bits][field_bits];
|
||||
|
||||
assert(field_name, 'Unknown field - header byte is 0x'
|
||||
+ tag_byte.toString(16));
|
||||
|
||||
// Get the parser class (ST...) for a field based on the type bits.
|
||||
var type = (field_name === 'Memo')
|
||||
? exports.STMemo
|
||||
: exports[binformat.types[type_bits]];
|
||||
|
||||
assert(type, 'Unknown type - header byte is 0x' + tag_byte.toString(16));
|
||||
|
||||
return [field_name, type.parse(so)]; // key, value
|
||||
}
|
||||
|
||||
exports.parse = exports.parse_whatever = parse;
|
||||
|
||||
var STInt16 = exports.Int16 = new SerializedType({
|
||||
serialize: function (so, val) {
|
||||
so.append(convertIntegerToByteArray(val, 2));
|
||||
@@ -765,37 +796,6 @@ exports.STMemo = new SerializedType({
|
||||
|
||||
});
|
||||
|
||||
// Take the serialized object, figure out what type/field it is, and return the
|
||||
// parsing of that.
|
||||
|
||||
function parse(so) {
|
||||
var tag_byte = so.read(1)[0];
|
||||
var type_bits = tag_byte >> 4;
|
||||
|
||||
if (type_bits === 0) {
|
||||
type_bits = so.read(1)[0];
|
||||
}
|
||||
|
||||
var field_bits = tag_byte & 0x0f;
|
||||
var field_name = (field_bits === 0)
|
||||
? field_name = binformat.fields[type_bits][so.read(1)[0]]
|
||||
: field_name = binformat.fields[type_bits][field_bits];
|
||||
|
||||
assert(field_name, 'Unknown field - header byte is 0x'
|
||||
+ tag_byte.toString(16));
|
||||
|
||||
// Get the parser class (ST...) for a field based on the type bits.
|
||||
var type = (field_name === 'Memo')
|
||||
? exports.STMemo
|
||||
: exports[binformat.types[type_bits]];
|
||||
|
||||
assert(type, 'Unknown type - header byte is 0x' + tag_byte.toString(16));
|
||||
|
||||
return [field_name, type.parse(so)]; // key, value
|
||||
}
|
||||
|
||||
exports.parse = exports.parse_whatever = parse;
|
||||
|
||||
var STObject = exports.Object = new SerializedType({
|
||||
serialize: function (so, val, no_marker) {
|
||||
var keys = [];
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
/* eslint-disable no-spaced-func*/
|
||||
/* eslint-disable space-before-blocks*/
|
||||
/* eslint-disable space-unary-ops*/
|
||||
/* eslint-disable no-multi-spaces*/
|
||||
/* eslint-disable no-void*/
|
||||
/* eslint-disable semi*/
|
||||
/* eslint-disable no-unused-vars*/
|
||||
|
||||
Reference in New Issue
Block a user