Skip to content

Commit

Permalink
(bugfix): fix rounding and sorting of claims
Browse files Browse the repository at this point in the history
  • Loading branch information
Jipperism committed Oct 16, 2024
1 parent 942eecb commit 41eaaff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
21 changes: 10 additions & 11 deletions components/hyperboard/ownership-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,18 @@ export const OwnershipTable = ({
if (!entries) {
return null;
}
const sortedEntries = _.sortBy(
entries,
(entry) => -entry.percentage_of_section,
);

const isRegistrySelected =
!selectedClaim && !selectedBlueprint && selectedRegistry === id;
const isFirstAfterSelected =
indexOfSelectedRegistry !== -1 &&
index === indexOfSelectedRegistry + 1;
const isLastRegistry =
index === hyperboardContentData.sections.data.length - 1;
const totalValueInRegistry = _.sum([
...sift(entries).map((entry) => entry.display_size),
]);
const isSingleSection =
hyperboardContentData.sections.data.length === 1;
return (
Expand Down Expand Up @@ -162,10 +164,10 @@ export const OwnershipTable = ({
)}
{selectedRegistry === id && (
<>
{entries.map((claim, index) => {
{sortedEntries.map((claim, index) => {
const isClaimSelected = claim.id === selectedClaim;
const isLastClaim =
!isLastRegistry && index === entries.length - 1;
!isLastRegistry && index === sortedEntries.length - 1;

if (claim.is_blueprint) {
const isBlueprintSelected =
Expand All @@ -177,10 +179,7 @@ export const OwnershipTable = ({
isSelected={isBlueprintSelected}
isLast={false}
text={claim.name || "No name"}
percentage={(
(claim.display_size / totalValueInRegistry) *
100
).toPrecision(2)}
percentage={claim.percentage_of_section}
onClick={() => {
setSelectedClaim(undefined);
setSelectedBlueprint(Number(claim.id));
Expand Down Expand Up @@ -245,7 +244,7 @@ export const OwnershipTable = ({
interface SelectionRowProps {
isSelected: boolean;
text: string;
percentage: number | string;
percentage: number;
onClick: () => void;
icon: React.JSX.Element;
}
Expand Down Expand Up @@ -351,7 +350,7 @@ const ClaimRow = ({
{icon}
<Text ml={4}>{text}</Text>
<Text textStyle={"secondary"} ml={"auto"}>
{percentage}%
{percentage.toFixed(2)}%
</Text>
{isSelected && <SelectedIcon />}
</Flex>
Expand Down
Loading

0 comments on commit 41eaaff

Please sign in to comment.