@ -1,17 +1,12 @@
import React , { useEffect , useRef , useState } from "react" ;
import React , { useEffect , useRef , useState } from "react" ;
import { Box } from "grommet" ;
import { Box } from "grommet" ;
import { useParams } from "react-router-dom" ;
import { useParams , useHistory } from "react-router-dom" ;
import {
import {
getByteCodeSignatureByHash ,
getByteCodeSignatureByHash ,
getRelatedTransactionsByType ,
getRelatedTransactionsByType ,
getRelatedTransactionsCountByType
getRelatedTransactionsCountByType
} from "src/api/client" ;
} from "src/api/client" ;
import { TransactionsTable } from "src/components/tables/TransactionsTable" ;
import { TransactionsTable } from "src/components/tables/TransactionsTable" ;
import {
Address ,
ONEValue ,
DateTime , ONEValueWithInternal , TipContent
} from "src/components/ui" ;
import {
import {
Filter ,
Filter ,
RelatedTransaction ,
RelatedTransaction ,
@ -26,8 +21,10 @@ import {
hmyv2_getTransactionsHistory
hmyv2_getTransactionsHistory
} from "../../../api/rpc" ;
} from "../../../api/rpc" ;
import { getColumns , getERC20Columns , getNFTColumns , getStackingColumns } from "./txsColumns" ;
import { getColumns , getERC20Columns , getNFTColumns , getStackingColumns } from "./txsColumns" ;
import useQuery from "../../../hooks/useQuery" ;
const internalTxsBlocksFrom = 23000000
const internalTxsBlocksFrom = 23000000
const allowedLimits = [ 10 , 25 , 50 , 100 ]
const relatedTxMap : Record < RelatedTransactionType , string > = {
const relatedTxMap : Record < RelatedTransactionType , string > = {
transaction : "Transaction" ,
transaction : "Transaction" ,
@ -49,11 +46,18 @@ export function Transactions(props: {
rowDetails ? : ( row : any ) = > JSX . Element ;
rowDetails ? : ( row : any ) = > JSX . Element ;
onTxsLoaded ? : ( txs : RelatedTransaction [ ] ) = > void ;
onTxsLoaded ? : ( txs : RelatedTransaction [ ] ) = > void ;
} ) {
} ) {
const limitValue = localStorage . getItem ( "tableLimitValue" ) ;
const history = useHistory ( )
const queryParams = useQuery ( ) ;
let limitParam = + ( queryParams . get ( 'limit' ) || localStorage . getItem ( "tableLimitValue" ) || allowedLimits [ 0 ] ) ;
const offsetParam = + ( queryParams . get ( 'offset' ) || 0 )
if ( ! allowedLimits . includes ( limitParam ) ) {
limitParam = allowedLimits [ 0 ]
}
const initFilter : Filter = {
const initFilter : Filter = {
offset : 0 ,
offset : offsetParam ,
limit : limitValue ? + limitValue : 10 ,
limit : limitParam ,
orderBy : "block_number" ,
orderBy : "block_number" ,
orderDirection : "desc" ,
orderDirection : "desc" ,
filters : [ { type : "gte" , property : "block_number" , value : 0 } ] ,
filters : [ { type : "gte" , property : "block_number" , value : 0 } ] ,
@ -111,18 +115,18 @@ export function Transactions(props: {
const loadTransactions = async ( ) = > {
const loadTransactions = async ( ) = > {
setIsLoading ( true )
setIsLoading ( true )
try {
try {
let txs = await getTransactionsFromRPC ( )
// let txs = await getTransactionsFromRPC()
// let txs = []
let txs = [ ]
// const txsFilter = {...filter[props.type]}
const txsFilter = { . . . filter [ props . type ] }
// if (props.type === 'internal_transaction') {
if ( props . type === 'internal_transaction' ) {
// txsFilter.filters = [{ type: "gte", property: "block_number", value: internalTxsBlocksFrom }]
txsFilter . filters = [ { type : "gte" , property : "block_number" , value : internalTxsBlocksFrom } ]
// }
}
// txs = await getRelatedTransactionsByType([
txs = await getRelatedTransactionsByType ( [
// 0,
0 ,
// id,
id ,
// props.type,
props . type ,
// txsFilter,
txsFilter ,
// ]);
] ) ;
// for transactions we display call method if any
// for transactions we display call method if any
if ( props . type === "transaction" ) {
if ( props . type === "transaction" ) {
@ -209,17 +213,23 @@ export function Transactions(props: {
if ( cachedValue && id === prevId ) {
if ( cachedValue && id === prevId ) {
setTotalElements ( cachedValue )
setTotalElements ( cachedValue )
} else {
} else {
getTxsCountFromRPC ( )
// getTxsCountFromRPC()
getTxsCount ( )
}
}
} , [ props . type , id ] )
} , [ props . type , id ] )
// Change active tab
useEffect ( ( ) = > {
useEffect ( ( ) = > {
if ( prevType === props . type ) {
// If tab changed (and not initially loaded), drop offset to zero
loadTransactions ( )
if ( prevType ) {
setFilter ( {
. . . initFilterState ,
[ props . type ] : {
. . . initFilter ,
offset : 0
}
} )
}
}
} , [ filter [ props . type ] , id ] ) ;
useEffect ( ( ) = > {
if ( cachedTxs [ props . type ] ) {
if ( cachedTxs [ props . type ] ) {
setRelatedTrxs ( cachedTxs [ props . type ] ) ;
setRelatedTrxs ( cachedTxs [ props . type ] ) ;
} else {
} else {
@ -227,6 +237,13 @@ export function Transactions(props: {
}
}
} , [ props . type ] )
} , [ props . type ] )
// Change params: offset, limit
useEffect ( ( ) = > {
if ( prevType === props . type ) {
loadTransactions ( )
}
} , [ filter [ props . type ] , id ] ) ;
let columns = [ ] ;
let columns = [ ] ;
switch ( props . type ) {
switch ( props . type ) {
@ -250,6 +267,16 @@ export function Transactions(props: {
}
}
}
}
const onFilterChanged = ( value : Filter ) = > {
const { offset , limit } = value
if ( limit !== filter [ props . type ] . limit ) {
localStorage . setItem ( "tableLimitValue" , ` ${ limit } ` ) ;
}
setFilter ( { . . . filter , [ props . type ] : value } ) ;
const activeTab = queryParams . get ( 'activeTab' ) || 0
history . push ( ` ?activeTab= ${ activeTab } &offset= ${ offset } &limit= ${ limit } ` )
}
return (
return (
< Box style = { { padding : "10px" } } >
< Box style = { { padding : "10px" } } >
< TransactionsTable
< TransactionsTable
@ -259,12 +286,7 @@ export function Transactions(props: {
limit = { + limit }
limit = { + limit }
filter = { filter [ props . type ] }
filter = { filter [ props . type ] }
isLoading = { isLoading }
isLoading = { isLoading }
setFilter = { ( value ) = > {
setFilter = { onFilterChanged }
if ( value . limit !== filter [ props . type ] . limit ) {
localStorage . setItem ( "tableLimitValue" , ` ${ value . limit } ` ) ;
}
setFilter ( { . . . filter , [ props . type ] : value } ) ;
} }
noScrollTop
noScrollTop
minWidth = "1266px"
minWidth = "1266px"
hideCounter
hideCounter