mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-22 11:18:01 +00:00
3c1acdf845
- Created useDelegation hook to fetch real delegation data from blockchain - Queries democracy.voting pallet for all delegations - Tracks delegate totals, delegator counts, and voting power - Calculates delegate performance metrics and success rates - Fetches user's own delegations with conviction levels - Auto-refreshes every 30 seconds for live updates - Provides delegateVotes and undelegateVotes transaction builders - Updated DelegationManager component to use live data - Replaced mock delegates with real blockchain delegates - Replaced mock delegations with user's actual delegations - Added loading states with spinner during data fetch - Added error handling with user-friendly messages - Added "Live Blockchain Data" badge for transparency - Formatted token amounts from blockchain units (12 decimals) - Show delegate addresses in monospace font - Display delegator count and conviction levels - Empty states for no delegates/delegations scenarios - Enhanced PolkadotContext with isConnected property - Added isConnected as alias for isApiReady - Maintains backward compatibility with existing hooks - Added formatNumber utility to lib/utils - Formats large numbers with K/M/B suffixes - Handles decimals and edge cases - Consistent formatting across all components All delegation data now comes from live blockchain queries.
25 lines
621 B
TypeScript
25 lines
621 B
TypeScript
import { clsx, type ClassValue } from "clsx"
|
|
import { twMerge } from "tailwind-merge"
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs))
|
|
}
|
|
|
|
export function formatNumber(value: number, decimals: number = 2): string {
|
|
if (value === 0) return '0';
|
|
if (value < 0.01) return '<0.01';
|
|
|
|
// For large numbers, use K, M, B suffixes
|
|
if (value >= 1e9) {
|
|
return (value / 1e9).toFixed(decimals) + 'B';
|
|
}
|
|
if (value >= 1e6) {
|
|
return (value / 1e6).toFixed(decimals) + 'M';
|
|
}
|
|
if (value >= 1e3) {
|
|
return (value / 1e3).toFixed(decimals) + 'K';
|
|
}
|
|
|
|
return value.toFixed(decimals);
|
|
}
|