mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-03-29 00:58:11 -04:00
bump to version v0.0.15, update dist
This commit is contained in:
parent
a7c5295cb0
commit
d430b4eb69
8
dist/HavenoClient.d.ts
vendored
8
dist/HavenoClient.d.ts
vendored
@ -310,13 +310,13 @@ export default class HavenoClient {
|
||||
*/
|
||||
relayXmrTx(metadata: string): Promise<string>;
|
||||
/**
|
||||
* Get all supported assets codes.
|
||||
* Get all asset codes with price information.
|
||||
*
|
||||
* TODO: replace this with getSupportedAssetCodes(): Promise<TradeCurrency[]>)
|
||||
*
|
||||
* @return {Promise<string[]>} all supported trade assets
|
||||
*/
|
||||
getSupportedAssetCodes(): Promise<string[]>;
|
||||
getPricedAssetCodes(): Promise<string[]>;
|
||||
/**
|
||||
* Get the current market price per 1 XMR in the given currency.
|
||||
*
|
||||
@ -360,10 +360,10 @@ export default class HavenoClient {
|
||||
/**
|
||||
* Get a form for the given payment method to complete and create a new payment account.
|
||||
*
|
||||
* @param {string} paymentMethodId - the id of the payment method
|
||||
* @param {string | PaymentAccountForm.FormId} paymentMethodId - the id of the payment method
|
||||
* @return {PaymentAccountForm} the payment account form
|
||||
*/
|
||||
getPaymentAccountForm(paymentMethodId: string): Promise<PaymentAccountForm>;
|
||||
getPaymentAccountForm(paymentMethodId: string | PaymentAccountForm.FormId): Promise<PaymentAccountForm>;
|
||||
/**
|
||||
* Get a form from the given payment account payload.
|
||||
*
|
||||
|
7
dist/HavenoClient.js
vendored
7
dist/HavenoClient.js
vendored
@ -729,13 +729,13 @@ class HavenoClient {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get all supported assets codes.
|
||||
* Get all asset codes with price information.
|
||||
*
|
||||
* TODO: replace this with getSupportedAssetCodes(): Promise<TradeCurrency[]>)
|
||||
*
|
||||
* @return {Promise<string[]>} all supported trade assets
|
||||
*/
|
||||
async getSupportedAssetCodes() {
|
||||
async getPricedAssetCodes() {
|
||||
const assetCodes = [];
|
||||
for (const price of await this.getPrices())
|
||||
assetCodes.push(price.getCurrencyCode());
|
||||
@ -837,11 +837,12 @@ class HavenoClient {
|
||||
/**
|
||||
* Get a form for the given payment method to complete and create a new payment account.
|
||||
*
|
||||
* @param {string} paymentMethodId - the id of the payment method
|
||||
* @param {string | PaymentAccountForm.FormId} paymentMethodId - the id of the payment method
|
||||
* @return {PaymentAccountForm} the payment account form
|
||||
*/
|
||||
async getPaymentAccountForm(paymentMethodId) {
|
||||
try {
|
||||
paymentMethodId = HavenoUtils_1.default.getPaymentMethodId(paymentMethodId); // validate and normalize
|
||||
return (await this._paymentAccountsClient.getPaymentAccountForm(new grpc_pb_1.GetPaymentAccountFormRequest().setPaymentMethodId(paymentMethodId), { password: this._password })).getPaymentAccountForm();
|
||||
}
|
||||
catch (e) {
|
||||
|
2
dist/HavenoClient.js.map
vendored
2
dist/HavenoClient.js.map
vendored
File diff suppressed because one or more lines are too long
18
dist/protobuf/pb_pb.d.ts
vendored
18
dist/protobuf/pb_pb.d.ts
vendored
@ -4552,9 +4552,6 @@ export namespace PopmoneyAccountPayload {
|
||||
}
|
||||
|
||||
export class RevolutAccountPayload extends jspb.Message {
|
||||
getAccountId(): string;
|
||||
setAccountId(value: string): RevolutAccountPayload;
|
||||
|
||||
getUserName(): string;
|
||||
setUserName(value: string): RevolutAccountPayload;
|
||||
|
||||
@ -4568,7 +4565,6 @@ export class RevolutAccountPayload extends jspb.Message {
|
||||
|
||||
export namespace RevolutAccountPayload {
|
||||
export type AsObject = {
|
||||
accountId: string,
|
||||
userName: string,
|
||||
}
|
||||
}
|
||||
@ -6754,8 +6750,8 @@ export class PreferencesPayload extends jspb.Message {
|
||||
getTacAccepted(): boolean;
|
||||
setTacAccepted(value: boolean): PreferencesPayload;
|
||||
|
||||
getUseTorForMonero(): boolean;
|
||||
setUseTorForMonero(value: boolean): PreferencesPayload;
|
||||
getUseTorForXmrOrdinal(): number;
|
||||
setUseTorForXmrOrdinal(value: number): PreferencesPayload;
|
||||
|
||||
getShowOwnOffersInOfferBook(): boolean;
|
||||
setShowOwnOffersInOfferBook(value: boolean): PreferencesPayload;
|
||||
@ -6942,7 +6938,7 @@ export namespace PreferencesPayload {
|
||||
autoSelectArbitrators: boolean,
|
||||
dontShowAgainMapMap: Array<[string, boolean]>,
|
||||
tacAccepted: boolean,
|
||||
useTorForMonero: boolean,
|
||||
useTorForXmrOrdinal: number,
|
||||
showOwnOffersInOfferBook: boolean,
|
||||
preferredTradeCurrency?: TradeCurrency.AsObject,
|
||||
withdrawalTxFeeInVbytes: number,
|
||||
@ -7354,11 +7350,6 @@ export namespace CryptoCurrency {
|
||||
}
|
||||
|
||||
export class TraditionalCurrency extends jspb.Message {
|
||||
getCurrency(): Currency | undefined;
|
||||
setCurrency(value?: Currency): TraditionalCurrency;
|
||||
hasCurrency(): boolean;
|
||||
clearCurrency(): TraditionalCurrency;
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): TraditionalCurrency.AsObject;
|
||||
static toObject(includeInstance: boolean, msg: TraditionalCurrency): TraditionalCurrency.AsObject;
|
||||
@ -7369,7 +7360,6 @@ export class TraditionalCurrency extends jspb.Message {
|
||||
|
||||
export namespace TraditionalCurrency {
|
||||
export type AsObject = {
|
||||
currency?: Currency.AsObject,
|
||||
}
|
||||
}
|
||||
|
||||
@ -7570,6 +7560,8 @@ export namespace PaymentAccountForm {
|
||||
FASTER_PAYMENTS = 10,
|
||||
UPHOLD = 11,
|
||||
PAXUM = 12,
|
||||
PAY_BY_MAIL = 13,
|
||||
CASH_AT_ATM = 14,
|
||||
}
|
||||
}
|
||||
|
||||
|
122
dist/protobuf/pb_pb.js
vendored
122
dist/protobuf/pb_pb.js
vendored
@ -38658,8 +38658,7 @@ proto.io.haveno.protobuffer.RevolutAccountPayload.prototype.toObject = function(
|
||||
*/
|
||||
proto.io.haveno.protobuffer.RevolutAccountPayload.toObject = function(includeInstance, msg) {
|
||||
var f, obj = {
|
||||
accountId: jspb.Message.getFieldWithDefault(msg, 1, ""),
|
||||
userName: jspb.Message.getFieldWithDefault(msg, 2, "")
|
||||
userName: jspb.Message.getFieldWithDefault(msg, 1, "")
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
@ -38697,10 +38696,6 @@ proto.io.haveno.protobuffer.RevolutAccountPayload.deserializeBinaryFromReader =
|
||||
var field = reader.getFieldNumber();
|
||||
switch (field) {
|
||||
case 1:
|
||||
var value = /** @type {string} */ (reader.readString());
|
||||
msg.setAccountId(value);
|
||||
break;
|
||||
case 2:
|
||||
var value = /** @type {string} */ (reader.readString());
|
||||
msg.setUserName(value);
|
||||
break;
|
||||
@ -38733,17 +38728,10 @@ proto.io.haveno.protobuffer.RevolutAccountPayload.prototype.serializeBinary = fu
|
||||
*/
|
||||
proto.io.haveno.protobuffer.RevolutAccountPayload.serializeBinaryToWriter = function(message, writer) {
|
||||
var f = undefined;
|
||||
f = message.getAccountId();
|
||||
if (f.length > 0) {
|
||||
writer.writeString(
|
||||
1,
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getUserName();
|
||||
if (f.length > 0) {
|
||||
writer.writeString(
|
||||
2,
|
||||
1,
|
||||
f
|
||||
);
|
||||
}
|
||||
@ -38751,38 +38739,20 @@ proto.io.haveno.protobuffer.RevolutAccountPayload.serializeBinaryToWriter = func
|
||||
|
||||
|
||||
/**
|
||||
* optional string account_id = 1;
|
||||
* optional string user_name = 1;
|
||||
* @return {string}
|
||||
*/
|
||||
proto.io.haveno.protobuffer.RevolutAccountPayload.prototype.getAccountId = function() {
|
||||
proto.io.haveno.protobuffer.RevolutAccountPayload.prototype.getUserName = function() {
|
||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @return {!proto.io.haveno.protobuffer.RevolutAccountPayload} returns this
|
||||
*/
|
||||
proto.io.haveno.protobuffer.RevolutAccountPayload.prototype.setAccountId = function(value) {
|
||||
return jspb.Message.setProto3StringField(this, 1, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional string user_name = 2;
|
||||
* @return {string}
|
||||
*/
|
||||
proto.io.haveno.protobuffer.RevolutAccountPayload.prototype.getUserName = function() {
|
||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, ""));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @return {!proto.io.haveno.protobuffer.RevolutAccountPayload} returns this
|
||||
*/
|
||||
proto.io.haveno.protobuffer.RevolutAccountPayload.prototype.setUserName = function(value) {
|
||||
return jspb.Message.setProto3StringField(this, 2, value);
|
||||
return jspb.Message.setProto3StringField(this, 1, value);
|
||||
};
|
||||
|
||||
|
||||
@ -54376,7 +54346,7 @@ proto.io.haveno.protobuffer.PreferencesPayload.toObject = function(includeInstan
|
||||
autoSelectArbitrators: jspb.Message.getBooleanFieldWithDefault(msg, 8, false),
|
||||
dontShowAgainMapMap: (f = msg.getDontShowAgainMapMap()) ? f.toObject(includeInstance, undefined) : [],
|
||||
tacAccepted: jspb.Message.getBooleanFieldWithDefault(msg, 10, false),
|
||||
useTorForMonero: jspb.Message.getBooleanFieldWithDefault(msg, 11, false),
|
||||
useTorForXmrOrdinal: jspb.Message.getFieldWithDefault(msg, 11, 0),
|
||||
showOwnOffersInOfferBook: jspb.Message.getBooleanFieldWithDefault(msg, 12, false),
|
||||
preferredTradeCurrency: (f = msg.getPreferredTradeCurrency()) && proto.io.haveno.protobuffer.TradeCurrency.toObject(includeInstance, f),
|
||||
withdrawalTxFeeInVbytes: jspb.Message.getFieldWithDefault(msg, 14, 0),
|
||||
@ -54513,8 +54483,8 @@ proto.io.haveno.protobuffer.PreferencesPayload.deserializeBinaryFromReader = fun
|
||||
msg.setTacAccepted(value);
|
||||
break;
|
||||
case 11:
|
||||
var value = /** @type {boolean} */ (reader.readBool());
|
||||
msg.setUseTorForMonero(value);
|
||||
var value = /** @type {number} */ (reader.readInt32());
|
||||
msg.setUseTorForXmrOrdinal(value);
|
||||
break;
|
||||
case 12:
|
||||
var value = /** @type {boolean} */ (reader.readBool());
|
||||
@ -54827,9 +54797,9 @@ proto.io.haveno.protobuffer.PreferencesPayload.serializeBinaryToWriter = functio
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getUseTorForMonero();
|
||||
if (f) {
|
||||
writer.writeBool(
|
||||
f = message.getUseTorForXmrOrdinal();
|
||||
if (f !== 0) {
|
||||
writer.writeInt32(
|
||||
11,
|
||||
f
|
||||
);
|
||||
@ -55477,20 +55447,20 @@ proto.io.haveno.protobuffer.PreferencesPayload.prototype.setTacAccepted = functi
|
||||
|
||||
|
||||
/**
|
||||
* optional bool use_tor_for_monero = 11;
|
||||
* @return {boolean}
|
||||
* optional int32 use_tor_for_xmr_ordinal = 11;
|
||||
* @return {number}
|
||||
*/
|
||||
proto.io.haveno.protobuffer.PreferencesPayload.prototype.getUseTorForMonero = function() {
|
||||
return /** @type {boolean} */ (jspb.Message.getBooleanFieldWithDefault(this, 11, false));
|
||||
proto.io.haveno.protobuffer.PreferencesPayload.prototype.getUseTorForXmrOrdinal = function() {
|
||||
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 11, 0));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {boolean} value
|
||||
* @param {number} value
|
||||
* @return {!proto.io.haveno.protobuffer.PreferencesPayload} returns this
|
||||
*/
|
||||
proto.io.haveno.protobuffer.PreferencesPayload.prototype.setUseTorForMonero = function(value) {
|
||||
return jspb.Message.setProto3BooleanField(this, 11, value);
|
||||
proto.io.haveno.protobuffer.PreferencesPayload.prototype.setUseTorForXmrOrdinal = function(value) {
|
||||
return jspb.Message.setProto3IntField(this, 11, value);
|
||||
};
|
||||
|
||||
|
||||
@ -59334,7 +59304,7 @@ proto.io.haveno.protobuffer.TraditionalCurrency.prototype.toObject = function(op
|
||||
*/
|
||||
proto.io.haveno.protobuffer.TraditionalCurrency.toObject = function(includeInstance, msg) {
|
||||
var f, obj = {
|
||||
currency: (f = msg.getCurrency()) && proto.io.haveno.protobuffer.Currency.toObject(includeInstance, f)
|
||||
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
@ -59371,11 +59341,6 @@ proto.io.haveno.protobuffer.TraditionalCurrency.deserializeBinaryFromReader = fu
|
||||
}
|
||||
var field = reader.getFieldNumber();
|
||||
switch (field) {
|
||||
case 1:
|
||||
var value = new proto.io.haveno.protobuffer.Currency;
|
||||
reader.readMessage(value,proto.io.haveno.protobuffer.Currency.deserializeBinaryFromReader);
|
||||
msg.setCurrency(value);
|
||||
break;
|
||||
default:
|
||||
reader.skipField();
|
||||
break;
|
||||
@ -59405,51 +59370,6 @@ proto.io.haveno.protobuffer.TraditionalCurrency.prototype.serializeBinary = func
|
||||
*/
|
||||
proto.io.haveno.protobuffer.TraditionalCurrency.serializeBinaryToWriter = function(message, writer) {
|
||||
var f = undefined;
|
||||
f = message.getCurrency();
|
||||
if (f != null) {
|
||||
writer.writeMessage(
|
||||
1,
|
||||
f,
|
||||
proto.io.haveno.protobuffer.Currency.serializeBinaryToWriter
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional Currency currency = 1;
|
||||
* @return {?proto.io.haveno.protobuffer.Currency}
|
||||
*/
|
||||
proto.io.haveno.protobuffer.TraditionalCurrency.prototype.getCurrency = function() {
|
||||
return /** @type{?proto.io.haveno.protobuffer.Currency} */ (
|
||||
jspb.Message.getWrapperField(this, proto.io.haveno.protobuffer.Currency, 1));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {?proto.io.haveno.protobuffer.Currency|undefined} value
|
||||
* @return {!proto.io.haveno.protobuffer.TraditionalCurrency} returns this
|
||||
*/
|
||||
proto.io.haveno.protobuffer.TraditionalCurrency.prototype.setCurrency = function(value) {
|
||||
return jspb.Message.setWrapperField(this, 1, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Clears the message field making it undefined.
|
||||
* @return {!proto.io.haveno.protobuffer.TraditionalCurrency} returns this
|
||||
*/
|
||||
proto.io.haveno.protobuffer.TraditionalCurrency.prototype.clearCurrency = function() {
|
||||
return this.setCurrency(undefined);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether this field is set.
|
||||
* @return {boolean}
|
||||
*/
|
||||
proto.io.haveno.protobuffer.TraditionalCurrency.prototype.hasCurrency = function() {
|
||||
return jspb.Message.getField(this, 1) != null;
|
||||
};
|
||||
|
||||
|
||||
@ -60802,7 +60722,9 @@ proto.io.haveno.protobuffer.PaymentAccountForm.FormId = {
|
||||
MONEY_GRAM: 9,
|
||||
FASTER_PAYMENTS: 10,
|
||||
UPHOLD: 11,
|
||||
PAXUM: 12
|
||||
PAXUM: 12,
|
||||
PAY_BY_MAIL: 13,
|
||||
CASH_AT_ATM: 14
|
||||
};
|
||||
|
||||
/**
|
||||
|
78
dist/utils/HavenoUtils.d.ts
vendored
78
dist/utils/HavenoUtils.d.ts
vendored
@ -42,6 +42,56 @@ export default class HavenoUtils {
|
||||
* @param {String} signal - the kill signal, e.g. SIGTERM, SIGKILL, SIGINT (default)
|
||||
*/
|
||||
static kill(process: any, signal?: string): Promise<void>;
|
||||
/**
|
||||
* Wait for the duration.
|
||||
*
|
||||
* @param {number} durationMs - the duration to wait for in milliseconds
|
||||
*/
|
||||
static waitFor(durationMs: number): Promise<unknown>;
|
||||
/**
|
||||
* Divide one bigint by another.
|
||||
*
|
||||
* @param {bigint} a dividend
|
||||
* @param {bigint} b divisor
|
||||
* @returns {number} the result
|
||||
*/
|
||||
static divideBI(a: bigint, b: bigint): number;
|
||||
/**
|
||||
* Calculate the difference from a first bigint to a second, as a percentage (float).
|
||||
*
|
||||
* @param {bigint} a first bigint to get the difference from
|
||||
* @param {bigint} b second bigint to get the difference from
|
||||
* @returns {number} the percentage difference as a float
|
||||
*/
|
||||
static percentageDiff(a: bigint, b: bigint): number;
|
||||
/**
|
||||
* Return the absolute value of the given bigint.
|
||||
*
|
||||
* @param {bigint} a the bigint to get the absolute value of
|
||||
* @returns {bigint} the absolute value of the given bigint
|
||||
*/
|
||||
static abs(a: bigint): bigint;
|
||||
/**
|
||||
* Convert XMR to atomic units.
|
||||
*
|
||||
* @param {number|string} amountXmr - amount in XMR to convert to atomic units
|
||||
* @return {BigInt} amount in atomic units
|
||||
*/
|
||||
static xmrToAtomicUnits(amountXmr: number | string): bigint;
|
||||
/**
|
||||
* Convert atomic units to XMR.
|
||||
*
|
||||
* @param {BigInt|string} amountAtomicUnits - amount in atomic units to convert to XMR
|
||||
* @return {number} amount in XMR
|
||||
*/
|
||||
static atomicUnitsToXmr(amountAtomicUnits: BigInt | string): number;
|
||||
/**
|
||||
* Get a validated payment method id from a string or form id.
|
||||
*
|
||||
* @param {string | PaymentAccountForm.FormId} id - identifies the payment method
|
||||
* @returns {string} the payment method id
|
||||
*/
|
||||
static getPaymentMethodId(id: string | PaymentAccountForm.FormId): string;
|
||||
/**
|
||||
* Stringify a payment account form.
|
||||
*
|
||||
@ -66,32 +116,4 @@ export default class HavenoUtils {
|
||||
* @return {string} the form field value
|
||||
*/
|
||||
static setFormValue(fieldId: PaymentAccountFormField.FieldId, value: string, form: PaymentAccountForm): void;
|
||||
/**
|
||||
* Wait for the duration.
|
||||
*
|
||||
* @param {number} durationMs - the duration to wait for in milliseconds
|
||||
*/
|
||||
static waitFor(durationMs: number): Promise<unknown>;
|
||||
/**
|
||||
* Divide one bigint by another.
|
||||
*
|
||||
* @param {bigint} a dividend
|
||||
* @param {bigint} b divisor
|
||||
* @returns {number} the result
|
||||
*/
|
||||
static divideBI(a: bigint, b: bigint): number;
|
||||
/**
|
||||
* Convert XMR to atomic units.
|
||||
*
|
||||
* @param {number|string} amountXmr - amount in XMR to convert to atomic units
|
||||
* @return {BigInt} amount in atomic units
|
||||
*/
|
||||
static xmrToAtomicUnits(amountXmr: number | string): bigint;
|
||||
/**
|
||||
* Convert atomic units to XMR.
|
||||
*
|
||||
* @param {BigInt|string} amountAtomicUnits - amount in atomic units to convert to XMR
|
||||
* @return {number} amount in XMR
|
||||
*/
|
||||
static atomicUnitsToXmr(amountAtomicUnits: BigInt | string): number;
|
||||
}
|
||||
|
153
dist/utils/HavenoUtils.js
vendored
153
dist/utils/HavenoUtils.js
vendored
@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const console_1 = __importDefault(require("console"));
|
||||
const pb_pb_1 = require("../protobuf/pb_pb");
|
||||
/**
|
||||
* Collection of utilities for working with Haveno.
|
||||
*/
|
||||
@ -66,6 +67,98 @@ class HavenoUtils {
|
||||
process.kill(signal ? signal : "SIGINT");
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Wait for the duration.
|
||||
*
|
||||
* @param {number} durationMs - the duration to wait for in milliseconds
|
||||
*/
|
||||
static async waitFor(durationMs) {
|
||||
return new Promise(function (resolve) { setTimeout(resolve, durationMs); });
|
||||
}
|
||||
/**
|
||||
* Divide one bigint by another.
|
||||
*
|
||||
* @param {bigint} a dividend
|
||||
* @param {bigint} b divisor
|
||||
* @returns {number} the result
|
||||
*/
|
||||
static divideBI(a, b) {
|
||||
return Number(a * 10000000000000n / b) / 10000000000000;
|
||||
}
|
||||
/**
|
||||
* Calculate the difference from a first bigint to a second, as a percentage (float).
|
||||
*
|
||||
* @param {bigint} a first bigint to get the difference from
|
||||
* @param {bigint} b second bigint to get the difference from
|
||||
* @returns {number} the percentage difference as a float
|
||||
*/
|
||||
static percentageDiff(a, b) {
|
||||
return HavenoUtils.divideBI(a - b, a);
|
||||
}
|
||||
/**
|
||||
* Return the absolute value of the given bigint.
|
||||
*
|
||||
* @param {bigint} a the bigint to get the absolute value of
|
||||
* @returns {bigint} the absolute value of the given bigint
|
||||
*/
|
||||
static abs(a) {
|
||||
return a < 0 ? -a : a;
|
||||
}
|
||||
/**
|
||||
* Convert XMR to atomic units.
|
||||
*
|
||||
* @param {number|string} amountXmr - amount in XMR to convert to atomic units
|
||||
* @return {BigInt} amount in atomic units
|
||||
*/
|
||||
static xmrToAtomicUnits(amountXmr) {
|
||||
if (typeof amountXmr === "number")
|
||||
amountXmr = "" + amountXmr;
|
||||
else if (typeof amountXmr !== "string")
|
||||
throw new Error("Must provide XMR amount as a string or js number to convert to atomic units");
|
||||
let decimalDivisor = 1;
|
||||
let decimalIdx = amountXmr.indexOf('.');
|
||||
if (decimalIdx > -1) {
|
||||
decimalDivisor = Math.pow(10, amountXmr.length - decimalIdx - 1);
|
||||
amountXmr = amountXmr.slice(0, decimalIdx) + amountXmr.slice(decimalIdx + 1);
|
||||
}
|
||||
return BigInt(amountXmr) * BigInt(HavenoUtils.AU_PER_XMR) / BigInt(decimalDivisor);
|
||||
}
|
||||
/**
|
||||
* Convert atomic units to XMR.
|
||||
*
|
||||
* @param {BigInt|string} amountAtomicUnits - amount in atomic units to convert to XMR
|
||||
* @return {number} amount in XMR
|
||||
*/
|
||||
static atomicUnitsToXmr(amountAtomicUnits) {
|
||||
if (typeof amountAtomicUnits === "string")
|
||||
amountAtomicUnits = BigInt(amountAtomicUnits);
|
||||
else if (typeof amountAtomicUnits !== "bigint")
|
||||
throw new Error("Must provide atomic units as BigInt or string to convert to XMR");
|
||||
const quotient = amountAtomicUnits / HavenoUtils.AU_PER_XMR;
|
||||
const remainder = amountAtomicUnits % HavenoUtils.AU_PER_XMR;
|
||||
return Number(quotient) + Number(remainder) / Number(HavenoUtils.AU_PER_XMR);
|
||||
}
|
||||
// ------------------------- PAYMENT ACCOUNT FORMS --------------------------
|
||||
/**
|
||||
* Get a validated payment method id from a string or form id.
|
||||
*
|
||||
* @param {string | PaymentAccountForm.FormId} id - identifies the payment method
|
||||
* @returns {string} the payment method id
|
||||
*/
|
||||
static getPaymentMethodId(id) {
|
||||
if (typeof id === "string") {
|
||||
id = id.toUpperCase();
|
||||
if (!(id in pb_pb_1.PaymentAccountForm.FormId))
|
||||
throw Error("Invalid payment method: " + id);
|
||||
return id;
|
||||
}
|
||||
else {
|
||||
let keyByValue = getKeyByValue(pb_pb_1.PaymentAccountForm.FormId, id);
|
||||
if (!keyByValue)
|
||||
throw Error("No payment method id with form id " + id);
|
||||
return keyByValue;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Stringify a payment account form.
|
||||
*
|
||||
@ -111,62 +204,18 @@ class HavenoUtils {
|
||||
}
|
||||
throw new Error("PaymentAccountForm does not have field " + fieldId);
|
||||
}
|
||||
/**
|
||||
* Wait for the duration.
|
||||
*
|
||||
* @param {number} durationMs - the duration to wait for in milliseconds
|
||||
*/
|
||||
static async waitFor(durationMs) {
|
||||
return new Promise(function (resolve) { setTimeout(resolve, durationMs); });
|
||||
}
|
||||
/**
|
||||
* Divide one bigint by another.
|
||||
*
|
||||
* @param {bigint} a dividend
|
||||
* @param {bigint} b divisor
|
||||
* @returns {number} the result
|
||||
*/
|
||||
static divideBI(a, b) {
|
||||
return Number(a * 10000000000000n / b) / 10000000000000;
|
||||
}
|
||||
/**
|
||||
* Convert XMR to atomic units.
|
||||
*
|
||||
* @param {number|string} amountXmr - amount in XMR to convert to atomic units
|
||||
* @return {BigInt} amount in atomic units
|
||||
*/
|
||||
static xmrToAtomicUnits(amountXmr) {
|
||||
if (typeof amountXmr === "number")
|
||||
amountXmr = "" + amountXmr;
|
||||
else if (typeof amountXmr !== "string")
|
||||
throw new Error("Must provide XMR amount as a string or js number to convert to atomic units");
|
||||
let decimalDivisor = 1;
|
||||
let decimalIdx = amountXmr.indexOf('.');
|
||||
if (decimalIdx > -1) {
|
||||
decimalDivisor = Math.pow(10, amountXmr.length - decimalIdx - 1);
|
||||
amountXmr = amountXmr.slice(0, decimalIdx) + amountXmr.slice(decimalIdx + 1);
|
||||
}
|
||||
return BigInt(amountXmr) * BigInt(HavenoUtils.AU_PER_XMR) / BigInt(decimalDivisor);
|
||||
}
|
||||
/**
|
||||
* Convert atomic units to XMR.
|
||||
*
|
||||
* @param {BigInt|string} amountAtomicUnits - amount in atomic units to convert to XMR
|
||||
* @return {number} amount in XMR
|
||||
*/
|
||||
static atomicUnitsToXmr(amountAtomicUnits) {
|
||||
if (typeof amountAtomicUnits === "string")
|
||||
amountAtomicUnits = BigInt(amountAtomicUnits);
|
||||
else if (typeof amountAtomicUnits !== "bigint")
|
||||
throw new Error("Must provide atomic units as BigInt or string to convert to XMR");
|
||||
const quotient = amountAtomicUnits / HavenoUtils.AU_PER_XMR;
|
||||
const remainder = amountAtomicUnits % HavenoUtils.AU_PER_XMR;
|
||||
return Number(quotient) + Number(remainder) / Number(HavenoUtils.AU_PER_XMR);
|
||||
}
|
||||
}
|
||||
exports.default = HavenoUtils;
|
||||
HavenoUtils.logLevel = 0;
|
||||
HavenoUtils.months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
HavenoUtils.lastLogTimeMs = 0;
|
||||
HavenoUtils.AU_PER_XMR = 1000000000000n;
|
||||
function getKeyByValue(object, value) {
|
||||
for (const key in object) {
|
||||
if (object.hasOwnProperty(key) && object[key] === value) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
//# sourceMappingURL=HavenoUtils.js.map
|
2
dist/utils/HavenoUtils.js.map
vendored
2
dist/utils/HavenoUtils.js.map
vendored
File diff suppressed because one or more lines are too long
965
package-lock.json
generated
965
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "haveno-ts",
|
||||
"version": "0.0.14",
|
||||
"version": "0.0.15",
|
||||
"description": "Haveno TypeScript interface",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
Loading…
x
Reference in New Issue
Block a user