ripple-lib-value
Version:
Classes for dealing with XRP Ledger amount values
48 lines • 1.69 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const value_1 = require("./value");
const IOUNumber = bignumber_js_1.default.clone({
ROUNDING_MODE: bignumber_js_1.default.ROUND_HALF_UP,
DECIMAL_PLACES: 40
});
const xrpUnits = new IOUNumber(1e6);
class XRPValue extends value_1.Value {
constructor(value) {
super(value);
if (this._value.dp() > 6) {
throw new Error('Value has more than 6 digits of precision past the decimal point, '
+ 'an IOUValue may be being cast to an XRPValue');
}
}
multiply(multiplicand) {
if (multiplicand instanceof XRPValue) {
return super.multiply(new XRPValue(multiplicand._value.times(xrpUnits)));
}
return super.multiply(multiplicand);
}
divide(divisor) {
if (divisor instanceof XRPValue) {
return super.divide(new XRPValue(divisor._value.times(xrpUnits)));
}
return super.divide(divisor);
}
negate() {
return new XRPValue(this._value.negated());
}
_canonicalize(value) {
if (value.isNaN()) {
throw new Error('Invalid result');
}
return new XRPValue(value.decimalPlaces(6, bignumber_js_1.default.ROUND_DOWN));
}
equals(comparator) {
return (comparator instanceof XRPValue)
&& this._value.isEqualTo(comparator._value);
}
}
exports.XRPValue = XRPValue;
//# sourceMappingURL=xrpvalue.js.map
;