UNPKG

bitpay-sdk

Version:

Complete version of the NodeJS library for the new cryptographically secure BitPay API

40 lines 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Rates = void 0; const BitPayExceptionProvider_1 = require("../../Exceptions/BitPayExceptionProvider"); class Rates { constructor(rates) { this.rates = Rates.castRatesObj(rates); } getRates() { return this.rates; } getRate(currencyCode) { let val = 0; this.rates.forEach(function (rate) { if (rate.code === currencyCode) { val = rate.rate; return val; } }); return val; } async update(rateClient) { const rates = await rateClient.getRates(null); this.rates = rates.getRates(); } static castRatesObj(ratesObj) { try { if (typeof ratesObj === 'string' || ratesObj instanceof String) { ratesObj = JSON.parse(ratesObj.toString()); } return ratesObj; } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwGenericExceptionWithMessage(e.message); throw new Error(); } } } exports.Rates = Rates; //# sourceMappingURL=Rates.js.map