import { FirmaUtil } from "@firmachain/firma-js" ; export const isElectron = navigator . userAgent . includes ( "Electron" ) ; export const isValid = ( data ) => { if ( data === null ) return false ; if ( data === undefined ) return false ; if ( Object . keys ( data ) . length === 0 ) return false ; return true ; } ; export const isValidString = ( data ) => { if ( data === null ) return false ; if ( data === undefined ) return false ; if ( data === "" ) return false ; return true ; } ; export const getValidDefaultValue = ( data , defaultValue ) => { if ( isValid ( data ) ) return data ; else return defaultValue ; } ; export const convertNumber = ( value ) => { if ( isNaN ( Number ( value ) ) ) return 0 ; return Number ( value ) ; } ; export const convertToTokenString = ( amount , decimal ) => { return FirmaUtil . getTokenStringFromUToken ( convertNumber ( amount ) , convertNumber ( decimal ) ) ; } ; export const convertToTokenNumber = ( amount , decimal ) => { return convertNumber ( FirmaUtil . getTokenStringFromUToken ( convertNumber ( amount ) , convertNumber ( decimal ) ) ) ; } ; export const convertToFctString = ( uFctAmount ) => { return FirmaUtil . getFCTStringFromUFCT ( convertNumber ( uFctAmount ) ) ; } ; export const convertToFctNumber = ( uFctAmount ) => { return convertNumber ( FirmaUtil . getFCTStringFromUFCT ( convertNumber ( uFctAmount ) ) ) ; } ; export const copyToClipboard = ( textToCopy ) => { try { if ( navigator . clipboard && window . isSecureContext ) { return navigator . clipboard . writeText ( textToCopy ) ; } else { let textArea = document . createElement ( "textarea" ) ; textArea . value = textToCopy ; textArea . style . position = "fixed" ; textArea . style . left = "-999999px" ; textArea . style . top = "-999999px" ; textArea . style . position = "absolute" ; textArea . style . opacity = "0" ; document . body . appendChild ( textArea ) ; textArea . focus ( ) ; textArea . select ( ) ; return new Promise ( ( res , rej ) => { document . execCommand ( "copy" ) ? res ( ) : rej ( ) ; textArea . remove ( ) ; } ) ; } } catch ( e ) { } } ;