Skip to content

Commit

Permalink
fix: fixed large payload issue
Browse files Browse the repository at this point in the history
  • Loading branch information
axelrod-blox committed Jan 16, 2025
1 parent 9e1a7bd commit e3e1705
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/app/routes/dashboard/clusters/cluster/bulk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ export const Bulk: FC<{ type: "remove" | "exit" }> = ({ type }) => {
const { clusterHash } = useClusterPageParams();
const { _selectedPublicKeys: selectedPublicKeys } = useBulkActionContext();
const params = useParams();
const externalValidators = params.publicKeys
? atob(params.publicKeys).split(",")
: undefined;
const externalValidators = params.publicKeys?.split(",");
const { infiniteQuery, validators, total } = useInfiniteClusterValidators(
clusterHash,
100,
externalValidators,
);

const validatorsToUse = externalValidators
? validators.filter((validator: Validator) =>
externalValidators?.includes(
validator.public_key.startsWith("0x")
? validator.public_key
: `0x${validator.public_key}`,
externalValidators.some((truncatedPublicKey: string) =>
validator.public_key.includes(truncatedPublicKey),
),
)
: validators;

const totalValidators = externalValidators
? externalValidators.length
: total;
Expand Down
6 changes: 3 additions & 3 deletions src/app/routes/reshare-dkg/remove-validators-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ const RemoveValidatorsSection = ({
{isEnabled && (
<div className="flex flex-col gap-4">
<a
href={`${window.location.origin}/clusters/${clusterHash}/remove/${btoa(
validators.map(({ publicKey }) => publicKey).join(","),
)}`}
href={`${window.location.origin}/clusters/${clusterHash}/remove/${validators
.map(({ publicKey }) => publicKey.slice(2, 22))
.join(",")}`}
className={"w-full"}
target="_blank"
>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/cluster/use-cluster-page-params.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useParams } from "react-router";

export const useClusterPageParams = () => {
return useParams<{ clusterHash: string }>();
return useParams<{ clusterHash: string; publicKeys?: string }>();
};
19 changes: 19 additions & 0 deletions src/hooks/cluster/use-infinite-cluster-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { filterOutRemovedValidators } from "@/lib/utils/cluster";
import { getNextPageParam } from "@/lib/utils/infinite-query";
import { useInfiniteQuery } from "@tanstack/react-query";
import { useChainId } from "wagmi";
import { useBulkActionContext } from "@/guard/bulk-action-guard.tsx";
import type { Validator } from "@/types/api.ts";

export const useInfiniteClusterValidators = (
clusterHash?: string,
perPage = 10,
externalValidators?: string[],
) => {
const params = useClusterPageParams();
const hash = clusterHash || params.clusterHash;
Expand Down Expand Up @@ -38,6 +41,22 @@ export const useInfiniteClusterValidators = (
removedOptimisticValidators.data || [],
);

if (
activeValidators.length &&
externalValidators &&
!useBulkActionContext.state._selectedPublicKeys.length
) {
const validatorsToUse = activeValidators.filter((validator: Validator) =>
externalValidators.some((truncatedPublicKey: string) =>
validator.public_key.includes(truncatedPublicKey),
),
);

useBulkActionContext.state._selectedPublicKeys = validatorsToUse.map(
({ public_key }) => public_key,
);
}

const total = Math.max(
(infiniteQuery.data?.pages[0]?.pagination.total || 0) -
(removedOptimisticValidators.data?.length || 0),
Expand Down

0 comments on commit e3e1705

Please sign in to comment.