import { BigNumber } from 'bignumber.js'; // TODO extract this into its own npm package @interblockchain/utils export const convertAmount = (amount: number, ticker: string) => { console.log(" Amount: " + amount + " ticker: " + ticker); let factor; let value = new BigNumber(amount); if (!value.isFinite() || value.isZero()) { throw { name: "convertAmount", message: "Amount is zero or not finite." } } switch (ticker.toUpperCase()) { case "ITGUSD": factor = new BigNumber(10).exponentiatedBy(2); return value.multipliedBy(factor).toString() // case "XLM": // return value.toString() case "TBTC": case "TLTC": case "ITLTC": case "ITBTC": case "TBCH": case "ITBCH": //Satoshi is 10^-8 BTC factor = new BigNumber(10).exponentiatedBy(8); return value.multipliedBy(factor).toString() case "TETH": case "ITETH": //Wei is 10^-18 ETH factor = new BigNumber(10).exponentiatedBy(18); return value.multipliedBy(factor).toString() default: return value.toString(); } } // TODO extract this into its own npm package @interblockchain/utils export const convertToAmount = (amount: number, ticker: string) => { console.log(" Amount: " + amount + " ticker: " + ticker); let factor; let value = new BigNumber(amount); if (!value.isFinite() || value.isZero()) { throw { name: "convertAmount", message: "Amount is zero or not finite." } } switch (ticker.toUpperCase()) { case "ITGUSD": factor = new BigNumber(10).exponentiatedBy(2); return value.dividedBy(factor).toString() // case "XLM": // return value.toString() case "TBTC": case "TLTC": case "ITLTC": case "ITBTC": case "TBCH": case "ITBCH": //Satoshi is 10^-8 BTC factor = new BigNumber(10).exponentiatedBy(8); return value.dividedBy(factor).toString() case "TETH": case "ITETH": //Wei is 10^-18 ETH factor = new BigNumber(10).exponentiatedBy(18); return value.dividedBy(factor).toString() default: return value.toString(); } }