UNPKG

chaingate

Version:

A complete TypeScript library for connecting to and making transactions on different blockchains

53 lines 2.19 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CurrencyAmount = void 0; const decimal_js_1 = __importDefault(require("decimal.js")); class CurrencyAmount { currencyInfo; baseAmount; get baseSymbol() { return this.currencyInfo.symbol; } get minimalUnitAmount() { return this.baseAmount.mul((new decimal_js_1.default(10)).pow(this.currencyInfo.decimals)); } get minimalUnitSymbol() { return this.currencyInfo.minimalUnitSymbol; } get str() { if (this.baseAmount.decimalPlaces() > 5) return `${this.baseAmount.toFixed(5)}... ${this.baseSymbol}`; return `${this.baseAmount.toString()} ${this.baseSymbol}`; } decimals; constructor(currencyInfo, baseAmount) { this.currencyInfo = currencyInfo; this.baseAmount = baseAmount; this.decimals = currencyInfo.decimals; } plus(currencyAmount) { if (currencyAmount.currencyInfo.id != currencyAmount.currencyInfo.id) throw new Error('Invalid amount'); return new CurrencyAmount(this.currencyInfo, this.baseAmount.plus(currencyAmount.baseAmount)); } minus(currencyAmount) { if (currencyAmount.currencyInfo.id != currencyAmount.currencyInfo.id) throw new Error('Invalid amount'); return new CurrencyAmount(this.currencyInfo, this.baseAmount.minus(currencyAmount.baseAmount)); } div(currencyAmount) { if (currencyAmount.currencyInfo.id != currencyAmount.currencyInfo.id) throw new Error('Invalid amount'); return new CurrencyAmount(this.currencyInfo, this.baseAmount.div(currencyAmount.baseAmount)); } mul(currencyAmount) { if (currencyAmount.currencyInfo.id != currencyAmount.currencyInfo.id) throw new Error('Invalid amount'); return new CurrencyAmount(this.currencyInfo, this.baseAmount.mul(currencyAmount.baseAmount)); } } exports.CurrencyAmount = CurrencyAmount; //# sourceMappingURL=CurrencyAmount.js.map