import React from "react"; import { ContractId, Party, Template, TemplateOrInterface } from "@daml/types"; import Ledger, { CreateEvent, Query, StreamCloseEvent, QueryResult, User } from "@daml/ledger"; export { QueryResult } from "@daml/ledger"; /** * React props to initiate a connect to a Daml ledger. */ export type LedgerProps = { token: string; httpBaseUrl?: string; wsBaseUrl?: string; user?: User; party: Party; reconnectThreshold?: number; }; /** * The result of a ``fetch`` against the ledger. * * @typeparam T The contract template type of the query. * @typeparam K The contract key type of the query. * @typeparam I The template id type. */ export type FetchResult = { /** Contracts of the given contract template and key. */ contract: CreateEvent | null; /** Indicator for whether the fetch is executing. */ loading: boolean; }; /** * The result of a streaming ``fetchByKeys`` against the ledger. * * @typeparam T The contract template type of the query. * @typeparam K The contract key type of the query. * @typeparam I The template id type. */ export type FetchByKeysResult = { /** Contracts of the given contract template and key. */ contracts: (CreateEvent | null)[]; /** Indicator for whether the fetch is executing. */ loading: boolean; }; /** * A LedgerContext is a React context that stores information about a Daml Ledger * and hooks necessary to use it. */ export type LedgerContext = { DamlLedger: React.FC; useParty: () => Party; useUser: () => User; useLedger: () => Ledger; useQuery: (template: TemplateOrInterface, queryFactory?: () => Query, queryDeps?: readonly unknown[]) => QueryResult; useFetch: (template: TemplateOrInterface, contractId: ContractId) => FetchResult; useFetchByKey: (template: Template, keyFactory: () => K, keyDeps: readonly unknown[]) => FetchResult; useStreamQuery: (template: TemplateOrInterface, queryFactory?: () => Query, queryDeps?: readonly unknown[], closeHandler?: (e: StreamCloseEvent) => void) => QueryResult; useStreamQueries: (template: TemplateOrInterface, queryFactory?: () => Query[], queryDeps?: readonly unknown[], closeHandler?: (e: StreamCloseEvent) => void) => QueryResult; useStreamFetchByKey: (template: Template, keyFactory: () => K, keyDeps: readonly unknown[], closeHandler?: (e: StreamCloseEvent) => void) => FetchResult; useStreamFetchByKeys: (template: Template, keyFactory: () => K[], keyDeps: readonly unknown[], closeHandler?: (e: StreamCloseEvent) => void) => FetchByKeysResult; useReload: () => () => void; }; /** * Create a [[LedgerContext]]. One should use this function, instead of the default [[DamlLedger]], * where one needs to be able to nest ledger interactions, by different parties or connections, within * one React application. * * @param contextName Used to refer to a context in case of errors. */ export declare function createLedgerContext(contextName?: string): LedgerContext;