From 51c07823695b175615146359c469d309a8dea175 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Fri, 23 Nov 2012 18:30:43 -0800 Subject: [PATCH] JS: Add is_valid() for UInt160 and Currency. --- src/js/amount.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/js/amount.js b/src/js/amount.js index 5f5f58e3..f3e6d310 100644 --- a/src/js/amount.js +++ b/src/js/amount.js @@ -217,6 +217,10 @@ UInt160.prototype.to_json = function () { return output; }; +UInt160.prototype.is_valid = function () { + return !isNaN(this_value); +}; + // XXX Internal form should be UInt160. var Currency = function () { // Internal form: 0 = XRP. 3 letter-code. @@ -272,6 +276,10 @@ Currency.prototype.parse_json = function(j) { return this; }; +Currency.prototype.is_valid = function () { + return !isNaN(this_value); +}; + Currency.prototype.to_json = function () { return this._value ? this._value : "XRP"; }; @@ -484,9 +492,9 @@ Amount.prototype.parse_native = function(j) { if (m[1]) this._value = this._value.negate(); - this._is_native = true; - this._offset = undefined; - this._is_negative = undefined; + this._is_native = true; + this._offset = undefined; + this._is_negative = undefined; if (this._value.compareTo(exports.consts.bi_xns_max) > 0 || this._value.compareTo(exports.consts.bi_xns_min) < 0) {