|
|
|
@ -29,6 +29,29 @@ const extractError = (err: any) => { |
|
|
|
|
return errorMessage || err; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const getTxInputSignature = async (trx: RPCTransactionHarmony) => { |
|
|
|
|
let signature |
|
|
|
|
try { |
|
|
|
|
const signatures = await getByteCodeSignatureByHash([trx.input.slice(0, 10)]) |
|
|
|
|
if(signatures && signatures.length > 0) { |
|
|
|
|
signature = signatures[0] |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
console.error('Cannot get tx input signature: ', (e as Error).message) |
|
|
|
|
} |
|
|
|
|
return signature |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getTransactionErrorMessage = (txHash: string, tx: RPCTransactionHarmony) => { |
|
|
|
|
if(txHash.length !== 66) { |
|
|
|
|
return 'Invalid Txn hash' |
|
|
|
|
} |
|
|
|
|
if(!tx || !tx.hash) { |
|
|
|
|
return 'Unable to locate this TxnHash' |
|
|
|
|
} |
|
|
|
|
return '' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const TransactionPage = () => { |
|
|
|
|
const history = useHistory(); |
|
|
|
|
const { id } = useParams<{id: string}>(); |
|
|
|
@ -40,27 +63,13 @@ export const TransactionPage = () => { |
|
|
|
|
const [txReceipt, setTxReceipt] = useState<TxReceipt>(); |
|
|
|
|
const [trxs, setTrxs] = useState<InternalTransaction[]>([]); |
|
|
|
|
const [logs, setLogs] = useState<any[]>([]); |
|
|
|
|
const [isLoading, setIsLoading] = useState<boolean>(false); |
|
|
|
|
const [txrsLoading, setTxrsLoading] = useState<boolean>(true); |
|
|
|
|
const [isLoading, setIsLoading] = useState(false); |
|
|
|
|
const [activeIndex, setActiveIndex] = useState(+activeTab); |
|
|
|
|
const [inputSignature, setInputSignature] = useState<IHexSignature>() |
|
|
|
|
|
|
|
|
|
const { availableShards } = config |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const getTxInputSignature = async (trx: RPCTransactionHarmony) => { |
|
|
|
|
let signature |
|
|
|
|
try { |
|
|
|
|
const signatures = await getByteCodeSignatureByHash([trx.input.slice(0, 10)]) |
|
|
|
|
if(signatures && signatures.length > 0) { |
|
|
|
|
signature = signatures[0] |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
console.error('Cannot get tx input signature: ', (e as Error).message) |
|
|
|
|
} |
|
|
|
|
return signature |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getTx = async () => { |
|
|
|
|
let trx; |
|
|
|
|
let trxInputSignature; |
|
|
|
@ -98,17 +107,14 @@ export const TransactionPage = () => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setTx((trx || {}) as RPCTransactionHarmony); |
|
|
|
|
const txData = trx || {} |
|
|
|
|
setTx(txData as RPCTransactionHarmony); |
|
|
|
|
setInputSignature(trxInputSignature) |
|
|
|
|
return txData |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
getTx(); |
|
|
|
|
}, [id]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const getInternalTxs = async () => { |
|
|
|
|
if (tx.hash && tx.shardID === 0) { |
|
|
|
|
try { |
|
|
|
|
//@ts-ignore
|
|
|
|
|
const txs = await getInternalTransactionsByField([ |
|
|
|
|
0, |
|
|
|
@ -132,34 +138,14 @@ export const TransactionPage = () => { |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
setTrxs(txsWithSignatures as InternalTransaction[]); |
|
|
|
|
setTxrsLoading(false); |
|
|
|
|
} catch (err) { |
|
|
|
|
console.log(err); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
setTrxs([]); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
getInternalTxs(); |
|
|
|
|
}, [tx.hash]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const getLogs = async () => { |
|
|
|
|
//
|
|
|
|
|
const contractShardID = process.env.REACT_APP_CONTRACT_SHARD ? (process.env.REACT_APP_CONTRACT_SHARD || 0) : 0 |
|
|
|
|
if (tx.hash && [0, contractShardID].includes(tx.shardID)) { |
|
|
|
|
|
|
|
|
|
// const SevenDaysBlock = 60 * 60 * 24 * 7 / 2
|
|
|
|
|
// const txDate = new Date(tx.timestamp).getTime()
|
|
|
|
|
// const now = Date.now()
|
|
|
|
|
//
|
|
|
|
|
// if (now - txDate > SevenDaysBlock) {
|
|
|
|
|
// console.log('no logs served')
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
//@ts-ignore
|
|
|
|
|
const logs: any[] = await getTransactionLogsByField([ |
|
|
|
|
0, |
|
|
|
@ -177,17 +163,31 @@ export const TransactionPage = () => { |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
setLogs(logsWithSignatures as any); |
|
|
|
|
setIsLoading(false); |
|
|
|
|
} catch (err) { |
|
|
|
|
console.log(err); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
setLogs([]); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
getLogs(); |
|
|
|
|
}, [tx]); |
|
|
|
|
const loadTxData = async () => { |
|
|
|
|
let tx = {} |
|
|
|
|
try { |
|
|
|
|
setIsLoading(true) |
|
|
|
|
tx = await getTx() |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log('Cannot load tx data:', e) |
|
|
|
|
} finally { |
|
|
|
|
setIsLoading(false) |
|
|
|
|
} |
|
|
|
|
if(tx) { |
|
|
|
|
try { |
|
|
|
|
await Promise.allSettled([getLogs(), getInternalTxs()]) |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log('Cannot load transaction logs:', e) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
loadTxData() |
|
|
|
|
}, [tx.hash]); |
|
|
|
|
|
|
|
|
|
if (isLoading) { |
|
|
|
|
return ( |
|
|
|
@ -197,15 +197,14 @@ export const TransactionPage = () => { |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const internalErrorMsg = txrsLoading |
|
|
|
|
? undefined |
|
|
|
|
: trxs.length |
|
|
|
|
? trxs |
|
|
|
|
const txErrorMsg = isLoading ? '' : getTransactionErrorMessage(id, tx) |
|
|
|
|
|
|
|
|
|
const internalErrorMsg = trxs |
|
|
|
|
.map((t) => t.error) |
|
|
|
|
.filter((_) => _) |
|
|
|
|
.map(extractError) |
|
|
|
|
.join(",") |
|
|
|
|
: "" |
|
|
|
|
|
|
|
|
|
const txReceiptErrorMsg = txReceipt && txReceipt.status === 0 |
|
|
|
|
? 'Failed (from receipt)' |
|
|
|
|
: '' |
|
|
|
@ -235,7 +234,8 @@ export const TransactionPage = () => { |
|
|
|
|
logs={logs} |
|
|
|
|
internalTxs={trxs} |
|
|
|
|
inputSignature={inputSignature} |
|
|
|
|
errorMsg={internalErrorMsg || txReceiptErrorMsg} |
|
|
|
|
errorMsg={txErrorMsg || internalErrorMsg || txReceiptErrorMsg} |
|
|
|
|
hideShowMore={isLoading || Boolean(txErrorMsg)} |
|
|
|
|
/> |
|
|
|
|
</Tab> |
|
|
|
|
{trxs.length ? ( |
|
|
|
|