hive-keychain-commons
Version:
Platform-agnostic functions used in Hive Keychain mobile and extensions
79 lines (78 loc) • 2.6 kB
TypeScript
import type { AssetSymbol, PriceType } from '@hiveio/dhive';
export declare class Asset {
amount: number;
symbol: AssetSymbol;
constructor(amount: number, symbol: AssetSymbol);
/**
* Create a new Asset instance from a string, e.g. `42.000 HIVE`.
*/
static fromString: (str: string, expectedSymbol?: AssetSymbol) => Asset;
/**
* Convenience to create new Asset.
* @param symbol Symbol to use when created from number. Will also be used to validate
* the asset, throws if the passed value has a different symbol than this.
*/
static from: (value: number | Asset | string, symbol?: AssetSymbol) => Asset;
/**
* Return the smaller of the two assets.
*/
static min: (a: Asset, b: Asset) => Asset;
/**
* Return the larger of the two assets.
*/
static max: (a: Asset, b: Asset) => Asset;
/**
* Return asset precision.
*/
getPrecision: () => 3 | 6;
/**
* Return a string representation of this asset, e.g. `42.000 HIVE`.
*/
toString: () => string;
/**
* Return a new Asset instance with amount added.
*/
add: (amount: number | Asset | string) => Asset;
/**
* Return a new Asset instance with amount subtracted.
*/
subtract: (amount: number | Asset | string) => Asset;
/**
* Return a new Asset with the amount multiplied by factor.
*/
multiply: (factor: number | Asset | string) => Asset;
/**
* Return a new Asset with the amount divided.
*/
divide: (divisor: number | Asset | string) => Asset;
/**
* For JSON serialization, same as toString().
*/
toJSON: () => string;
}
export declare class Price {
/**
* @param base - represents a value of the price object to be expressed relatively to quote
* asset. Cannot have amount == 0 if you want to build valid price.
* @param quote - represents an relative asset. Cannot have amount == 0, otherwise
* asertion fail.
*
* Both base and quote shall have different symbol defined.
*/
base: Asset;
quote: Asset;
constructor(base: Asset, quote: Asset);
/**
* Convenience to create new Price.
*/
static from: (value: PriceType) => Price;
/**
* Return a string representation of this price pair.
*/
toString: () => string;
/**
* Return a new Asset with the price converted between the symbols in the pair.
* Throws if passed asset symbol is not base or quote.
*/
convert: (asset: Asset) => Asset;
}