Skip to content

Commit

Permalink
Show chain name in proposal detail (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
devpavan04 authored Sep 26, 2023
1 parent e4ebd19 commit cb3710c
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions apps/stats-dapp/src/utils/getProposalsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
WrappingFeeUpdateProposal,
} from '@webb-tools/proposals';
import { hexToU8a, u8aToHex } from '@polkadot/util';
import { ChainType, calculateTypedChainId } from '@webb-tools/sdk-core';
import { chainsConfig } from '@webb-tools/dapp-config';

export function getProposalsData(
propType: ProposalType,
Expand All @@ -27,10 +29,17 @@ export function getProposalsData(
switch (propType) {
case ProposalType.AnchorUpdate: {
const decoded = AnchorUpdateProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
merkleRoot: decoded.merkleRoot,
functionSignature: u8aToHex(decoded.header.functionSignature),
nonce: String(decoded.header.nonce),
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
Expand All @@ -46,32 +55,53 @@ export function getProposalsData(
}
case ProposalType.FeeRecipientUpdate: {
const decoded = FeeRecipientUpdateProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
newFeeRecipient: decoded.newFeeRecipient,
functionSignature: u8aToHex(decoded.header.functionSignature),
nonce: String(decoded.header.nonce),
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
};
}
case ProposalType.MaxDepositLimitUpdate: {
const decoded = MaxDepositLimitProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
maxDepositLimitBytes: decoded.maxDepositLimitBytes,
functionSignature: u8aToHex(decoded.header.functionSignature),
nonce: String(decoded.header.nonce),
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
};
}
case ProposalType.MinWithdrawalLimitUpdate: {
const decoded = MinWithdrawalLimitProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
minWithdrawalLimitBytes: decoded.minWithdrawalLimitBytes,
functionSignature: u8aToHex(decoded.header.functionSignature),
nonce: String(decoded.header.nonce),
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
Expand All @@ -86,33 +116,54 @@ export function getProposalsData(
}
case ProposalType.RescueTokens: {
const decoded = RescueTokensProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
toAddress: decoded.toAddress,
tokenAddress: decoded.tokenAddress,
amount: decoded.amount,
functionSignature: u8aToHex(decoded.header.functionSignature),
nonce: String(decoded.header.nonce),
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
};
}
case ProposalType.ResourceIdUpdate: {
const decoded = ResourceIdUpdateProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
handlerAddress: decoded.handlerAddress,
newResourceId: decoded.newResourceId,
functionSignature: u8aToHex(decoded.header.functionSignature),
nonce: String(decoded.header.nonce),
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
};
}
case ProposalType.SetTreasuryHandler: {
const decoded = SetTreasuryHandlerProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
newTreasuryHandler: decoded.newTreasuryHandler,
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
Expand All @@ -122,43 +173,71 @@ export function getProposalsData(
}
case ProposalType.SetVerifier: {
const decoded = SetVerifierProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
newVerifier: decoded.newVerifier,
functionSignature: u8aToHex(decoded.header.functionSignature),
nonce: String(decoded.header.nonce),
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
};
}
case ProposalType.TokenAdd: {
const decoded = TokenAddProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
newTokenAddress: decoded.newTokenAddress,
functionSignature: u8aToHex(decoded.header.functionSignature),
nonce: String(decoded.header.nonce),
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
};
}
case ProposalType.TokenRemove: {
const decoded = TokenRemoveProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
removeTokenAddress: decoded.removeTokenAddress,
functionSignature: u8aToHex(decoded.header.functionSignature),
nonce: String(decoded.header.nonce),
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
};
}
case ProposalType.WrappingFeeUpdate: {
const decoded = WrappingFeeUpdateProposal.fromBytes(bytes);

const chainName = getChainName(
decoded.header.resourceId.chainType,
decoded.header.resourceId.chainId
);

return {
newFee: decoded.newFee,
functionSignature: u8aToHex(decoded.header.functionSignature),
nonce: String(decoded.header.nonce),
chainName: chainName,
chainType: String(decoded.header.resourceId.chainType),
chainId: String(decoded.header.resourceId.chainId),
targetSystem: u8aToHex(decoded.header.resourceId.targetSystem),
Expand All @@ -169,3 +248,11 @@ export function getProposalsData(
}
}
}

const getChainName = (chainType: ChainType, chainId: number) => {
const chainTypedChainId = calculateTypedChainId(chainType, chainId);

const chain = chainsConfig[chainTypedChainId];

return chain.name;
};

0 comments on commit cb3710c

Please sign in to comment.