From d7af76ae3eed9dca70b896625b8c701f036d235c Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 2 Dec 2024 23:23:28 +0900 Subject: [PATCH] feat: support searching fiber node id and peer id --- src/components/GraphChannelList/index.tsx | 14 ++++++------- .../Search/AggregateSearchResults.tsx | 16 +++++++++++++++ src/components/Search/index.tsx | 1 + src/components/Search/utils.ts | 6 ++++++ src/locales/en.json | 7 ++++--- src/locales/zh.json | 3 ++- src/pages/Fiber/GraphNode/index.tsx | 2 +- src/services/ExplorerService/fetcher.ts | 20 +++++++++++++------ 8 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/components/GraphChannelList/index.tsx b/src/components/GraphChannelList/index.tsx index 1653f4cac0..a32a02b114 100644 --- a/src/components/GraphChannelList/index.tsx +++ b/src/components/GraphChannelList/index.tsx @@ -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}` @@ -72,10 +72,10 @@ const GraphChannelList: FC<{ list: Fiber.Graph.Channel[]; node?: string }> = ({ )} from - - -
{channel.outpointInfo.fundingAddress.slice(0, -15)}
-
{channel.outpointInfo.fundingAddress.slice(-15)}
+ + +
{channel.openTransactionInfo.address.slice(0, -15)}
+
{channel.openTransactionInfo.address.slice(-15)}
diff --git a/src/components/Search/AggregateSearchResults.tsx b/src/components/Search/AggregateSearchResults.tsx index de54979bc0..6f0d451ff0 100644 --- a/src/components/Search/AggregateSearchResults.tsx +++ b/src/components/Search/AggregateSearchResults.tsx @@ -259,6 +259,22 @@ const SearchResultItem: FC<{ keyword?: string; item: AggregateSearchResult }> = ) } + if (item.type === SearchResultType.FiberGraphNode) { + return ( + +
+ + +
+ + {t('search.fiber_graph_node')} # {localeNumberString(item.attributes.alias)} + +
+
+ + ) + } + return (
diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 8123799b50..8d628193ab 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -45,6 +45,7 @@ const ALLOW_SEARCH_TYPES = [ SearchResultType.UDT, SearchResultType.DID, SearchResultType.BtcAddress, + SearchResultType.FiberGraphNode, ] async function fetchAggregateSearchResult(searchValue: string): Promise { diff --git a/src/components/Search/utils.ts b/src/components/Search/utils.ts index 0425169ef4..0bb9527b83 100644 --- a/src/components/Search/utils.ts +++ b/src/components/Search/utils.ts @@ -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 } @@ -97,4 +100,7 @@ export const getDisplayNameByAggregateSearchResult = (result: AggregateSearchRes if (type === SearchResultType.BtcAddress) { return attributes.addressHash } + if (type === SearchResultType.FiberGraphNode) { + return attributes.peerId + } } diff --git a/src/locales/en.json b/src/locales/en.json index 1a1f645731..5d13a056a4 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -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", @@ -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", @@ -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", diff --git a/src/locales/zh.json b/src/locales/zh.json index 21935169ab..2e68c32b53 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -407,7 +407,8 @@ "bitcoin_address": "BTC 地址", "token_collection": "藏品集", "token_item": "藏品", - "did": "分布式数字身份(DID)" + "did": "分布式数字身份(DID)", + "fiber_graph_node": "Fiber Graph Node" }, "address": { "address": "地址", diff --git a/src/pages/Fiber/GraphNode/index.tsx b/src/pages/Fiber/GraphNode/index.tsx index 3019596b9d..7a548367af 100644 --- a/src/pages/Fiber/GraphNode/index.tsx +++ b/src/pages/Fiber/GraphNode/index.tsx @@ -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, })) diff --git a/src/services/ExplorerService/fetcher.ts b/src/services/ExplorerService/fetcher.ts index 2a10199fe1..26af615c28 100644 --- a/src/services/ExplorerService/fetcher.ts +++ b/src/services/ExplorerService/fetcher.ts @@ -70,6 +70,7 @@ export enum SearchResultType { TokenItem = 'token_item', DID = 'did', BtcAddress = 'bitcoin_address', + FiberGraphNode = 'fiber_graph_node', } enum SearchQueryType { @@ -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> => { if (idList.length === 0) return Promise.resolve({}) @@ -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 { @@ -1575,7 +1583,7 @@ export namespace Fiber { node1ToNode2FeeRate: string node2ToNode1FeeRate: string capacity: string - outpointInfo: FundingInfo + openTransactionInfo: OpenTransactionInfo } export interface NodeDetail extends Node {