Skip to content

Commit

Permalink
fix: update with search type
Browse files Browse the repository at this point in the history
  • Loading branch information
tiendn committed Nov 1, 2022
1 parent 0e4b8ca commit 1a48ece
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
8 changes: 5 additions & 3 deletions components/Search/ResultView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface SearchResultViewItem {
type: 'Address' | 'Block' | 'Transaction' | 'Validator' | 'Token'
time?: string
status?: string
value: string
value: string | number
key: string | number
linkValue?: string
}
Expand All @@ -27,7 +27,7 @@ export default function ResultView({ item }: ResultViewProps) {
return LinkMaker.block(linkValue)
}

if (type === 'Address') {
if (type === 'Address' || type === 'Validator') {
return LinkMaker.address(linkValue)
}

Expand All @@ -40,7 +40,9 @@ export default function ResultView({ item }: ResultViewProps) {
return (
<Link href={_link()}>
<div className={clsx(styles.item, 'money money-sm padding-left-xs pointer')}>
<div className={clsx('text-bold')}>{isMobile ? ellipseBetweenText(value, 10, 10) : value}</div>
<div className={clsx('text-bold')}>
{isMobile ? ellipseBetweenText(value?.toString(), 10, 10) : value}
</div>
<div
className={clsx(
styles.viewMoreInfo,
Expand Down
31 changes: 16 additions & 15 deletions components/Search/SearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,38 @@ export default function SearchResult({ status, data }: SearchResultProps) {
if (!data) {
return []
}
const { blocks, accounts, transactions, validators, tokens } = data?.result
const { blocks, addresses, transactions, validators, tokens } = data?.result
const items: SearchResultViewItem[] = []
if (blocks && blocks.length > 0) {
for (let item of blocks) {
items.push({
time: item.blockTime,
time: item.insertedAt,
type: 'Block',
key: item.blockHeight,
value: item.blockHash,
linkValue: `${item.blockHeight}`
key: item.blockNumber,
value: item.blockNumber,
linkValue: `${item.blockNumber}`
})
}
}
if (accounts && accounts.length > 0) {
for (let item of blocks) {
if (addresses && addresses.length > 0) {
for (let item of addresses) {
items.push({
time: item.blockTime,
type: 'Block',
key: item.blockHash,
value: item.blockHash
time: item.insertedAt,
type: 'Address',
key: item.addressHash,
value: item.addressHash,
linkValue: item.addressHash
})
}
}
if (transactions && transactions.length > 0) {
for (let item of transactions) {
items.push({
time: item.blockTime,
key: item.hash,
time: item.insertedAt,
key: item.evmHash || item.cosmosHash,
type: 'Transaction',
value: item.hash,
linkValue: item.hash
value: item.evmHash || item.cosmosHash,
linkValue: `${item.evmHash}&type=evm` || item.cosmosHash
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

interface SearchItemResponse {
result: {
blocks: BlockItem[]
transactions: TransactionItem[]
blocks: BlockSearchResponse[]
transactions: TransactionSearchResponse[]
validators: ValidatorData[]
accounts: never[]
addresses: AddressSearchResponse[]
tokens: TokenSearchResponse[]
}
}
Expand Down
7 changes: 7 additions & 0 deletions types/address.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,10 @@ interface AddressTransactionResponse {
timeoutHeight: number
messages: TransactionMessage[]
}

interface AddressSearchResponse {
addressHash: string
address: string
name: string
insertedAt: string
}
6 changes: 6 additions & 0 deletions types/blocks.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ interface BlockItem {
newBlock?: boolean
}

interface BlockSearchResponse {
blockHash: string
blockNumber: number
insertedAt: string
}

interface BlockResponse {
result: BlockItem[]
pagination: Pagination
Expand Down
6 changes: 6 additions & 0 deletions types/transactions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ interface TransactionItem {
signers: Signer[]
}

interface TransactionSearchResponse {
evmHash: string
cosmosHash: string
insertedAt: string
}

interface TransactionResponse {
result: TransactionItem[]
pagination: Pagination
Expand Down

0 comments on commit 1a48ece

Please sign in to comment.