Skip to content

Commit

Permalink
process the pre-selected FP inside the child component
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab committed Nov 27, 2024
1 parent 9a534b7 commit b3066df
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import { useDebounce } from "@uidotdev/usehooks";
import { useSearchParams } from "next/navigation";
import React, { useEffect, useState } from "react";
import { FiSearch } from "react-icons/fi";

interface FinalityProviderSearchProps {
initialSearchValue: string | null;
onSearch: (searchTerm: string) => void;
}

export const FinalityProviderSearch: React.FC<FinalityProviderSearchProps> = ({
initialSearchValue,
onSearch,
}) => {
const [searchTerm, setSearchTerm] = useState("");
const debouncedSearchTerm = useDebounce(searchTerm, 300);
// Get the finality provider from the search params
const searchParams = useSearchParams();
const initialSearchFp = searchParams.get("fp");

useEffect(() => {
onSearch(debouncedSearchTerm);
}, [debouncedSearchTerm, onSearch]);
const [searchTerm, setSearchTerm] = useState(initialSearchFp);
const debouncedSearchTerm = useDebounce(searchTerm, 300);

useEffect(() => {
if (initialSearchValue) {
setSearchTerm(initialSearchValue);
onSearch(initialSearchValue);
if (debouncedSearchTerm) {
onSearch(debouncedSearchTerm);
}
}, [initialSearchValue, onSearch]);
}, [debouncedSearchTerm, onSearch]);

const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearchTerm(e.target.value);
Expand All @@ -38,7 +36,7 @@ export const FinalityProviderSearch: React.FC<FinalityProviderSearchProps> = ({
<input
type="text"
placeholder="Search by Name or Public Key"
value={searchTerm}
value={searchTerm ?? ""}
onChange={handleSearch}
className="w-full pl-10 pr-4 py-2 text-sm bg-transparent border-b border-gray-300 focus:outline-none focus:border-primary"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { FinalityProvider } from "./FinalityProvider";
import { FinalityProviderSearch } from "./FinalityProviderSearch";

export const FinalityProviders: React.FC<FinalityProvidersProps> = ({
initialSearchValue,
selectedFinalityProvider,
onFinalityProviderChange,
onFinalityProvidersLoad,
Expand Down Expand Up @@ -107,10 +106,7 @@ export const FinalityProviders: React.FC<FinalityProvidersProps> = ({
<strong>Step-1:</strong> Select a finality provider
</p>
<div className="flex gap-3">
<FinalityProviderSearch
initialSearchValue={initialSearchValue}
onSearch={handleSearch}
/>
<FinalityProviderSearch onSearch={handleSearch} />
</div>
<div className="hidden gap-2 px-4 lg:grid lg:grid-cols-stakingFinalityProvidersDesktop">
<p>Finality Provider</p>
Expand Down
8 changes: 0 additions & 8 deletions src/app/components/Staking/Staking.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"use client";

import { useQuery, useQueryClient } from "@tanstack/react-query";
import { networks, Transaction } from "bitcoinjs-lib";
import { useSearchParams } from "next/navigation";
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from "react";
import { Tooltip } from "react-tooltip";
import { useLocalStorage } from "usehooks-ts";
Expand Down Expand Up @@ -85,10 +82,6 @@ export const Staking: React.FC<StakingProps> = ({
btcWalletBalanceSat,
availableUTXOs,
}) => {
// Get the finality provider from the search params
const searchParams = useSearchParams();
const initialSearchFp = searchParams.get("fp");

// Staking form state
const [stakingAmountSat, setStakingAmountSat] = useState(0);
const [stakingTimeBlocks, setStakingTimeBlocks] = useState(0);
Expand Down Expand Up @@ -688,7 +681,6 @@ export const Staking: React.FC<StakingProps> = ({
onFinalityProvidersLoad={setFinalityProviders}
selectedFinalityProvider={finalityProvider}
onFinalityProviderChange={handleChooseFinalityProvider}
initialSearchValue={initialSearchFp}
/>
</div>
<div className="divider m-0 lg:divider-horizontal lg:m-0" />
Expand Down
1 change: 0 additions & 1 deletion src/app/types/finalityProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface Description {
}

export interface FinalityProvidersProps {
initialSearchValue: string | null;
onFinalityProvidersLoad: Dispatch<
SetStateAction<FinalityProvider[] | undefined>
>;
Expand Down

0 comments on commit b3066df

Please sign in to comment.