@airgap/etherlink
Version:
The @airgap/etherlink package is an implementation of the ICoinProtocol interface from @airgap/coinlib-core.
46 lines • 1.81 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AmountEnhanced = void 0;
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
var AmountEnhanced = /** @class */ (function () {
function AmountEnhanced(value, unit) {
this.unit = unit;
this.bnValue = new bignumber_1.default(value);
}
Object.defineProperty(AmountEnhanced.prototype, "value", {
get: function () {
return this.bnValue.toString(10);
},
enumerable: false,
configurable: true
});
AmountEnhanced.prototype.convert = function (unit, unitsMetadata) {
var blockchainAmount = this.blockchain(unitsMetadata);
var unitValue = blockchainAmount.bnValue.shiftedBy(-unitsMetadata[unit].decimals);
return new AmountEnhanced(unitValue, unit);
};
AmountEnhanced.prototype.blockchain = function (unitsMetadata) {
if (this.unit === 'blockchain') {
return new AmountEnhanced(this.bnValue, this.unit);
}
var blockchainValue = this.bnValue.shiftedBy(unitsMetadata[this.unit].decimals);
return new AmountEnhanced(blockchainValue, 'blockchain');
};
// Different representations
AmountEnhanced.prototype.toBigNumber = function () {
return new bignumber_1.default(this.value);
};
// Serialization
AmountEnhanced.prototype.toJSON = function () {
return {
value: this.value,
unit: this.unit
};
};
return AmountEnhanced;
}());
exports.AmountEnhanced = AmountEnhanced;
//# sourceMappingURL=amount.js.map