|
|
|
@ -87,46 +87,28 @@ export function Transactions(props: { |
|
|
|
|
|
|
|
|
|
const { limit = 10, offset = 0 } = filter[props.type]; |
|
|
|
|
|
|
|
|
|
const getTransactionsFromRPC = async (): Promise<RelatedTransaction[]> => { |
|
|
|
|
let txs = [] |
|
|
|
|
if (props.type ==='transaction' || props.type === 'staking_transaction') { |
|
|
|
|
const pageSize = limit |
|
|
|
|
const pageIndex = Math.floor(offset / limit) |
|
|
|
|
const params = [{ address: id, pageIndex, pageSize }] |
|
|
|
|
txs = props.type ==='transaction' |
|
|
|
|
? await hmyv2_getTransactionsHistory(params) |
|
|
|
|
: await hmyv2_getStakingTransactionsHistory(params) |
|
|
|
|
txs = txs.map(tx => mapBlockchainTxToRelated(tx)) |
|
|
|
|
} else { |
|
|
|
|
const txsFilter = {...filter[props.type]} |
|
|
|
|
if (props.type === 'internal_transaction') { |
|
|
|
|
txsFilter.filters = [{ type: "gte", property: "block_number", value: internalTxsBlocksFrom }] |
|
|
|
|
} |
|
|
|
|
txs = await getRelatedTransactionsByType([ |
|
|
|
|
0, |
|
|
|
|
id, |
|
|
|
|
props.type, |
|
|
|
|
txsFilter, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
return txs |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const loadTransactions = async () => { |
|
|
|
|
setIsLoading(true) |
|
|
|
|
try { |
|
|
|
|
// let txs = await getTransactionsFromRPC()
|
|
|
|
|
let txs = [] |
|
|
|
|
const txsFilter = {...filter[props.type]} |
|
|
|
|
if (props.type === 'internal_transaction') { |
|
|
|
|
txsFilter.filters = [{ type: "gte", property: "block_number", value: internalTxsBlocksFrom }] |
|
|
|
|
} |
|
|
|
|
if (props.type === 'transaction') { |
|
|
|
|
const pageSize = limit |
|
|
|
|
const pageIndex = Math.floor(offset / limit) |
|
|
|
|
const params = [{ address: id, pageIndex, pageSize }] |
|
|
|
|
txs = await hmyv2_getTransactionsHistory(params) |
|
|
|
|
txs = txs.map(tx => mapBlockchainTxToRelated(tx)) |
|
|
|
|
} else { |
|
|
|
|
txs = await getRelatedTransactionsByType([ |
|
|
|
|
0, |
|
|
|
|
id, |
|
|
|
|
props.type, |
|
|
|
|
txsFilter, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// for transactions we display call method if any
|
|
|
|
|
if (props.type === "transaction") { |
|
|
|
@ -167,23 +149,6 @@ export function Transactions(props: { |
|
|
|
|
}, [id]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const getTxsCountFromRPC = async () => { |
|
|
|
|
try { |
|
|
|
|
if (props.type ==='transaction' || props.type === 'staking_transaction') { |
|
|
|
|
const count = props.type ==='transaction' |
|
|
|
|
? await hmyv2_getTransactionsCount(id) |
|
|
|
|
: await hmyv2_getStakingTransactionsCount(id) |
|
|
|
|
setTotalElements(count) |
|
|
|
|
setCachedTotalElements({ ...cachedTotalElements, [props.type]: count }) |
|
|
|
|
} else { |
|
|
|
|
setTotalElements(0) |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
console.error('Cannot get txs count', (e as Error).message) |
|
|
|
|
setTotalElements(initTotalElements) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getTxsCount = async () => { |
|
|
|
|
try { |
|
|
|
|
const countFilter = {...filter[props.type]} |
|
|
|
@ -191,12 +156,17 @@ export function Transactions(props: { |
|
|
|
|
if (props.type === 'internal_transaction') { |
|
|
|
|
countFilter.filters = [{ type: "gte", property: "block_number", value: internalTxsBlocksFrom }] |
|
|
|
|
} |
|
|
|
|
const txsCount = await getRelatedTransactionsCountByType([ |
|
|
|
|
let txsCount |
|
|
|
|
if (props.type ==='transaction') { |
|
|
|
|
txsCount = await hmyv2_getTransactionsCount(id) |
|
|
|
|
} else { |
|
|
|
|
txsCount = await getRelatedTransactionsCountByType([ |
|
|
|
|
0, |
|
|
|
|
id, |
|
|
|
|
props.type, |
|
|
|
|
countFilter, |
|
|
|
|
]) |
|
|
|
|
} |
|
|
|
|
setTotalElements(txsCount) |
|
|
|
|
setCachedTotalElements({ |
|
|
|
|
...cachedTotalElements, |
|
|
|
@ -213,7 +183,6 @@ export function Transactions(props: { |
|
|
|
|
if (cachedValue && id === prevId) { |
|
|
|
|
setTotalElements(cachedValue) |
|
|
|
|
} else { |
|
|
|
|
// getTxsCountFromRPC()
|
|
|
|
|
getTxsCount() |
|
|
|
|
} |
|
|
|
|
}, [props.type, id]) |
|
|
|
|