This document provides detailed information about the components, hooks, and utilities available in Stellar DeFi Analytics.
A reusable card component for displaying dashboard metrics.
import { DashboardCard } from '@/components/DashboardCard';
<DashboardCard
title="Total Value Locked"
value="$1,234,567"
change={12.5}
icon={<TrendingUpIcon />}
/>Props:
title: string- Card titlevalue: string | number- Main value to displaychange?: number- Percentage change (optional)icon?: ReactNode- Icon element (optional)loading?: boolean- Loading state (optional)
Displays information about a DeFi protocol.
import { ProtocolCard } from '@/components/ProtocolCard';
<ProtocolCard
name="Aquarius"
tvl={5000000}
volume24h={125000}
apy={15.3}
logo="/protocols/aquarius.png"
/>Props:
name: string- Protocol nametvl: number- Total Value Lockedvolume24h: number- 24-hour trading volumeapy: number- Annual Percentage Yieldlogo: string- Logo image URL
Wrapper component for Recharts visualizations.
import { ChartContainer } from '@/components/ChartContainer';
import { LineChart, Line, XAxis, YAxis } from 'recharts';
<ChartContainer title="Price History">
<LineChart data={priceData}>
<XAxis dataKey="date" />
<YAxis />
<Line type="monotone" dataKey="price" stroke="#8884d8" />
</LineChart>
</ChartContainer>Props:
title: string- Chart titlechildren: ReactNode- Recharts componentsloading?: boolean- Loading stateerror?: string- Error message
Displays portfolio holdings in a table format.
import { PortfolioTable } from '@/components/PortfolioTable';
<PortfolioTable
holdings={[
{ asset: 'XLM', amount: 1000, value: 100, change24h: 5.2 },
{ asset: 'USDC', amount: 500, value: 500, change24h: 0.1 },
]}
/>Props:
holdings: Array<Holding>- Array of holdingssortBy?: 'asset' | 'value' | 'change'- Sort columnonRowClick?: (holding: Holding) => void- Row click handler
Fetches and manages Stellar account data.
import { useStellarAccount } from '@/hooks/useStellarAccount';
const { account, balances, loading, error, refresh } = useStellarAccount(publicKey);Parameters:
publicKey: string- Stellar account public key
Returns:
account: Account | null- Account databalances: Balance[]- Account balancesloading: boolean- Loading stateerror: Error | null- Error objectrefresh: () => void- Refresh function
Fetches DeFi protocol metrics.
import { useProtocolData } from '@/hooks/useProtocolData';
const { protocols, tvlTotal, volume24h, loading } = useProtocolData();Returns:
protocols: Protocol[]- Array of protocolstvlTotal: number- Total TVL across all protocolsvolume24h: number- Total 24h volumeloading: boolean- Loading stateerror: Error | null- Error object
Fetches liquidity pool data.
import { useLiquidityPools } from '@/hooks/useLiquidityPools';
const { pools, loading, error } = useLiquidityPools();Returns:
pools: LiquidityPool[]- Array of liquidity poolsloading: boolean- Loading stateerror: Error | null- Error object
Fetches historical price data for an asset.
import { usePriceHistory } from '@/hooks/usePriceHistory';
const { prices, loading } = usePriceHistory('XLM', '7d');Parameters:
asset: string- Asset codeperiod: '1d' | '7d' | '30d' | '1y'- Time period
Returns:
prices: PricePoint[]- Array of price pointsloading: boolean- Loading stateerror: Error | null- Error object
Formats a number as currency.
import { formatCurrency } from '@/lib/format';
formatCurrency(1234.56); // "$1,234.56"
formatCurrency(1234.56, 'EUR'); // "€1,234.56"Parameters:
amount: number- Amount to formatcurrency?: string- Currency code (default: 'USD')
Formats a number as percentage.
import { formatPercent } from '@/lib/format';
formatPercent(0.1523); // "15.23%"
formatPercent(0.1523, 1); // "15.2%"Parameters:
value: number- Value to format (0.1523 = 15.23%)decimals?: number- Decimal places (default: 2)
Formats a Stellar address for display.
import { formatAddress } from '@/lib/format';
formatAddress('GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
// "GXXXX...XXXX"Parameters:
address: string- Full Stellar addresschars?: number- Characters to show on each end (default: 4)
Calculates Annual Percentage Yield.
import { calculateAPY } from '@/lib/calculations';
calculateAPY(100000, 105000, 30); // 73.91% APYParameters:
principal: number- Initial amountcurrent: number- Current amountdays: number- Number of days
Returns: number - APY as percentage
Fetches Total Value Locked for a protocol.
import { fetchProtocolTVL } from '@/lib/api';
const tvl = await fetchProtocolTVL('aquarius');Parameters:
protocolId: string- Protocol identifier
Returns: Promise<number> - TVL in USD
interface Protocol {
id: string;
name: string;
logo: string;
tvl: number;
volume24h: number;
apy: number;
category: 'dex' | 'lending' | 'liquidity';
url: string;
}interface LiquidityPool {
id: string;
tokenA: string;
tokenB: string;
reserves: {
tokenA: number;
tokenB: number;
};
totalShares: number;
apy: number;
volume24h: number;
fees24h: number;
}interface PricePoint {
timestamp: number;
price: number;
volume: number;
}interface Holding {
asset: string;
amount: number;
value: number;
change24h: number;
logo?: string;
}All API calls and hooks implement consistent error handling:
const { data, error, loading } = useProtocolData();
if (error) {
// Handle error
console.error('Failed to fetch protocols:', error.message);
}
if (loading) {
// Show loading state
return <LoadingSpinner />;
}
// Use data
return <ProtocolList protocols={data} />;API calls are automatically rate-limited to prevent abuse:
- Maximum 60 requests per minute per endpoint
- Exceeded requests receive 429 status code
- Retry after header indicates when to retry
SWR provides automatic caching with configurable options:
const { data } = useSWR('/api/protocols', fetcher, {
refreshInterval: 30000, // Refresh every 30 seconds
dedupingInterval: 5000, // Dedupe requests within 5 seconds
revalidateOnFocus: true, // Revalidate when window regains focus
});When adding new components, hooks, or utilities, please:
- Add TypeScript types/interfaces
- Include JSDoc comments
- Update this API documentation
- Add unit tests
- Include usage examples
For questions or issues, please open a GitHub issue.