import { OperatorFunction, Observable, Subject, ReplaySubject } from 'rxjs'; import BigNumber from 'bignumber.js'; declare const addTrailingSlash: (url: string) => string; /** * Javascript's `Math` library for `BigInt`. * Taken from https://stackoverflow.com/questions/51867270/is-there-a-library-similar-to-math-that-supports-javascript-bigint/64953280#64953280 */ declare const BigMath: { abs(x: bigint): bigint; sign(x: bigint): 0n | 1n | -1n; min(value: bigint, ...values: bigint[]): bigint; max(value: bigint, ...values: bigint[]): bigint; }; /** * In TypeScript, a deferred promise refers to a pattern that involves creating a promise that can be * resolved or rejected at a later point in time, typically by code outside of the current function scope. * * This pattern is often used when dealing with asynchronous operations that involve multiple steps or when * the result of an operation cannot be immediately determined. */ declare function Deferred(): { promise: Promise; resolve: (value: T | PromiseLike) => void; reject: (reason?: unknown) => void; isPending: () => boolean; isResolved: () => boolean; isRejected: () => boolean; }; /** biome-ignore-all lint/complexity/noBannedTypes: legacy */ type FunctionPropertyNames = { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]; type FunctionProperties = Pick>; type NonFunctionPropertyNames = { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]; type NonFunctionProperties = Pick>; /** * An rxjs operator which: * * 1. Emits the first value it receives from the source observable, then: * 2. Debounces any future values by `timeout` ms. */ declare const firstThenDebounce: (timeout: number) => OperatorFunction; declare const MAX_DECIMALS_FORMAT = 12; /** * Custom decimal number formatting for Talisman * note that the NumberFormat().format() call is the ressource heavy part, it's not worth trying to optimize other parts * @param num input number * @param digits number of significant digits to display * @param locale locale used to format the number * @param options formatting options * @returns the formatted value */ declare const formatDecimals: (num?: string | number | null | BigNumber, digits?: number, options?: Partial, locale?: string) => string; declare const formatPrice: (price: number, currency: string, compact: boolean) => string; type LoadableError = { name: string; message: string; }; type Loadable = { status: "loading"; data?: T; error?: undefined; } | { status: "success"; data: T; error?: undefined; } | { status: "error"; data?: T; error: LoadableError; }; type LoadableStatus = Loadable["status"]; type LoadableOptions = { getError?: (error: unknown) => LoadableError; refreshInterval?: number; }; declare function getLoadable$(factory: () => Promise, options?: LoadableOptions): Observable>; type GetLoadableQueryParams = { namespace: string; args: TArgs; queryFn: (args: TArgs, signal: AbortSignal) => Promise; refreshInterval?: number; defaultValue?: TResult; }; /** * Thin wrapper around getQuery$ that returns Loadable and optionally * primes the stream with a loading state using the provided default value. * * TODO: consolidate with getQuery$ */ declare const getLoadableQuery$: (params: GetLoadableQueryParams) => Observable>; type QueryStatus = "loading" | "loaded" | "error"; type QueryResult = S extends "loading" ? { status: "loading"; data: T | undefined; error: undefined; } : S extends "loaded" ? { status: "loaded"; data: T; error: undefined; } : { status: "error"; data: undefined; error: unknown; }; type QueryOptions = { namespace: string; args: Args; queryFn: (args: Args, signal: AbortSignal) => Promise; defaultValue?: Output; refreshInterval?: number; serializer?: (args: Args) => string; }; /** * Creates a shared observable for executing queries with caching, loading states, and automatic refresh capabilities. * * @example * ```typescript * const userQuery$ = getQuery$({ * namespace: 'users', * args: { userId: 123 }, * queryFn: async ({ userId }) => fetchUser(userId), * defaultValue: null, * refreshInterval: 30000 * }); * * userQuery$.subscribe(result => { * if (result.status === 'loaded') { * console.log(result.data); * } * }); * ``` * * @deprecated use getLoadableQuery$ instead */ declare const getQuery$: ({ namespace, args, queryFn, defaultValue, refreshInterval, serializer, }: QueryOptions) => Observable>; /** * When using react-rxjs hooks and state observables, the options are used as weak map keys. * This means that if the options object is recreated on each render, the observable will be recreated as well. * This utility function allows you to create a shared observable based on a namespace and arguments that, so react-rxjs can reuse the same observables * * @param namespace * @param args * @param createObservable * @param serializer * @returns */ declare const getSharedObservable: >(namespace: string, args: Args, createObservable: (args: Args) => ObsOutput, serializer?: (args: Args) => string) => ObsOutput; declare function hasOwnProperty(obj: X, prop: Y): obj is X & Record; declare const isAbortError: (error: unknown) => boolean; declare function isArrayOf>(array: unknown[], func: new (...args: P) => T): array is T[]; declare const isAscii: (str: string) => boolean; declare const isBigInt: (value: unknown) => value is bigint; declare const isBooleanTrue: (x: T | null | undefined) => x is T; type HexString = `0x${string}`; declare const REGEX_HEX_STRING: RegExp; declare const isHexString: (value: unknown) => value is HexString; /** * WARNING: This function only checks against null or undefined, it does not coerce the value. * ie: false and 0 are considered not nil * Use isTruthy instead for a regular coercion check. * * @param value * @returns whether the value is neither null nor undefined */ declare const isNotNil: (value: T | null | undefined) => value is T; declare const isPromise: (value: any) => value is Promise; /** * Tests to see if an object is an RxJS {@link Subject}. */ declare function isSubject(object?: Subject | object): object is Subject; declare const isTruthy: (value: T | null | undefined) => value is T; /** * An RxJS operator that keeps the source observable alive for a specified duration * after all subscribers have unsubscribed. This prevents expensive re-subscriptions * when subscribers come and go frequently. * * @param keepAliveMs - Duration in milliseconds to keep the source alive after last unsubscription * @returns MonoTypeOperatorFunction that can be used in pipe() * * @example * ```typescript * const data$ = expensive_api_call$.pipe( * keepAlive(3000) // Keep alive for 3 seconds * ); * ``` */ declare const keepAlive: (timeout: number) => OperatorFunction; type Prettify = { [K in keyof T]: T[K]; } & {}; declare function planckToTokens(planck: string, tokenDecimals: number): string; declare function planckToTokens(planck: string, tokenDecimals?: number): string | undefined; declare function planckToTokens(planck?: string, tokenDecimals?: number): string | undefined; /** * Turns a value into a {@link ReplaySubject} of size 1. * * If the value is already a {@link ReplaySubject}, it will be returned as-is. * * If the value is a {@link Promise}, it will be awaited, * and the awaited value will be published into the {@link ReplaySubject} when it becomes available. * * For any other type of value, it will be immediately published into the {@link ReplaySubject}. */ declare const replaySubjectFrom: (initialValue: T | Promise | ReplaySubject) => ReplaySubject; declare const sleep: (ms: number) => Promise; /** * Takes a subject and splits it into two parts: * * 1. A function to submit new values into the subject. * 2. An observable for subscribing to new values from the subject. * * This can be helpful when, to avoid bugs, you want to expose only one * of these parts to external code and keep the other part private. */ declare function splitSubject(subject: Subject): readonly [(value: T) => void, Observable]; declare const throwAfter: (ms: number, reason: string) => Promise; declare function tokensToPlanck(tokens: string, tokenDecimals: number): string; declare function tokensToPlanck(tokens: string, tokenDecimals?: number): string | undefined; declare function tokensToPlanck(tokens?: string, tokenDecimals?: number): string | undefined; /** * @name validateHexString * @description Checks if a string is a hex string. Required to account for type differences between different polkadot libraries * @param {string} str - string to check * @returns {`0x${string}`} - boolean * @example * validateHexString("0x1234") // "0x1234" * validateHexString("1234") // Error: Expected a hex string * validateHexString(1234) // Error: Expected a string **/ declare const validateHexString: (str: string) => `0x${string}`; export { BigMath, Deferred, type FunctionProperties, type FunctionPropertyNames, type GetLoadableQueryParams, type HexString, type Loadable, type LoadableOptions, type LoadableStatus, MAX_DECIMALS_FORMAT, type NonFunctionProperties, type NonFunctionPropertyNames, type Prettify, type QueryResult, type QueryStatus, REGEX_HEX_STRING, addTrailingSlash, firstThenDebounce, formatDecimals, formatPrice, getLoadable$, getLoadableQuery$, getQuery$, getSharedObservable, hasOwnProperty, isAbortError, isArrayOf, isAscii, isBigInt, isBooleanTrue, isHexString, isNotNil, isPromise, isSubject, isTruthy, keepAlive, planckToTokens, replaySubjectFrom, sleep, splitSubject, throwAfter, tokensToPlanck, validateHexString };