mysterium-vpn-js
Version:
Javascript SDK for Mysterium node
32 lines (31 loc) • 1.34 kB
JavaScript
;
/**
* Copyright (c) 2020 BlockDev AG
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.displayMoney = exports.DECIMAL_PART = void 0;
const price_1 = require("../proposal/price");
exports.DECIMAL_PART = 1000000000000000000;
const displayedCurrency = (currency, showCurrency) => {
return showCurrency ? ` ${currency}` : '';
};
/**
* @deprecated For every token value, use *Tokens field and display it using Tokens.Human.
*/
const displayMoney = (m, { showCurrency = false, fractionDigits = 6, removeInsignificantZeros = true, decimalPart = exports.DECIMAL_PART, } = {}) => {
var _a;
if (m.currency == price_1.Currency.MYST || m.currency == price_1.Currency.MYSTTestToken) {
let amount = (_a = m.amount) !== null && _a !== void 0 ? _a : 0;
amount = amount / decimalPart; // adjust
let amountStr = amount.toFixed(fractionDigits); // fractions
if (removeInsignificantZeros) {
amountStr = Number(amountStr).toString();
}
return `${amountStr}${displayedCurrency(m.currency, showCurrency)}`;
}
return `${m.amount}${displayedCurrency(m.currency, showCurrency)}`;
};
exports.displayMoney = displayMoney;