Skip to content

Commit

Permalink
feat: support searching fiber node id and peer id
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Dec 2, 2024
1 parent 16a9aad commit 07039b2
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/components/Search/AggregateSearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,22 @@ const SearchResultItem: FC<{ keyword?: string; item: AggregateSearchResult }> =
)
}

if (item.type === SearchResultType.FiberGraphNode) {
return (
<Link className={styles.searchResult} to={to}>
<div className={styles.boxContent}>
<HighlightText style={{ width: '100%' }} text={item.attributes.nodeId} keyword={keyword} />

<div className={classNames(styles.secondaryText, styles.subTitle, 'monospace')}>
<span style={{ marginRight: 4, flexShrink: 0 }}>
{t('search.fiber_graph_node')} # {localeNumberString(item.attributes.alias)}
</span>
</div>
</div>
</Link>
)
}

return (
<Link className={styles.searchResult} to={to}>
<div className={styles.content}>
Expand Down
1 change: 1 addition & 0 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const ALLOW_SEARCH_TYPES = [
SearchResultType.UDT,
SearchResultType.DID,
SearchResultType.BtcAddress,
SearchResultType.FiberGraphNode,
]

async function fetchAggregateSearchResult(searchValue: string): Promise<AggregateSearchResult[]> {
Expand Down
6 changes: 6 additions & 0 deletions src/components/Search/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export const getURLByAggregateSearchResult = (result: AggregateSearchResult) =>
case SearchResultType.BtcAddress:
return `/address/${attributes.addressHash}`

case SearchResultType.FiberGraphNode:
return `/fiber/graph/node/${attributes.nodeId}`

default:
break
}
Expand Down Expand Up @@ -97,4 +100,7 @@ export const getDisplayNameByAggregateSearchResult = (result: AggregateSearchRes
if (type === SearchResultType.BtcAddress) {
return attributes.addressHash
}
if (type === SearchResultType.FiberGraphNode) {
return attributes.peerId
}
}
7 changes: 4 additions & 3 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"sUDT": "sUDT",
"inscriptions": "Inscriptions",
"docs": "Docs",
"search_placeholder": "Block/Transaction/Address/Script Hash/Args/BTC Address/BTC Txid/DID",
"search_placeholder": "Block/Transaction/Address/Script Hash/Args/BTC Address/BTC Txid/DID/Fiber Peer Id/Fiber Node Id",
"search_by_name_placeholder": "Token Name",
"more": "More",
"mainnet": "LINA",
Expand Down Expand Up @@ -368,7 +368,7 @@
"loading": "Loading...",
"no_search_result": "Oops! Your search did not match any record.",
"empty_result": "Oops! Your search did not match any record. \n\nPlease make sure input contains only one of the following items:\n",
"empty_result_items": "Block Number/ Block Hash/ Transaction Hash/ Address/ Script Hash/ Args/ BTC Address/ BTC Txid/DID",
"empty_result_items": "Block Number/ Block Hash/ Transaction Hash/ Address/ Script Hash/ Args/ BTC Address/ BTC Txid/DID/Fiber Peer Id/Fiber Node Id",
"address_type_testnet_error": "Testnet address detected,please goto",
"address_type_mainnet_error": "Mainnet address detected,please goto",
"address_type_testnet_url": "testnet explorer",
Expand All @@ -392,7 +392,8 @@
"bitcoin_address": "BTC Address",
"token_collection": "Token Collection",
"token_item": "Token Item",
"did": "DID"
"did": "DID",
"fiber_graph_node": "Fiber Graph Node"
},
"cell": {
"live_cell": "Live Cell",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@
"bitcoin_address": "BTC 地址",
"token_collection": "藏品集",
"token_item": "藏品",
"did": "分布式数字身份(DID)"
"did": "分布式数字身份(DID)",
"fiber_graph_node": "Fiber Graph Node"
},
"address": {
"address": "地址",
Expand Down
9 changes: 9 additions & 0 deletions src/services/ExplorerService/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export enum SearchResultType {
TokenItem = 'token_item',
DID = 'did',
BtcAddress = 'bitcoin_address',
FiberGraphNode = 'fiber_graph_node',
}

enum SearchQueryType {
Expand Down Expand Up @@ -113,6 +114,14 @@ export type AggregateSearchResult =
},
SearchResultType.BtcAddress
>
| Response.Wrapper<
{
alias: string
nodeId: string
peerId: string
},
SearchResultType.FiberGraphNode
>

export const getBtcTxList = (idList: string[]): Promise<Record<string, RawBtcRPC.BtcTx>> => {
if (idList.length === 0) return Promise.resolve({})
Expand Down
3 changes: 3 additions & 0 deletions src/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export const hexToUtf8 = (value: string = '') => {
}

export const addPrefixForHash = (value: string) => {
// FIXME: should be handled in the backend
if (value?.length === 66) return value // prefixed or pubkey of fiber node
if (value?.length === 68) return value.replace(/^0x/, '')
if (value && value.length >= 32 && /\b[A-Fa-f0-9]+\b/.test(value)) {
return `0x${value}`
}
Expand Down

0 comments on commit 07039b2

Please sign in to comment.