diff --git a/src/app/pages/SearchResultsPage/SearchResultsList.tsx b/src/app/pages/SearchResultsPage/SearchResultsList.tsx index 4bef49c210..8d4eef19b0 100644 --- a/src/app/pages/SearchResultsPage/SearchResultsList.tsx +++ b/src/app/pages/SearchResultsPage/SearchResultsList.tsx @@ -5,7 +5,14 @@ import { BlockDetailView } from '../BlockDetailPage' import { RouteUtils } from '../../utils/route-utils' import { TransactionDetailView } from '../TransactionDetailPage' import { AccountDetailsView } from '../AccountDetailsPage' -import { AccountResult, BlockResult, SearchResults, TokenResult, TransactionResult } from './hooks' +import { + AccountResult, + BlockResult, + ContractResult, + SearchResults, + TokenResult, + TransactionResult, +} from './hooks' import { getThemesForNetworks } from '../../../styles/theme' import { Network } from '../../../types/network' import { SubPageCard } from '../../components/SubPageCard' @@ -84,6 +91,22 @@ export const SearchResultsList: FC<{ linkLabel={t('search.results.accounts.viewLink')} /> + item.resultType === 'contract')} + resultComponent={item => ( + + )} + link={acc => RouteUtils.getAccountRoute(acc, acc.address_eth ?? acc.address)} + linkLabel={t('search.results.contracts.viewLink')} + /> + item.resultType === 'token')} diff --git a/src/app/pages/SearchResultsPage/hooks.ts b/src/app/pages/SearchResultsPage/hooks.ts index 422e08e3c9..04c0c61ead 100644 --- a/src/app/pages/SearchResultsPage/hooks.ts +++ b/src/app/pages/SearchResultsPage/hooks.ts @@ -23,7 +23,7 @@ function isDefined(item: T): item is NonNullable { export type ConditionalResults = { isLoading: boolean; results: T[] } type SearchResultItemCore = HasScope & { - resultType: 'block' | 'transaction' | 'account' | 'token' + resultType: 'block' | 'transaction' | 'account' | 'contract' | 'token' } export type BlockResult = SearchResultItemCore & RuntimeBlock & { resultType: 'block' } @@ -32,9 +32,11 @@ export type TransactionResult = SearchResultItemCore & RuntimeTransaction & { re export type AccountResult = SearchResultItemCore & RuntimeAccount & { resultType: 'account' } +export type ContractResult = SearchResultItemCore & RuntimeAccount & { resultType: 'contract' } + export type TokenResult = SearchResultItemCore & EvmToken & { resultType: 'token' } -export type SearchResultItem = BlockResult | TransactionResult | AccountResult | TokenResult +export type SearchResultItem = BlockResult | TransactionResult | AccountResult | ContractResult | TokenResult export type SearchResults = SearchResultItem[] @@ -157,7 +159,12 @@ export const useSearch = (q: SearchParams) => { : [ ...blocks.map((block): BlockResult => ({ ...block, resultType: 'block' })), ...transactions.map((tx): TransactionResult => ({ ...tx, resultType: 'transaction' })), - ...accounts.map((account): AccountResult => ({ ...account, resultType: 'account' })), + ...accounts + .filter(account => !account.evm_contract) + .map((account): AccountResult => ({ ...account, resultType: 'account' })), + ...accounts + .filter(account => account.evm_contract) + .map((account): ContractResult => ({ ...account, resultType: 'contract' })), ...tokens.map((token): TokenResult => ({ ...token, resultType: 'token' })), ] return { diff --git a/src/app/pages/SearchResultsPage/useRedirectIfSingleResult.ts b/src/app/pages/SearchResultsPage/useRedirectIfSingleResult.ts index 1b8d4c3dbd..5854f9e45b 100644 --- a/src/app/pages/SearchResultsPage/useRedirectIfSingleResult.ts +++ b/src/app/pages/SearchResultsPage/useRedirectIfSingleResult.ts @@ -30,6 +30,9 @@ export function useRedirectIfSingleResult(scope: SearchScope | undefined, result case 'account': redirectTo = RouteUtils.getAccountRoute(item, item.address_eth ?? item.address) break + case 'contract': + redirectTo = RouteUtils.getAccountRoute(item, item.address_eth ?? item.address) + break case 'token': redirectTo = RouteUtils.getTokenRoute(item, item.eth_contract_addr || item.contract_addr) break diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 59973d3b74..0050f6b859 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -407,6 +407,10 @@ "title": "Blocks", "viewLink": "View Block" }, + "contracts": { + "title": "Contracts", + "viewLink": "View Contract" + }, "tokens": { "title": "Tokens", "viewLink": "View Token"