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 3, 2024
1 parent 16a9aad commit d7af76a
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/components/GraphChannelList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const GraphChannelList: FC<{ list: Fiber.Graph.Channel[]; node?: string }> = ({
const ckb = shannonToCkb(channel.capacity)
const amount = parseNumericAbbr(ckb)

const fundingCkb = shannonToCkb(channel.outpointInfo.fundingCapacity)
const fundingCkb = shannonToCkb(channel.openTransactionInfo.capacity)
const fundingCkbAmount = parseNumericAbbr(fundingCkb)

const fundingUdtAmount = channel.outpointInfo.fundingUdtAmount
? parseNumericAbbr(channel.outpointInfo.fundingUdtAmount)
const fundingUdtAmount = channel.openTransactionInfo.udtAmount
? parseNumericAbbr(channel.openTransactionInfo.udtAmount)
: null

const outpoint = `${outPoint.txHash}#${outPoint.index}`
Expand Down Expand Up @@ -72,10 +72,10 @@ const GraphChannelList: FC<{ list: Fiber.Graph.Channel[]; node?: string }> = ({
</Tooltip>
)}
from
<Tooltip title={channel.outpointInfo.fundingAddress}>
<Link to={`/address/${channel.outpointInfo.fundingAddress}`} className={styles.address}>
<div>{channel.outpointInfo.fundingAddress.slice(0, -15)}</div>
<div>{channel.outpointInfo.fundingAddress.slice(-15)}</div>
<Tooltip title={channel.openTransactionInfo.address}>
<Link to={`/address/${channel.openTransactionInfo.address}`} className={styles.address}>
<div>{channel.openTransactionInfo.address.slice(0, -15)}</div>
<div>{channel.openTransactionInfo.address.slice(-15)}</div>
</Link>
</Tooltip>
</dd>
Expand Down
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
2 changes: 1 addition & 1 deletion src/pages/Fiber/GraphNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const GraphNode = () => {
const chain = ChainHash.get(node.chainHash) ?? '-'

const openTxs = node.fiberGraphChannels.map(c => ({
hash: c.outpointInfo.txHash,
hash: c.openTransactionInfo.txHash,
index: c.fundingTxIndex,
}))

Expand Down
20 changes: 14 additions & 6 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 Expand Up @@ -1541,14 +1550,13 @@ export namespace Fiber {
autoAcceptAmount: string
}

interface FundingInfo {
interface OpenTransactionInfo {
address: string
blockNumber: number
blockTimestamp: number
fundingAddress: string
fundingCapacity: string
fundingUdtAmount: string | null
transactionFee: number
capacity: string
txHash: string
udtAmount?: string
}

export interface Node {
Expand All @@ -1575,7 +1583,7 @@ export namespace Fiber {
node1ToNode2FeeRate: string
node2ToNode1FeeRate: string
capacity: string
outpointInfo: FundingInfo
openTransactionInfo: OpenTransactionInfo
}

export interface NodeDetail extends Node {
Expand Down

0 comments on commit d7af76a

Please sign in to comment.