-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
528 UI show delegation with slashed design (#539)
* show delegation with slashed design * resolve comments
- Loading branch information
1 parent
49ac8d7
commit f72682d
Showing
8 changed files
with
250 additions
and
89 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
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 |
---|---|---|
@@ -1,26 +1,52 @@ | ||
import { type PropsWithChildren, useId } from "react"; | ||
import { useId, type PropsWithChildren, type ReactNode } from "react"; | ||
import { AiOutlineInfoCircle } from "react-icons/ai"; | ||
import { Tooltip } from "react-tooltip"; | ||
import { twJoin } from "tailwind-merge"; | ||
|
||
type HintStatus = "default" | "warning" | "error"; | ||
|
||
interface HintProps { | ||
tooltip: string; | ||
tooltip: ReactNode; | ||
status?: HintStatus; | ||
} | ||
|
||
export function Hint({ children, tooltip }: PropsWithChildren<HintProps>) { | ||
const STATUS_COLORS = { | ||
default: "text-primary-main", | ||
warning: "text-warning-main", | ||
error: "text-error-main", | ||
} as const; | ||
|
||
export function Hint({ | ||
children, | ||
tooltip, | ||
status = "default", | ||
}: PropsWithChildren<HintProps>) { | ||
const id = useId(); | ||
|
||
return ( | ||
<div className="inline-flex items-center gap-1"> | ||
<div | ||
className={twJoin( | ||
"inline-flex items-center gap-1", | ||
STATUS_COLORS[status], | ||
)} | ||
> | ||
{children && <p>{children}</p>} | ||
<span | ||
className="cursor-pointer text-xs" | ||
className={twJoin("cursor-pointer text-xs", STATUS_COLORS[status])} | ||
data-tooltip-id={id} | ||
data-tooltip-content={tooltip} | ||
data-tooltip-content={typeof tooltip === "string" ? tooltip : undefined} | ||
data-tooltip-place="top" | ||
> | ||
<AiOutlineInfoCircle /> | ||
</span> | ||
<Tooltip id={id} className="tooltip-wrap" /> | ||
<Tooltip | ||
id={id} | ||
className="tooltip-wrap" | ||
openOnClick={false} | ||
clickable={true} | ||
> | ||
{typeof tooltip !== "string" && tooltip} | ||
</Tooltip> | ||
</div> | ||
); | ||
} |
64 changes: 59 additions & 5 deletions
64
src/components/delegations/DelegationList/components/FinalityProviderMoniker.tsx
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 |
---|---|---|
@@ -1,15 +1,69 @@ | ||
import Link from "next/link"; | ||
|
||
import { DOCUMENTATION_LINKS } from "@/app/constants"; | ||
import { useFinalityProviderState } from "@/app/state/FinalityProviderState"; | ||
import { FinalityProviderState } from "@/app/types/finalityProviders"; | ||
import { Hint } from "@/components/common/Hint"; | ||
|
||
interface FinalityProviderMoniker { | ||
interface FinalityProviderMonikerProps { | ||
value: string; | ||
} | ||
|
||
export function FinalityProviderMoniker({ value }: FinalityProviderMoniker) { | ||
const { getFinalityProviderMoniker } = useFinalityProviderState(); | ||
const STATUSES: Record< | ||
FinalityProviderState, | ||
{ | ||
tooltip?: React.ReactNode; | ||
status?: "warning" | "error"; | ||
} | ||
> = { | ||
[FinalityProviderState.ACTIVE]: {}, | ||
[FinalityProviderState.INACTIVE]: {}, | ||
[FinalityProviderState.JAILED]: { | ||
tooltip: ( | ||
<span> | ||
This finality provider has been jailed. | ||
<Link | ||
className="text-secondary-main" | ||
target="_blank" | ||
href={DOCUMENTATION_LINKS.TECHNICAL_PRELIMINARIES} | ||
> | ||
Learn more | ||
</Link> | ||
</span> | ||
), | ||
status: "error", | ||
}, | ||
[FinalityProviderState.SLASHED]: { | ||
tooltip: ( | ||
<span> | ||
This finality provider has been slashed. | ||
<Link | ||
className="text-secondary-main" | ||
target="_blank" | ||
href={DOCUMENTATION_LINKS.TECHNICAL_PRELIMINARIES} | ||
> | ||
Learn more | ||
</Link> | ||
</span> | ||
), | ||
status: "error", | ||
}, | ||
}; | ||
|
||
export function FinalityProviderMoniker({ | ||
value, | ||
}: FinalityProviderMonikerProps) { | ||
const { getFinalityProvider } = useFinalityProviderState(); | ||
|
||
const moniker = getFinalityProviderMoniker(value); | ||
const finalProvider = getFinalityProvider(value); | ||
const moniker = finalProvider?.description?.moniker ?? "-"; | ||
const state = finalProvider?.state ?? FinalityProviderState.ACTIVE; | ||
const { tooltip = "unknown", status } = | ||
STATUSES[state as FinalityProviderState] ?? {}; | ||
|
||
return ( | ||
<div className="order-4 lg:order-2 text-right lg:text-left">{moniker}</div> | ||
<Hint tooltip={tooltip} status={status}> | ||
{moniker} | ||
</Hint> | ||
); | ||
} |
Oops, something went wrong.