@provex/react 1.11.0 → 2.0.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.
@@ -10,6 +10,7 @@ import { TokenInfo } from '@provex/utils/tokens';
10
10
  import { CaptureAdapter, ProvingState, CaptureCandidate } from '@provex/proving';
11
11
  import * as _provex_utils from '@provex/utils';
12
12
  import { WriteHookParams } from '@valve-tech/wallet-adapter';
13
+ import { C as Clock } from './clock-BDtn-Itb.cjs';
13
14
 
14
15
  /**
15
16
  * @fileoverview Hook for fetching deposits that match a buyer's criteria.
@@ -439,31 +440,6 @@ interface PayeeDetails {
439
440
  platformName?: string;
440
441
  [key: string]: unknown;
441
442
  }
442
- /** Attestation request for zkTLS proof submission. */
443
- interface AttestationParams {
444
- /** Payment platform (e.g. 'chase', 'venmo') */
445
- platform: string;
446
- /** Action type (e.g. 'transfer_zelle', 'transfer_venmo') */
447
- actionType: string;
448
- /** Reclaim proofs */
449
- proofs: unknown[];
450
- /** Chain ID for the attestation */
451
- chainId: number;
452
- /** Verifying contract address */
453
- verifyingContract: Hex;
454
- /** Intent data for the attestation */
455
- intent: unknown;
456
- }
457
- /** Attestation response with signed payment proof. */
458
- interface AttestationResponse {
459
- success: boolean;
460
- message?: string;
461
- statusCode?: number;
462
- responseObject: {
463
- paymentProof?: unknown;
464
- [key: string]: unknown;
465
- };
466
- }
467
443
  /**
468
444
  * Human-readable params for signaling an intent (buyer side).
469
445
  *
@@ -653,55 +629,114 @@ interface CreateDepositParams {
653
629
  }
654
630
 
655
631
  /**
656
- * @fileoverview React hook for the V3 intent signaling flow.
632
+ * @fileoverview React hook for the intent signaling flow (reserve a deposit).
657
633
  *
658
- * Thin state wrapper around ProveXClient.signalIntent() —
659
- * manages status, error messages, and loading state for the UI.
634
+ * A thin state wrapper around `ProveXClient.signalIntent()`. It manages the
635
+ * status, the message and the loading flag for the interface.
636
+ *
637
+ * The hook is headless. App-only concerns come in through options:
638
+ * - `beginTransaction`: a pre-flight gate and a progress tracker, for
639
+ * example a stuck-transaction check and a transaction strip.
640
+ * - `isRejection` and `formatError`: the app's own error handling, for
641
+ * example translated messages.
642
+ * - `messages`: copy for the guard and success states.
643
+ * - `chainId`, `indexer` and `apiUrl`: use these when the app has no
644
+ * `ProvexProvider`. Each falls back to the provider value.
660
645
  */
661
646
 
662
647
  /** Status of the signal intent flow. */
663
648
  type SignalIntentStatus = 'input' | 'loading_payee' | 'loading_intent' | 'prompt_wallet_confirm' | 'writing_intent' | 'success' | 'error';
649
+ /** The deposit to reserve. A `DepositInfo` fits this shape. */
650
+ interface SignalIntentDeposit {
651
+ /** The escrow contract that holds the deposit. Required to send the order. */
652
+ escrow?: Hex | null;
653
+ /** The deposit id inside that escrow. Falls back to the order's `depositId`. */
654
+ localId?: bigint | null;
655
+ }
656
+ /** Progress callbacks for one signal-intent attempt. */
657
+ interface SignalIntentTransaction {
658
+ /** The wallet is about to show a signature prompt. */
659
+ awaitingSignature: () => void;
660
+ /** The wallet sent the transaction and returned its hash. */
661
+ attach: (hash: Hex) => void;
662
+ /** The attempt failed or the user rejected it. */
663
+ failed: (error: unknown) => void;
664
+ }
665
+ /** Copy for the states the hook reports itself. */
666
+ interface SignalIntentMessages {
667
+ clientOrDepositUnavailable: string;
668
+ noEscrowAddress: string;
669
+ success: string;
670
+ }
671
+ /** English defaults for {@link SignalIntentMessages}. */
672
+ declare const DEFAULT_SIGNAL_INTENT_MESSAGES: SignalIntentMessages;
673
+ /** Options for {@link useSignalIntent}. */
674
+ interface UseSignalIntentOptions {
675
+ /** Wallet adapter for signing transactions. `null` until a wallet connects. */
676
+ wallet: WalletAdapter | null | undefined;
677
+ /**
678
+ * The chain to send on. Resolved through the shared chain table. When
679
+ * omitted, or unknown, the `ProvexProvider` chain is used.
680
+ */
681
+ chainId?: ChainId;
682
+ /** Indexer adapter. Defaults to the `ProvexProvider` adapter. */
683
+ indexer?: IndexerAdapter;
684
+ /** Backend API origin. Defaults to the `ProvexProvider` `apiUrl`. */
685
+ apiUrl?: string;
686
+ /** Called when the intent is signaled successfully. */
687
+ onSuccess: (intentHash: Hex) => void;
688
+ /** Called when the flow fails. A wallet rejection is not a failure. */
689
+ onFailure?: () => void;
690
+ /** The deposit to signal intent against. */
691
+ deposit: SignalIntentDeposit | null;
692
+ /** Called on failure to refresh deposit data. */
693
+ refetchDeposits?: () => void;
694
+ /**
695
+ * Pre-flight gate and progress tracker. It runs after the guards and
696
+ * before the wallet prompt. Resolve to `null` to stop silently (the user
697
+ * cancelled, or the gate handled the screen); the form stays at `input`.
698
+ */
699
+ beginTransaction?: () => Promise<SignalIntentTransaction | null>;
700
+ /** Whether an error is a wallet rejection. Defaults to the client's own flag. */
701
+ isRejection?: (error: unknown) => boolean;
702
+ /** Turns an error into the message a buyer reads. Defaults to English text. */
703
+ formatError?: (error: unknown) => string;
704
+ /** Overrides for the guard and success messages. */
705
+ messages?: Partial<SignalIntentMessages>;
706
+ }
707
+ /** One order to reserve. */
708
+ interface StartOrderParams {
709
+ paymentMethod: Hex;
710
+ depositId: bigint;
711
+ tokenAmount: bigint;
712
+ toAddress: Hex;
713
+ fiatCurrencyCode: Hex;
714
+ conversionRate: bigint;
715
+ subProvider?: SubProviderKey;
716
+ }
664
717
  /**
665
- * Hook for signaling intent to buy tokens via the V3 Orchestrator.
718
+ * Hook for signaling intent to buy tokens via the Orchestrator.
719
+ *
720
+ * Delegates to `ProveXClient.signalIntent()` for the full multi-step flow:
721
+ * 1. Fetch payee details from the indexer
722
+ * 2. Request a gating signature from the API
723
+ * 3. Simulate, submit, and parse the IntentSignaled event
666
724
  *
667
- * Delegates to ProveXClient.signalIntent() for the full multi-step flow:
668
- * 1. Fetch payee details from indexer
669
- * 2. Request gating signature from API
670
- * 3. Simulate, submit, and parse IntentSignaled event
725
+ * The client binds to `deposit.escrow`. Without that binding the client falls
726
+ * back to the v3 escrow, and a v4 reservation would go to the wrong
727
+ * orchestrator and revert at simulation.
671
728
  *
672
729
  * @example
673
730
  * ```ts
674
731
  * const { startOrder, status, message, isLoading } = useSignalIntent({
675
732
  * wallet,
676
- * chainId: 369,
677
733
  * deposit: selectedDeposit,
678
734
  * onSuccess: (intentHash) => navigate(`/verify/${intentHash}`),
679
735
  * })
680
736
  * ```
681
737
  */
682
- declare function useSignalIntent({ wallet, onSuccess, onFailure, deposit, refetchDeposits, }: {
683
- /** Wallet adapter for signing transactions. */
684
- wallet: WalletAdapter;
685
- /** @deprecated Chain is resolved from ProvexProvider. Kept for API compat. */
686
- chainId?: ChainId;
687
- /** Called when the intent is signaled successfully. */
688
- onSuccess: (intentHash: Hex) => void;
689
- /** Called when the flow fails. */
690
- onFailure?: () => void;
691
- /** The deposit to signal intent against. */
692
- deposit: DepositInfo | null;
693
- /** Called on failure to refresh deposit data. */
694
- refetchDeposits?: () => void;
695
- }): {
696
- startOrder: ({ paymentMethod, depositId, tokenAmount, toAddress, fiatCurrencyCode, conversionRate, subProvider, }: {
697
- paymentMethod: Hex;
698
- depositId: bigint;
699
- tokenAmount: bigint;
700
- toAddress: Hex;
701
- fiatCurrencyCode: Hex;
702
- conversionRate: bigint;
703
- subProvider?: SubProviderKey;
704
- }) => Promise<void>;
738
+ declare function useSignalIntent({ wallet, chainId, indexer, apiUrl, onSuccess, onFailure, deposit, refetchDeposits, beginTransaction, isRejection, formatError, messages, }: UseSignalIntentOptions): {
739
+ startOrder: ({ paymentMethod, depositId, tokenAmount, toAddress, fiatCurrencyCode, conversionRate, subProvider, }: StartOrderParams) => Promise<void>;
705
740
  status: SignalIntentStatus;
706
741
  message: string | null;
707
742
  isLoading: boolean;
@@ -710,10 +745,14 @@ declare function useSignalIntent({ wallet, onSuccess, onFailure, deposit, refetc
710
745
  /**
711
746
  * @fileoverview Hook for calculating reputation-based trading limits.
712
747
  *
713
- * Applies tier-based restrictions on transaction caps and cooldowns.
714
- * Pure computation -- no Ponder, no contract reads.
748
+ * Applies tier-based restrictions on order caps and cooldowns. Pure
749
+ * computation: no indexer query and no contract read.
715
750
  *
716
- * @see {@link useReputation} for fetching the user's tier
751
+ * The hook is headless. It reads no build-time environment value. The host
752
+ * app passes the kill switch as the `disabled` option, or sets
753
+ * `reputationDisabled` in the `ProvexProvider` config.
754
+ *
755
+ * @see {@link useUserReputation} for fetching the user's tier
717
756
  * @see {@link @provex/utils/reputation} for tier definitions
718
757
  */
719
758
 
@@ -725,30 +764,38 @@ interface ReputationLimitsParams {
725
764
  selectedPaymentMethod: ProviderKey;
726
765
  /** User's reputation tier */
727
766
  tier: TakerTier;
728
- /** Settlement-token decimals — used to scale the tier cap into token
729
- * base units so the comparison against `amountInInt` is a direct
730
- * bigint compare. Pass `6` for USDC; future non-USDC tokens supply
731
- * their own decimals. */
767
+ /** Settlement-token decimals. Scales the tier cap into token base units
768
+ * so the comparison against the order amount is a direct bigint compare.
769
+ * Pass `6` for USDC; future tokens supply their own decimals. */
732
770
  decimals: number;
733
771
  /** The ORDER's token amount: what the buyer would receive from the matched
734
772
  * seller (the intent amount), in settlement-token base units matching
735
773
  * `decimals`. Not the typed fiat figure: the server checks the cap on the
736
774
  * token amount, so 100 USDC allows 140,000 won at 1,400 won per USDC. Null
737
- * when no seller is matched, so nothing exceeds. (The name is kept for
738
- * compatibility with the published API.) */
775
+ * when no seller is matched, so nothing exceeds. */
776
+ orderTokenAmount?: bigint | null;
777
+ /** @deprecated Use `orderTokenAmount`. Read only when `orderTokenAmount`
778
+ * is absent. */
739
779
  amountInInt?: bigint | null;
740
- /** When the user's cooldown ends (from useReputation) */
780
+ /** When the user's cooldown ends (from useUserReputation) */
741
781
  cooldownEndsAt?: Date | null;
782
+ /**
783
+ * Kill switch. When true the hook returns the no-limits result. Defaults
784
+ * to `ProvexProvider` `config.reputationDisabled`, then `false`.
785
+ */
786
+ disabled?: boolean;
787
+ /** Time source for the cooldown countdown. Defaults to the provider clock, then `systemClock`. */
788
+ clock?: Clock;
742
789
  }
743
790
  /** Result of the useReputationLimits hook. */
744
791
  interface ReputationLimits {
745
- /** Whether reputation limits apply */
792
+ /** Whether reputation limits apply (false when the kill switch is on) */
746
793
  hasLimits: boolean;
747
794
  /** Alternative providers with no cooldown */
748
795
  noCooldownProviders: ProviderKey[];
749
796
  /** Cooldown hours for the selected payment method (category, not remaining) */
750
797
  selectedProviderCooldownHours: number;
751
- /** Remaining cooldown time in formatted string (e.g., "5h 30m") - null if not on cooldown */
798
+ /** Remaining cooldown time as a string (e.g. "5h 30m"), null if not on cooldown */
752
799
  cooldownRemaining: string | null;
753
800
  /** Whether user is currently on cooldown for the selected payment method */
754
801
  isOnCooldown: boolean;
@@ -761,6 +808,18 @@ interface ReputationLimits {
761
808
  amountExceedsCap: boolean;
762
809
  /** Error message when cap is exceeded */
763
810
  capExceededMessage: string | null;
811
+ /**
812
+ * Display values for the cap math, so consumers can render a tooltip like
813
+ * "Entry: $100 x Revolut 5x = $500" without re-deriving the lookups.
814
+ * All five are `null` when limits do not apply (kill switch on) or when the
815
+ * platform is locked at the user's tier (`effectiveCap === null`). The
816
+ * numeric three are also `null` for the unlimited (president) cap.
817
+ */
818
+ tierName: string | null;
819
+ tierBaseCapUsd: number | null;
820
+ capMultiplier: number | null;
821
+ effectiveCapUsd: number | null;
822
+ providerName: string | null;
764
823
  }
765
824
  /**
766
825
  * Hook to calculate reputation-based limits for payment methods.
@@ -777,11 +836,12 @@ interface ReputationLimits {
777
836
  * chainId,
778
837
  * selectedPaymentMethod,
779
838
  * tier: reputation.tier,
780
- * amountInInt,
839
+ * decimals: 6,
840
+ * orderTokenAmount,
781
841
  * })
782
842
  * ```
783
843
  */
784
- declare function useReputationLimits({ chainId, selectedPaymentMethod, tier, decimals, amountInInt, cooldownEndsAt, }: ReputationLimitsParams): ReputationLimits;
844
+ declare function useReputationLimits({ chainId, selectedPaymentMethod, tier, decimals, orderTokenAmount, amountInInt, cooldownEndsAt, disabled, clock, }: ReputationLimitsParams): ReputationLimits;
785
845
 
786
846
  /** Intent status values representing the lifecycle state. */
787
847
  declare const intentStatuses: {
@@ -843,6 +903,12 @@ interface ProvexConfig {
843
903
  apiUrl: string;
844
904
  /** The viem Chain object. Import from `viem/chains`. */
845
905
  chain: Chain;
906
+ /**
907
+ * Reputation kill switch. When true, `useUserReputation` reports the
908
+ * neutral default and `useReputationLimits` applies no cap or cooldown.
909
+ * A per-call `disabled` option overrides it.
910
+ */
911
+ reputationDisabled?: boolean;
846
912
  /** @deprecated Use `chain.id` — kept for backward compat during migration. */
847
913
  chainId?: ChainId;
848
914
  }
@@ -1043,6 +1109,8 @@ interface ProvexContextValue {
1043
1109
  publicClients: Record<number, PublicClient>;
1044
1110
  /** Optional wallet adapter for write operations. */
1045
1111
  wallet?: WalletAdapter;
1112
+ /** Time source for polling and countdowns. Always set by ProvexProvider; `systemClock` unless overridden. */
1113
+ clock?: Clock;
1046
1114
  }
1047
1115
  /** Props for the ProvexProvider component. */
1048
1116
  interface ProvexProviderProps {
@@ -1071,6 +1139,11 @@ interface ProvexProviderProps {
1071
1139
  * Omit for read-only apps.
1072
1140
  */
1073
1141
  wallet?: WalletAdapter;
1142
+ /**
1143
+ * Time source for polling loops and countdowns. Defaults to `systemClock`.
1144
+ * Tests pass `createManualClock()` from `@provex/react/testing`.
1145
+ */
1146
+ clock?: Clock;
1074
1147
  /** Child components that consume the context. */
1075
1148
  children: React__default.ReactNode;
1076
1149
  }
@@ -1096,7 +1169,7 @@ interface ProvexProviderProps {
1096
1169
  * </ProvexProvider>
1097
1170
  * ```
1098
1171
  */
1099
- declare function ProvexProvider({ config, indexer, queryClient, publicClient, publicClients, wallet, children, }: ProvexProviderProps): react_jsx_runtime.JSX.Element;
1172
+ declare function ProvexProvider({ config, indexer, queryClient, publicClient, publicClients, wallet, clock, children, }: ProvexProviderProps): react_jsx_runtime.JSX.Element;
1100
1173
  /**
1101
1174
  * useProvex — access the Provex context (config, indexer, apiClient,
1102
1175
  * publicClients, wallet).
@@ -1123,5 +1196,10 @@ declare function useProvexWallet(): WalletAdapter | undefined;
1123
1196
  * Get the optional wallet adapter without requiring ProvexProvider.
1124
1197
  */
1125
1198
  declare function useOptionalProvexWallet(): WalletAdapter | undefined;
1199
+ /**
1200
+ * Get the configured clock. Falls back to `systemClock` when no
1201
+ * ProvexProvider is mounted or the provider has no clock.
1202
+ */
1203
+ declare function useClock(): Clock;
1126
1204
 
1127
- export { type SignalIntentStatus as $, type AttestationParams as A, type BuyProps as B, type CreateDepositRawParams as C, type DepositPaymentMethod as D, useDeposits as E, type FulfillIntentParams as F, getRate as G, usePayeeDetails as H, type IndexerAdapter as I, intentStatuses as J, useSignalIntent as K, useProvexPublicClient as L, type MakerRegistrationParams as M, useOptionalProvexPublicClient as N, useProvexWallet as O, type ProveXClientConfig as P, useOptionalProvexWallet as Q, type ReputationData as R, type SignalIntentParams as S, type TransactionResult as T, type UseProvexBuyOptions as U, type ReputationLimitsParams as V, type WritableMethod as W, type ReputationLimits as X, type DepositInfo as Y, type IntentStatus as Z, type PayeeInfo as _, type PaginationOptions as a, type IndexedVerifier as a0, type PaginatedResult as b, type IndexedDeposit as c, type IndexedIntent as d, type CreateDepositParams as e, type PreparedTransaction as f, type SignalIntentResult as g, type PayeeDetails as h, type AttestationResponse as i, type WalletAdapter as j, type UseProvexBuyReturn as k, type PhaseRenderProps as l, type ProvexConfig as m, type BuyPhase as n, type ProvexTheme as o, type PhaseComponentProps as p, ProvexProvider as q, type ProvexContextValue as r, type ProvexProviderProps as s, ProveXError as t, useProvex as u, type ProveXErrorCode as v, type SignalIntentRawParams as w, createApiClient as x, type ApiClient as y, useReputationLimits as z };
1205
+ export { type SignalIntentStatus as $, type ApiClient as A, type BuyProps as B, type CreateDepositRawParams as C, type DepositPaymentMethod as D, getRate as E, type FulfillIntentParams as F, usePayeeDetails as G, intentStatuses as H, type IndexerAdapter as I, useSignalIntent as J, DEFAULT_SIGNAL_INTENT_MESSAGES as K, useProvexPublicClient as L, type MakerRegistrationParams as M, useOptionalProvexPublicClient as N, useProvexWallet as O, type ProveXClientConfig as P, useOptionalProvexWallet as Q, type ReputationData as R, type SignalIntentParams as S, type TransactionResult as T, type UseProvexBuyOptions as U, type ReputationLimitsParams as V, type WritableMethod as W, type ReputationLimits as X, type DepositInfo as Y, type IntentStatus as Z, type PayeeInfo as _, type PaginationOptions as a, type SignalIntentDeposit as a0, type SignalIntentTransaction as a1, type SignalIntentMessages as a2, type UseSignalIntentOptions as a3, type StartOrderParams as a4, type IndexedVerifier as a5, type PaginatedResult as b, type IndexedDeposit as c, type IndexedIntent as d, type CreateDepositParams as e, type PreparedTransaction as f, type SignalIntentResult as g, type PayeeDetails as h, type WalletAdapter as i, type UseProvexBuyReturn as j, type PhaseRenderProps as k, type ProvexConfig as l, type BuyPhase as m, type ProvexTheme as n, type PhaseComponentProps as o, ProvexProvider as p, useClock as q, type ProvexContextValue as r, type ProvexProviderProps as s, ProveXError as t, useProvex as u, type ProveXErrorCode as v, type SignalIntentRawParams as w, createApiClient as x, useReputationLimits as y, useDeposits as z };