Integrate live blockchain data for delegation features

- 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.
This commit is contained in:
Claude
2025-11-14 01:37:08 +00:00
parent b66fc2472a
commit 298ef7aa68
4 changed files with 406 additions and 151 deletions
+2
View File
@@ -6,6 +6,7 @@ import type { InjectedAccountWithMeta } from '@polkadot/extension-inject/types';
interface PolkadotContextType {
api: ApiPromise | null;
isApiReady: boolean;
isConnected: boolean;
accounts: InjectedAccountWithMeta[];
selectedAccount: InjectedAccountWithMeta | null;
setSelectedAccount: (account: InjectedAccountWithMeta | null) => void;
@@ -119,6 +120,7 @@ export const PolkadotProvider: React.FC<PolkadotProviderProps> = ({
const value: PolkadotContextType = {
api,
isApiReady,
isConnected: isApiReady, // Alias for backward compatibility
accounts,
selectedAccount,
setSelectedAccount,