diff --git a/src/index.ts b/src/index.ts index de885fd..ad5c40a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -588,4 +588,4 @@ export { LaconicClient }; export * from './constants'; export * from './types/cerc/bond/message'; export * from './types/cerc/onboarding/message'; -export * from './util'; +export { getGasPrice, parseGasAndFees } from './util'; diff --git a/src/util.ts b/src/util.ts index 8bbac57..11bc5a7 100644 --- a/src/util.ts +++ b/src/util.ts @@ -24,7 +24,7 @@ export class Util { let keys = Object.keys(obj); keys = keys.sort(); - const newObject: {[key: string]: any} = {}; + const newObject: { [key: string]: any } = {}; for (let i = 0; i < keys.length; i++) { newObject[keys[i]] = Util.sortJSON(obj[keys[i]]); @@ -79,7 +79,7 @@ export class Util { * Unmarshal attributes array to object. */ static fromGQLAttributes (attributes: any[] = []) { - const res: {[key: string]: any} = {}; + const res: { [key: string]: any } = {}; attributes.forEach(attr => { res[attr.key] = (attr.value === null) ? null : this.fromGQLValue(attr.value); @@ -120,35 +120,34 @@ export class Util { return block.cid.toString(); } - - /** - * Get gas in proper format - */ - static parseGasAndFees (gas?: string, fees?: string): StdFee | undefined | number { - // If fees is not given or a number, treat it as a gas estimation multiplier - if (fees === null || fees === undefined) { - return undefined; - } - - const isFeesANumber = !isNaN(Number(fees)); - if (isFeesANumber) { - return Number(fees); - } - - // If fees is not a gas estimation multiplier, gas is required - assert(gas, 'Invalid gas.'); - - return { - amount: parseCoins(String(fees)), - gas: String(gas) - }; - } - - /** - * Get gas price in proper format - */ - static getGasPrice (gasPrice: string | null): GasPrice | undefined { - const gasPriceString = gasPrice; - return gasPriceString != null ? GasPrice.fromString(String(gasPriceString)) : undefined; - } } + +/** + * Get gas in proper format + */ +export const parseGasAndFees = (gas?: string, fees?: string): StdFee | undefined | number => { + // If fees is not given or a number, treat it as a gas estimation multiplier + if (fees === null || fees === undefined) { + return undefined; + } + + const isFeesANumber = !isNaN(Number(fees)); + if (isFeesANumber) { + return Number(fees); + } + + // If fees is not a gas estimation multiplier, gas is required + assert(gas, 'Invalid gas.'); + + return { + amount: parseCoins(String(fees)), + gas: String(gas) + }; +}; + +/** + * Get gas price in proper format + */ +export const getGasPrice = (gasPrice: string | null): GasPrice | undefined => { + return gasPrice != null ? GasPrice.fromString(String(gasPrice)) : undefined; +};