@usearete/react 0.45.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -1
- package/dist/index.cjs +909 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +423 -5
- package/dist/index.esm.js +900 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/testing.d.ts +9 -1
- package/dist/wallet-standard.cjs +129 -0
- package/dist/wallet-standard.cjs.map +1 -0
- package/dist/wallet-standard.d.ts +73 -0
- package/dist/wallet-standard.esm.js +120 -0
- package/dist/wallet-standard.esm.js.map +1 -0
- package/package.json +30 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { StackDefinition, WalletAdapter, ConnectOptions, AuthConfig, AreteError, Schema, ProgramSdkDefinition, ConnectionState, ConnectedArete, StackWithAttachedPrograms, PreparedOperation, TransactionFailureOutcome, OperationExecutionEvent, OperationExecutionSuccessEvent, OperationTransactionReceipt, TransactionOutcome, ProgramInterface, TypedInstruction, OperationReceiptFor, StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate, ViewSortConfig, QueriesInterface, ChainClient, StackConnectedExtensions, SocketIssue, StackQueryDefinition, ViewGroup, ViewDef, ContextSlotOptions, NativeBalanceInfo, TokenBalanceInput, TokenBalanceInfo, ProtocolTypeMap, ProtocolClient, ProtocolKeyClass, ProtocolInstanceDetail, ProtocolStepAvailabilityFor, ProtocolWalletActions, ProtocolParticipantDetail, ProtocolStreamEvent, WaitForProcessedSlotOptions } from '@usearete/sdk';
|
|
3
|
-
export { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, Arete, AreteError, AreteOptions, AreteOptionsWithStorage, ArgSchema, ArgType, AuthConfig, BuildOptions, BuiltAccountMeta, BuiltInstruction, ConfirmationLevel, ConnectOptions, ConnectedArete, ConnectionManager, ConnectionState, ContextSlotOptions, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, DefaultViewKey, EntityFrame, ErrorFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, Frame, FrameMode, FrameOp, FrameProcessor, FrameProcessorConfig, FrameValidationDiagnostic, InstructionError, InstructionExecutor, InstructionHandler, InstructionHandlerConfig, MemoryAdapter, MergeProgramMaps, NativeBalanceInfo, OperationCallbackError, OperationExecutionError, OperationExecutionOptions, OperationReceiptFor, OperationTransactionReceipt, PdaConfig, PdaSeed, PreparedFlow, PreparedInstruction, PreparedOperation, PreparedTransaction, PreparedTransactionInstruction, ProcessedSlotTimeoutError, ProgramError, QueryLease, QuerySnapshot, QueryStore, ReadRequestError, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback, Schema, SendOptions, SendResult, SnapshotEntity, SnapshotFrame, SocketIssue, StackDefinition, StackWithAttachedPrograms, StorageAdapter, StorageAdapterConfig, StringifiedBigints, SubscribedFrame, Subscription, SubscriptionQuery, SubscriptionRegistry, SubscriptionRequest, SubscriptionSnapshotOptions, TokenBalanceInfo, TokenBalanceInput, TransactionExecutionError, TransactionFailureOutcome, TransactionOptions, TransactionOutcome, TypedInstruction, UnsubscribedFrame, Update, UpdateCallback, ViewDef, ViewGroup, ViewKeyValue, WaitForProcessedSlotOptions, WalletAdapter, WalletConnectOptions, WalletState, buildInstruction, canonicalQueryKey, createInstructionExecutor, createInstructionHandler, createPublicKeySeed, createSeed, derivePda, executeInstruction, formatProgramError, formatRawToUi, getTransactionFailureOutcome, isErrorFrame, isHostedAreteEndpoint, isSnapshotFrame, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, normalizeSubscriptionQuery, parseFrame, parseFrameFromBlob, parseInstructionError, resolveAccounts, safeToRawAmount, serializeInstructionData, serializeViewKey, stringifyBigints, toRawAmount, unwrapOperationExecutionError, validateAccountResolution, withPrograms } from '@usearete/sdk';
|
|
2
|
+
import { StackDefinition, WalletAdapter, ConnectOptions, AuthConfig, AreteError, Schema, ProgramSdkDefinition, ConnectionState, ConnectedArete, StackWithAttachedPrograms, Session, SessionDefinition, CompositionSessionOptions, SessionOptions, PreparedOperation, TransactionFailureOutcome, OperationExecutionEvent, OperationExecutionSuccessEvent, OperationTransactionReceipt, TransactionOutcome, ProgramInterface, TypedInstruction, OperationReceiptFor, StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate, ViewSortConfig, QueriesInterface, ChainClient, StackConnectedExtensions, SocketIssue, StackQueryDefinition, ViewGroup, ViewDef, OperationExecutionOptions, SendOptions, ProgramError, PlatformHttpClient, ContextSlotOptions, NativeBalanceInfo, TokenBalanceInput, TokenBalanceInfo, ProtocolTypeMap, ProtocolClient, ProtocolKeyClass, ProtocolInstanceDetail, ProtocolStepAvailabilityFor, ProtocolWalletActions, ProtocolParticipantDetail, ProtocolStreamEvent, WaitForProcessedSlotOptions } from '@usearete/sdk';
|
|
3
|
+
export { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, Arete, AreteError, AreteOptions, AreteOptionsWithStorage, ArgSchema, ArgType, AuthConfig, AuthTokenRequest, BuildOptions, BuiltAccountMeta, BuiltInstruction, ConfirmationLevel, ConnectOptions, ConnectedArete, ConnectionManager, ConnectionState, ContextSlotOptions, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, DefaultViewKey, EntityFrame, ErrorFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, Frame, FrameMode, FrameOp, FrameProcessor, FrameProcessorConfig, FrameValidationDiagnostic, InstructionError, InstructionExecutor, InstructionHandler, InstructionHandlerConfig, MemoryAdapter, MergeProgramMaps, NativeBalanceInfo, OperationCallbackError, OperationExecutionError, OperationExecutionOptions, OperationReceiptFor, OperationTransactionReceipt, PdaConfig, PdaSeed, PlatformHttpClient, PlatformHttpRequest, PlatformHttpResponse, PreparedFlow, PreparedInstruction, PreparedOperation, PreparedTransaction, PreparedTransactionInstruction, ProcessedSlotTimeoutError, ProgramError, QueryLease, QuerySnapshot, QueryStore, ReadRequestError, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback, Schema, SendOptions, SendResult, Session, SessionDefinition, SessionOptions, SnapshotEntity, SnapshotFrame, SocketIssue, StackDefinition, StackWithAttachedPrograms, StorageAdapter, StorageAdapterConfig, StringifiedBigints, SubscribedFrame, Subscription, SubscriptionQuery, SubscriptionRegistry, SubscriptionRequest, SubscriptionSnapshotOptions, TokenBalanceInfo, TokenBalanceInput, TransactionExecutionError, TransactionFailureOutcome, TransactionOptions, TransactionOutcome, TypedInstruction, UnsubscribedFrame, Update, UpdateCallback, ViewDef, ViewGroup, ViewKeyValue, WaitForProcessedSlotOptions, WalletAdapter, WalletConnectOptions, WalletState, buildInstruction, canonicalQueryKey, createInstructionExecutor, createInstructionHandler, createPlatformHttpClient, createPublicKeySeed, createSeed, derivePda, executeInstruction, formatProgramError, formatRawToUi, getTransactionFailureOutcome, isErrorFrame, isHostedAreteEndpoint, isSnapshotFrame, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, normalizeSubscriptionQuery, parseFrame, parseFrameFromBlob, parseInstructionError, resolveAccounts, safeToRawAmount, serializeInstructionData, serializeViewKey, stringifyBigints, toRawAmount, unwrapOperationExecutionError, validateAccountResolution, withPrograms } from '@usearete/sdk';
|
|
4
4
|
import { UseBoundStore, StoreApi } from 'zustand';
|
|
5
5
|
|
|
6
6
|
type ViewMode = 'state' | 'list';
|
|
@@ -62,7 +62,15 @@ interface AreteConfig {
|
|
|
62
62
|
* holds no entity for (`reason: 'unknown-key'`).
|
|
63
63
|
*/
|
|
64
64
|
onFrameValidationError?: ConnectOptions['onFrameValidationError'];
|
|
65
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Authentication configuration. An app whose users sign in to Arete (a
|
|
67
|
+
* dashboard) passes their login as an API credential:
|
|
68
|
+
* `{ tokenKind: 'api', tokenEndpoint: '/api/arete-token' }` or
|
|
69
|
+
* `{ tokenKind: 'api', getToken }`. Stack, gateway and program read
|
|
70
|
+
* connections then mint their sessions with it, and
|
|
71
|
+
* `usePlatformHttpClient()` calls the Arete API with it. A changed `auth`
|
|
72
|
+
* applies to clients created afterwards; call `retry()` to reconnect one.
|
|
73
|
+
*/
|
|
66
74
|
auth?: AuthConfig;
|
|
67
75
|
}
|
|
68
76
|
/**
|
|
@@ -244,6 +252,128 @@ declare function AreteProvider({ children, ...config }: AreteConfig & {
|
|
|
244
252
|
declare function useAreteContext(): AreteContextValue;
|
|
245
253
|
declare function useConnectionState(stack?: StackDefinition, options?: ClientLookupOptions): ConnectionState;
|
|
246
254
|
|
|
255
|
+
/** Any session from `createSession`. */
|
|
256
|
+
type AnySession = Session<any, any, any>;
|
|
257
|
+
/**
|
|
258
|
+
* The session type for `T`: a session type as it is, or the session
|
|
259
|
+
* `createSession(definition)` opens for a definition type.
|
|
260
|
+
*/
|
|
261
|
+
type SessionOf<T> = T extends AnySession ? T : T extends SessionDefinition ? Session<T> : never;
|
|
262
|
+
/**
|
|
263
|
+
* Options for the session the provider opens: `createSession`'s options
|
|
264
|
+
* without `wallet` (the provider's `wallet` prop sets it, without reopening).
|
|
265
|
+
*/
|
|
266
|
+
type AreteSessionOptions<TDef extends SessionDefinition = SessionDefinition> = Omit<TDef extends {
|
|
267
|
+
readonly mode: 'composition';
|
|
268
|
+
} ? CompositionSessionOptions<TDef> : SessionOptions<TDef>, 'wallet'>;
|
|
269
|
+
/**
|
|
270
|
+
* - `opening`: the session is being opened (or, for a provider given a
|
|
271
|
+
* `session`, none has been given yet).
|
|
272
|
+
* - `open`: `session` is ready.
|
|
273
|
+
* - `error`: opening failed; `error` says why and `retry()` tries again.
|
|
274
|
+
*/
|
|
275
|
+
type AreteSessionStatus = 'opening' | 'open' | 'error';
|
|
276
|
+
interface UseAreteSessionResult<TSession extends AnySession = AnySession> {
|
|
277
|
+
/** The open session; `null` while it opens, after a failure, and while it is reopened. */
|
|
278
|
+
readonly session: TSession | null;
|
|
279
|
+
readonly status: AreteSessionStatus;
|
|
280
|
+
/** Why the session could not be opened. */
|
|
281
|
+
readonly error: Error | null;
|
|
282
|
+
/**
|
|
283
|
+
* The session once it is open. Waits through a reopen (new auth or
|
|
284
|
+
* options) and resolves with the new session; rejects when opening fails,
|
|
285
|
+
* and with an {@link AreteSessionUnavailableError} when the provider is
|
|
286
|
+
* unmounted first.
|
|
287
|
+
* Stable, so it can be a `useOperationMutation` executor:
|
|
288
|
+
* `{ executor: ready }`.
|
|
289
|
+
*/
|
|
290
|
+
ready(): Promise<TSession>;
|
|
291
|
+
/** Open the session again after a failure. Only for sessions the provider opens. */
|
|
292
|
+
retry(): void;
|
|
293
|
+
}
|
|
294
|
+
interface SessionProviderBaseProps {
|
|
295
|
+
children: ReactNode;
|
|
296
|
+
/**
|
|
297
|
+
* The wallet the session signs with (`session.wallet`). Changing it calls
|
|
298
|
+
* `session.setWallet`; the session is not reopened.
|
|
299
|
+
*/
|
|
300
|
+
wallet?: WalletAdapter;
|
|
301
|
+
}
|
|
302
|
+
/** The provider opens (and closes) the session. */
|
|
303
|
+
interface OwnedAreteSessionProviderProps<TDef extends SessionDefinition> extends SessionProviderBaseProps {
|
|
304
|
+
/** What to open, as for `createSession(definition, options)`. */
|
|
305
|
+
definition: TDef;
|
|
306
|
+
/**
|
|
307
|
+
* `createSession` options. `auth` and `fetch` default to the enclosing
|
|
308
|
+
* `AreteProvider`'s. A change reopens the session (see the README).
|
|
309
|
+
*/
|
|
310
|
+
options?: AreteSessionOptions<TDef>;
|
|
311
|
+
session?: never;
|
|
312
|
+
}
|
|
313
|
+
/** The app opened the session; the provider shares it and never closes it. */
|
|
314
|
+
interface ExternalAreteSessionProviderProps extends SessionProviderBaseProps {
|
|
315
|
+
/** The session to share; `null`/`undefined` while the app is still opening it. */
|
|
316
|
+
session: AnySession | null | undefined;
|
|
317
|
+
definition?: never;
|
|
318
|
+
options?: never;
|
|
319
|
+
}
|
|
320
|
+
type AreteSessionProviderProps<TDef extends SessionDefinition = SessionDefinition> = OwnedAreteSessionProviderProps<TDef> | ExternalAreteSessionProviderProps;
|
|
321
|
+
/**
|
|
322
|
+
* `ready()` rejects with this when its `AreteSessionProvider` was removed
|
|
323
|
+
* before the session opened (or is called after the provider is gone): no
|
|
324
|
+
* session will come. `code` is `provider_unmounted`.
|
|
325
|
+
*/
|
|
326
|
+
declare class AreteSessionUnavailableError extends Error {
|
|
327
|
+
readonly code: "provider_unmounted";
|
|
328
|
+
constructor(message?: string);
|
|
329
|
+
}
|
|
330
|
+
/** Whether `error` is an {@link AreteSessionUnavailableError}. */
|
|
331
|
+
declare function isAreteSessionUnavailableError(error: unknown): error is AreteSessionUnavailableError;
|
|
332
|
+
/**
|
|
333
|
+
* One Arete session (`createSession`) for everything below it, read with
|
|
334
|
+
* {@link useAreteSession}.
|
|
335
|
+
*
|
|
336
|
+
* ```tsx
|
|
337
|
+
* const SQUADS = { programs: { squads: SQUADS_V4_PROGRAM } };
|
|
338
|
+
* const auth = { tokenKind: 'api', tokenEndpoint: '/api/arete-token' } as const;
|
|
339
|
+
*
|
|
340
|
+
* <AreteSessionProvider definition={SQUADS} options={{ auth }} wallet={wallet}>
|
|
341
|
+
* <App />
|
|
342
|
+
* </AreteSessionProvider>;
|
|
343
|
+
*
|
|
344
|
+
* // below it
|
|
345
|
+
* const { session } = useAreteSession<typeof SQUADS>();
|
|
346
|
+
* session?.programs.squads; // typed
|
|
347
|
+
* ```
|
|
348
|
+
*
|
|
349
|
+
* Given `definition`, the provider opens the session when it mounts and
|
|
350
|
+
* closes it when it unmounts. `options.auth` and `options.fetch` default to
|
|
351
|
+
* the enclosing `AreteProvider`'s. When the definition or the options
|
|
352
|
+
* change, the old session is closed at once and a new one is opened:
|
|
353
|
+
* `session` is `null` until it is ready, so nothing runs against a session
|
|
354
|
+
* opened with credentials that no longer apply. Options are compared by
|
|
355
|
+
* shape two levels deep (an inline `auth` object with the same fields is the
|
|
356
|
+
* same auth); functions such as `getToken` or `fetch` compare by identity,
|
|
357
|
+
* so keep them stable. The wallet never reopens the session: changing
|
|
358
|
+
* `wallet` calls `session.setWallet`.
|
|
359
|
+
*
|
|
360
|
+
* Given `session`, the provider only shares it: the app opened it and closes
|
|
361
|
+
* it. `wallet`, when passed, is set on it the same way.
|
|
362
|
+
*/
|
|
363
|
+
declare function AreteSessionProvider<TDef extends SessionDefinition>(props: AreteSessionProviderProps<TDef>): React.ReactElement;
|
|
364
|
+
/**
|
|
365
|
+
* The nearest {@link AreteSessionProvider}'s session. Pass the definition
|
|
366
|
+
* (or the session type) for typed members:
|
|
367
|
+
*
|
|
368
|
+
* ```tsx
|
|
369
|
+
* const { session, status, ready } = useAreteSession<typeof SQUADS>();
|
|
370
|
+
* const squads = session?.programs.squads;
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* Throws outside an `AreteSessionProvider`.
|
|
374
|
+
*/
|
|
375
|
+
declare function useAreteSession<T extends SessionDefinition | AnySession = AnySession>(): UseAreteSessionResult<SessionOf<T>>;
|
|
376
|
+
|
|
247
377
|
type MutationStatus = 'idle' | 'pending' | 'success' | 'error';
|
|
248
378
|
type MutationPhase = 'idle' | 'preparing' | 'awaiting-wallet' | 'submitted' | 'confirmed' | 'reconciling' | 'reconciled' | 'confirmed-unreconciled' | 'not-submitted' | 'submitted-unknown' | 'chain-failed';
|
|
249
379
|
interface MutationLifecycleEvent<TResult = unknown, TPrepared extends PreparedOperation = PreparedOperation> {
|
|
@@ -483,6 +613,7 @@ declare class ZustandAdapter implements StorageAdapter {
|
|
|
483
613
|
getViewConfig(viewPath: string): ViewSortConfig | undefined;
|
|
484
614
|
}
|
|
485
615
|
|
|
616
|
+
type AnyClient = ConnectedArete<StackDefinition>;
|
|
486
617
|
type ProgramMap$1 = Record<string, ProgramSdkDefinition>;
|
|
487
618
|
type ResolvedStack<TStack extends StackDefinition, TPrograms extends ProgramMap$1 | undefined> = StackWithAttachedPrograms<TStack, TPrograms>;
|
|
488
619
|
type StackQueries<TStack> = TStack extends {
|
|
@@ -554,6 +685,55 @@ type UseAreteResult<TStack extends StackDefinition, TPrograms extends ProgramMap
|
|
|
554
685
|
socketIssue: SocketIssue | null;
|
|
555
686
|
retry: () => Promise<void>;
|
|
556
687
|
};
|
|
688
|
+
/**
|
|
689
|
+
* A connected stack client: a session member (`session.stacks.<key>` from
|
|
690
|
+
* `createSession`) or a client from `Arete.connect`.
|
|
691
|
+
*/
|
|
692
|
+
type AnyStackClient = Pick<AnyClient, 'getSubscriptionRegistry' | 'onConnectionStateChange' | 'onSocketIssue' | 'connectionState'>;
|
|
693
|
+
/** The stack a connected client was connected for (with its attached programs). */
|
|
694
|
+
type StackOfClient<TClient> = NonNullable<TClient> extends ConnectedArete<infer TStack extends StackDefinition, infer _TExtensions> ? TStack : never;
|
|
695
|
+
/**
|
|
696
|
+
* The definition of a member's stack, for `useArete(member, { stack })`: any
|
|
697
|
+
* stack definition with the member's views (the generated stack, before or
|
|
698
|
+
* after `programs` are attached).
|
|
699
|
+
*/
|
|
700
|
+
type MemberStackDefinition<TStack extends StackDefinition> = StackDefinition & Pick<TStack, 'views'>;
|
|
701
|
+
/** Options for `useArete(member)`, where `member` is a client someone else connected. */
|
|
702
|
+
interface UseAreteMemberOptions<TStack extends StackDefinition = StackDefinition> {
|
|
703
|
+
/**
|
|
704
|
+
* The member's stack definition. Required while the member can be `null` or
|
|
705
|
+
* `undefined` (the session is still opening), so views, programs,
|
|
706
|
+
* addresses and constants exist before it opens; once it has opened, the
|
|
707
|
+
* member's own `stack` is used.
|
|
708
|
+
*/
|
|
709
|
+
stack?: MemberStackDefinition<TStack>;
|
|
710
|
+
/**
|
|
711
|
+
* Programs the session attached to this member (its member options'
|
|
712
|
+
* `programs`), for the placeholders while the session opens: their
|
|
713
|
+
* addresses, PDAs and constants work before it opens, as with
|
|
714
|
+
* `useArete(stack, { programs })`. Once it has opened, the member's own
|
|
715
|
+
* programs are used. TypeScript asks for every attached program `stack`
|
|
716
|
+
* does not already have.
|
|
717
|
+
*/
|
|
718
|
+
programs?: ProgramMap$1;
|
|
719
|
+
}
|
|
720
|
+
type ProgramKeysOf<TStack> = TStack extends {
|
|
721
|
+
programs?: infer TPrograms;
|
|
722
|
+
} ? TPrograms extends object ? keyof TPrograms & string : never : never;
|
|
723
|
+
/**
|
|
724
|
+
* Options for `useArete(member, options)` while the member may be missing:
|
|
725
|
+
* the placeholder `stack`, plus `programs` for each program the member has
|
|
726
|
+
* (one attached through the session's member options) that `stack` lacks.
|
|
727
|
+
*/
|
|
728
|
+
type UseAreteMemberPlaceholderOptions<TStack extends StackDefinition, TPlaceholder extends MemberStackDefinition<TStack>> = {
|
|
729
|
+
stack: TPlaceholder;
|
|
730
|
+
} & ([
|
|
731
|
+
Exclude<ProgramKeysOf<TStack>, ProgramKeysOf<TPlaceholder>>
|
|
732
|
+
] extends [never] ? {
|
|
733
|
+
programs?: ProgramMap$1;
|
|
734
|
+
} : {
|
|
735
|
+
programs: ProgramMap$1 & Record<Exclude<ProgramKeysOf<TStack>, ProgramKeysOf<TPlaceholder>>, ProgramSdkDefinition>;
|
|
736
|
+
});
|
|
557
737
|
/**
|
|
558
738
|
* Module-augmentation point for the default stack's type. When the provider
|
|
559
739
|
* declares a default stack (`<AreteProvider stack={...}>`), register its type
|
|
@@ -572,6 +752,30 @@ type RegisteredDefaultStack = AreteDefaultStackRegistry extends {
|
|
|
572
752
|
} ? TStack : StackDefinition;
|
|
573
753
|
declare function useArete(stack?: undefined, options?: UseAreteOptions): UseAreteResult<RegisteredDefaultStack, undefined>;
|
|
574
754
|
declare function useArete<TStack extends StackDefinition, TPrograms extends ProgramMap$1 | undefined = undefined>(stack: TStack, options?: UseAreteOptions<TPrograms>): UseAreteResult<TStack, TPrograms>;
|
|
755
|
+
/**
|
|
756
|
+
* The hooks for a stack client that is already connected, typically a
|
|
757
|
+
* session member: `useArete(session.stacks.ore)`. The hooks read the
|
|
758
|
+
* member's own connection and store, so nothing connects again, and the
|
|
759
|
+
* member's owner (the session) disconnects it; unmounting never does.
|
|
760
|
+
* Mutations sign with the member's wallet, which `session.setWallet` (or
|
|
761
|
+
* `AreteSessionProvider`'s `wallet`) sets.
|
|
762
|
+
*
|
|
763
|
+
* While the session opens, pass the member as it may be (`null` or
|
|
764
|
+
* `undefined`) together with its stack definition, and the result is the
|
|
765
|
+
* connecting state `useArete(stack)` reports before its client exists:
|
|
766
|
+
*
|
|
767
|
+
* ```tsx
|
|
768
|
+
* const { session } = useAreteSession<typeof APP>();
|
|
769
|
+
* const ore = useArete(session?.stacks.ore, { stack: APP.stacks.ore });
|
|
770
|
+
* ```
|
|
771
|
+
*
|
|
772
|
+
* A member the session attached programs to (`createSession(APP, { stacks:
|
|
773
|
+
* { ore: { programs: { memo } } } })`) also takes them, so their helpers work
|
|
774
|
+
* while it opens: `useArete(session?.stacks.ore, { stack: APP.stacks.ore,
|
|
775
|
+
* programs: { memo } })`. TypeScript asks for any it is missing.
|
|
776
|
+
*/
|
|
777
|
+
declare function useArete<TClient extends AnyStackClient>(member: TClient, options?: UseAreteMemberOptions<StackOfClient<TClient>>): UseAreteResult<StackOfClient<TClient>>;
|
|
778
|
+
declare function useArete<TClient extends AnyStackClient, TPlaceholder extends MemberStackDefinition<StackOfClient<TClient>>>(member: TClient | null | undefined, options: UseAreteMemberPlaceholderOptions<StackOfClient<TClient>, TPlaceholder>): UseAreteResult<StackOfClient<TClient>>;
|
|
575
779
|
|
|
576
780
|
type ProgramMap = Record<string, ProgramSdkDefinition>;
|
|
577
781
|
type BoundAreteProviderProps = Omit<AreteConfig, 'stack'> & {
|
|
@@ -629,6 +833,220 @@ declare const summarizeViews: typeof summarizeStatuses;
|
|
|
629
833
|
type StatusSource = ViewStatusSource;
|
|
630
834
|
type SummarizedStatus = SummarizedViewStatus;
|
|
631
835
|
|
|
836
|
+
/**
|
|
837
|
+
* Where an operation run is:
|
|
838
|
+
*
|
|
839
|
+
* - `idle`: nothing has run (or `reset()` was called).
|
|
840
|
+
* - `preparing`: `prepare` is building the operation.
|
|
841
|
+
* - `signing`: a transaction is waiting for its signatures, which for a
|
|
842
|
+
* browser wallet means its approval prompt is open ("check your wallet").
|
|
843
|
+
* - `sending`: signed; the transaction is being submitted.
|
|
844
|
+
* - `confirming`: submitted; waiting for the commitment.
|
|
845
|
+
* - `done`: every transaction of the operation confirmed; `result` is set.
|
|
846
|
+
* - `error`: the run failed; `error` says how.
|
|
847
|
+
*
|
|
848
|
+
* `sending` and `confirming` are reported by wallets that publish their
|
|
849
|
+
* activity (the `@usearete/adapter-kit` adapters do, through `onActivity`).
|
|
850
|
+
* With any other wallet a transaction stays `signing` until it confirms.
|
|
851
|
+
* A flow walks `signing` → `sending` → `confirming` once per transaction.
|
|
852
|
+
*/
|
|
853
|
+
type OperationMutationStatus = 'idle' | 'preparing' | 'signing' | 'sending' | 'confirming' | 'done' | 'error';
|
|
854
|
+
/** Something that executes a prepared operation: a connected client or a session. */
|
|
855
|
+
interface OperationExecutor {
|
|
856
|
+
execute<TPrepared extends PreparedOperation, TSigner = unknown>(prepared: TPrepared, options?: OperationExecutionOptions<TSigner, TPrepared>): Promise<OperationReceiptFor<TPrepared>>;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* The executor, or a function that resolves it when a run starts (for
|
|
860
|
+
* example a session opened on first use). `null` while it is not available
|
|
861
|
+
* yet: a run then fails with `not-ready`. Omitted (or `undefined`), the hook
|
|
862
|
+
* uses the nearest `AreteSessionProvider`'s session, waiting for it to open.
|
|
863
|
+
*/
|
|
864
|
+
type OperationExecutorSource = OperationExecutor | (() => OperationExecutor | Promise<OperationExecutor>) | null | undefined;
|
|
865
|
+
/** A prepared operation with signers made while preparing it (a create key). */
|
|
866
|
+
interface PreparedOperationWithSigners<TPrepared extends PreparedOperation> {
|
|
867
|
+
readonly operation: TPrepared;
|
|
868
|
+
readonly signers?: readonly unknown[];
|
|
869
|
+
}
|
|
870
|
+
/** Builds the operation for one run, e.g. `(input) => program.flows.x.y.prepare(input)`. */
|
|
871
|
+
type OperationPrepareFn<TInput, TPrepared extends PreparedOperation> = (input: TInput) => TPrepared | PreparedOperationWithSigners<TPrepared> | Promise<TPrepared | PreparedOperationWithSigners<TPrepared>>;
|
|
872
|
+
/** Per-run settings; each also has a hook-level default. */
|
|
873
|
+
interface OperationRunOptions {
|
|
874
|
+
/**
|
|
875
|
+
* The wallet that signs. Without one the run fails with `not-ready` and
|
|
876
|
+
* nothing is prepared or signed, unless the hook sets
|
|
877
|
+
* `allowExecutorWallet`.
|
|
878
|
+
*/
|
|
879
|
+
readonly wallet?: WalletAdapter;
|
|
880
|
+
/** Extra local signers for this run, added to the hook's and `prepare`'s. */
|
|
881
|
+
readonly signers?: readonly unknown[];
|
|
882
|
+
/** Send options forwarded to the wallet (transaction version, resources). */
|
|
883
|
+
readonly send?: SendOptions;
|
|
884
|
+
}
|
|
885
|
+
interface UseOperationMutationOptions<TPrepared extends PreparedOperation> extends OperationRunOptions {
|
|
886
|
+
/** What runs the operation; defaults to the nearest `AreteSessionProvider`'s session. */
|
|
887
|
+
readonly executor?: OperationExecutorSource;
|
|
888
|
+
/**
|
|
889
|
+
* Sign with the executor's own wallet (`session.wallet`, the client's
|
|
890
|
+
* wallet) when neither the run nor the hook names one. Off by default, so
|
|
891
|
+
* a run never signs with a wallet the component did not pass.
|
|
892
|
+
*/
|
|
893
|
+
readonly allowExecutorWallet?: boolean;
|
|
894
|
+
readonly onSuccess?: (result: OperationReceiptFor<TPrepared>, prepared: TPrepared) => void | Promise<void>;
|
|
895
|
+
readonly onError?: (error: OperationMutationError<TPrepared>) => void | Promise<void>;
|
|
896
|
+
/**
|
|
897
|
+
* Called on every status change of a run, as it happens (React may batch
|
|
898
|
+
* the re-renders of quick changes, this callback never skips one).
|
|
899
|
+
* `transactionIndex` is the transaction of the operation it is about.
|
|
900
|
+
*/
|
|
901
|
+
readonly onStatusChange?: (status: OperationMutationStatus, context: {
|
|
902
|
+
readonly transactionIndex: number | null;
|
|
903
|
+
}) => void;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* How a run failed:
|
|
907
|
+
*
|
|
908
|
+
* - `busy`: a run of this hook is already in progress; nothing was started.
|
|
909
|
+
* - `not-ready`: no executor, or no wallet, to run with; nothing was
|
|
910
|
+
* prepared or signed.
|
|
911
|
+
* - `prepare-failed`: `prepare` threw; nothing was signed.
|
|
912
|
+
* - `wallet-rejected`: the user declined (or closed) the wallet prompt.
|
|
913
|
+
* - `wallet-feature-unsupported`: the wallet cannot sign without sending
|
|
914
|
+
* (it lacks `solana:signTransaction`), so Arete cannot relay for it.
|
|
915
|
+
* - `wallet-chain-unsupported`: the wallet (or the account) does not sign
|
|
916
|
+
* for the chain it was asked to.
|
|
917
|
+
* - `wallet-version-unsupported`: the wallet signs, but not this
|
|
918
|
+
* transaction version (a v0-only wallet and a V1 transaction).
|
|
919
|
+
* - `wallet-modified`: the wallet changed the transaction it was asked to
|
|
920
|
+
* sign (for example to add a priority fee), so it was not sent.
|
|
921
|
+
* - `not-submitted`: failed before anything reached the chain.
|
|
922
|
+
* - `submitted-unknown`: sent, but its confirmation did not arrive; check
|
|
923
|
+
* the chain before trying again.
|
|
924
|
+
* - `chain-failed`: the transaction failed on chain; see `programError`.
|
|
925
|
+
*/
|
|
926
|
+
type OperationMutationErrorKind = 'busy' | 'not-ready' | 'prepare-failed' | 'wallet-rejected' | 'wallet-feature-unsupported' | 'wallet-chain-unsupported' | 'wallet-version-unsupported' | 'wallet-modified' | 'not-submitted' | 'submitted-unknown' | 'chain-failed';
|
|
927
|
+
/** The typed failure of a {@link useOperationMutation} run. */
|
|
928
|
+
declare class OperationMutationError<TPrepared extends PreparedOperation = PreparedOperation> extends Error {
|
|
929
|
+
readonly kind: OperationMutationErrorKind;
|
|
930
|
+
/** The transaction outcome, when the failure happened at or after signing. */
|
|
931
|
+
readonly failure: TransactionFailureOutcome | null;
|
|
932
|
+
/** The operation that was running, once prepared. */
|
|
933
|
+
readonly prepared: TPrepared | null;
|
|
934
|
+
/** Signatures of the transactions that confirmed before the failure. */
|
|
935
|
+
readonly completedSignatures: readonly string[];
|
|
936
|
+
/** The failing transaction's signature, when it was signed. */
|
|
937
|
+
readonly signature?: string;
|
|
938
|
+
readonly programError?: ProgramError;
|
|
939
|
+
readonly cause: unknown;
|
|
940
|
+
constructor(input: {
|
|
941
|
+
kind: OperationMutationErrorKind;
|
|
942
|
+
message: string;
|
|
943
|
+
cause: unknown;
|
|
944
|
+
failure?: TransactionFailureOutcome | null;
|
|
945
|
+
prepared?: TPrepared | null;
|
|
946
|
+
completedSignatures?: readonly string[];
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Whether `error` (or anything in its `cause` chain) is a wallet prompt the
|
|
951
|
+
* user declined or closed. Wallets report this in a few ways: EIP-1193 code
|
|
952
|
+
* 4001 (Phantom, Solflare), a `...RejectedError`, or the message.
|
|
953
|
+
*/
|
|
954
|
+
declare function isWalletRejection(error: unknown): boolean;
|
|
955
|
+
/**
|
|
956
|
+
* Classify an execution failure. Exported so code outside the hook (an
|
|
957
|
+
* imperative `session.execute`) can show the same messages.
|
|
958
|
+
*/
|
|
959
|
+
declare function toOperationMutationError<TPrepared extends PreparedOperation = PreparedOperation>(error: unknown, prepared?: TPrepared | null, completedSignatures?: readonly string[]): OperationMutationError<TPrepared>;
|
|
960
|
+
interface UseOperationMutationResult<TInput, TPrepared extends PreparedOperation> {
|
|
961
|
+
/** Run the operation; rejects with an {@link OperationMutationError}. */
|
|
962
|
+
run(input: TInput, options?: OperationRunOptions): Promise<OperationReceiptFor<TPrepared>>;
|
|
963
|
+
/** Event-handler form of `run`: the failure is kept in `error`, never thrown. */
|
|
964
|
+
mutate(input: TInput, options?: OperationRunOptions): void;
|
|
965
|
+
readonly status: OperationMutationStatus;
|
|
966
|
+
/**
|
|
967
|
+
* `preparing`, `signing`, `sending` or `confirming`. Exactly when it is
|
|
968
|
+
* true, `run()` is refused with `busy`: once `status` is `done` or `error`
|
|
969
|
+
* the hook takes a new run, even while `onSuccess`/`onError` are pending.
|
|
970
|
+
*/
|
|
971
|
+
readonly isBusy: boolean;
|
|
972
|
+
/** The wallet is waiting for the user: show "check your wallet". */
|
|
973
|
+
readonly isAwaitingWallet: boolean;
|
|
974
|
+
/** The operation of the latest run, once prepared. */
|
|
975
|
+
readonly prepared: TPrepared | null;
|
|
976
|
+
/** The prepared operation's artifacts (derived addresses and the like). */
|
|
977
|
+
readonly artifacts: TPrepared['artifacts'] | undefined;
|
|
978
|
+
/** The receipt of the latest successful run. */
|
|
979
|
+
readonly result: OperationReceiptFor<TPrepared> | undefined;
|
|
980
|
+
readonly error: OperationMutationError<TPrepared> | null;
|
|
981
|
+
/** Signatures of the transactions confirmed so far in the latest run. */
|
|
982
|
+
readonly signatures: readonly string[];
|
|
983
|
+
/** Which of `transactionCount` transactions is in progress (0-based). */
|
|
984
|
+
readonly transactionIndex: number | null;
|
|
985
|
+
readonly transactionCount: number | null;
|
|
986
|
+
reset(): void;
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Run a prepared instruction, transaction or flow with a wallet and report
|
|
990
|
+
* where it is: idle → preparing → signing → sending → confirming → done (or
|
|
991
|
+
* error). Works with anything that has `execute(prepared, options)`, a
|
|
992
|
+
* connected client or a session, so it needs no stack:
|
|
993
|
+
*
|
|
994
|
+
* ```tsx
|
|
995
|
+
* const createMultisig = useOperationMutation(
|
|
996
|
+
* async (input: CreateInput) => {
|
|
997
|
+
* const createKey = await generateKeyPairSigner();
|
|
998
|
+
* return {
|
|
999
|
+
* operation: await squads.flows.arete.createMultisig.prepare({ ...input, createKey: createKey.address }),
|
|
1000
|
+
* signers: [createKey],
|
|
1001
|
+
* };
|
|
1002
|
+
* },
|
|
1003
|
+
* { executor: session, wallet },
|
|
1004
|
+
* );
|
|
1005
|
+
* // Inside an AreteSessionProvider, `executor` can be left out.
|
|
1006
|
+
* // createMultisig.mutate(input); createMultisig.isAwaitingWallet → "Approve in your wallet"
|
|
1007
|
+
* ```
|
|
1008
|
+
*
|
|
1009
|
+
* Signers returned by `prepare`, given to the hook and given to the run are
|
|
1010
|
+
* all passed to `execute`. A run without a wallet fails with `not-ready`
|
|
1011
|
+
* before `prepare` is called; set `allowExecutorWallet` to sign with the
|
|
1012
|
+
* executor's own wallet instead. A second run while one is in progress rejects
|
|
1013
|
+
* with `busy` and leaves the first alone, so a double click never opens two
|
|
1014
|
+
* wallet prompts. "In progress" is exactly `isBusy`: a run ends when its
|
|
1015
|
+
* `done` or `error` status is published, before `onSuccess`/`onError` are
|
|
1016
|
+
* awaited, so a button disabled by `isBusy` is never enabled while `run()`
|
|
1017
|
+
* would refuse it. A run started during those callbacks is a new run; the
|
|
1018
|
+
* earlier run's `run()` promise still settles after its callback.
|
|
1019
|
+
*/
|
|
1020
|
+
declare function useOperationMutation<TInput, TPrepared extends PreparedOperation>(prepare: OperationPrepareFn<TInput, TPrepared>, options: UseOperationMutationOptions<TPrepared>): UseOperationMutationResult<TInput, TPrepared>;
|
|
1021
|
+
|
|
1022
|
+
interface UsePlatformHttpClientOptions {
|
|
1023
|
+
/** API origin, with or without `/api`. Defaults to `https://api.arete.run`. */
|
|
1024
|
+
readonly apiUrl?: string;
|
|
1025
|
+
/** Defaults to the provider's `auth`. */
|
|
1026
|
+
readonly auth?: AuthConfig;
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* A client for the Arete API's account routes, authenticated with the
|
|
1030
|
+
* provider's `auth` (and `fetch`). With `auth.tokenKind: 'api'`, the same
|
|
1031
|
+
* credential the provider mints its stack and gateway sessions with, so one
|
|
1032
|
+
* login drives both:
|
|
1033
|
+
*
|
|
1034
|
+
* ```tsx
|
|
1035
|
+
* <AreteProvider auth={{ tokenKind: 'api', tokenEndpoint: '/api/arete-token' }}>
|
|
1036
|
+
* …
|
|
1037
|
+
* </AreteProvider>
|
|
1038
|
+
* // in a component
|
|
1039
|
+
* const http = usePlatformHttpClient({ apiUrl });
|
|
1040
|
+
* const squads = useMemo(() => createSquadsClient({ http }), [http]);
|
|
1041
|
+
* ```
|
|
1042
|
+
*
|
|
1043
|
+
* The client is stable while `apiUrl`, `auth` and `fetch` keep their
|
|
1044
|
+
* identity, so pass a memoized (or module-level) `auth` object. Throws
|
|
1045
|
+
* during render when the auth carries no API credential, like
|
|
1046
|
+
* `createPlatformHttpClient`.
|
|
1047
|
+
*/
|
|
1048
|
+
declare function usePlatformHttpClient(options?: UsePlatformHttpClientOptions): PlatformHttpClient;
|
|
1049
|
+
|
|
632
1050
|
interface BalanceHookOptions<T> extends ContextSlotOptions, UseAsyncReadOptions<T> {
|
|
633
1051
|
}
|
|
634
1052
|
declare function useNativeBalance(chain: ChainClient | null | undefined, address: string | null | undefined, options?: BalanceHookOptions<NativeBalanceInfo>): UseAsyncReadResult<NativeBalanceInfo>;
|
|
@@ -744,5 +1162,5 @@ interface DefaultReconciliationFn {
|
|
|
744
1162
|
*/
|
|
745
1163
|
declare function createProcessedSlotReconciliation(client: ProcessedSlotClient | null | undefined, baseOverrides?: MutationReconcileOverrides): DefaultReconciliationFn;
|
|
746
1164
|
|
|
747
|
-
export { AreteProvider, DEFAULT_RECONCILIATION_TIMEOUT_MS, ZustandAdapter, createAreteReact, createProcessedSlotReconciliation, reconcileProcessedSlot, summarizeStatuses, summarizeViews, useAllowedSteps, useArete, useAreteContext, useAsyncRead, useConnectionState, useInstructionMutation, useNativeBalance, useProtocolEvents, useProtocolInstance, useProtocolParticipant, useReconcileProcessedSlot, useTokenBalance, useWalletActions };
|
|
748
|
-
export type { AnyProtocolClient, AreteConfig, AreteDefaultStackRegistry, AreteStore, AsyncReadContext, AsyncReadKey, AsyncReadStatus, BalanceHookOptions, BoundAreteProviderProps, ClientLookupOptions, DefaultReconciliationFn, ListOneViewHookOptions, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, ListViewHookOptions, MutationExecutionObserver, MutationExecutor, MutationLifecycleEvent, MutationPhase, MutationReconcileFn, MutationReconcileOverrides, MutationReconciliationContext, MutationStatus, ProcessedSlotClient, ProcessedSlotReconciliationOptions, ProcessedSlotReconciliationResult, ReactReadInterface, ReadHookInterface, ReadHookOptions, ReconciliationRefresh, ReconciliationRefreshTarget, StateViewHook, StateViewHookOptions, StatusSource, SummarizedStatus, SummarizedViewStatus, TransactionDefinition, UseAreteOptions, UseAreteResult, UseAsyncReadOptions, UseAsyncReadResult, UseMutationOptions, UseMutationResult, UseMutationReturn, UseProtocolEventsOptions, UseProtocolInstanceOptions, UseProtocolInstanceResult, UseProtocolStepsOptions, UseWalletActionsInput, ViewHookOptions, ViewHookResult, ViewMode, ViewSchemaValidationDiagnostic, ViewSchemaValidationErrorCallback, ViewStatus, ViewStatusSource };
|
|
1165
|
+
export { AreteProvider, AreteSessionProvider, AreteSessionUnavailableError, DEFAULT_RECONCILIATION_TIMEOUT_MS, OperationMutationError, ZustandAdapter, createAreteReact, createProcessedSlotReconciliation, isAreteSessionUnavailableError, isWalletRejection, reconcileProcessedSlot, summarizeStatuses, summarizeViews, toOperationMutationError, useAllowedSteps, useArete, useAreteContext, useAreteSession, useAsyncRead, useConnectionState, useInstructionMutation, useNativeBalance, useOperationMutation, usePlatformHttpClient, useProtocolEvents, useProtocolInstance, useProtocolParticipant, useReconcileProcessedSlot, useTokenBalance, useWalletActions };
|
|
1166
|
+
export type { AnyProtocolClient, AnySession, AnyStackClient, AreteConfig, AreteDefaultStackRegistry, AreteSessionOptions, AreteSessionProviderProps, AreteSessionStatus, AreteStore, AsyncReadContext, AsyncReadKey, AsyncReadStatus, BalanceHookOptions, BoundAreteProviderProps, ClientLookupOptions, DefaultReconciliationFn, ExternalAreteSessionProviderProps, ListOneViewHookOptions, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, ListViewHookOptions, MemberStackDefinition, MutationExecutionObserver, MutationExecutor, MutationLifecycleEvent, MutationPhase, MutationReconcileFn, MutationReconcileOverrides, MutationReconciliationContext, MutationStatus, OperationExecutor, OperationExecutorSource, OperationMutationErrorKind, OperationMutationStatus, OperationPrepareFn, OperationRunOptions, OwnedAreteSessionProviderProps, PreparedOperationWithSigners, ProcessedSlotClient, ProcessedSlotReconciliationOptions, ProcessedSlotReconciliationResult, ReactReadInterface, ReadHookInterface, ReadHookOptions, ReconciliationRefresh, ReconciliationRefreshTarget, SessionOf, StackOfClient, StateViewHook, StateViewHookOptions, StatusSource, SummarizedStatus, SummarizedViewStatus, TransactionDefinition, UseAreteMemberOptions, UseAreteMemberPlaceholderOptions, UseAreteOptions, UseAreteResult, UseAreteSessionResult, UseAsyncReadOptions, UseAsyncReadResult, UseMutationOptions, UseMutationResult, UseMutationReturn, UseOperationMutationOptions, UseOperationMutationResult, UsePlatformHttpClientOptions, UseProtocolEventsOptions, UseProtocolInstanceOptions, UseProtocolInstanceResult, UseProtocolStepsOptions, UseWalletActionsInput, ViewHookOptions, ViewHookResult, ViewMode, ViewSchemaValidationDiagnostic, ViewSchemaValidationErrorCallback, ViewStatus, ViewStatusSource };
|