mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
JS: Fix Amount#equals and Amount#not_equals_why to pass all tests.
This commit is contained in:
@@ -283,21 +283,29 @@ Amount.prototype.currency = function () {
|
|||||||
return this._currency;
|
return this._currency;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check BigInteger NaN
|
|
||||||
// Checks currency, does not check issuer.
|
|
||||||
Amount.prototype.equals = function (d) {
|
Amount.prototype.equals = function (d) {
|
||||||
return 'string' === typeof (d)
|
if ("string" === typeof d) {
|
||||||
? this.equals(Amount.from_json(d))
|
return this.equals(Amount.from_json(d));
|
||||||
: this === d
|
}
|
||||||
|| (d instanceof Amount
|
|
||||||
&& this._is_native === d._is_native
|
if (this === d) return true;
|
||||||
&& (this._is_native
|
|
||||||
? this._value.equals(d._value)
|
if (d instanceof Amount) {
|
||||||
: this._currency.equals(d._currency)
|
if (!this.is_valid() || !d.is_valid()) return false;
|
||||||
? this._is_negative === d._is_negative
|
if (this._is_native !== d._is_native) return false;
|
||||||
? this._value.equals(d._value)
|
|
||||||
: this._value.equals(BigInteger.ZERO) && d._value.equals(BigInteger.ZERO)
|
if (!this._value.equals(d._value) || this._offset !== d._offset) {
|
||||||
: false));
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._is_negative !== d._is_negative) return false;
|
||||||
|
|
||||||
|
if (!this._is_native) {
|
||||||
|
if (!this._currency.equals(d._currency)) return false;
|
||||||
|
if (!this._issuer.equals(d._issuer)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Result in terms of this' currency and issuer.
|
// Result in terms of this' currency and issuer.
|
||||||
@@ -910,27 +918,30 @@ Amount.prototype.to_text_full = function (opts) {
|
|||||||
|
|
||||||
// For debugging.
|
// For debugging.
|
||||||
Amount.prototype.not_equals_why = function (d) {
|
Amount.prototype.not_equals_why = function (d) {
|
||||||
return 'string' === typeof (d)
|
if ("string" === typeof d) {
|
||||||
? this.not_equals_why(Amount.from_json(d))
|
return this.not_equals_why(Amount.from_json(d));
|
||||||
: this === d
|
}
|
||||||
? false
|
|
||||||
: d instanceof Amount
|
if (this === d) return false;
|
||||||
? this._is_native === d._is_native
|
|
||||||
? this._is_native
|
if (d instanceof Amount) {
|
||||||
? this._value.equals(d._value)
|
if (!this.is_valid() || !d.is_valid()) return "Invalid amount.";
|
||||||
? false
|
if (this._is_native !== d._is_native) return "Native mismatch.";
|
||||||
: "XRP value differs."
|
|
||||||
: this._currency.equals(d._currency)
|
var type = this._is_native ? "XRP" : "Non-XRP";
|
||||||
? this._is_negative === d._is_negative
|
|
||||||
? this._value.equals(d._value)
|
if (!this._value.equals(d._value) || this._offset !== d._offset) {
|
||||||
? false
|
return type+" value differs.";
|
||||||
: this._value.equals(BigInteger.ZERO) && d._value.equals(BigInteger.ZERO)
|
}
|
||||||
? false
|
|
||||||
: "Non-XRP value differs."
|
if (this._is_negative !== d._is_negative) return type+" sign differs.";
|
||||||
: "Non-XRP sign differs."
|
|
||||||
: "Non-XRP currency differs (" + JSON.stringify(this._currency) + "/" + JSON.stringify(d._currency) + ")"
|
if (!this._is_native) {
|
||||||
: "Native mismatch"
|
if (!this._currency.equals(d._currency)) return "Non-XRP currency differs.";
|
||||||
: "Wrong constructor."
|
if (!this._issuer.equals(d._issuer)) return "Non-XRP issuer differs.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else return "Wrong constructor.";
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.Amount = Amount;
|
exports.Amount = Amount;
|
||||||
|
|||||||
Reference in New Issue
Block a user