Skip to content

Commit

Permalink
Update contract-function.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-ngo committed Oct 4, 2024
1 parent aa2abe2 commit 6cad961
Showing 1 changed file with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ import type { AbiEvent, AbiFunction } from "abitype";
import { camelToTitle } from "contract-ui/components/solidity-inputs/helpers";
import { SearchIcon } from "lucide-react";
import { usePathname, useSearchParams } from "next/navigation";
import { type Dispatch, type SetStateAction, useMemo, useState } from "react";
import {
type ChangeEvent,
type Dispatch,
type SetStateAction,
useMemo,
useState,
} from "react";
import type { ThirdwebContract } from "thirdweb";
import * as ERC20Ext from "thirdweb/extensions/erc20";
import * as ERC721Ext from "thirdweb/extensions/erc721";
import * as ERC1155Ext from "thirdweb/extensions/erc1155";
import { useReadContract } from "thirdweb/react";
import { toFunctionSelector } from "thirdweb/utils";
import { Badge, Button, Card, Heading, Text } from "tw-components";
import { useDebouncedCallback } from "use-debounce";
import { type DebouncedState, useDebouncedCallback } from "use-debounce";
import { useContractFunctionSelectors } from "../../contract-ui/hooks/useContractFunctionSelectors";
import {
COMMANDS,
Expand Down Expand Up @@ -256,6 +262,23 @@ type ExtensionFunctions = {
functions: AbiFunction[];
};

const FunctionInputSearch = ({
searchFn,
}: {
searchFn: DebouncedState<(e: ChangeEvent<HTMLInputElement>) => void>;
}) => (
<div className="sticky top-0 z-10 mb-3">
<div className="relative w-full">
<SearchIcon className="-translate-y-1/2 absolute top-[50%] left-3 size-4 text-muted-foreground" />
<Input
placeholder="Search"
className="rounded-none border-r-none border-l-none py-2 pl-9 focus-visible:ring-0"
onChange={searchFn}
/>
</div>
</div>
);

export const ContractFunctionsPanel: React.FC<ContractFunctionsPanelProps> = ({
fnsOrEvents,
contract,
Expand Down Expand Up @@ -349,7 +372,7 @@ export const ContractFunctionsPanel: React.FC<ContractFunctionsPanelProps> = ({
)
: e.functions;
return (
<Flex key={e.extension} flexDir="column" mb={6} m={4}>
<Flex key={e.extension} flexDir="column" mb={6} p={4}>
{e.extension ? (
<>
<Flex alignItems="center" alignContent="center" gap={2}>
Expand Down Expand Up @@ -428,31 +451,13 @@ export const ContractFunctionsPanel: React.FC<ContractFunctionsPanelProps> = ({
<TabPanels h="auto" overflow="auto">
{writeFunctions.length > 0 && (
<TabPanel p="0">
<div className="sticky top-0 z-10 mb-3">
<div className="relative w-full">
<SearchIcon className="-translate-y-1/2 absolute top-[50%] left-3 size-4 text-muted-foreground" />
<Input
placeholder="Search"
className="rounded-none border-r-none border-l-none py-2 pl-9 focus-visible:ring-0"
onChange={handleKeywordSearch}
/>
</div>
</div>
<FunctionInputSearch searchFn={handleKeywordSearch} />
{writeFunctions.map((e) => functionSection(e))}
</TabPanel>
)}
{viewFunctions.length > 0 && (
<TabPanel p="0">
<div className="sticky top-0 z-10 mb-3">
<div className="relative w-full">
<SearchIcon className="-translate-y-1/2 absolute top-[50%] left-3 size-4 text-muted-foreground" />
<Input
placeholder="Search"
className="rounded-none border-r-none border-l-none py-2 pl-9 focus-visible:ring-0"
onChange={handleKeywordSearch}
/>
</div>
</div>
<FunctionInputSearch searchFn={handleKeywordSearch} />
{viewFunctions.map((e) => functionSection(e))}
</TabPanel>
)}
Expand Down

0 comments on commit 6cad961

Please sign in to comment.