This repository was archived by the owner on Sep 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathDelegationsList.tsx
More file actions
102 lines (95 loc) · 2.93 KB
/
Copy pathDelegationsList.tsx
File metadata and controls
102 lines (95 loc) · 2.93 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
91
92
93
94
95
96
97
98
99
100
101
102
import { Button } from "@babylonlabs-io/core-ui";
import { ubbnToBaby } from "@/ui/legacy/utils/bbn";
interface Delegation {
delegation?: {
validatorAddress: string;
};
balance?: {
amount: string;
denom: string;
};
}
interface Validator {
operatorAddress: string;
description?: {
moniker: string;
};
}
interface DelegationsListProps {
delegations: Delegation[];
validators: Validator[];
getRewardsForValidator: (validatorAddress: string) => number;
onUnstakeAll: (validatorAddress: string, amount: string) => void;
onClaimRewards: (validatorAddress: string) => Promise<void>;
loading: boolean;
}
export function DelegationsList({
delegations,
validators,
getRewardsForValidator,
onUnstakeAll,
onClaimRewards,
loading,
}: DelegationsListProps) {
if (delegations.length === 0) {
return null;
}
return (
<div className="bg-secondary-highlight text-accent-primary p-6 rounded mb-6">
<h2 className="text-xl font-semibold mb-4">My Delegations</h2>
<div className="space-y-2">
{delegations.map((delegation, index) => {
const validatorAddress =
delegation.delegation?.validatorAddress || "";
const stakedAmount = ubbnToBaby(
parseFloat(delegation.balance?.amount || "0"),
);
const rewardsAmount = getRewardsForValidator(validatorAddress);
return (
<div
key={index}
className="flex justify-between items-center p-3 rounded bg-secondary-highlight text-accent-primary"
>
<div>
<p className="font-medium">
{validators.find(
(v) => v.operatorAddress === validatorAddress,
)?.description?.moniker || validatorAddress}
</p>
<p className="text-sm text-gray-600">
Staked: {stakedAmount.toLocaleString()} tBABY
</p>
{rewardsAmount > 0 && (
<p className="text-sm text-green-600">
Rewards: {rewardsAmount.toLocaleString()} tBABY
</p>
)}
</div>
<div className="flex gap-2">
<Button
variant="outlined"
size="small"
onClick={() =>
onUnstakeAll(validatorAddress, stakedAmount.toString())
}
>
Unstake All
</Button>
{rewardsAmount > 0 && (
<Button
variant="outlined"
size="small"
onClick={() => onClaimRewards(validatorAddress)}
disabled={loading}
>
{loading ? "Claiming..." : "Claim"}
</Button>
)}
</div>
</div>
);
})}
</div>
</div>
);
}