1- import { useMemo , useState } from 'react'
1+ import { useMemo } from 'react'
22import { useTranslation } from 'react-i18next'
33
44import { Alert } from '@app/components/ui'
55import { COPY_BUTTON_TYPES , CopyTextButton } from '@app/components/ui/buttons'
66import { useGetAddressName } from '@app/hooks'
77import { useGetSmartContractsQuery } from '@app/store/apis/qubic-static'
88import type { QueryServiceTransaction } from '@app/store/apis/query-service'
9- import { clsxTwMerge , formatDate , formatHex , formatString } from '@app/utils'
9+ import { clsxTwMerge , formatDate , formatString } from '@app/utils'
1010import { getProcedureName } from '@app/utils/qubic'
11- import { type AssetTransfer , type Transfer , isSmartContractTx } from '@app/utils/qubic-ts'
11+ import { type AssetTransfer , type Transfer } from '@app/utils/qubic-ts'
1212import AddressLink from '../AddressLink'
1313import SubCardItem from '../SubCardItem'
1414import TickLink from '../TickLink'
1515import TxLink from '../TxLink'
16+ import DecodedDataSection from './DecodedDataSection'
17+ import InputDataSection from './InputDataSection'
1618import TransferList from './TransferList/TransferList'
1719import type { TxItemVariant } from './TxItem.types'
20+ import { useDecodedContractInput } from './useDecodedContractInput'
1821
1922type Props = {
2023 readonly txDetails : Omit < QueryServiceTransaction , 'inputSize' | 'moneyFlew' | 'timestamp' >
@@ -51,11 +54,9 @@ export default function TransactionDetails({
5154} : Props ) {
5255 const { t } = useTranslation ( 'network-page' )
5356 const { data : smartContracts } = useGetSmartContractsQuery ( )
54- const [ inputDataFormat , setInputDataFormat ] = useState < 'base64' | 'hex' > ( 'hex' )
5557
5658 const isSecondaryVariant = variant === 'secondary'
5759 const { date, time } = useMemo ( ( ) => formatDate ( timestamp , { split : true } ) , [ timestamp ] )
58- const inputDataHex = useMemo ( ( ) => formatHex ( inputData ) , [ inputData ] )
5960
6061 const destAddress = assetDetails ?. newOwnerAndPossessor ?? destination
6162 const sourceAddressNameData = useGetAddressName ( source )
@@ -65,14 +66,20 @@ export default function TransactionDetails({
6566 ( ) => getProcedureName ( destination , inputType , smartContracts ) ,
6667 [ destination , inputType , smartContracts ]
6768 )
69+ const { isContractTransaction, shouldDecodeInput, decodedInput } = useDecodedContractInput ( {
70+ showExtendedDetails,
71+ destination,
72+ inputType,
73+ inputData
74+ } )
6875
6976 const transactionTypeDisplay = useMemo ( ( ) => {
7077 const baseType = formatString ( inputType )
71- const txCategory = isSmartContractTx ( destination , inputType ) ? 'SC' : 'Standard'
78+ const txCategory = isContractTransaction ? 'SC' : 'Standard'
7279 return procedureName
7380 ? `${ baseType } ${ txCategory } (${ procedureName } )`
7481 : `${ baseType } ${ txCategory } `
75- } , [ inputType , destination , procedureName ] )
82+ } , [ inputType , isContractTransaction , procedureName ] )
7683
7784 return (
7885 < TransactionDetailsWrapper variant = { variant } >
@@ -184,37 +191,17 @@ export default function TransactionDetails({
184191 />
185192 ) }
186193
187- { showExtendedDetails && inputData && inputData . length > 0 && (
188- < SubCardItem
189- title = { t ( 'data' ) }
190- variant = { variant }
191- content = {
192- < div className = "min-w-0 flex-1" >
193- < p className = "break-all rounded-8 bg-primary-60 p-12 font-space text-sm text-gray-50" >
194- < span className = "float-right mb-4 ml-8 inline-flex overflow-hidden rounded-8 border border-gray-50 bg-primary-80" >
195- { ( [ 'hex' , 'base64' ] as const ) . map ( ( format , index ) => (
196- < button
197- key = { format }
198- type = "button"
199- onClick = { ( ) => setInputDataFormat ( format ) }
200- className = { clsxTwMerge (
201- 'px-8 py-2 text-xs font-medium transition-colors' ,
202- index > 0 && 'border-l border-gray-50' ,
203- inputDataFormat === format
204- ? 'bg-primary-60 text-white'
205- : 'bg-transparent text-gray-50 hover:bg-primary-70 hover:text-white'
206- ) }
207- >
208- { format === 'hex' ? 'Hex' : 'Base64' }
209- </ button >
210- ) ) }
211- </ span >
212- { inputDataFormat === 'hex' ? `0x${ inputDataHex } ` : inputData }
213- </ p >
214- </ div >
215- }
216- />
217- ) }
194+ < DecodedDataSection
195+ variant = { variant }
196+ shouldDecodeInput = { shouldDecodeInput }
197+ decodedInput = { decodedInput }
198+ />
199+
200+ < InputDataSection
201+ variant = { variant }
202+ showExtendedDetails = { showExtendedDetails }
203+ inputData = { inputData }
204+ />
218205
219206 < TransferList entries = { entries } variant = { variant } />
220207 </ TransactionDetailsWrapper >
0 commit comments