From af5688a1cc753c26779bcf86db820b8df0074a33 Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 27 Jan 2025 17:22:22 +0900 Subject: [PATCH] feat: optimize asset amount of channels --- src/components/GraphChannelList/index.tsx | 80 ++++++++++------------- src/locales/en.json | 4 ++ src/locales/zh.json | 4 ++ src/pages/Fiber/GraphNode/index.tsx | 30 +++++---- src/pages/Fiber/GraphNodeList/index.tsx | 2 +- src/services/ExplorerService/fetcher.ts | 12 +++- src/utils/fiber.tsx | 65 ++++++++++++++++++ 7 files changed, 134 insertions(+), 63 deletions(-) create mode 100644 src/utils/fiber.tsx diff --git a/src/components/GraphChannelList/index.tsx b/src/components/GraphChannelList/index.tsx index 9a2b58b65..327c9ee31 100644 --- a/src/components/GraphChannelList/index.tsx +++ b/src/components/GraphChannelList/index.tsx @@ -5,9 +5,8 @@ import type { FC } from 'react' import { Link } from 'react-router-dom' import { TIME_TEMPLATE } from '../../constants/common' import type { Fiber } from '../../services/ExplorerService/fetcher' -import { parseNumericAbbr } from '../../utils/chart' +import { formalizeChannelAsset } from '../../utils/fiber' import { localeNumberString } from '../../utils/number' -import { shannonToCkb } from '../../utils/util' import styles from './index.module.scss' const GraphChannelList: FC<{ list: Fiber.Graph.Channel[]; node?: string }> = ({ list, node }) => { @@ -17,26 +16,18 @@ const GraphChannelList: FC<{ list: Fiber.Graph.Channel[]; node?: string }> = ({ return (
- {list.map((channel, i) => { + {list.map((ch, i) => { + const { totalLiquidity, funding } = formalizeChannelAsset(ch) + const outPoint = { - txHash: channel.channelOutpoint.slice(0, -8), - index: parseInt(channel.channelOutpoint.slice(-8), 16), + txHash: ch.channelOutpoint.slice(0, -8), + index: parseInt(ch.channelOutpoint.slice(-8), 16), } - const ckb = shannonToCkb(channel.capacity) - const amount = parseNumericAbbr(ckb) - - const fundingCkb = shannonToCkb(channel.openTransactionInfo.capacity) - const fundingCkbAmount = parseNumericAbbr(fundingCkb) - - const fundingUdtAmount = channel.openTransactionInfo.udtAmount - ? parseNumericAbbr(channel.openTransactionInfo.udtAmount) - : null - const outpoint = `${outPoint.txHash}#${outPoint.index}` return ( -
+

Channel #{i + 1}

@@ -55,26 +46,23 @@ const GraphChannelList: FC<{ list: Fiber.Graph.Channel[]; node?: string }> = ({
-
Capacity
+
Liquidity
- - {`${amount} CKB`} - + {totalLiquidity}
+
Source
- {fundingUdtAmount || ( - - {`${fundingCkbAmount} CKB`} - - )} + + {`${funding.amount} ${funding.symbol}`} + from - - -
{channel.openTransactionInfo.address.slice(0, -15)}
-
{channel.openTransactionInfo.address.slice(-15)}
+ + +
{ch.openTransactionInfo.address.slice(0, -15)}
+
{ch.openTransactionInfo.address.slice(-15)}
@@ -83,9 +71,9 @@ const GraphChannelList: FC<{ list: Fiber.Graph.Channel[]; node?: string }> = ({
Position
On - - - {localeNumberString(channel.openTransactionInfo.blockNumber)} + + + {localeNumberString(ch.openTransactionInfo.blockNumber)}
@@ -98,49 +86,49 @@ const GraphChannelList: FC<{ list: Fiber.Graph.Channel[]; node?: string }> = ({

First Node - {node ? {node === channel.node1 ? : } : null} + {node ? {node === ch.node1 ? : } : null}

ID
- - -
{`0x${channel.node1.slice(0, -8)}`}
-
{channel.node1.slice(-8)}
+ + +
{`0x${ch.node1.slice(0, -8)}`}
+
{ch.node1.slice(-8)}
-
Fee Rate
-
{`${localeNumberString(channel.feeRateOfNode1)} shannon/kB`}
+
{`${localeNumberString(ch.feeRateOfNode1)} shannon/kB`}

Second Node - {node ? {node === channel.node2 ? : } : null} + {node ? {node === ch.node2 ? : } : null}

ID
- - -
{`0x${channel.node2.slice(0, -8)}`}
-
{channel.node2.slice(-8)}
+ + +
{`0x${ch.node2.slice(0, -8)}`}
+
{ch.node2.slice(-8)}
-
Fee Rate
-
{`${localeNumberString(channel.feeRateOfNode2)} shannon/kB`}
+
{`${localeNumberString(ch.feeRateOfNode2)} shannon/kB`}
diff --git a/src/locales/en.json b/src/locales/en.json index 215684be8..bf1056496 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1159,6 +1159,10 @@ "offered": "Offered", "received": "Received" }, + "action": { + "open": "Open", + "close": "Close" + }, "graph": { "node": { "id": "Node ID", diff --git a/src/locales/zh.json b/src/locales/zh.json index 62e9daf4b..d0bd32f2e 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -1134,6 +1134,10 @@ "offered": "已提供", "received": "已接收" }, + "action": { + "open": "开启", + "close": "关闭" + }, "graph": { "node": { "id": "节点 ID", diff --git a/src/pages/Fiber/GraphNode/index.tsx b/src/pages/Fiber/GraphNode/index.tsx index cc7244e28..6e7374373 100644 --- a/src/pages/Fiber/GraphNode/index.tsx +++ b/src/pages/Fiber/GraphNode/index.tsx @@ -16,10 +16,10 @@ import { getFundingThreshold } from '../utils' import { shannonToCkb } from '../../../utils/util' import { parseNumericAbbr } from '../../../utils/chart' import { Link } from '../../../components/Link' -import { localeNumberString } from '../../../utils/number' import { Fiber } from '../../../services/ExplorerService/fetcher' import { useSearchParams } from '../../../hooks' import { TIME_TEMPLATE } from '../../../constants/common' +import { formalizeChannelAsset } from '../../../utils/fiber' const GraphNode = () => { const [t] = useTranslation() @@ -93,7 +93,9 @@ const GraphNode = () => { if (!node?.fiberGraphChannels) return list node.fiberGraphChannels.forEach(c => { - const isUdt = !!c.openTransactionInfo.udtAmount + const assets = formalizeChannelAsset(c) + + const isUdt = !!c.openTransactionInfo.udtInfo const open = { isOpen: true, isUdt, @@ -105,9 +107,7 @@ const GraphNode = () => { accounts: [ { address: c.openTransactionInfo.address, - amount: - c.openTransactionInfo.udtAmount ?? - `${localeNumberString(shannonToCkb(c.openTransactionInfo.capacity))} CKB`, + amount: `${assets.funding.amount} ${assets.funding.symbol}`, }, ], } @@ -123,12 +123,11 @@ const GraphNode = () => { timestamp: c.closedTransactionInfo.blockTimestamp, }, isUdt, - accounts: c.closedTransactionInfo.closeAccounts.map(acc => { - return { - amount: acc.udtAmount ?? `${localeNumberString(shannonToCkb(acc.capacity))} CKB`, - address: acc.address, - } - }), + accounts: + assets.close?.map(a => ({ + address: a.addr, + amount: `${a.amount} ${a.symbol}`, + })) ?? [], } : null if (close) { @@ -242,7 +241,10 @@ const GraphNode = () => {
-
Coming soon
+
+
Total Liquidity
+
Distribution
+
@@ -259,7 +261,7 @@ const GraphNode = () => { const account = tx.accounts[0]! return (
-
+
at