Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Open
Show file tree
Hide file tree
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 @@ -12,7 +12,7 @@ export const FinalityProviderFilter = () => {
placeholder="Select Status"
value={filter.searchTerm ? "" : filter.providerStatus}
disabled={Boolean(filter.searchTerm)}
renderSelectedOption={(option) => `Showing ${option.label}`}
renderSelectedOption={(option) => `${option.label}`}
className="h-10"
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const FinalityProviderFilter = () => {
placeholder="Select Status"
value={filter.search ? "" : filter.status}
disabled={Boolean(filter.search)}
renderSelectedOption={(option) => `Showing ${option.label}`}
renderSelectedOption={(option) => `${option.label}`}
/>
);
};
36 changes: 33 additions & 3 deletions src/ui/common/state/FinalityProviderBsnState.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { useDebounce } from "@uidotdev/usehooks";
import { useCallback, useMemo, useState, type PropsWithChildren } from "react";
import {
useCallback,
useEffect,
useMemo,
useState,
type PropsWithChildren,
} from "react";
import { useSearchParams } from "react-router";

import { BSN_TYPE_COSMOS } from "@/ui/common/api/getBsn";
Expand Down Expand Up @@ -89,6 +95,20 @@ const SORT_DIRECTIONS = {

// Component-specific constants remain in the state file

/**
* Get default provider status based on BSN type
*/
export const getDefaultProviderStatus = (
bsn?: Bsn,
): FinalityProviderFilterState["providerStatus"] => {
if (!bsn || bsn.id === BBN_CHAIN_ID) return "active";
return bsn.type === "COSMOS"
? "registered"
: bsn.type === "ROLLUP"
? "allowlisted"
: "active";
};

const FILTERS = {
searchTerm: (fp: FinalityProvider, filter: FilterState) => {
const searchTerm = filter.searchTerm.toLowerCase();
Expand All @@ -102,7 +122,7 @@ const FILTERS = {
const defaultState: FinalityProviderBsnState = {
filter: {
searchTerm: "",
providerStatus: "active",
providerStatus: getDefaultProviderStatus(),
allowlistStatus: "",
},
finalityProviders: [],
Expand Down Expand Up @@ -144,7 +164,7 @@ export function FinalityProviderBsnState({ children }: PropsWithChildren) {

const [filter, setFilter] = useState<FilterState>({
searchTerm: fpParam || "",
providerStatus: "active",
providerStatus: getDefaultProviderStatus(),
allowlistStatus: "",
});
const [sortState, setSortState] = useState<SortState>({});
Expand Down Expand Up @@ -178,6 +198,16 @@ export function FinalityProviderBsnState({ children }: PropsWithChildren) {
[bsnList, selectedBsnId],
);

useEffect(() => {
const newProviderStatus = getDefaultProviderStatus(selectedBsn);
if (newProviderStatus !== filter.providerStatus) {
setFilter((prevFilter) => ({
...prevFilter,
providerStatus: newProviderStatus,
}));
}
}, [selectedBsn, filter.providerStatus]);

Copilot AI Sep 5, 2025

Copy link

Choose a reason for hiding this comment

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

The useEffect has filter.providerStatus in its dependency array, which could cause unnecessary re-renders. Since the effect only reads this value for comparison, consider using a ref to track the current status or restructure to avoid the dependency.

Suggested change
}, [selectedBsn, filter.providerStatus]);
}, [selectedBsn]);

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jeremy-babylonlabs could you check this comment?


// BSN configuration derived from selected BSN (moved from components)
const bsnConfig = useMemo(() => getBsnConfig(selectedBsn), [selectedBsn]);

Expand Down