-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1208 from oasisprotocol/csillag/detect-and-displa…
…y-proposal-type Proposal details: detect and display type
- Loading branch information
Showing
4 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Proposal details: detect and display type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |