forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalanceDisplay.tsx
More file actions
90 lines (79 loc) · 2.84 KB
/
Copy pathBalanceDisplay.tsx
File metadata and controls
90 lines (79 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React from 'react';
import { RefreshCw } from 'lucide-react';
import { useBalance } from '@/hooks/useBalance';
import { RefreshIndicator } from './RefreshIndicator';
import { formatTokenAmount } from '@/lib/utils';
interface BalanceDisplayProps {
className?: string;
showStaked?: boolean;
showPending?: boolean;
}
export const BalanceDisplay: React.FC<BalanceDisplayProps> = ({
className = '',
showStaked = true,
showPending = true,
}) => {
const { balance, isLoading, isRefreshing, error, lastUpdated, refreshBalance } = useBalance(true);
if (isLoading && !balance) {
return (
<div className={`animate-pulse ${className}`}>
<div className="h-8 w-32 rounded bg-gray-200 dark:bg-gray-700" />
<div className="mt-1 h-4 w-20 rounded bg-gray-200 dark:bg-gray-700" />
</div>
);
}
if (error && !balance) {
return (
<div className={`text-red-500 ${className}`}>
<p>Failed to load balance</p>
<button
onClick={refreshBalance}
className="mt-1 text-sm text-blue-500 hover:underline"
>
Retry
</button>
</div>
);
}
if (!balance) return null;
return (
<div className={`space-y-2 ${className}`}>
{/* Main Balance */}
<div className="flex items-baseline gap-2">
<span className="text-2xl font-bold text-gray-900 dark:text-white">
{formatTokenAmount(balance.novaBalance)} NOVA
</span>
<span className="text-sm text-gray-500">≈ ${balance.usdValue}</span>
</div>
{/* Additional Info */}
<div className="flex flex-wrap items-center gap-4 text-sm">
{showStaked && balance.stakedBalance && (
<div className="flex items-center gap-1 text-gray-600 dark:text-gray-400">
<span className="font-medium">Staked:</span>
<span>{formatTokenAmount(balance.stakedBalance)} NOVA</span>
</div>
)}
{showPending && balance.pendingRewards && (
<div className="flex items-center gap-1 text-green-600 dark:text-green-400">
<span className="font-medium">Pending Rewards:</span>
<span>{formatTokenAmount(balance.pendingRewards)} NOVA</span>
</div>
)}
{/* Refresh Status */}
<div className="flex items-center gap-2">
<RefreshIndicator isRefreshing={isRefreshing} lastUpdated={lastUpdated} />
{/* Manual Refresh Button */}
<button
onClick={refreshBalance}
disabled={isRefreshing}
className="rounded p-1 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-50"
aria-label="Refresh balance"
>
<RefreshCw className={`h-3 w-3 ${isRefreshing ? 'animate-spin' : ''}`} />
</button>
</div>
</div>
</div>
);
};
export default BalanceDisplay;