Skip to content
Snippets Groups Projects
Commit 0cd17e37 authored by Lukas's avatar Lukas
Browse files

Update AccountVestingDelegationsCard

parent d5385d07
No related branches found
No related tags found
1 merge request!585Lbudginas/#318 add hp incoming delegation account page
...@@ -14,26 +14,40 @@ import { ...@@ -14,26 +14,40 @@ import {
import Explorer from "@/types/Explorer"; import Explorer from "@/types/Explorer";
import useConvertedVestingShares from "@/hooks/common/useConvertedVestingShares"; import useConvertedVestingShares from "@/hooks/common/useConvertedVestingShares";
import { buildTableHead, handleSortDelegations } from "@/utils/DelegationsSort"; import { buildTableHead, handleSortDelegations } from "@/utils/DelegationsSort";
import { capitalizeFirst } from "@/utils/StringUtils";
type AccountVestingDelegationsCardProps = { type AccountVestingDelegationsCardProps = {
direction: "incoming" | "outgoing";
delegatorAccount: string; delegatorAccount: string;
liveDataEnabled: boolean; liveDataEnabled: boolean;
dynamicGlobalData?: Explorer.HeadBlockCardData; dynamicGlobalData?: Explorer.HeadBlockCardData;
}; };
const buildTableBody = (delegations: Explorer.VestingDelegation[]) => { const buildTableBody = (
direction: "outgoing" | "incoming",
delegations: Explorer.VestingDelegation[]
) => {
return delegations.map((delegation, index: number) => { return delegations.map((delegation, index: number) => {
return ( return (
<Fragment key={index}> <Fragment key={index}>
<TableRow className={"border-b border-gray-700 hover:bg-inherit"}> <TableRow className={"border-b border-gray-700 hover:bg-inherit"}>
<TableCell>{index + 1}</TableCell> <TableCell>{index + 1}</TableCell>
<TableCell className="text-right"> <TableCell className="text-right">
<Link {direction === "outgoing" ? (
className="text-blue-400" <Link
href={`/@${delegation.delegatee}`} className="text-link"
> href={`/@${delegation.delegatee}`}
{delegation.delegatee} >
</Link> {delegation.delegatee}
</Link>
) : (
<Link
className="text-link"
href={`/@${delegation.delegator}`}
>
{delegation.delegator}
</Link>
)}
</TableCell> </TableCell>
<TableCell className="text-right"> <TableCell className="text-right">
{delegation.vesting_shares} {delegation.vesting_shares}
...@@ -45,10 +59,11 @@ const buildTableBody = (delegations: Explorer.VestingDelegation[]) => { ...@@ -45,10 +59,11 @@ const buildTableBody = (delegations: Explorer.VestingDelegation[]) => {
}; };
const AccountVestingDelegationsCard: React.FC< const AccountVestingDelegationsCard: React.FC<
AccountVestingDelegationsCardProps AccountVestingDelegationsCardProps
> = ({ delegatorAccount, liveDataEnabled, dynamicGlobalData }) => { > = ({ direction, delegatorAccount, liveDataEnabled, dynamicGlobalData }) => {
const [isPropertiesHidden, setIsPropertiesHidden] = useState(true); const [isPropertiesHidden, setIsPropertiesHidden] = useState(true);
const { hiveChain } = useHiveChainContext(); const { hiveChain } = useHiveChainContext();
const delegations = useConvertedVestingShares( const delegations = useConvertedVestingShares(
direction,
delegatorAccount, delegatorAccount,
liveDataEnabled, liveDataEnabled,
dynamicGlobalData dynamicGlobalData
...@@ -65,7 +80,6 @@ const AccountVestingDelegationsCard: React.FC< ...@@ -65,7 +80,6 @@ const AccountVestingDelegationsCard: React.FC<
if (!hiveChain || !dynamicGlobalData || !delegations || !delegations.length) if (!hiveChain || !dynamicGlobalData || !delegations || !delegations.length)
return; return;
const handlePropertiesVisibility = () => { const handlePropertiesVisibility = () => {
setIsPropertiesHidden(!isPropertiesHidden); setIsPropertiesHidden(!isPropertiesHidden);
}; };
...@@ -78,10 +92,14 @@ const AccountVestingDelegationsCard: React.FC< ...@@ -78,10 +92,14 @@ const AccountVestingDelegationsCard: React.FC<
delegations, delegations,
key, key,
isAscending, isAscending,
recipient: "delegatee", recipient: direction === "outgoing" ? "delegatee" : "delegator",
amount: "vesting_shares", amount: "vesting_shares",
}) as Explorer.VestingDelegation[]; }) as Explorer.VestingDelegation[];
const headerText = `${capitalizeFirst(direction)} HP Delegations (${
delegations.length
})`;
return ( return (
<Card <Card
data-testid="vesting-delegations-dropdown" data-testid="vesting-delegations-dropdown"
...@@ -92,7 +110,7 @@ const AccountVestingDelegationsCard: React.FC< ...@@ -92,7 +110,7 @@ const AccountVestingDelegationsCard: React.FC<
onClick={handlePropertiesVisibility} onClick={handlePropertiesVisibility}
className="h-full flex justify-between align-center p-2 hover:bg-rowHover cursor-pointer px-4" className="h-full flex justify-between align-center p-2 hover:bg-rowHover cursor-pointer px-4"
> >
<div className="text-lg">HP Delegations ({delegations.length})</div> <div className="text-lg">{headerText}</div>
{isPropertiesHidden ? <ArrowDown /> : <ArrowUp />} {isPropertiesHidden ? <ArrowDown /> : <ArrowUp />}
</div> </div>
</CardHeader> </CardHeader>
...@@ -101,7 +119,7 @@ const AccountVestingDelegationsCard: React.FC< ...@@ -101,7 +119,7 @@ const AccountVestingDelegationsCard: React.FC<
<TableHeader> <TableHeader>
<TableRow>{buildTableHead(sortBy, key, isAscending)}</TableRow> <TableRow>{buildTableHead(sortBy, key, isAscending)}</TableRow>
</TableHeader> </TableHeader>
<TableBody>{buildTableBody(sortedDelegations)}</TableBody> <TableBody>{buildTableBody(direction, sortedDelegations)}</TableBody>
</Table> </Table>
</CardContent> </CardContent>
</Card> </Card>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment