diff --git a/examples/chain-template/components/contract/MyContractsTable.tsx b/examples/chain-template/components/contract/MyContractsTable.tsx index 8d9138422..ccb30f731 100644 --- a/examples/chain-template/components/contract/MyContractsTable.tsx +++ b/examples/chain-template/components/contract/MyContractsTable.tsx @@ -1,6 +1,6 @@ -import { useState } from 'react'; +import { useMemo, useState } from 'react'; import { useChain } from '@cosmos-kit/react'; -import { Box, Icon, Spinner, Text } from '@interchain-ui/react'; +import { Box, Icon, Spinner, Text, TextField } from '@interchain-ui/react'; import { useCopyToClipboard, useMyContracts } from '@/hooks'; import { Button, Table } from '../common'; @@ -8,6 +8,7 @@ import { shortenAddress } from '@/utils'; import { TabLabel } from '@/pages/contract'; import { EmptyState } from './EmptyState'; import { useChainStore } from '@/contexts'; +import styles from '@/styles/comp.module.css'; type MyContractsTableProps = { show: boolean; @@ -22,16 +23,54 @@ export const MyContractsTable = ({ title, createContractTrigger, }: MyContractsTableProps) => { + const [searchValue, setSearchValue] = useState(''); + const { selectedChain } = useChainStore(); const { address } = useChain(selectedChain); const { data: myContracts = [], isLoading } = useMyContracts(); + const filteredContracts = useMemo(() => { + return myContracts.filter(({ address, contractInfo }) => + [address, contractInfo?.label, contractInfo?.codeId.toString()].some( + (value) => + value && value.toLowerCase().includes(searchValue.toLowerCase()), + ), + ); + }, [myContracts, searchValue]); + return ( {title} - + + + + setSearchValue(e.target.value)} + placeholder="Search" + autoComplete="off" + inputClassName={styles['input-pl']} + /> + {createContractTrigger} ) : myContracts.length === 0 ? ( + ) : filteredContracts.length === 0 ? ( + ) : ( @@ -60,7 +101,7 @@ export const MyContractsTable = ({ - {myContracts.map(({ address, contractInfo }) => ( + {filteredContracts.map(({ address, contractInfo }) => (