Skip to content

Commit

Permalink
Merge pull request #1208 from oasisprotocol/csillag/detect-and-displa…
Browse files Browse the repository at this point in the history
…y-proposal-type

Proposal details: detect and display type
  • Loading branch information
csillag authored Feb 1, 2024
2 parents 7be380d + 232f460 commit 04aaf56
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions .changelog/1208.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Proposal details: detect and display type
8 changes: 5 additions & 3 deletions src/app/pages/ProposalDetailsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ProposalStatusIcon } from '../../components/Proposals/ProposalStatusIco
import { TextSkeleton } from '../../components/Skeleton'
import { AccountLink } from '../../components/Account/AccountLink'
import { COLORS } from 'styles/theme/colors'
import { getTypeNameForProposal } from '../../../types/proposalType'

export const ProposalDetailsPage: FC = () => {
const { t } = useTranslation()
Expand Down Expand Up @@ -50,6 +51,8 @@ export const ProposalDetailView: FC<{
const { isMobile } = useScreenSize()
if (isLoading) return <TextSkeleton numberOfRows={7} />

const proposalType = getTypeNameForProposal(t, proposal)

return (
<StyledDescriptionList titleWidth={isMobile ? '100px' : '200px'} standalone={standalone}>
{showLayer && (
Expand All @@ -67,9 +70,8 @@ export const ProposalDetailView: FC<{
<dt>{t('common.title')}</dt>
<dd>{proposal.handler}</dd>

{/*Not enough data*/}
{/*<dt>{t('common.type')}</dt>*/}
{/*<dd>???</dd>*/}
<dt>{t('common.type')}</dt>
<dd>{proposalType}</dd>

<dt>{t('common.submitter')}</dt>
<dd>
Expand Down
5 changes: 5 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@
"failed": "Failed",
"passed": "Passed",
"rejected": "Rejected"
},
"type": {
"upgrade": "Upgrade",
"parameterUpgrade": "Parameter upgrade",
"cancellation": "Cancellation"
}
},
"nft": {
Expand Down
37 changes: 37 additions & 0 deletions src/types/proposalType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { TFunction } from 'i18next'
import { Proposal } from '../oasis-nexus/api'

export type ProposalType = (typeof ProposalType)[keyof typeof ProposalType]

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const ProposalType = {
upgrade: 'upgrade',
parameterUpgrade: 'parameterUpgrade',
cancellation: 'cancellation',
} as const

/**
* Detect the proposal type from looking at the data
*
* if type=Cancellation, the cancels field will be nonempty
* if type=ParameterUpgrade, the parameters_change_module and parameters_change fields will be nonempty
* if type=Upgrade, all of the above fields will be empty
*/
export const detectProposalType = (proposal: Proposal): ProposalType => {
const { cancels, parameters_change } = proposal
if (cancels) return ProposalType.cancellation
if (parameters_change) return ProposalType.parameterUpgrade
return ProposalType.upgrade
}

export const getProposalTypeNames = (t: TFunction): Record<ProposalType, string> => ({
[ProposalType.upgrade]: t('networkProposal.type.upgrade'),
[ProposalType.parameterUpgrade]: t('networkProposal.type.parameterUpgrade'),
[ProposalType.cancellation]: t('networkProposal.type.cancellation'),
})

export const getTypeNameForProposal = (t: TFunction, proposal: Proposal) => {
const names = getProposalTypeNames(t)
const wantedType = detectProposalType(proposal)
return names[wantedType]
}

0 comments on commit 04aaf56

Please sign in to comment.