Skip to content

Commit

Permalink
fix: update MsgExec
Browse files Browse the repository at this point in the history
  • Loading branch information
vien.nguyen2-tiki committed Feb 10, 2023
1 parent e7284a4 commit 209ab6e
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 160 deletions.
2 changes: 1 addition & 1 deletion components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Footer } from '@astraprotocol/astra-ui'
import API_LIST from 'api/api_list'
import clsx from 'clsx'
import React, { ReactNode, useEffect } from 'react'
import { setAstraSummary, setValidatorSummary } from 'slices/commonSlice'
import useSWR from 'swr'
import { selectTheme } from '../slices/themeSlice'
import { useAppDispatch, useAppSelector } from '../store/hooks'
import Footer from './Footer'
import styles from './Layout.module.scss'
import Navbar from './Navbar'

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"license": "MIT",
"dependencies": {
"@astradefi/address-converter": "^0.4.1",
"@astraprotocol/astra-ui": "^1.0.32",
"@astraprotocol/astra-ui": "^1.0.33",
"@cosmjs/crypto": "^0.29.0",
"@cosmjs/encoding": "^0.29.0",
"@reduxjs/toolkit": "^1.8.5",
Expand Down
2 changes: 1 addition & 1 deletion pages/tx/[tx].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const TransactionDetailPage: React.FC<Props> = ({ errorMessage, data, evmHash, c
{data.cosmosMsgCount ? (
<span className="flex flex-align-center">
{data.pageTitle}
<PolygonTag text={`+ ${data.cosmosMsgCount.toString()}`} />
<PolygonTag text={`${data.cosmosMsgCount.toString()}`} />
</span>
) : (
data.pageTitle || ''
Expand Down
16 changes: 16 additions & 0 deletions types/message.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,19 @@ interface MsgAcknowledgementContent {
msgIndex: number
name: string
}

interface MsgRevokeContent {
txHash: string
msgName: string
version: number
msgIndex: number
name: string
uuid: string
height: number
params: {
'@type': string
'grantee': string
'granter': string
'msgTypeUrl': string
}
}
4 changes: 2 additions & 2 deletions types/transactions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface TransactionItemModified extends TransactionItem {
to?: string
value?: string
evmHash?: string
typeCount?: number
typeCount?: string
}

interface TransactionSearchResponse {
Expand Down Expand Up @@ -278,7 +278,7 @@ interface CosmosTxMessage {

interface TransactionDetail {
pageTitle?: string
cosmosMsgCount?: number
cosmosMsgCount?: string
evmHash?: string
cosmosHash?: string
result?: string
Expand Down
3 changes: 2 additions & 1 deletion utils/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export enum TransactionTypeEnum {
MsgCreateClient = '/ibc.core.client.v1.MsgCreateClient',
MsgCreateClawbackVestingAccount = '/evmos.vesting.v1.MsgCreateClawbackVestingAccount',
CommunityPoolSpendProposal = '/cosmos.distribution.v1beta1.CommunityPoolSpendProposal',
MsgAcknowledgement = '/ibc.core.channel.v1.MsgAcknowledgement'
MsgAcknowledgement = '/ibc.core.channel.v1.MsgAcknowledgement',
MsgRevoke = '/cosmos.authz.v1beta1.MsgRevoke'
}

export enum AddressTypeEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CONFIG } from 'utils/constants'
import { isEvmTransactionType } from 'utils/evm'
import { convertBalanceToView, ellipseBetweenText, LinkMaker } from 'utils/helper'
import { useTransactionType } from 'views/accounts/hook/useTransactionType'
import { comosTransactionMsgCount } from 'views/transactions/utils'
import styles from './style.module.scss'

interface Props {
Expand Down Expand Up @@ -68,7 +69,7 @@ const AddressTransaction = ({ transaction }: Props) => {
/>
{!isEmpty(transaction.messages) && transaction.messages.length > 1 ? (
<span className="margin-left-2xs contrast-color-70 text-bold">
+{transaction.messages.length - 1}
{comosTransactionMsgCount(transaction.messages)}
</span>
) : null}
</div>
Expand Down
2 changes: 1 addition & 1 deletion views/transactions/TransactionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type TransactionRowProps = {
contractAddress?: string
toName?: string
height?: string
typeCount?: number
typeCount?: string
}

export default function TransactionRow({
Expand Down
4 changes: 2 additions & 2 deletions views/transactions/TransactionRowContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type TransactionRowContentProps = {
toName?: string
height?: string
transactionType?: string
typeCount?: number
typeCount?: string
}

export default function TransactionRowContent({
Expand Down Expand Up @@ -133,7 +133,7 @@ export default function TransactionRowContent({
/>
{typeCount ? (
<Typography.Label
text={`+${typeCount}`}
text={`${typeCount}`}
// backgroundShape="rectangle"
radius="radius-2xl margin-left-2xs"
font="text-bold text text-sm"
Expand Down
35 changes: 24 additions & 11 deletions views/transactions/cosmosMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,38 @@ const _mapMsgBeginRedelegate = (msg: TransactionMessage): CosmosTxMessage => {
const _mapMsgExec = (msg: TransactionMessage, messages: TransactionMessage[]): CosmosTxMessage => {
const content = msg.content as unknown as MsgExecContent
// const msgs =
const msgGrants = messages.filter(msg => msg.type === TransactionTypeEnum.MsgGrant)
let tableTitles = ['TYPE', 'GRANTER', 'GRANTEE', 'GRANT']
let msgsObj = {}
const msgGrants = messages.filter(msg =>
[TransactionTypeEnum.MsgGrant, TransactionTypeEnum.MsgRevoke].includes(msg.type)
)
let tableTitles = ['TYPE', 'GRANTER', 'GRANTEE', 'GRANT', 'MSG TYPE URL']
let tableContent = []
if (!isEmpty(msgGrants)) {
for (let grant of msgGrants) {
const { params } = grant.content as MsgGrantContent
tableContent.push([
params.maybeGenericGrant['@type'],
params.maybeGenericGrant.granter,
params.maybeGenericGrant.grantee,
JSON.stringify(params.maybeGenericGrant.grant)
])
for (let msg of msgGrants) {
if (msg.type === TransactionTypeEnum.MsgGrant) {
tableTitles = ['TYPE', 'GRANTER', 'GRANTEE', 'GRANT']
const { params } = msg.content as MsgGrantContent
tableContent.push([
params.maybeGenericGrant['@type'],
params.maybeGenericGrant.granter,
params.maybeGenericGrant.grantee,
JSON.stringify(params.maybeGenericGrant.grant)
])
}

if (msg.type === TransactionTypeEnum.MsgRevoke) {
tableTitles = ['TYPE', 'GRANTER', 'GRANTEE', 'MSG TYPE URL']
const { params } = msg.content as unknown as MsgRevokeContent
tableContent.push([params['@type'], params.granter, params.grantee, params.msgTypeUrl])
}
}
msgsObj = { msgs: { content: tableContent, titles: tableTitles } }
}
if (msg && content) {
return {
type: msg.type,
grantee: content.params.grantee,
msgs: { content: tableContent, titles: tableTitles }
...msgsObj
}
}
}
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 @@ -5,7 +5,13 @@ import { useCallback, useEffect, useState } from 'react'
import useSWR from 'swr'
import { getTransactionEvmType, getTransactionType } from 'utils/cosmos'
import { isEvmTransactionType } from 'utils/evm'
import { caculateAmount, caculateCosmosTxAmount, caculateEthereumTxAmount, getFromToTxFromCosmosEntry } from '../utils'
import {
caculateAmount,
caculateCosmosTxAmount,
caculateEthereumTxAmount,
comosTransactionMsgCount,
getFromToTxFromCosmosEntry
} from '../utils'

export default function useTransaction() {
const [_items, _setTransactionItem] = useState<TransactionItemModified[]>()
Expand Down Expand Up @@ -36,7 +42,7 @@ export default function useTransaction() {
const totalFee = caculateAmount(item.fee)
const evmType = getTransactionEvmType(item.messages)
const type = getTransactionType(item?.messages[0]?.type)
const typeCount = item?.messages.length > 1 ? item?.messages.length - 1 : 0
const typeCount = comosTransactionMsgCount(item?.messages)
const { from, to, evmHash } = getFromToTxFromCosmosEntry(item.messages[0])

return {
Expand Down
19 changes: 18 additions & 1 deletion views/transactions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const cosmsTransactionDetail = (result: TransactionItem): TransactionDeta
const fee = caculateAmount(result.fee)
data.type = 'cosmos'
data.pageTitle = getTransactionType(result?.messages[0]?.type)
data.cosmosMsgCount = result.messages.length > 1 ? result.messages.length - 1 : 0
data.cosmosMsgCount = comosTransactionMsgCount(result.messages)
data.evmHash = ''
data.cosmosHash = result.hash
data.result = result.success ? 'Success' : 'Error'
Expand Down Expand Up @@ -223,6 +223,23 @@ export const getFromToTxFromCosmosEntry = (message: TransactionMessage) => {

return { evmHash, from, to }
}
/**
* [TransactionTypeEnum.MsgGrant, TransactionTypeEnum.MsgRevoke] are msg of TransactionTypeEnum.MsgExec
* @param messages
* @returns
*/
export const comosTransactionMsgCount = (messages: TransactionMessage[]): string => {
if (!isEmpty(messages) && messages.length > 1) {
let countMsg = [...messages]
if (messages[0].type === TransactionTypeEnum.MsgExec) {
countMsg = countMsg.filter(
msg => ![TransactionTypeEnum.MsgGrant, TransactionTypeEnum.MsgRevoke].includes(msg.type)
)
}
return countMsg.length > 1 ? `+ ${countMsg.length - 1}` : ''
}
return ''
}

const _convertTransfer = (
data: TransactionDetail,
Expand Down
Loading

0 comments on commit 209ab6e

Please sign in to comment.