From 6e63d164bb8c3d2b59609276044cb83c6f58b341 Mon Sep 17 00:00:00 2001 From: Tien Nam Dao Date: Tue, 8 Nov 2022 13:38:27 +0700 Subject: [PATCH] fix: calculate tx value in tx list --- pages/tx/index.tsx | 5 ++--- types/transactions.d.ts | 2 ++ views/transactions/hook/useTransaction.ts | 10 ++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pages/tx/index.tsx b/pages/tx/index.tsx index cd5ae4b8..7e928a19 100644 --- a/pages/tx/index.tsx +++ b/pages/tx/index.tsx @@ -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' @@ -81,10 +80,10 @@ const BlockDetailPage: React.FC = _ => { 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" /> diff --git a/types/transactions.d.ts b/types/transactions.d.ts index 252ec54f..b90f5d82 100644 --- a/types/transactions.d.ts +++ b/types/transactions.d.ts @@ -43,6 +43,7 @@ interface TransactionItem { timeoutHeight: number messages: TransactionMessage[] signers: Signer[] + type?: string } interface TransactionItemModified extends TransactionItem { @@ -50,6 +51,7 @@ interface TransactionItemModified extends TransactionItem { evmType: string from?: string to?: string + value?: string evmHash?: string } diff --git a/views/transactions/hook/useTransaction.ts b/views/transactions/hook/useTransaction.ts index f4d3d7bb..0a32b8b4 100644 --- a/views/transactions/hook/useTransaction.ts +++ b/views/transactions/hook/useTransaction.ts @@ -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() @@ -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,