import * as constants from "@/app/app.constants" ; import { SafeBigNumber as BigNumber } from "./bignumber" ; export class ArkUtility { public static getRandomInt ( min , max ) { return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ; } public static arktoshiToArk ( arktoshi , returnRaw = false ) { let result = arktoshi / constants . WALLET_UNIT_TO_SATOSHI ; if ( ! returnRaw ) { result = Number ( new BigNumber ( result . toString ( ) ) . toFixed ( constants . ARKTOSHI_DP ) ) ; } return result ; } public static subToUnit ( value , parseScientificNotation = true ) { if ( ! value ) { return "" ; } let amount = new BigNumber ( value . toString ( ) ) . dividedBy ( constants . WALLET_UNIT_TO_SATOSHI ) . toString ( ) ; if ( parseScientificNotation ) { const parts = amount . split ( "e-" ) ; if ( parts . length > 1 ) { amount = parseFloat ( amount ) . toFixed ( parseInt ( parts [ 1 ] ) ) ; } } return amount ; } public static unitToSub ( value ) { if ( ! value ) { return "" ; } return new BigNumber ( value . toString ( ) ) . multipliedBy ( constants . WALLET_UNIT_TO_SATOSHI ) . toString ( ) ; } }