Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: delegate table username/rank adjustments #427

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cn from "classnames";
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";

import { useResizeDetector } from "react-resize-detector";
import { DelegateRowSkeleton } from "./DelegateRowSkeleton";
import { DelegateVoteAmount } from "./DelegateVoteAmount";
import { DelegateVoteButton } from "./DelegateVoteButton";
Expand All @@ -13,6 +14,7 @@ import { TableCell, TableRow } from "@/app/components/Table";
import { VoteDelegateProperties } from "@/domains/vote/components/DelegateTable/DelegateTable.contracts";
import { delegateExistsInVotes } from "@/domains/vote/components/DelegateTable/DelegateTable.helpers";
import { Tooltip } from "@/app/components/Tooltip";
import { TruncateMiddleDynamic } from "@/app/components/TruncateMiddleDynamic";

interface DelegateRowProperties {
index: number;
Expand Down Expand Up @@ -83,6 +85,8 @@ export const DelegateRow = ({
return !!voted && (alreadyExistsInVotes || alreadyExistsInUnvotes);
}, [selectedVotes, selectedUnvotes, isSelectedUnvote, voted, delegate]);

const { ref, width } = useResizeDetector<HTMLSpanElement>({ handleHeight: false });

const rowColor = useMemo(() => {
if (isChanged) {
return "bg-theme-warning-50 dark:bg-theme-background dark:border-theme-warning-600";
Expand Down Expand Up @@ -194,7 +198,7 @@ export const DelegateRow = ({
isCompact={isCompact}
innerClassName={cn("font-bold border-2 border-r-0 border-transparent", rowColor, { "h-12": isCompact })}
>
<span>{delegate.rank()}</span>
<span>{delegate.rank() ?? '0'}</span>
</TableCell>

<TableCell
Expand All @@ -207,9 +211,14 @@ export const DelegateRow = ({
isCompact={isCompact}
>
<Avatar size={isCompact ? "xs" : "lg"} className="-ml-0.5" address={delegate.address()} noShadow />
<div className="relative grow">
<span className="absolute flex w-full items-center">
<div className="overflow-hidden text-ellipsis">{delegate.username()}</div>
<div className="relative grow ">
<span className="absolute flex w-full items-center whitespace-nowrap" ref={ref}>
{delegate.username() ? (
<div className="overflow-hidden text-ellipsis">{delegate.username()}</div>
): (
<TruncateMiddleDynamic value={delegate.address()} availableWidth={width} />
)}
Comment on lines +216 to +220
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will leave this for now, but later on we need a generic handler as it will apply to regular wallets and other parts of the UI as well


<Link
className="ml-2 block sm:hidden"
to={delegate.explorerLink()}
Expand Down
Loading