Skip to content

Commit 6cad961

Browse files
committed
Update contract-function.tsx
1 parent aa2abe2 commit 6cad961

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

apps/dashboard/src/components/contract-functions/contract-function.tsx

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,21 @@ import type { AbiEvent, AbiFunction } from "abitype";
2727
import { camelToTitle } from "contract-ui/components/solidity-inputs/helpers";
2828
import { SearchIcon } from "lucide-react";
2929
import { usePathname, useSearchParams } from "next/navigation";
30-
import { type Dispatch, type SetStateAction, useMemo, useState } from "react";
30+
import {
31+
type ChangeEvent,
32+
type Dispatch,
33+
type SetStateAction,
34+
useMemo,
35+
useState,
36+
} from "react";
3137
import type { ThirdwebContract } from "thirdweb";
3238
import * as ERC20Ext from "thirdweb/extensions/erc20";
3339
import * as ERC721Ext from "thirdweb/extensions/erc721";
3440
import * as ERC1155Ext from "thirdweb/extensions/erc1155";
3541
import { useReadContract } from "thirdweb/react";
3642
import { toFunctionSelector } from "thirdweb/utils";
3743
import { Badge, Button, Card, Heading, Text } from "tw-components";
38-
import { useDebouncedCallback } from "use-debounce";
44+
import { type DebouncedState, useDebouncedCallback } from "use-debounce";
3945
import { useContractFunctionSelectors } from "../../contract-ui/hooks/useContractFunctionSelectors";
4046
import {
4147
COMMANDS,
@@ -256,6 +262,23 @@ type ExtensionFunctions = {
256262
functions: AbiFunction[];
257263
};
258264

265+
const FunctionInputSearch = ({
266+
searchFn,
267+
}: {
268+
searchFn: DebouncedState<(e: ChangeEvent<HTMLInputElement>) => void>;
269+
}) => (
270+
<div className="sticky top-0 z-10 mb-3">
271+
<div className="relative w-full">
272+
<SearchIcon className="-translate-y-1/2 absolute top-[50%] left-3 size-4 text-muted-foreground" />
273+
<Input
274+
placeholder="Search"
275+
className="rounded-none border-r-none border-l-none py-2 pl-9 focus-visible:ring-0"
276+
onChange={searchFn}
277+
/>
278+
</div>
279+
</div>
280+
);
281+
259282
export const ContractFunctionsPanel: React.FC<ContractFunctionsPanelProps> = ({
260283
fnsOrEvents,
261284
contract,
@@ -349,7 +372,7 @@ export const ContractFunctionsPanel: React.FC<ContractFunctionsPanelProps> = ({
349372
)
350373
: e.functions;
351374
return (
352-
<Flex key={e.extension} flexDir="column" mb={6} m={4}>
375+
<Flex key={e.extension} flexDir="column" mb={6} p={4}>
353376
{e.extension ? (
354377
<>
355378
<Flex alignItems="center" alignContent="center" gap={2}>
@@ -428,31 +451,13 @@ export const ContractFunctionsPanel: React.FC<ContractFunctionsPanelProps> = ({
428451
<TabPanels h="auto" overflow="auto">
429452
{writeFunctions.length > 0 && (
430453
<TabPanel p="0">
431-
<div className="sticky top-0 z-10 mb-3">
432-
<div className="relative w-full">
433-
<SearchIcon className="-translate-y-1/2 absolute top-[50%] left-3 size-4 text-muted-foreground" />
434-
<Input
435-
placeholder="Search"
436-
className="rounded-none border-r-none border-l-none py-2 pl-9 focus-visible:ring-0"
437-
onChange={handleKeywordSearch}
438-
/>
439-
</div>
440-
</div>
454+
<FunctionInputSearch searchFn={handleKeywordSearch} />
441455
{writeFunctions.map((e) => functionSection(e))}
442456
</TabPanel>
443457
)}
444458
{viewFunctions.length > 0 && (
445459
<TabPanel p="0">
446-
<div className="sticky top-0 z-10 mb-3">
447-
<div className="relative w-full">
448-
<SearchIcon className="-translate-y-1/2 absolute top-[50%] left-3 size-4 text-muted-foreground" />
449-
<Input
450-
placeholder="Search"
451-
className="rounded-none border-r-none border-l-none py-2 pl-9 focus-visible:ring-0"
452-
onChange={handleKeywordSearch}
453-
/>
454-
</div>
455-
</div>
460+
<FunctionInputSearch searchFn={handleKeywordSearch} />
456461
{viewFunctions.map((e) => functionSection(e))}
457462
</TabPanel>
458463
)}

0 commit comments

Comments
 (0)