diff --git a/package-lock.json b/package-lock.json
index 21ac8bdd..47ee79ab 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "simple-staking",
- "version": "0.3.21",
+ "version": "0.3.22",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "simple-staking",
- "version": "0.3.21",
+ "version": "0.3.22",
"dependencies": {
"@babylonlabs-io/btc-staking-ts": "0.3.0",
"@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
diff --git a/package.json b/package.json
index 30e50b8a..cc8613a6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "simple-staking",
- "version": "0.3.21",
+ "version": "0.3.22",
"private": true,
"scripts": {
"dev": "next dev",
diff --git a/src/app/components/Staking/FinalityProviders/FinalityProviderSearch.tsx b/src/app/components/Staking/FinalityProviders/FinalityProviderSearch.tsx
index 6889d7e2..f2f6a9d2 100644
--- a/src/app/components/Staking/FinalityProviders/FinalityProviderSearch.tsx
+++ b/src/app/components/Staking/FinalityProviders/FinalityProviderSearch.tsx
@@ -1,36 +1,19 @@
-import { useDebounce } from "@uidotdev/usehooks";
-import { useSearchParams } from "next/navigation";
-import React, { useEffect, useState } from "react";
+"use client";
+
+import React from "react";
import { FiSearch } from "react-icons/fi";
interface FinalityProviderSearchProps {
+ searchValue: string;
onSearch: (searchTerm: string) => void;
}
export const FinalityProviderSearch: React.FC
Finality Provider
diff --git a/src/app/hooks/finalityProviders/useFinalityProvidersData.ts b/src/app/hooks/finalityProviders/useFinalityProvidersData.ts index 97d08c20..60c50647 100644 --- a/src/app/hooks/finalityProviders/useFinalityProvidersData.ts +++ b/src/app/hooks/finalityProviders/useFinalityProvidersData.ts @@ -1,33 +1,40 @@ -import { useCallback, useEffect, useState } from "react"; +"use client"; + +import { useDebounce } from "@uidotdev/usehooks"; +import { useSearchParams } from "next/navigation"; +import { useCallback, useMemo, useState } from "react"; import { FinalityProvider as FinalityProviderInterface } from "@/app/types/finalityProviders"; export const useFinalityProvidersData = ( initialProviders: FinalityProviderInterface[] | undefined, ) => { - const [filteredProviders, setFilteredProviders] = useState(initialProviders); + const searchParams = useSearchParams(); + const [searchTerm, setSearchTerm] = useState(searchParams.get("fp") || ""); + const debouncedSearchTerm = useDebounce(searchTerm, 300); - useEffect(() => { - setFilteredProviders(initialProviders); - }, [initialProviders]); + const filteredProviders = useMemo( + () => + initialProviders?.filter((fp) => { + const matchesMoniker = fp.description?.moniker + ?.toLowerCase() + .includes(debouncedSearchTerm.toLowerCase()); + const matchesPk = fp.btcPk + .toLowerCase() + .includes(debouncedSearchTerm.toLowerCase()); - const handleSearch = useCallback( - (searchTerm: string) => { - const filtered = initialProviders?.filter( - (fp) => - fp.description?.moniker - ?.toLowerCase() - .includes(searchTerm.toLowerCase()) || - fp.btcPk.toLowerCase().includes(searchTerm.toLowerCase()), - ); - setFilteredProviders(filtered); - }, - [initialProviders], + return matchesMoniker || matchesPk; + }), + [initialProviders, debouncedSearchTerm], ); + const handleSearch = useCallback((searchValue: string) => { + setSearchTerm(searchValue); + }, []); + return { filteredProviders, - setFilteredProviders, handleSearch, + searchValue: searchTerm, }; };