Skip to content

Commit

Permalink
Separate contracts from accounts search results
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Jul 12, 2023
1 parent 5c8d40f commit e2aa5fa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
25 changes: 24 additions & 1 deletion src/app/pages/SearchResultsPage/SearchResultsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -84,6 +91,22 @@ export const SearchResultsList: FC<{
linkLabel={t('search.results.accounts.viewLink')}
/>

<ResultsGroupByType
title={t('search.results.contracts.title')}
results={searchResults.filter((item): item is ContractResult => item.resultType === 'contract')}
resultComponent={item => (
<AccountDetailsView
isLoading={false}
isError={false}
account={item}
tokenPriceInfo={tokenPrices[item.network]}
showLayer={true}
/>
)}
link={acc => RouteUtils.getAccountRoute(acc, acc.address_eth ?? acc.address)}
linkLabel={t('search.results.contracts.viewLink')}
/>

<ResultsGroupByType
title={t('search.results.tokens.title')}
results={searchResults.filter((item): item is TokenResult => item.resultType === 'token')}
Expand Down
13 changes: 10 additions & 3 deletions src/app/pages/SearchResultsPage/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function isDefined<T>(item: T): item is NonNullable<T> {
export type ConditionalResults<T> = { 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' }
Expand All @@ -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[]

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/app/pages/SearchResultsPage/useRedirectIfSingleResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@
"title": "Blocks",
"viewLink": "View Block"
},
"contracts": {
"title": "Contracts",
"viewLink": "View Contract"
},
"tokens": {
"title": "Tokens",
"viewLink": "View Token"
Expand Down

0 comments on commit e2aa5fa

Please sign in to comment.