Skip to content

Commit

Permalink
fix: update some cosmos msg transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
tiendn committed Dec 8, 2022
1 parent f9cc16e commit 5202b15
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 115 deletions.
2 changes: 1 addition & 1 deletion components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Tabs = ({ tabs, contents, classes, headerBorder = true, headerPadding, def
title={tab.title}
key={tab.id}
padding={tab.padding}
></Tab>
/>
))}
</Row>
<div className={classes || 'margin-top-xl padding-bottom-lg'}>{contents[tabId]}</div>
Expand Down
11 changes: 3 additions & 8 deletions pages/tx/[tx].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@ import Typography from 'components/Typography'
import { pickBy } from 'lodash'
import Head from 'next/head'
import React from 'react'
import { TransacionTypeEnum } from 'utils/enum'
import { TransactionTypeEnum } from 'utils/enum'
import { ellipseBetweenText, LinkMaker } from 'utils/helper'
import DecodeInput from 'views/transactions/DecodeInput'
import useConvertData from 'views/transactions/hook/useConvertData'
import TransactionTabs from 'views/transactions/TransactionTabs'
import {
cosmsTransactionDetail,
evmTransactionDetail,
TransactionDetail,
TransactionQuery
} from 'views/transactions/utils'
import { cosmsTransactionDetail, evmTransactionDetail, TransactionQuery } from 'views/transactions/utils'
import Layout from '../../components/Layout'

type Props = {
Expand Down Expand Up @@ -105,7 +100,7 @@ export async function getServerSideProps({ query }) {
let _data = cosmosDetailRes?.data?.result
if (_data) {
const type = _data?.messages[0]?.type
if (type === TransacionTypeEnum.Ethermint) {
if (type === TransactionTypeEnum.Ethermint) {
evmHash = (_data?.messages[0]?.content as MsgEthereumTxContent)?.params.hash
data = await evmTransactionDetail(evmHash, cosmosHash)
} else {
Expand Down
48 changes: 30 additions & 18 deletions types/message.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
enum TransacionTypeEnum {
enum TransactionTypeEnum {
Ethermint = '/ethermint.evm.v1.MsgEthereumTx',
MsgVote = '/cosmos.gov.v1beta1.MsgVote',
MsgDelegate = '/cosmos.staking.v1beta1.MsgDelegate',
MsgSend = '/cosmos.bank.v1beta1.MsgSend',
MultipleMsgWithdrawDelegatorReward = '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward',
MsgWithdrawDelegatorReward = '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward',
MsgBeginRedelegate = '/cosmos.staking.v1beta1.MsgBeginRedelegate',
MsgExec = '/cosmos.authz.v1beta1.MsgExec',
MsgGrant = '/cosmos.authz.v1beta1.MsgGrant'
MsgGrant = '/cosmos.authz.v1beta1.MsgGrant',
MsgCreateValidator = '/cosmos.staking.v1beta1.MsgCreateValidator',
MsgUnjail = '/cosmos.slashing.v1beta1.MsgUnjail'
}

interface MsgCreateValidator {
Expand All @@ -15,7 +17,7 @@ interface MsgCreateValidator {
content: {
height: number
txHash: string
msgName: TransactionTypeEnum
msgName: TransactionTypeEnum.MsgCreateValidator
msgIndex: number
delegatorAddress: string
validatorAddress: string
Expand Down Expand Up @@ -45,7 +47,7 @@ interface MsgUnjail {
type: '/cosmos.slashing.v1beta1.MsgUnjail'
content: {
txHash: string
msgName: TransactionTypeEnum
msgName: TransactionTypeEnum.MsgUnjail
version: number
msgIndex: number
validatorAddress: string
Expand Down Expand Up @@ -78,13 +80,13 @@ interface MsgEthereumTxContent {
'from': string
'hash': string
'size': number
'@type': TransacionTypeEnum
'@type': TransactionTypeEnum.Ethermint
'data': {
'to': string
'gas': string
'r': string
'v': string
'@type': TransacionTypeEnum
'@type': TransactionTypeEnum.Ethermint
'nonce': string
'value': string
'gasPrice': string
Expand All @@ -93,13 +95,13 @@ interface MsgEthereumTxContent {
}
}
txHash: string
msgName: TransactionTypeEnum
msgName: TransactionTypeEnum.Ethermint
version: number
}

interface MsgBeginRedelegateContent {
height: number
msgName: TransactionTypeEnum
msgName: TransactionTypeEnum.MsgBeginRedelegate
delegatorAddress: string
autoClaimedRewards: TokenAmount
validatorSrcAddress: string
Expand All @@ -115,7 +117,7 @@ interface MsgBeginRedelegateContent {
interface MsgSendContent {
amount: TokenAmount[]
txHash: string
msgName: TransactionTypeEnum
msgName: TransactionTypeEnum.MsgSend
msgIndex: number
toAddress: string
fromAddress: string
Expand All @@ -126,10 +128,18 @@ interface MsgSendContent {
}

interface MsgExecContent {
'@type': string
'amount': TokenAmount
'delegator_address': string
'validator_address': string
uuid: string
height: number
params: {
'@type': TransactionTypeEnum.MsgExec
'grantee': string
'msgs': any[]
}
txHash: string
msgName: TransactionTypeEnum.MsgExec
version: number
msgIndex: number
name: string
}

interface MsgGrantContent {
Expand Down Expand Up @@ -160,7 +170,7 @@ interface MsgGrantContent {
interface MsgVoteContent {
option: string
txHash: string
msgName: TransactionTypeEnum
msgName: TransactionTypeEnum.MsgVote
version: number
proposalId: string
name: string
Expand All @@ -173,7 +183,7 @@ interface MsgVoteContent {
interface MsgDelegateContent {
txHash: string
msgIndex: number
msgName: TransactionTypeEnum
msgName: TransactionTypeEnum.MsgDelegate
version: number
delegatorAddress: string
validatorAddress: string
Expand All @@ -184,10 +194,10 @@ interface MsgDelegateContent {
autoClaimedRewards: TokenAmount
}

interface CosmosMsgWithdrawDelegatorReward {
interface MsgWithdrawDelegatorRewardContent {
amount: TokenAmount[]
height: number
msgName: TransactionTypeEnum
msgName: TransactionTypeEnum.MsgWithdrawDelegatorReward
version: number
msgIndex: number
validatorAddress: string
Expand All @@ -197,3 +207,5 @@ interface CosmosMsgWithdrawDelegatorReward {
delegatorAddress: string
recipientAddress: string
}

interface MsgCreateValidatorContent {}
62 changes: 61 additions & 1 deletion types/transactions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface TokenAmount {
}

interface TransactionMessage {
type: TransacionTypeEnum
type: TransactionTypeEnum
evmType?: string
content:
| MsgCreateValidatorContent
Expand Down Expand Up @@ -195,3 +195,63 @@ interface EvmTransactionDetailResponse {
}
status: string
}

interface TransactionDetail {
pageTitle?: string
evmHash?: string
cosmosHash?: string
result?: string
confirmations?: string
blockHeight?: string
time?: string | number
from?: string | string[] // Multisig or unique address
fromAddressName?: string
to?: string
toAddressName?: string
createdContractAddressHash?: string
createdContractAddressName?: string
value?: string
valueToken?: string
fee?: string
feeToken?: string
gasPrice?: string
type?: 'evm' | 'cosmos'
typeOfTransfer?: string
gasLimit?: string
gasUsed?: string
maxFeePerGas?: string
maxPriorityFeePerGas?: string
priorityFeePerGas?: string
gasUsedByTransaction?: string
nonce?: string
rawInput?: string
tokenTransfers?: TransferItem[]
tabTokenTransfers?: TransactionRowProps[]
index?: number
nonceText?: string
failLog?: string
//msvote
voter?: string
proposalId?: string
option?: string
//msgDelegate
delegatorAddress?: string
validatorAddress?: string
//MsgBeginRedelegate
validatorSrcAddress?: string
validatorDstAddress?: string

revertReason?: string
logs?: EvmLog[]
memo?: string
}

interface TransactionMsgExecDetail extends TransactionDetail {
grantee: string
}

interface TransactionMsgWithdrawDelegatorRewardDetail extends TransactionDetail {
recipientAddress: string
validatorAddress: string
delegatorAddress: string
}
16 changes: 8 additions & 8 deletions utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { astraToEth } from '@astradefi/address-converter'
import { formatEther } from 'ethers/lib/utils'
import { TransactionRowProps } from 'views/transactions/TransactionRow'
import { caculateAmount } from 'views/transactions/utils'
import { TransacionTypeEnum } from './enum'
import { TransactionTypeEnum } from './enum'

/**
* get last word of text with separate is dot
* @param type
* @returns
*/
export const getTransactionType = (type: TransacionTypeEnum) => type?.split('.').slice(-1).join('') || ''
export const getTransactionType = (type: string) => type?.split('.').slice(-1).join('') || ''
export const getTransactionEvmType = (messages: TransactionMessage[]) =>
messages.length > 0 ? messages[0].evmType : ''

Expand All @@ -19,15 +19,15 @@ export const convertMessageToTransfer = (
status: boolean
): TransactionRowProps[] => {
const rows: TransactionRowProps[] = []
const type: TransacionTypeEnum = messages[0]?.type
const type: string = messages[0]?.type
for (let message of messages) {
const content = message.content
if (type === TransacionTypeEnum.MsgSend) {
if (type === TransactionTypeEnum.MsgSend) {
rows.push(_parseCosmosMsgSend(content as MsgSendContent, blockTime, status))
} else if (type === TransacionTypeEnum.MsgBeginRedelegate) {
} else if (type === TransacionTypeEnum.MsgDelegate) {
} else if (type === TransacionTypeEnum.MsgVote) {
} else if (type === TransacionTypeEnum.MultipleMsgWithdrawDelegatorReward) {
} else if (type === TransactionTypeEnum.MsgBeginRedelegate) {
} else if (type === TransactionTypeEnum.MsgDelegate) {
} else if (type === TransactionTypeEnum.MsgVote) {
} else if (type === TransactionTypeEnum.MsgWithdrawDelegatorReward) {
}
}
return rows
Expand Down
6 changes: 4 additions & 2 deletions utils/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export enum Icon {
Wallet = 'wallet'
}

export enum TransacionTypeEnum {
export enum TransactionTypeEnum {
Ethermint = '/ethermint.evm.v1.MsgEthereumTx',
MsgVote = '/cosmos.gov.v1beta1.MsgVote',
MsgDelegate = '/cosmos.staking.v1beta1.MsgDelegate',
MsgSend = '/cosmos.bank.v1beta1.MsgSend',
MultipleMsgWithdrawDelegatorReward = '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward',
MsgWithdrawDelegatorReward = '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward',
MsgBeginRedelegate = '/cosmos.staking.v1beta1.MsgBeginRedelegate',
MsgExec = '/cosmos.authz.v1beta1.MsgExec',
MsgGrant = '/cosmos.authz.v1beta1.MsgGrant'
Expand Down Expand Up @@ -49,8 +49,10 @@ export enum CardInfoLabels {
option = 'Option:',
delegatorAddress = 'Delegator Address:',
validatorAddress = 'Validator Address:',
recipientAddress = 'Recipient Address:',
validatorSrcAddress = 'Validator Src Address:',
validatorDstAddress = 'Validator Dst Address:',
grantee = 'Grantee',
failLog = 'Fail reason:',
// Revert_Reason =
revertReason = 'Revert reason:',
Expand Down
4 changes: 2 additions & 2 deletions utils/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { formatUnits } from 'ethers/lib/utils'
import { isEmpty } from 'lodash'
import { TransactionRowProps } from 'views/transactions/TransactionRow'
import { ZERO_ADDRESS } from './constants'
import { TransacionTypeEnum } from './enum'
import { TransactionTypeEnum } from './enum'
import { isERC721 } from './helper'

export const evmTransactionType = (type: number): string => {
Expand Down Expand Up @@ -108,7 +108,7 @@ export const evmAddressName = (addressName: string, addresValue: string) => {
}

export const getFromToEvmTxFromCosmosEntry = (message: TransactionMessage) => {
if (isEmpty(message) || message?.type !== TransacionTypeEnum.Ethermint) {
if (isEmpty(message) || message?.type !== TransactionTypeEnum.Ethermint) {
return { evmHash: '', from: '', to: '' }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const AddressTransaction = ({ transaction }: Props) => {
</div>
<div className={clsx('col-2 block-ver-center')}>
<Typography.Label
text={transaction.type}
text={ellipseBetweenText(transaction.type)}
// titleText={type}
backgroundShape="rectangle"
radius="radius-2xl"
Expand Down
4 changes: 2 additions & 2 deletions views/block/hook/useBlockById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import usePagination from 'hooks/usePagination'
import { isEmpty } from 'lodash'
import { useEffect, useState } from 'react'
import useSWRImmutable from 'swr/immutable'
import { TransacionTypeEnum } from 'utils/enum'
import { TransactionTypeEnum } from 'utils/enum'
import { caculateAmount, getEvmTxhash } from 'views/transactions/utils'

export default function useBlockById(blockHeight: string) {
Expand All @@ -25,7 +25,7 @@ export default function useBlockById(blockHeight: string) {
return result.map(item => ({
...item,
totalFee: caculateAmount(item.fee),
hash: item?.messages[0]?.type === TransacionTypeEnum.Ethermint ? getEvmTxhash(item?.messages) : item.hash
hash: item?.messages[0]?.type === TransactionTypeEnum.Ethermint ? getEvmTxhash(item?.messages) : item.hash
}))
}

Expand Down
2 changes: 1 addition & 1 deletion views/block/tabs/BlockTransactionTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const BlockTransactionTab = ({ blockHeight }: Props) => {
to={''}
value={undefined}
valueToken={process.env.NEXT_PUBLIC_NATIVE_TOKEN as CryptoIconNames}
type={getTransactionType(transaction?.messages[0]?.type as TransacionTypeEnum)}
type={getTransactionType(transaction?.messages[0]?.type as TransactionTypeEnum)}
newBlock={false}
style="normal"
/>
Expand Down
6 changes: 3 additions & 3 deletions views/transactions/TransactionBriefRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Timer from 'components/Timer'
import Typography from 'components/Typography'
import Tag from 'components/Typography/Tag'
import Image from 'next/image'
import { TransacionTypeEnum } from 'utils/enum'
import { TransactionTypeEnum } from 'utils/enum'
import { ellipseBetweenText, LinkMaker } from 'utils/helper'
import styles from './style.module.scss'

Expand All @@ -21,7 +21,7 @@ type TransactionBriefRowProps = {
newTransaction?: boolean
border?: boolean
evmType: string
transactionType: TransacionTypeEnum
transactionType: string
}

export default function TransactionBriefRow({
Expand All @@ -35,7 +35,7 @@ export default function TransactionBriefRow({
evmType,
transactionType
}: TransactionBriefRowProps) {
const isEvm = transactionType === TransacionTypeEnum.Ethermint
const isEvm = transactionType === TransactionTypeEnum.Ethermint
const transactionQuery = isEvm ? { type: 'evm' } : null
return (
<RowShowAnimation action={newTransaction}>
Expand Down
Loading

0 comments on commit 5202b15

Please sign in to comment.