Skip to content

Commit

Permalink
fix: adjust logic for different event phases (#5677)
Browse files Browse the repository at this point in the history
* fix: adjust logic for different event phases

* chore: cleanup imports

* chore: change function name
  • Loading branch information
maxwellmattryan committed Jan 26, 2023
1 parent b7a6195 commit 4a625c6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
48 changes: 40 additions & 8 deletions packages/shared/components/organisms/ProposalInformation.svelte
@@ -1,17 +1,49 @@
<script lang="typescript">
import { Text, Pane, KeyValueBox } from 'shared/components'
import { KeyValueBox, Pane, Text } from 'shared/components'
import { formatDate, localize } from '@core/i18n'
import { networkStatus } from '@core/network'
import { activeProfileId } from '@core/profile'
import { networkStatus } from '@core/network/stores'
import { activeProfileId } from '@core/profile/stores'
import { DATE_FORMAT, IKeyValueBoxList, milestoneToDate, truncateString } from '@core/utils'
import { ProposalStatus } from '@contexts/governance/enums'
import { proposalsState, selectedProposal } from '@contexts/governance/stores'
interface IProposalDateData {
propertyKey: 'votingOpens' | 'countingStarts' | 'countingEnds' | 'countingEnded'
milestone: number
}
const proposalDateData = getNextProposalDateData()
function getNextProposalDateData(): IProposalDateData {
switch ($selectedProposal?.status) {
case ProposalStatus.Upcoming:
return {
propertyKey: 'votingOpens',
milestone: $selectedProposal?.milestones?.commencing,
}
case ProposalStatus.Commencing:
return {
propertyKey: 'countingStarts',
milestone: $selectedProposal?.milestones?.holding,
}
case ProposalStatus.Holding:
return {
propertyKey: 'countingEnds',
milestone: $selectedProposal?.milestones?.ended,
}
case ProposalStatus.Ended:
return {
propertyKey: 'countingEnded',
milestone: $selectedProposal?.milestones?.ended,
}
default:
throw new Error('Unable to determine proposal status')
}
}
const proposalInformation: IKeyValueBoxList = {
countingEnds: {
data: formatDate(
milestoneToDate($networkStatus.currentMilestone, $selectedProposal.milestones?.ended),
DATE_FORMAT
),
[proposalDateData.propertyKey]: {
data: formatDate(milestoneToDate($networkStatus.currentMilestone, proposalDateData.milestone), DATE_FORMAT),
},
eventId: {
data: truncateString($selectedProposal?.id, 9, 9),
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/locales/en.json
Expand Up @@ -603,7 +603,10 @@
},
"proposalInformation": {
"title": "Proposal information",
"votingOpens": "Voting opens on",
"countingStarts": "Counting starts on",
"countingEnds": "Counting ends on",
"countingEnded": "Counting ended on",
"eventId": "Event ID",
"nodeUrl": "Node URL"
},
Expand Down

0 comments on commit 4a625c6

Please sign in to comment.