-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(phase-2): delegation tabs (#240)
* feat(phase-2): delegation tabs * fix(phase-2): add todo for mock files
- Loading branch information
Showing
33 changed files
with
993 additions
and
32 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Tab, TabList, TabPanel, Tabs } from "react-tabs"; | ||
|
||
import { Delegations } from "@/app/components/Delegations/Delegations"; | ||
import { AuthGuard } from "@/components/common/AuthGuard"; | ||
import { DelegationList } from "@/components/delegations/DelegationList"; | ||
|
||
export function DelegationTabs() { | ||
return ( | ||
<AuthGuard> | ||
<Tabs> | ||
<div className="card flex flex-col gap-2 bg-base-300 p-4 shadow-sm lg:flex-1"> | ||
<div className="flex gap-2 mb-4"> | ||
<h3 className="font-bold">Staking history</h3> | ||
|
||
<TabList className="flex gap-2"> | ||
<Tab | ||
className="text-primary cursor-pointer" | ||
selectedClassName="border-b border-dashed border-primary" | ||
> | ||
Phase 1 | ||
</Tab> | ||
<Tab | ||
className="text-primary cursor-pointer" | ||
selectedClassName="border-b border-dashed border-primary" | ||
> | ||
Phase 2 | ||
</Tab> | ||
</TabList> | ||
</div> | ||
|
||
<TabPanel> | ||
<Delegations /> | ||
</TabPanel> | ||
<TabPanel> | ||
<DelegationList /> | ||
</TabPanel> | ||
</div> | ||
</Tabs> | ||
</AuthGuard> | ||
); | ||
} |
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
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
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,17 @@ | ||
import { useDelegationState } from "@/app/state/DelegationState"; | ||
|
||
export function useDelegationService() { | ||
const { | ||
delegations = [], | ||
fetchMoreDelegations, | ||
hasMoreDelegations, | ||
isLoading, | ||
} = useDelegationState(); | ||
|
||
return { | ||
delegations, | ||
fetchMoreDelegations, | ||
hasMoreDelegations, | ||
isLoading, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { PropsWithChildren, ReactNode } from "react"; | ||
|
||
import { useWalletConnection } from "@/app/context/wallet/WalletConnectionProvider"; | ||
|
||
interface AuthGuardProps { | ||
fallback?: ReactNode; | ||
} | ||
|
||
export function AuthGuard({ | ||
children, | ||
fallback, | ||
}: PropsWithChildren<AuthGuardProps>) { | ||
const { isConnected } = useWalletConnection(); | ||
|
||
return isConnected ? children : fallback; | ||
} |
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,26 @@ | ||
import { MouseEventHandler, type ReactNode } from "react"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
interface TCellProps { | ||
className?: string; | ||
align?: "left" | "right" | "center"; | ||
children?: ReactNode; | ||
onClick?: MouseEventHandler<HTMLTableCellElement>; | ||
} | ||
|
||
const ALIGN = { | ||
left: "justify-start", | ||
right: "justify-end", | ||
center: "justify-center", | ||
} as const; | ||
|
||
export function GridCell({ className, align, children, onClick }: TCellProps) { | ||
return ( | ||
<div | ||
className={twMerge("text-left", className, align && ALIGN[align])} | ||
onClick={onClick} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} |
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,48 @@ | ||
import { useCallback, type ReactNode } from "react"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
import type { SortColumn } from "../types"; | ||
|
||
interface THeadProps { | ||
field: string; | ||
title: ReactNode; | ||
className?: string; | ||
sortable?: boolean; | ||
align?: "left" | "right" | "center"; | ||
sortColumn?: SortColumn; | ||
onSortChange: (sortColumn: SortColumn) => void; | ||
} | ||
|
||
const SORT_DIRECTIONS = { | ||
"": "ASC", | ||
ASC: "DESC", | ||
DESC: "", | ||
} as const; | ||
|
||
export function GridHead({ | ||
field, | ||
title, | ||
className, | ||
align, | ||
sortable = false, | ||
sortColumn, | ||
onSortChange, | ||
}: THeadProps) { | ||
const direction = SORT_DIRECTIONS[sortColumn?.direction || ""]; | ||
|
||
const handleColumnClick = useCallback(() => { | ||
if (sortable) { | ||
onSortChange({ field, direction }); | ||
} | ||
}, [field, direction, sortable, onSortChange]); | ||
|
||
return ( | ||
<p | ||
className={twMerge(className, sortable ? "cursor-pointer" : "")} | ||
style={{ textAlign: align }} | ||
onClick={handleColumnClick} | ||
> | ||
{title} | ||
</p> | ||
); | ||
} |
Oops, something went wrong.