JS: Add to_human_full and support for gateways to addresses.

This commit is contained in:
Arthur Britto
2013-02-02 01:32:00 -08:00
committed by Stefan Thomas
parent 72448737d6
commit 70d556b4a1
4 changed files with 36 additions and 4 deletions

View File

@@ -737,7 +737,7 @@ Amount.prototype.to_text = function (allow_nan) {
{
return "0";
}
else if (this._offset < -25 || this._offset > -4)
else if (this._offset && (this._offset < -25 || this._offset > -4))
{
// Use e notation.
// XXX Clamp output.
@@ -832,6 +832,27 @@ Amount.prototype.to_human = function (opts)
return formatted;
};
Amount.prototype.to_human_full = function (opts) {
opts = opts || {};
var a = this.to_human(opts);
var c = this._currency.to_human(opts);
var i = this._issuer.to_json();
var o;
if (this._is_native)
{
o = a + "/" + c;
}
else
{
o = a + "/" + c + "/" + i;
}
return o;
};
Amount.prototype.to_json = function () {
if (this._is_native) {
return this.to_text();
@@ -849,11 +870,11 @@ Amount.prototype.to_json = function () {
}
};
Amount.prototype.to_text_full = function () {
Amount.prototype.to_text_full = function (opts) {
return this._value instanceof BigInteger
? this._is_native
? this.to_text() + "/XRP"
: this.to_text() + "/" + this._currency.to_json() + "/" + this._issuer.to_json()
: this.to_text() + "/" + this._currency.to_json() + "/" + this._issuer.to_json(opts)
: NaN;
};

View File

@@ -79,3 +79,5 @@ Currency.prototype.to_human = function () {
};
exports.Currency = Currency;
// vim:sw=2:sts=2:ts=8:et

View File

@@ -219,3 +219,5 @@ UInt.prototype.to_bn = function () {
};
exports.UInt = UInt;
// vim:sw=2:sts=2:ts=8:et

View File

@@ -51,13 +51,20 @@ UInt160.prototype.parse_json = function (j) {
};
// XXX Json form should allow 0 and 1, C++ doesn't currently allow it.
UInt160.prototype.to_json = function () {
UInt160.prototype.to_json = function (opts) {
opts = opts || {};
if (!(this._value instanceof BigInteger))
return NaN;
var output = Base.encode_check(Base.VER_ACCOUNT_ID, this.to_bytes());
if (opts.gateways && output in opts.gateways)
output = opts.gateways[output];
return output;
};
exports.UInt160 = UInt160;
// vim:sw=2:sts=2:ts=8:et