diff --git a/src/locales/en.json b/src/locales/en.json index cfd2acae6..68f6c528e 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1087,7 +1087,17 @@ }, "channel": { "channel_id": "Channel ID", - "state": "State" + "fiber_peers": "Fiber Peers", + "state": "State", + "open_time": "Open Time", + "update_time": "Last Update Time", + "shutdown_time": "Shutdown Time", + "balance": "Balance", + "local": "Local", + "remote": "Remote", + "tlc_balance": "TLC Balance", + "offered": "Offered", + "received": "Received" } } } diff --git a/src/pages/Fiber/Channel/index.module.scss b/src/pages/Fiber/Channel/index.module.scss new file mode 100644 index 000000000..0ed140108 --- /dev/null +++ b/src/pages/Fiber/Channel/index.module.scss @@ -0,0 +1,91 @@ +@import '../../../styles//variables.module.scss'; + +.container { + text-wrap: nowrap; + display: flex; + flex-direction: column; + align-items: stretch; + margin: 24px 120px; + font-size: 1rem; + + svg { + pointer-events: none; + } + + dl { + display: flex; + + dt, + dd { + display: flex; + align-items: center; + gap: 4px; + margin: 0; + padding: 0; + } + + dt::after { + content: ':'; + margin-right: 4px; + } + } + + button { + display: flex; + align-items: center; + appearance: none; + padding: 0; + border: none; + background: none; + cursor: pointer; + + &:hover { + color: var(--primary-color); + } + } + + .id { + overflow: hidden; + + & > span:first-child { + overflow: hidden; + text-overflow: ellipsis; + flex-shrink: 1; + } + } + + .transactions { + margin-top: 16px; + border-top: 1px solid #ccc; + padding-top: 16px; + + h3 { + margin: 0; + padding: 0; + } + } + + .peers { + display: flex; + flex-wrap: wrap; + + .local, + .remote { + flex: 1 0 50%; + border: 1px solid #ccc; + padding: 32px; + + dl:last-child { + margin: 0; + } + } + } + + @media screen and (width < $extraLargeBreakPoint) { + margin: 24px 20px; + } + + @media screen and (width < 1030px) { + font-size: 14px; + } +} diff --git a/src/pages/Fiber/Channel/index.tsx b/src/pages/Fiber/Channel/index.tsx index 6da23d743..eb6782ff3 100644 --- a/src/pages/Fiber/Channel/index.tsx +++ b/src/pages/Fiber/Channel/index.tsx @@ -1,5 +1,147 @@ +import { useTranslation } from 'react-i18next' +import { useParams } from 'react-router-dom' +import { useQuery } from '@tanstack/react-query' +import { CopyIcon } from '@radix-ui/react-icons' +import BigNumber from 'bignumber.js' +import dayjs from 'dayjs' +import Content from '../../../components/Content' +import { useSetToast } from '../../../components/Toast' +import Loading from '../../../components/Loading' +import { explorerService } from '../../../services/ExplorerService' +import styles from './index.module.scss' +import { shannonToCkb } from '../../../utils/util' +import { localeNumberString } from '../../../utils/number' + +const TIME_TEMPLATE = 'YYYY/MM/DD hh:mm:ss' + const Channel = () => { - return
Channel
+ const [t] = useTranslation() + const { id } = useParams<{ id: string }>() + const setToast = useSetToast() + + const { data, isLoading } = useQuery({ + queryKey: ['fiber', 'channels', id], + queryFn: () => { + return explorerService.api.getFiberChannel(id) + }, + enabled: !!id, + }) + + if (isLoading) { + return + } + + if (!data) { + return
Fiber Peer Not Found
+ } + const channel = data.data + + const handleCopy = (e: React.SyntheticEvent) => { + const elm = e.target + if (!(elm instanceof HTMLElement)) return + const { copyText } = elm.dataset + if (!copyText) return + e.stopPropagation() + e.preventDefault() + navigator?.clipboard.writeText(copyText).then(() => setToast({ message: t('common.copied') })) + } + + const totalBalance = BigNumber(channel.localBalance).plus(BigNumber(channel.remoteBalance)) + const totalTLCBalance = BigNumber(channel.offeredTlcBalance).plus(BigNumber(channel.receivedTlcBalance)) + + return ( + +
+
+
+
{t('fiber.channel.channel_id')}
+
+ {channel.channelId} + +
+
+
+
{t('fiber.channel.state')}
+
{channel.stateName}
+
+ +
+
{t('fiber.channel.balance')}
+
{`${localeNumberString( + shannonToCkb(totalBalance.toFormat({ groupSeparator: '' })), + )} CKB(Total) | ${localeNumberString( + shannonToCkb(totalTLCBalance.toFormat({ groupSeparator: '' })), + )} CKB(TLC)`}
+
+
+
{t('fiber.channel.open_time')}
+
+ +
+
+
+
{t('fiber.channel.update_time')}
+
+ +
+
+ {channel.shutdownAt ? ( +
+
{t('fiber.channel.shutdown_time')}
+
+ +
+
+ ) : null} +
+
+
+
Fiber Peer
+
+ Coming soon(Local) +
+
+ +
+
{t('fiber.channel.balance')}
+
{`${localeNumberString(shannonToCkb(channel.localBalance))} CKB`}
+
+ +
+
{t('fiber.channel.tlc_balance')}
+
{`${localeNumberString(shannonToCkb(channel.offeredTlcBalance))} CKB`}
+
+
+ +
+
+
Fiber Peer
+
+ Coming soon(Remote) +
+
+ +
+
{t('fiber.channel.balance')}
+
{`${localeNumberString(shannonToCkb(channel.remoteBalance))} CKB`}
+
+ +
+
{t('fiber.channel.tlc_balance')}
+
{`${localeNumberString(shannonToCkb(channel.receivedTlcBalance))} CKB`}
+
+
+
+
+
+

Open | Close Transactions

+
Coming soon
+
+
+
+ ) } export default Channel diff --git a/src/pages/Fiber/Peer/index.module.scss b/src/pages/Fiber/Peer/index.module.scss index 457ac40fb..2aae9fdbe 100644 --- a/src/pages/Fiber/Peer/index.module.scss +++ b/src/pages/Fiber/Peer/index.module.scss @@ -70,7 +70,33 @@ } } + .id { + overflow: hidden; + + & > span:first-child { + overflow: hidden; + text-overflow: ellipsis; + flex-shrink: 1; + } + } + + .channels, + .transactions { + margin-top: 16px; + border-top: 1px solid #ccc; + padding-top: 16px; + + h3 { + margin: 0; + padding: 0; + } + } + @media screen and (width < $extraLargeBreakPoint) { margin: 24px 20px; } + + @media screen and (width < 1030px) { + font-size: 14px; + } } diff --git a/src/pages/Fiber/Peer/index.tsx b/src/pages/Fiber/Peer/index.tsx index 5e2db3930..b474c791c 100644 --- a/src/pages/Fiber/Peer/index.tsx +++ b/src/pages/Fiber/Peer/index.tsx @@ -6,10 +6,6 @@ import { Tooltip } from 'antd' import Content from '../../../components/Content' import { explorerService } from '../../../services/ExplorerService' import { useSetToast } from '../../../components/Toast' -// import type { Fiber } from '../../../services/ExplorerService/fetcher' -// import { shannonToCkb } from '../../../utils/util' -// import { localeNumberString } from '../../../utils/number' -// import { parseNumericAbbr } from '../../../utils/chart' import styles from './index.module.scss' import Loading from '../../../components/Loading' @@ -19,7 +15,7 @@ const Peer = () => { const setToast = useSetToast() const { data, isLoading } = useQuery({ - queryKey: ['fiber', 'peer', id], + queryKey: ['fiber', 'peers', id], queryFn: () => { return explorerService.api.getFiberPeerDetail(id) }, @@ -51,8 +47,8 @@ const Peer = () => {
{t('fiber.peer.peer_id')}
-
- {peer.peerId} +
+ {peer.peerId} @@ -85,8 +81,8 @@ const Peer = () => {
-
-
{`${t('fiber.peer.channels')}(${channels.length})`}
+
+

{`${t('fiber.peer.channels')}(${channels.length})`}

@@ -112,6 +108,10 @@ const Peer = () => {
+
+

Open | Close Transactions

+ Coming soon +
) diff --git a/src/pages/Fiber/PeerList/index.module.scss b/src/pages/Fiber/PeerList/index.module.scss index 471327740..8706ec6c5 100644 --- a/src/pages/Fiber/PeerList/index.module.scss +++ b/src/pages/Fiber/PeerList/index.module.scss @@ -77,6 +77,11 @@ } } + .balance { + display: flex; + flex-direction: column; + } + @media screen and (width < $extraLargeBreakPoint) { margin: 24px 20px; } @@ -127,3 +132,25 @@ } } } + +.addFiberPeer { + width: min-content; + margin: 16px auto; + + fieldset { + margin: 8px 0; + } + + input { + width: 250px; + padding: 4px 8px; + } + + button { + padding: 4px 16px; + } + + @media screen and (width < 1030px) { + font-size: 14px; + } +} diff --git a/src/pages/Fiber/PeerList/index.tsx b/src/pages/Fiber/PeerList/index.tsx index 14a93a01a..7131f0717 100644 --- a/src/pages/Fiber/PeerList/index.tsx +++ b/src/pages/Fiber/PeerList/index.tsx @@ -43,9 +43,12 @@ const fields = [ const ckb = shannonToCkb(v) const amount = parseNumericAbbr(ckb) return ( - - {`${amount} CKB`} - +
+ + {`${amount} CKB`} + + Share: coming soon +
) }, }, @@ -71,7 +74,9 @@ const fields = [ return ( - {`${v.slice(0, 8)}...${v.slice(-8)}`} + + {v.length > 16 ? `${v.slice(0, 8)}...${v.slice(-8)}` : v} + + ) } diff --git a/src/services/ExplorerService/fetcher.ts b/src/services/ExplorerService/fetcher.ts index e5c7602e0..4d04a7915 100644 --- a/src/services/ExplorerService/fetcher.ts +++ b/src/services/ExplorerService/fetcher.ts @@ -1222,7 +1222,27 @@ export const apiFetcher = { }, getFiberChannel: (id: string) => { - return requesterV2.get(`/fiber/channels/${id}`).then(res => toCamelcase(res.data)) + return requesterV2 + .get(`/fiber/channels/${id}`) + .then(res => toCamelcase>(res.data)) + }, + + addFiberPeer: (params: { rpc: string; id: string; name?: string }) => { + return requesterV2 + .post(`/fiber/peers`, { + name: params.name, + rpc_listening_addr: params.rpc, + peer_id: params.id, + }) + .catch(e => { + if (Array.isArray(e.response?.data)) { + const res = e.response.data[0] + if (res) { + throw new Error(res.title) + } + } + throw e + }) }, }