Merge pull request #197 from ArtemKolodko/txs_from_rpc

Get transactions and transactions count from RPC, minor refactoring
pull/199/head
Artem 2 years ago committed by GitHub
commit 30b127fbea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 81
      src/pages/AddressPage/tabs/Transactions.tsx
  2. 3
      src/utils/utils.ts

@ -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 }]
}
txs = await getRelatedTransactionsByType([
0,
id,
props.type,
txsFilter,
]);
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([
0,
id,
props.type,
countFilter,
])
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])

@ -1,4 +1,5 @@
import dayjs from "dayjs";
import Big from "big.js";
import { RelatedTransaction, RelatedTransactionType, RPCTransactionHarmony, TransactionExtraMark } from "../types";
import { getAddress } from "./getAddress/GetAddress";
import { bridgeTokensMap } from "src/config";
@ -50,7 +51,7 @@ export const mapBlockchainTxToRelated = (
resultedTx.to = getAddress(tx.to).basicHex
}
if (typeof tx.value !== 'undefined') {
resultedTx.value = BigInt(tx.value).toString()
resultedTx.value = Big(tx.value).toString()
}
return resultedTx
}

Loading…
Cancel
Save