Skip to content

Commit

Permalink
fix: update msgUndelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
Tien Nam Dao committed Jan 16, 2023
1 parent afe453f commit 1917e5b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions types/message.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ enum TransactionTypeEnum {
Ethermint = '/ethermint.evm.v1.MsgEthereumTx',
MsgVote = '/cosmos.gov.v1beta1.MsgVote',
MsgDelegate = '/cosmos.staking.v1beta1.MsgDelegate',
MsgUndelegate = '/cosmos.staking.v1beta1.MsgUndelegate',
MsgSend = '/cosmos.bank.v1beta1.MsgSend',
MsgWithdrawDelegatorReward = '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward',
MsgBeginRedelegate = '/cosmos.staking.v1beta1.MsgBeginRedelegate',
Expand Down Expand Up @@ -169,6 +170,21 @@ interface MsgDelegateContent {
autoClaimedRewards: TokenAmount
}

interface MsgUndelegateContent {
name: string
amount: TokenAmount
txHash: string
version: number
delegatorAddress: string
autoClaimedRewards: TokenAmount
uuid: string
height: number
msgName: string
msgIndex: number
unbondCompleteAt: string
validatorAddress: string
}

interface MsgWithdrawDelegatorRewardContent {
amount: TokenAmount[]
height: number
Expand Down
3 changes: 3 additions & 0 deletions types/transactions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface TransactionMessage {
| MsgSendContent
| MsgExecContent
| MsgGrantContent
| MsgUndelegateContent
}

interface TransactionItem {
Expand Down Expand Up @@ -264,3 +265,5 @@ interface TransactionMsgCreateValidatorDetail extends TransactionDetail {
commissionRates: CommissionRates
minSelfDelegation: string
}

interface TransactionMsgUndelegateDetail extends TransactionDetail {}
1 change: 1 addition & 0 deletions utils/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum TransactionTypeEnum {
Ethermint = '/ethermint.evm.v1.MsgEthereumTx',
MsgVote = '/cosmos.gov.v1beta1.MsgVote',
MsgDelegate = '/cosmos.staking.v1beta1.MsgDelegate',
MsgUndelegate = '/cosmos.staking.v1beta1.MsgUndelegate',
MsgSend = '/cosmos.bank.v1beta1.MsgSend',
MsgWithdrawDelegatorReward = '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward',
MsgBeginRedelegate = '/cosmos.staking.v1beta1.MsgBeginRedelegate',
Expand Down
12 changes: 12 additions & 0 deletions views/transactions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const cosmsTransactionDetail = (result: TransactionItem): TransactionDeta
_mapMsgSendField(data, result)
_mapMsgVoteField(data, result?.messages)
_mapMsgDelegate(data, result?.messages)
_mapMsgUndelegate(data, result?.messages)
_mapMsgBeginRedelegate(data, result?.messages)
_mapMsgExec(data as TransactionMsgExecDetail, result?.messages)
_mapMsgGrant(data, result?.messages)
Expand Down Expand Up @@ -296,6 +297,17 @@ const _mapMsgDelegate = (data: TransactionDetail, messages: TransactionMessage[]
}
}

const _mapMsgUndelegate = (data: TransactionDetail, messages: TransactionMessage[]) => {
const type: string = messages[0]?.type
if (type === TransactionTypeEnum.MsgUndelegate) {
const content = messages[0].content as unknown as MsgUndelegateContent
data.delegatorAddress = content.delegatorAddress
data.validatorAddress = content.validatorAddress
data.value = formatEther(content.amount.amount)
// Missing amount of auto claim reward
}
}

const _mapMsgBeginRedelegate = (data: TransactionDetail, messages: TransactionMessage[]) => {
const type: string = messages[0]?.type
if (type === TransactionTypeEnum.MsgBeginRedelegate) {
Expand Down

0 comments on commit 1917e5b

Please sign in to comment.