Skip to content

Commit

Permalink
fix: display evm Txhash for address transaction if exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Tien Nam Dao committed Nov 22, 2022
1 parent 4e608dd commit 093fca9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions types/message.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum TransacionTypeEnum {
}

interface MsgCreateValidator {
evmType?: string
type: '/cosmos.staking.v1beta1.MsgCreateValidator'
content: {
height: number
Expand Down Expand Up @@ -40,6 +41,7 @@ interface MsgCreateValidator {
}

interface MsgUnjail {
evmType?: string
type: '/cosmos.slashing.v1beta1.MsgUnjail'
content: {
txHash: string
Expand All @@ -54,11 +56,13 @@ interface MsgUnjail {
}

interface MsgEthereumTx {
evmType?: string
type: '/ethermint.evm.v1.MsgEthereumTx'
content: MsgEthereumTxContent
}

interface MsgBeginRedelegate {
evmType?: string
type: string
content: MsgBeginRedelegateContent
}
Expand Down
5 changes: 1 addition & 4 deletions types/transactions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,7 @@ interface EvmTransactionDetailResponse {
type: number
v: string
value: string
messages?: {
type: TransacionTypeEnum
content: MsgEthereumTxContent
}[]
messages?: MsgEthereumTx[]
}
status: string
}
6 changes: 3 additions & 3 deletions views/accounts/hook/useAddressTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import API_LIST from 'api/api_list'
import { formatEther } from 'ethers/lib/utils'
import { useEffect, useState } from 'react'
import useSWR from 'swr'
import { caculateCosmosTxAmount, caculateEthereumTxAmount } from 'views/transactions/utils'
import { caculateCosmosTxAmount, caculateEthereumTxAmount, getEvmTxhash } from 'views/transactions/utils'

export default function useAddressTransactions(address: string, page: number) {
const [hookData, setState] = useState<UseAddressTransactionData>({
Expand Down Expand Up @@ -35,7 +35,7 @@ export default function useAddressTransactions(address: string, page: number) {
// if (numberOfMsgTypes >= 2) type = `${msgTypeShort} (+${numberOfMsgTypes - 1})`
// else type = msgTypeShort
type = msgTypeShort

const evmHash = getEvmTxhash(d.messages)
return {
value:
(d.value
Expand All @@ -48,7 +48,7 @@ export default function useAddressTransactions(address: string, page: number) {
blockHeight: d.blockHeight,
blockTime: d.blockTime,
fee: d.fee.length > 0 ? d.fee[0]?.amount : 0,
hash: d.hash,
hash: evmHash || d.hash,
messageTypes: d.messageTypes,
messages: d.messages,
success: d.success,
Expand Down
15 changes: 12 additions & 3 deletions views/transactions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ export const evmTransactionDetail = async (evmHash?: string, cosmosHash?: string
if (!result) return
data.evmHash = isUndefined(evmHash)
? result.messages && result.messages.length > 0
? result.messages?.[0].content.params.hash
? getEvmTxhash(result.messages)
: result.hash
: evmHash
data.pageTitle = result.messages ? getTransactionType(result.messages[0]?.type) : ''
// data.pageTitle = result.messages ? getTransactionType(result.messages[0]?.type) : ''
data.cosmosHash = cosmosHash || result.cosmosHash
data.result = result.success ? 'Success' : 'Error'
data.confirmations = result.confirmations ? result.confirmations.toString() : ''
Expand Down Expand Up @@ -199,7 +199,7 @@ export const getAstraTokenAmount = (amounts: TokenAmount[]): string => {
* @param tx messages
* @returns amount in string
*/
export const caculateEthereumTxAmount = (messages: TransactionMessage[]): string => {
export const caculateEthereumTxAmount = (messages: MsgEthereumTx[] | TransactionMessage[]): string => {
if (messages && messages.length > 0) {
let totalAmount = BigNumber.from('0')
for (let message of messages) {
Expand Down Expand Up @@ -246,6 +246,15 @@ export const caculateAmount = (amounts: TokenAmount[]): TokenAmount => {
}
}

/**
* Get Evm TxHash from messages
* @param messages: MsgEthereumTx[]
* @returns
*/
export const getEvmTxhash = (messages: MsgEthereumTx[] | TransactionMessage[]): string | undefined => {
return messages?.[0]?.content?.params?.hash || undefined
}

export const getSignerEthAddress = (signers: Signer[]) => {
const addresses = []
signers.forEach((s: Signer) => {
Expand Down

0 comments on commit 093fca9

Please sign in to comment.