import { GROTHS_IN_BEAM } from '@app/containers/Wallet/constants' ; import { Transaction } from '@core/types' ; export const copyToClipboard = ( value ) => navigator . clipboard . writeText ( value ) ; export function compact ( value , stringLength = 5 ) { if ( value . length <= 11 ) { return value ; } return `${ value . substr ( 0 , stringLength ) }…${ value . substr ( - stringLength , stringLength ) }` ; } const LENGTH_MAX = 8 ; export function truncate ( value ) { if ( ! value ) { return '' ; } if ( value . length <= LENGTH_MAX ) { return value ; } return `${ value . slice ( 0 , LENGTH_MAX ) }…` ; } export function toUSD ( amount , rate ) { switch ( true ) { case amount === 0 || Number . isNaN ( amount ) : return '0 USD' ; case amount > 0.01 : { const value = amount * rate ; return `${ value . toFixed ( 2 ) } USD` ; } default : return '< 1 cent' ; } } export function fromGroths ( value ) { return value && value !== 0 ? value / GROTHS_IN_BEAM : 0 ; } export function toGroths ( value ) { return value > 0 ? Math . floor ( value * GROTHS_IN_BEAM ) : 0 ; } export function getSign ( positive ) { return positive ? '+ ' : '- ' ; } export function createdComparator ( { create_time : a } , { create_time : b } ) { if ( a === b ) { return 0 ; } return a < b ? 1 : - 1 ; }