View on GitHub

reachduck

A front-end helper for your blockchain DApp.

Utility Functions

General helper/utility functions. Most functions do not require stdlib or other dependencies.


checkVersionChanged

App Migration helper: check if your app version has changed

function checkVersionChanged(currentVersion: string | number, APP_VERSION_KEY?: string): string;

top


setAppVersion

App Migration helper: set your current app version

function setAppVersion(version: string | number, APP_VERSION_KEY?: string): string;

top


copyToClipboard

Copy text to clipboard

function copyToClipboard(val: string): Promise<void>;

top


formatAddress

Requires stdlib. Convenience over stdlib.formatAddress

function formatAddress(acc: ReachAccount): string;

top


formatCurrency

Requires stdlib. UI-friendly currency formatting. Takes the decimal places of the currency, and an abbr boolean which, when true, will abbreviate the formatted value

function formatCurrency(amount: any, decimals?: number | undefined, abbr?: boolean): string;

top


formatCurrencyLocale

Builtin JS locale currency formatter (returns comma-delineated string)

function formatCurrencyLocale(val: number): string;

top


formatNumberShort

Abbreviated number formatting (e.g. 1000 -> 1K)

function formatNumberShort(val: number, decimalPlaces?: number): string;

top


asMaybe

Convert a value into a Maybe value-type

function asMaybe<T>(val: T): Maybe<T>;

top


asMaybeNone

Generate a falsy (null) Maybe value

function asMaybeNone(): Maybe<T>;

top


fromMaybe

Extract a value from a Maybe value, or provide a fallback

function fromMaybe<T>(mVal: Maybe<T>, format?: (v: T) => any, fallback?: any): any;

top


isMaybe

Assert a value is a Maybe value

function isMaybe(mVal: any): boolean;

top


isSome

Assert a value is a Maybe type that resolves to a defined value

function isSome(mVal: any): boolean;

isNone

Assert a value is a Maybe type that resolves to null

function isNone(mVal: any): boolean;

top


getBlockchain

Get the current stdlib instance’s connector (blockchain)

function getBlockchain(): string;

top


getBlockchainNetwork

Get current chain network. (e.g "TestNet" | "MainNet" on Algorand)

function getBlockchainNetwork(): string;

top


isImageFile

Assert path represents an image file

function isImageFile(path: string): boolean;

top


isVideoFile

Assert path represents a video file

function isVideoFile(path: string): boolean;

top


listSupportedNetworks

/* List all networks currently supported by this library */
function listSupportedNetworks(): NetworkData[];

top


noOp

Doesn’t do anything. Useful when you need a function stub.

function noOp(): null;

selectBlockchain

Set current consensus network (e.g. Algorand or Ethereum). May trigger window reload. Requires an stdlib instance.
This will affect what createConnectorAPI returns, if you call the latter without arguments.
This function may trigger window reload if a second argument is specified.

function selectBlockchain(network: string, reload?: boolean): string;

top


selectBlockchainNetwork

Set network provider preference MainNet or TestNet (or BetaNet on Algo). BetaNet is only supported on Algorand.
This function may trigger window reload if a second argument is specified.

function selectBlockchainNetwork(network: "MainNet" | "TestNet" | "BetaNet", reload?: boolean): string;

top


trimByteString

Trims empty bytes (\0...) from a string

function trimByteString(str: string): string;

top


truncateString

Shrink an address to radiusradius-length string. Default would be (WXWXWXWXWXWXWXWXWXWXWXWXWXWXWXWX) => “WXWXWX…WXWXWX”

function truncateString(acct: string, radius = 6): string;


top