From b32833f702ba56e572f9f0999b516049ac113c95 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Wed, 18 Dec 2024 16:24:58 +0800 Subject: [PATCH] feat: cell_deps api (#428) --- src/components/TransactionParameters/index.tsx | 13 ++++++------- src/models/Transaction/index.ts | 3 +++ src/pages/Transaction/state.ts | 3 +++ src/utils/transformer.ts | 3 +++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/components/TransactionParameters/index.tsx b/src/components/TransactionParameters/index.tsx index dbe6ce379..3238cfd3c 100644 --- a/src/components/TransactionParameters/index.tsx +++ b/src/components/TransactionParameters/index.tsx @@ -3,7 +3,7 @@ import { FC, ReactNode } from 'react' import { Trans, useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' import classNames from 'classnames' -import { useCKBNode } from '../../hooks/useCKBNode' +import { explorerService } from '../../services/ExplorerService' import { matchTxHash } from '../../utils/util' import Loading from '../AwesomeLoadings/Spinner' import HashTag from '../HashTag' @@ -48,9 +48,8 @@ const Field = ({ const TransactionParameters: FC<{ hash: string }> = ({ hash }) => { const [t] = useTranslation() - const { nodeService } = useCKBNode() - const { data, isLoading } = useQuery(['tx', hash], () => nodeService.getTx(hash)) + const { data, isLoading } = useQuery(['explorer-tx', hash], () => explorerService.api.fetchTransactionByHash(hash)) if (isLoading) { return (
@@ -59,9 +58,9 @@ const TransactionParameters: FC<{ hash: string }> = ({ hash }) => { ) } - if (!data?.result?.transaction) return
{`Transaction ${hash} not loaded`}
+ if (!data) return
{`Transaction ${hash} not loaded`}
- const { header_deps: headerDeps, cell_deps: cellDeps, witnesses } = data.result.transaction + const { headerDeps, cellDeps, witnesses } = data const parameters = [ { @@ -84,8 +83,8 @@ const TransactionParameters: FC<{ hash: string }> = ({ hash }) => { content: cellDeps.length ? ( cellDeps.map(cellDep => { const { - out_point: { tx_hash: txHash, index }, - dep_type: depType, + outPoint: { txHash, index }, + depType, } = cellDep const hashTag = matchTxHash(txHash, Number(index)) return ( diff --git a/src/models/Transaction/index.ts b/src/models/Transaction/index.ts index 75403c826..c40985eb6 100644 --- a/src/models/Transaction/index.ts +++ b/src/models/Transaction/index.ts @@ -35,6 +35,9 @@ export interface Transaction { maxCyclesInEpoch: number | null maxCycles: number | null createTimestamp?: number + cellDeps: CellDep[] + headerDeps: string[] + witnesses: string[] } export interface BtcTx { diff --git a/src/pages/Transaction/state.ts b/src/pages/Transaction/state.ts index 7e37461c2..384a2c8d7 100644 --- a/src/pages/Transaction/state.ts +++ b/src/pages/Transaction/state.ts @@ -26,6 +26,9 @@ export const defaultTransactionInfo: Transaction = { cycles: null, maxCyclesInEpoch: null, maxCycles: null, + cellDeps: [], + headerDeps: [], + witnesses: [], } export const defaultTransactionLiteDetails: TransactionRecord[] = [ diff --git a/src/utils/transformer.ts b/src/utils/transformer.ts index 81c91492e..1b1c3f105 100644 --- a/src/utils/transformer.ts +++ b/src/utils/transformer.ts @@ -35,6 +35,9 @@ export const transformToTransaction = ( cycles: null, maxCyclesInEpoch: null, maxCycles: null, + cellDeps: [], + headerDeps: [], + witnesses: [], } }