Hooks
Custom React hooks for data fetching and state management.
use-escrow
Primary hook for escrow data, powered by TanStack React Query.
typescriptimport { useEscrow, useEscrows, useUserEscrows } from "@/hooks/use-escrow"; // Single escrow const { data: escrow, isLoading } = useEscrow(escrowId); // All escrows (paginated from Supabase) const { data: escrows } = useEscrows({ status: "pending", limit: 20 }); // User's escrows const { data: myEscrows } = useUserEscrows(address);
use-block-height
Fetches the current Stacks block height. Used for expiry calculations.
typescriptimport { useBlockHeight } from "@/hooks/use-block-height"; const { blockHeight, isLoading } = useBlockHeight(); // Check if escrow is expired const isExpired = blockHeight > escrow.expiresAt;
use-block-rate
Estimates the current block production rate for time calculations.
typescriptimport { useBlockRate } from "@/hooks/use-block-rate"; const { blocksPerHour, secondsPerBlock } = useBlockRate(); // Convert blocks to time const remainingBlocks = escrow.expiresAt - blockHeight; const remainingSeconds = remainingBlocks * secondsPerBlock;
use-admin
Checks if the connected wallet is the contract owner.
typescriptimport { useAdmin } from "@/hooks/use-admin"; const { isAdmin, isLoading } = useAdmin(); if (isAdmin) { // Show admin controls }
use-stx-price
Fetches the current STX/USD price for display purposes.
typescriptimport { useStxPrice } from "@/hooks/use-stx-price"; const { price, isLoading } = useStxPrice(); // price = 1.25 (USD)
use-settings
Manages user preferences stored in localStorage.
typescriptimport { useSettings } from "@/hooks/use-settings"; const { settings, updateSettings } = useSettings();
use-escrow-realtime
Subscribes to realtime escrow updates via Supabase.
typescriptimport { useEscrowRealtime } from "@/hooks/use-escrow-realtime"; // Automatically invalidates React Query cache on updates useEscrowRealtime();
This hook sets up a Supabase Realtime subscription on the escrows table. When a row is inserted or updated, it invalidates the relevant React Query keys, causing automatic re-fetching.
use-dispute-count
Returns the count of active disputes (for admin badge).
typescriptimport { useDisputeCount } from "@/hooks/use-dispute-count"; const { count } = useDisputeCount();
use-mobile
Detects mobile viewport for responsive behavior.
typescriptimport { useIsMobile } from "@/hooks/use-mobile"; const isMobile = useIsMobile();