-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): add finalized status field to block (#531)
* feat(web): add finalised status field to block * feat: Add BlockStatus component to Blob and Tx pages * chore: update changeset * chore: update how block-status is added to tx * feat: Update Badge components to use class-variance-authority * refactor: Update StatusBadge component styles * feat: Update StatusBadge component styles * refactor: Update StatusBadge component styles * refactor: Update StatusBadge component styles * fix: linter * update pnpm-lock.yaml --------- Co-authored-by: Pablo Castellano <[email protected]>
- Loading branch information
1 parent
7cd9a73
commit 308db72
Showing
11 changed files
with
215 additions
and
91 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,5 @@ | ||
--- | ||
"@blobscan/web": patch | ||
--- | ||
|
||
Added finalized status field to block, tx and blob views |
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,58 +1,46 @@ | ||
import type { ReactNode } from "react"; | ||
import React from "react"; | ||
import { cva } from "class-variance-authority"; | ||
import type { VariantProps } from "class-variance-authority"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
import type { Size } from "~/types"; | ||
const badgeVariants = cva( | ||
` | ||
w-fit | ||
flex | ||
items-center | ||
gap-1.5 | ||
rounded-full | ||
px-2.5 | ||
py-0.5 | ||
transition-colors | ||
`, | ||
{ | ||
variants: { | ||
size: { | ||
xs: "text-xs", | ||
sm: "text-sm", | ||
md: "text-md", | ||
lg: "text-lg", | ||
}, | ||
}, | ||
defaultVariants: { | ||
size: "md", | ||
}, | ||
} | ||
); | ||
|
||
type BadgeProps = { | ||
className?: string; | ||
label?: ReactNode; | ||
icon?: ReactNode; | ||
size?: Size; | ||
}; | ||
|
||
const BADGE_STYLES: Record< | ||
Size, | ||
{ labelStyles: string; containerStyles?: string } | ||
> = { | ||
xs: { | ||
labelStyles: "text-xs", | ||
containerStyles: "py-0.5", | ||
}, | ||
sm: { | ||
labelStyles: "text-sm", | ||
}, | ||
md: { | ||
labelStyles: "text-md", | ||
}, | ||
lg: { | ||
labelStyles: "text-lg", | ||
}, | ||
xl: { | ||
labelStyles: "text-lg", | ||
}, | ||
"2xl": { | ||
labelStyles: "text-lg", | ||
}, | ||
}; | ||
export type BadgeProps = React.HTMLAttributes<HTMLDivElement> & | ||
VariantProps<typeof badgeVariants>; | ||
|
||
export const Badge: React.FC<BadgeProps> = ({ | ||
className = "", | ||
label, | ||
icon, | ||
size = "md", | ||
className, | ||
size, | ||
children, | ||
...props | ||
}) => { | ||
const { labelStyles, containerStyles } = BADGE_STYLES[size]; | ||
|
||
return ( | ||
<div | ||
className={`flex w-fit items-center gap-1.5 rounded-full px-2.5 transition-colors ${ | ||
containerStyles ?? "py-0.5" | ||
} ${className}`} | ||
> | ||
{icon && ( | ||
<div className="text-content-light dark:text-content-dark">{icon}</div> | ||
)} | ||
<div className={labelStyles}>{label}</div> | ||
<div className={twMerge(badgeVariants({ size }), className)} {...props}> | ||
{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
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,65 @@ | ||
import type { FC } from "react"; | ||
import { cva } from "class-variance-authority"; | ||
import type { VariantProps } from "class-variance-authority"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
import { Badge } from "./Badge"; | ||
import type { BadgeProps } from "./Badge"; | ||
|
||
const statusBadgeVariants = cva( | ||
` | ||
rounded-lg | ||
font-medium | ||
text-xs | ||
h-6 | ||
p-1.5 | ||
bg-opacity-10 | ||
dark:bg-opacity-10 | ||
border | ||
border-opacity-30 | ||
dark:border-opacity-30 | ||
`, | ||
{ | ||
variants: { | ||
variant: { | ||
green: ` | ||
bg-green-600 | ||
text-green-600 | ||
border-green-600 | ||
dark:bg-green-500 | ||
dark:text-green-500 | ||
dark:border-green-500 | ||
`, | ||
gray: ` | ||
bg-contentTertiary-light | ||
text-warmGray-500 | ||
border-contentTertiary-light | ||
dark:bg-contentTertiary-dark | ||
dark:text-contentTertiary-dark | ||
dark:border-contentTertiary-dark | ||
`, | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "green", | ||
}, | ||
} | ||
); | ||
|
||
type StatusBadgeProps = BadgeProps & VariantProps<typeof statusBadgeVariants>; | ||
|
||
export const StatusBadge: FC<StatusBadgeProps> = ({ | ||
className, | ||
variant, | ||
...props | ||
}) => { | ||
return ( | ||
<Badge | ||
className={twMerge(statusBadgeVariants({ variant }), className)} | ||
{...props} | ||
/> | ||
); | ||
}; |
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,28 @@ | ||
import { CheckCircleIcon, ClockIcon } from "@heroicons/react/24/solid"; | ||
|
||
import { api } from "~/api-client"; | ||
import { StatusBadge } from "./Badges/StatusBadge"; | ||
|
||
export function BlockStatus({ blockNumber }: { blockNumber: number }) { | ||
const { data: syncState } = api.syncState.getState.useQuery(); | ||
|
||
if (!syncState || typeof syncState.lastFinalizedBlock !== "number") { | ||
return; | ||
} | ||
|
||
if (blockNumber <= syncState.lastFinalizedBlock) { | ||
return ( | ||
<StatusBadge variant="green"> | ||
<CheckCircleIcon className="h-4 w-4" /> | ||
Finalized | ||
</StatusBadge> | ||
); | ||
} | ||
|
||
return ( | ||
<StatusBadge variant="gray"> | ||
<ClockIcon className="h-4 w-4" /> | ||
Unfinalized | ||
</StatusBadge> | ||
); | ||
} |
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
Oops, something went wrong.