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 c1ae1e6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 3 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
4 changes: 2 additions & 2 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 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 c1ae1e6

Please sign in to comment.