import { ReactNode } from 'react'; import { CantonService, CantonSubmitPreparedOptions } from '../../services/cantonService'; import { CantonMeResponseDto, CantonQueryCompletionResponseDto, CantonWalletBalancesResponseDto, CantonIncomingTransferDto, CantonTransactionDto, CantonTransactionsParams, CantonPriceInterval, CantonPriceCandleDto, CantonPrepareTransferRequestDto, CantonCalculateTransferFeeResponseDto } from '../../core/types'; import { CantonWallet } from '../../utils/wallet'; import { SigningWalletInfo } from './signingWalletResolver'; export interface CantonSendCoinOptions extends CantonSubmitPreparedOptions { /** Skip confirmation modal. Default: false */ skipModal?: boolean; /** * Instrument ID to transfer. * Defaults to "Amulet" (CC). */ instrumentId?: CantonPrepareTransferRequestDto['instrumentId']; /** * Optional instrument admin party ID. * Useful for CIP-56 tokens. */ instrumentAdmin?: CantonPrepareTransferRequestDto['instrumentAdmin']; } export interface CantonContextValue { /** First Stellar wallet (primary) */ cantonWallet: CantonWallet | null; /** All Stellar wallets */ cantonWallets: CantonWallet[]; /** Create new Stellar wallet */ createCantonWallet: () => Promise; /** Register Canton wallet on backend */ registerCanton: (inviteCode?: string) => Promise; /** Whether Canton wallet is registered */ isRegistered: boolean; /** Canton user info (partyId, email, transferPreapprovalSet) */ cantonUser: CantonMeResponseDto | null; /** Get Canton user info */ getMe: () => Promise; /** Get active contracts with optional filtering and pagination */ getActiveContracts: (templateIds?: string[], pagination?: { limit: number; offset?: number; } | { limit?: number; }) => Promise; /** Canton wallet balances */ cantonBalances: CantonWalletBalancesResponseDto | null; /** Get Canton wallet balances */ getBalances: () => Promise; /** Tap devnet faucet */ tapDevnet: (amount: string, options?: CantonSubmitPreparedOptions) => Promise; /** Sign hash with Stellar wallet */ signHash: (hashBase64: string, options?: { skipModal?: boolean; }) => Promise; /** * Resolve the signing wallet by matching `cantonUser.publicKey` against * available Privy wallets (stellar + solana). Returns the wallet whose * derived Canton public key matches the registered one, falling back to * the configured default chain when no match is possible. * * Use this from any hook that needs to sign a prepared Canton hash, to * avoid the "bad signature" failure mode where the wrong-chain wallet * signs a backend hash prepared for a different public key. */ resolveSigningWallet: () => Promise; /** Sign text message */ signMessage: (message: string) => Promise; /** Prepare and submit transaction with polling for completion */ sendTransaction: (commands: unknown, disclosedContracts?: unknown, options?: CantonSubmitPreparedOptions) => Promise; /** Send transfer to another party (defaults to Canton Coin / Amulet) */ sendCantonCoin: (receiverPartyId: string, amount: string, memo?: string, options?: CantonSendCoinOptions) => Promise; /** Calculate transfer fee in CC (optional partyId override, receiver recommended for transfers) */ calculateTransferFee: (instrumentId?: string, instrumentAdmin?: string, partyId?: string) => Promise; /** Setup transfer preapproval (internal, called automatically) */ setupTransferPreapproval: () => Promise; /** Get pending incoming transfers */ getPendingIncomingTransfers: () => Promise; /** Respond to incoming transfer (accept or reject) */ respondToIncomingTransfer: (contractId: string, accept: boolean, options?: CantonSubmitPreparedOptions) => Promise; /** Get Canton transactions history with pagination */ getTransactions: (params?: CantonTransactionsParams) => Promise; /** Get Canton price history (candles from Bybit) */ getPriceHistory: (interval: CantonPriceInterval) => Promise; /** Reset all Canton state (for logout) */ resetState: () => void; /** Loading state */ loading: boolean; /** Error state */ error: Error | null; /** Clear error */ clearError: () => void; } export interface CantonProviderProps { cantonService: CantonService; children: ReactNode; /** Enable wallet export (uses Solana instead of Stellar). Default: false */ withExport?: boolean; /** Enable automatic onboarding (create wallet + register Canton on login). Default: true */ autoOnboarding?: boolean; /** * Legacy onboarding stage: automatically setup transfer preapproval after registration. * Default: false (new onboarding uses prepare_initialization_transactions). */ autoTransferPreapproval?: boolean; }