forked from nervosnetwork/ckb-explorer-frontend
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: address page support
node-connect
mode (#391)
- Loading branch information
1 parent
efd7b32
commit 65b5020
Showing
17 changed files
with
718 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/components/TransactionItem/TransactionItemCell/NodeCellCapacityAmount.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { Cell } from '@ckb-lumos/base' | ||
import { useTranslation } from 'react-i18next' | ||
import { useQuery } from '@tanstack/react-query' | ||
import { parseUDTAmount } from '../../../utils/number' | ||
import { shannonToCkb } from '../../../utils/util' | ||
import { explorerService } from '../../../services/ExplorerService' | ||
import { UDT_CELL_TYPES, getCellType, calculateScriptHash, getUDTAmountByData } from '../../../utils/cell' | ||
import Capacity from '../../Capacity' | ||
|
||
export const NodeCellCapacityAmount = ({ cell }: { cell: Cell }) => { | ||
const { t } = useTranslation() | ||
const cellType = getCellType(cell) | ||
const isUDTCell = UDT_CELL_TYPES.findIndex(type => type === cellType) !== -1 | ||
const udtTypeHash = isUDTCell ? calculateScriptHash(cell.cellOutput.type!) : undefined | ||
const udtInfo = useQuery( | ||
['udt', udtTypeHash], | ||
() => { | ||
if (!udtTypeHash) return undefined | ||
return explorerService.api.fetchSimpleUDT(udtTypeHash) | ||
}, | ||
{ | ||
enabled: isUDTCell, | ||
staleTime: Infinity, | ||
}, | ||
) | ||
|
||
if (isUDTCell && udtTypeHash && udtInfo.data) { | ||
const amount = getUDTAmountByData(cell.data) | ||
if (cellType === 'udt' && udtInfo.data.published) { | ||
return <span>{`${parseUDTAmount(amount, udtInfo.data.decimal)} ${udtInfo.data.symbol}`}</span> | ||
} | ||
|
||
if (cellType === 'xudt' && udtInfo.data.decimal && udtInfo.data.symbol) { | ||
return <span>{`${parseUDTAmount(amount, udtInfo.data.decimal)} ${udtInfo.data.symbol}`}</span> | ||
} | ||
|
||
return <span>{`${t('udt.unknown_token')} #${udtTypeHash.substring(udtTypeHash.length - 4)}`}</span> | ||
} | ||
|
||
if (isUDTCell && udtTypeHash) { | ||
return <span>{`${t('udt.unknown_token')} #${udtTypeHash.substring(udtTypeHash.length - 4)}`}</span> | ||
} | ||
|
||
return <Capacity capacity={shannonToCkb(cell.cellOutput.capacity)} layout="responsive" /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { RPC } from '@ckb-lumos/rpc' | ||
import { Hash, Transaction } from '@ckb-lumos/base' | ||
import { useInfiniteQuery } from '@tanstack/react-query' | ||
import { useCKBNode } from './useCKBNode' | ||
|
||
export const useTransactions = ({ | ||
searchKey, | ||
pageSize = 100, | ||
order = 'desc', | ||
}: { | ||
searchKey: Parameters<RPC['getTransactions']>['0'] | ||
pageSize?: number | ||
order?: 'desc' | 'asc' | ||
}) => { | ||
const { nodeService } = useCKBNode() | ||
|
||
return useInfiniteQuery({ | ||
queryKey: ['node', 'transactions', searchKey, pageSize, order], | ||
queryFn: async ({ pageParam = undefined }) => { | ||
const { lastCursor, objects } = await nodeService.rpc.getTransactions( | ||
{ ...searchKey, groupByTransaction: true }, | ||
order, | ||
`0x${pageSize.toString(16)}`, | ||
pageParam, | ||
) | ||
|
||
if (objects.length === 0) { | ||
return { | ||
lastCursor: undefined, | ||
txs: [], | ||
} | ||
} | ||
|
||
const txHashes = objects.map(tx => tx.txHash) | ||
|
||
const txs = await nodeService.rpc | ||
.createBatchRequest<'getTransaction', [Hash], CKBComponents.TransactionWithStatus[]>( | ||
txHashes.map(txHash => ['getTransaction', txHash]), | ||
) | ||
.exec() | ||
|
||
return { | ||
lastCursor, | ||
txs: txs.map(tx => ({ | ||
transaction: tx.transaction as Transaction, | ||
txStatus: tx.txStatus, | ||
})), | ||
} | ||
}, | ||
getNextPageParam: options => { | ||
if (options.txs.length < pageSize) return undefined | ||
return options.lastCursor | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.