Skip to content

Commit

Permalink
fix: calculate tx value in tx list
Browse files Browse the repository at this point in the history
  • Loading branch information
Tien Nam Dao committed Nov 8, 2022
1 parent 3dfdecb commit 6e63d16
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 2 additions & 3 deletions pages/tx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { isEmpty } from 'lodash'
import { NextPage } from 'next'
import Head from 'next/head'
import React, { useEffect, useState } from 'react'
import { getTransactionType } from 'utils/cosmos'
import useTransaction from 'views/transactions/hook/useTransaction'
import TransactionRow from 'views/transactions/TransactionRow'
import Layout from '../../components/Layout'
Expand Down Expand Up @@ -81,10 +80,10 @@ const BlockDetailPage: React.FC<NextPage> = _ => {
hash={item.evmHash || item.hash}
from={item.from}
to={item.to}
value={undefined}
value={item.value}
valueToken={process.env.NEXT_PUBLIC_EVM_TOKEN as CryptoIconNames}
labelStatus={item.evmType}
type={getTransactionType(item?.messages[0]?.type)}
type={item.type}
newBlock={item.newTransaction}
height="auto"
/>
Expand Down
2 changes: 2 additions & 0 deletions types/transactions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ interface TransactionItem {
timeoutHeight: number
messages: TransactionMessage[]
signers: Signer[]
type?: string
}

interface TransactionItemModified extends TransactionItem {
totalFee: TokenAmount
evmType: string
from?: string
to?: string
value?: string
evmHash?: string
}

Expand Down
10 changes: 8 additions & 2 deletions views/transactions/hook/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import usePagination from 'hooks/usePagination'
import { differenceWith, isEmpty } from 'lodash'
import { useCallback, useEffect, useState } from 'react'
import useSWR from 'swr'
import { getTransactionEvmType } from 'utils/cosmos'
import { getTransactionEvmType, getTransactionType } from 'utils/cosmos'
import { getFromToEvmTxFromCosmosEntry } from 'utils/evm'
import { caculateAmount } from '../utils'
import { caculateAmount, caculateCosmosTxAmount, caculateEthereumTxAmount } from '../utils'

export default function useTransaction() {
const [_items, _setTransactionItem] = useState<TransactionItemModified[]>()
Expand Down Expand Up @@ -35,10 +35,16 @@ export default function useTransaction() {
return transactionResult.map((item: TransactionItem) => {
const totalFee = caculateAmount(item.fee)
const evmType = getTransactionEvmType(item.messages)
const type = getTransactionType(item?.messages[0]?.type)
const { from, to, evmHash } = getFromToEvmTxFromCosmosEntry(item.messages[0])
return {
...item,
value:
(type === 'MsgEthereumTx'
? caculateEthereumTxAmount(item.messages)
: caculateCosmosTxAmount(item.messages)) || '0',
totalFee,
type,
evmType,
from,
to,
Expand Down

0 comments on commit 6e63d16

Please sign in to comment.