-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from elliotsayes/dev
Add delegates
- Loading branch information
Showing
5 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { z } from "zod" | ||
import { zGatewayAddressRegistryItem } from "@/types"; | ||
import { useMemo } from "react"; | ||
import { Table, TableBody, TableCell, TableHeader, TableRow } from "./ui/table"; | ||
import { ScrollArea } from "./ui/scroll-area"; | ||
|
||
interface Props { | ||
delegates: z.infer<typeof zGatewayAddressRegistryItem>['delegates'] | ||
} | ||
|
||
const DelegateSummary = ({delegates}: Props) => { | ||
const sortedDelegates = useMemo(() => { | ||
return Object.entries(delegates).sort((a, b) => { | ||
return b[1].delegatedStake - a[1].delegatedStake | ||
}) | ||
}, [delegates]); | ||
|
||
return ( | ||
<div> | ||
<ScrollArea className="h-60 w-full pr-4"> | ||
{/* <p className="text-lg">Delegates</p> */} | ||
<Table> | ||
<TableHeader> | ||
<TableCell className="text-md"> | ||
Delegate Address | ||
</TableCell> | ||
<TableCell className="text-md text-right"> | ||
Stake | ||
</TableCell> | ||
</TableHeader> | ||
<TableBody> | ||
{sortedDelegates.map(([delegateId, delegateInfo]) => ( | ||
<TableRow key={delegateId} className="py-2"> | ||
<TableCell className="py-1"> | ||
<a | ||
href={`https://viewblock.io/arweave/address/${delegateId}`} | ||
target="_blank" | ||
className="text-secondary-foreground/80 underline" | ||
> | ||
<code className="text-secondary-foreground/80"> | ||
{delegateId.slice(0, 5)}...{delegateId.slice(delegateId.length-5)} | ||
</code> | ||
</a> | ||
</TableCell> | ||
<TableCell className="text-right py-2"> | ||
<code className="text-secondary-foreground/80"> | ||
{delegateInfo.delegatedStake} | ||
</code> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</ScrollArea> | ||
</div> | ||
) | ||
} | ||
|
||
export { DelegateSummary } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { HoverCard, HoverCardContent, HoverCardTrigger } from "./ui/hover-card" | ||
import { z } from "zod" | ||
import { useState } from "react" | ||
import { zGatewayAddressRegistryItem } from "@/types" | ||
import { DelegateSummary } from "./DelegateSummary" | ||
|
||
interface Props { | ||
totalDelegatedStake: z.infer<typeof zGatewayAddressRegistryItem>['totalDelegatedStake'] | ||
delegates: z.infer<typeof zGatewayAddressRegistryItem>['delegates'] | ||
} | ||
|
||
const DelegatedStakeHoverCard = ({totalDelegatedStake, delegates}: Props) => { | ||
const [open, setOpen] = useState(false); | ||
|
||
return ( | ||
<HoverCard | ||
open={open} | ||
onOpenChange={(o) => setOpen(o)} | ||
> | ||
<HoverCardTrigger | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
setOpen(true); | ||
}} | ||
> | ||
<span className="line-clamp-1 underline cursor-pointer text-center"> | ||
{totalDelegatedStake} | ||
</span> | ||
</HoverCardTrigger> | ||
<HoverCardContent | ||
onClick={(e) => e.stopPropagation()} | ||
className="w-full" | ||
> | ||
<DelegateSummary delegates={delegates} /> | ||
</HoverCardContent> | ||
</HoverCard> | ||
) | ||
} | ||
|
||
export default DelegatedStakeHoverCard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters