Skip to content

Commit

Permalink
feat: add MsgEditValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
vien.nguyen2-tiki committed Feb 2, 2023
1 parent 64399c7 commit a1b01d4
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 70 deletions.
8 changes: 5 additions & 3 deletions components/Card/CardInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export default function CardInfo({
})}
>
<div
className={clsx(styles.leftColumn, 'col-2 gutter-right padding-bottom-sm block-ver-center')}
className={clsx(styles.leftColumn, 'col-2 gutter-right block-ver-center', {
'padding-bottom-sm': items.length > 1
})}
>
<Typography.CardLabel>{label}</Typography.CardLabel>
{type === 'nonce' && <Tag text={'Position'} />}
Expand All @@ -120,8 +122,8 @@ export default function CardInfo({
className={clsx(
styles.rightColumn,
'col-10',
'block-ver-center margin-right-sm padding-bottom-sm',
'border border-bottom-base',
'block-ver-center margin-right-sm',
{ 'padding-bottom-sm border border-bottom-base': items.length > 1 },
{ [`${responsive?.wrap}-full`]: responsive?.wrap }
)}
>
Expand Down
3 changes: 2 additions & 1 deletion utils/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export enum TransactionTypeEnum {
MsgUnjail = '/cosmos.slashing.v1beta1.MsgUnjail',
TextProposal = '/cosmos.gov.v1beta1.TextProposal',
MsgSubmitProposal = '/cosmos.params.v1beta1.ParameterChangeProposal',
MsgDeposit = '/cosmos.gov.v1beta1.MsgDeposit'
MsgDeposit = '/cosmos.gov.v1beta1.MsgDeposit',
MsgEditValidator = '/cosmos.staking.v1beta1.MsgEditValidator'
}

export enum AddressTypeEnum {
Expand Down
60 changes: 60 additions & 0 deletions views/transactions/hook/convertDataConstants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { CardInfoLabels } from 'utils/enum'

export const MAIN_FIELD_SORT_ORDER = [
CardInfoLabels.evmHash,
CardInfoLabels.cosmosHash,
CardInfoLabels.result,
CardInfoLabels.failLog,
CardInfoLabels.revertReason,
CardInfoLabels.memo,
CardInfoLabels.confirmations,
CardInfoLabels.block,
CardInfoLabels.blockHeight,

CardInfoLabels.time,

CardInfoLabels.value,
CardInfoLabels.fee,
CardInfoLabels.gasPrice,
CardInfoLabels.typeOfTransfer
]

export const EXT_FIELD_SORT_ORDER = [
CardInfoLabels.from,
CardInfoLabels.to,
CardInfoLabels.interactWith,
CardInfoLabels.tokenTransfers,
//msgvote
CardInfoLabels.voter,
CardInfoLabels.proposalId,
CardInfoLabels.option,
//delegate
CardInfoLabels.delegatorAddress,
CardInfoLabels.recipientAddress,
CardInfoLabels.validatorAddress,
//MsgBeginRedelegate

CardInfoLabels.validatorSrcAddress,
CardInfoLabels.validatorDstAddress,
//MsgExec
CardInfoLabels.grantee,
//MsgCreateValidator
CardInfoLabels.validatorDescription,
CardInfoLabels.commissionRates,
CardInfoLabels.minSelfDelegation,
//MsgTextProposal
CardInfoLabels.textProposalContent,
CardInfoLabels.initialDepositValue,
CardInfoLabels.proposer,
// Msg Deposit
CardInfoLabels.depositor
]

export const MORE_ITEM_FIELD_SORT_ORDER = [
CardInfoLabels.gasLimit,
CardInfoLabels.maxFeePerGas,
CardInfoLabels.maxPriorityFeePerGas,
CardInfoLabels.gasUsedByTransaction,
CardInfoLabels.nonce,
CardInfoLabels.rawInput
]
69 changes: 5 additions & 64 deletions views/transactions/hook/useConvertData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CONFIG } from 'utils/constants'
import { CardInfoLabels } from 'utils/enum'
import { evmAddressName } from 'utils/evm'
import { ellipseBetweenText, formatCurrencyValue, LinkMaker, sortArrayFollowValue } from 'utils/helper'
import { EXT_FIELD_SORT_ORDER, MAIN_FIELD_SORT_ORDER, MORE_ITEM_FIELD_SORT_ORDER } from './convertDataConstants'

export default function useConvertData({ data }: { data: TransactionDetail }) {
const astraSummary = useAppSelector(getAstraSummary)
Expand All @@ -25,17 +26,10 @@ export default function useConvertData({ data }: { data: TransactionDetail }) {
for (let key of keys) {
switch (key) {
case 'evmHash':
if (data[key] !== undefined && data[key] !== null)
items.push({
label: CardInfoLabels[key],
type: 'copy',
contents: [{ value: data[key] }]
})
break
case 'cosmosHash':
if (data[key] !== undefined && data[key] !== null)
items.push({
label: CardInfoLabels.cosmosHash,
label: CardInfoLabels[key],
type: 'copy',
contents: [{ value: data[key] }]
})
Expand Down Expand Up @@ -343,24 +337,7 @@ export default function useConvertData({ data }: { data: TransactionDetail }) {
break
}
}
const mainItems = sortArrayFollowValue(items, 'label', [
CardInfoLabels.evmHash,
CardInfoLabels.cosmosHash,
CardInfoLabels.result,
CardInfoLabels.failLog,
CardInfoLabels.revertReason,
CardInfoLabels.memo,
CardInfoLabels.confirmations,
CardInfoLabels.block,
CardInfoLabels.blockHeight,

CardInfoLabels.time,

CardInfoLabels.value,
CardInfoLabels.fee,
CardInfoLabels.gasPrice,
CardInfoLabels.typeOfTransfer
])
const mainItems = sortArrayFollowValue(items, 'label', MAIN_FIELD_SORT_ORDER)
//remove label of Token Transfers
let hashTransfer = false
mainItems.map(item => {
Expand All @@ -373,45 +350,9 @@ export default function useConvertData({ data }: { data: TransactionDetail }) {
}
})

const extraItems = sortArrayFollowValue(items, 'label', [
CardInfoLabels.from,
CardInfoLabels.to,
CardInfoLabels.interactWith,
CardInfoLabels.tokenTransfers,
//msgvote
CardInfoLabels.voter,
CardInfoLabels.proposalId,
CardInfoLabels.option,
//delegate
CardInfoLabels.delegatorAddress,
CardInfoLabels.recipientAddress,
CardInfoLabels.validatorAddress,
//MsgBeginRedelegate

CardInfoLabels.validatorSrcAddress,
CardInfoLabels.validatorDstAddress,
//MsgExec
CardInfoLabels.grantee,
//MsgCreateValidator
CardInfoLabels.validatorDescription,
CardInfoLabels.commissionRates,
CardInfoLabels.minSelfDelegation,
//MsgTextProposal
CardInfoLabels.textProposalContent,
CardInfoLabels.initialDepositValue,
CardInfoLabels.proposer,
// Msg Deposit
CardInfoLabels.depositor
])
const extraItems = sortArrayFollowValue(items, 'label', EXT_FIELD_SORT_ORDER)

const moreItems = sortArrayFollowValue(items, 'label', [
CardInfoLabels.gasLimit,
CardInfoLabels.maxFeePerGas,
CardInfoLabels.maxPriorityFeePerGas,
CardInfoLabels.gasUsedByTransaction,
CardInfoLabels.nonce,
CardInfoLabels.rawInput
])
const moreItems = sortArrayFollowValue(items, 'label', MORE_ITEM_FIELD_SORT_ORDER)
// console.log(mainItems, moreItems, items, data)
return [mainItems, extraItems, moreItems]
},
Expand Down
13 changes: 11 additions & 2 deletions views/transactions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ export const cosmsTransactionDetail = (result: TransactionItem): TransactionDeta
_mapMsgGrant(data, result?.messages)
_mapMsgWithdrawDelegatorReward(data as TransactionMsgWithdrawDelegatorRewardDetail, result?.messages)
_mapMsgCreateValidator(data as TransactionMsgCreateValidatorDetail, result?.messages)
_mapMsgTextProposal(data, result)
_mapMsgTextProposalOrMsgSubmitProposal(data, result)
_mapMsgDeposit(data, result?.messages)
_mapMsgUnjailOrMsgEditValidator(data, result.messages)
return data
}

Expand Down Expand Up @@ -372,7 +373,7 @@ const _mapMsgCreateValidator = (data: TransactionMsgCreateValidatorDetail, messa
}
}

const _mapMsgTextProposal = (data: TransactionDetail, result: TransactionItem) => {
const _mapMsgTextProposalOrMsgSubmitProposal = (data: TransactionDetail, result: TransactionItem) => {
const type: string = result?.messages[0]?.type
if (type === TransactionTypeEnum.TextProposal || type === TransactionTypeEnum.MsgSubmitProposal) {
const content = result?.messages[0].content as unknown as TextProposalFullContent
Expand Down Expand Up @@ -420,3 +421,11 @@ const _mapMsgDeposit = (data: TransactionDetail, messages: TransactionMessage[])
data.proposalId = content.proposalId
}
}

const _mapMsgUnjailOrMsgEditValidator = (data: TransactionDetail, messages: TransactionMessage[]) => {
const type: string = messages[0]?.type
if (type === TransactionTypeEnum.MsgUnjail || type === TransactionTypeEnum.MsgEditValidator) {
const content = messages[0] as MsgUnjail
data.validatorAddress = content.content.validatorAddress
}
}

0 comments on commit a1b01d4

Please sign in to comment.