import BigNumber from "bignumber.js" ; import { Ledger } from "../model" ; import { LEDGER_CREATED , pubsub } from "../pubsub" ; import { setBaseReserve } from "./base_reserve" ; export const STELLAR_AMOUNT_PRECISION = 7 ; export type MemoType = "hash" | "return" | "text" | "id" ; export function toFloatAmountString ( amount ) { return toFloat ( amount ) . toFixed ( STELLAR_AMOUNT_PRECISION ) ; } export function toFloat ( amount ) { return new BigNumber ( amount ) . div ( new BigNumber ( "1e" + STELLAR_AMOUNT_PRECISION ) ) ; } export function toInt ( amount ) { return new BigNumber ( amount ) . times ( new BigNumber ( "1e" + STELLAR_AMOUNT_PRECISION ) ) ; } export function listenBaseReserveChange ( ) { pubsub . subscribe ( LEDGER_CREATED , ( ledger ) => { if ( ! ledger . header ) { return ; } setBaseReserve ( ledger . header . baseReserve ) ; } ) ; }