Skip to content

Commit

Permalink
Handle missing consensus tx method names
Browse files Browse the repository at this point in the history
 - Add missing methods
 - Use exhaustedTypeWarning for warning on new,
   unhandled values

Co-authored-by: Luka Jeran <[email protected]>

Add exhaustedTypeWarning for consensus method label generation
  • Loading branch information
csillag committed Jan 15, 2025
1 parent 855dd9c commit e6dcb06
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 31 deletions.
102 changes: 71 additions & 31 deletions src/app/components/ConsensusTransactionMethod/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { tooltipDelay } from '../../../styles/theme'
import { ConsensusTxMethod } from '../../../oasis-nexus/api'
import { COLORS } from '../../../styles/theme/colors'
import { SelectOptionBase } from '../Select'
import { exhaustedTypeWarning } from '../../../types/errors'

type MethodIconProps = {
border?: boolean
Expand Down Expand Up @@ -172,30 +173,9 @@ const MethodIconWithTruncatedLabel: FC<MethodIconProps> = props => {
}

const getConsensusTransactionLabel = (t: TFunction, method: ConsensusTxMethod | undefined): string => {
/**
* TODO: Missing values:
*
* consensusMeta
* keymanagerPublishEphemeralSecret
* keymanagerPublishMasterSecret
* keymanagerUpdatePolicy
* registryDeregisterEntity
* registryProveFreshness
* registryUnfreezeNode
* roothashEvidence
* roothashSubmitMsg
* stakingBurn
* keymanager/churpApply
* keymanager/churpConfirm
* keymanager/churpCreate
* keymanager/churpUpdate
* vaultAuthorizeAction
* vaultCancelAction
* vaultCreate
*/

// Please note: when updating this, keep it in sync
// with the knownConsensusTxMethods array below!

switch (method) {
case ConsensusTxMethod.stakingTransfer:
return t('transactions.method.stakingTransfer')
Expand Down Expand Up @@ -229,29 +209,89 @@ const getConsensusTransactionLabel = (t: TFunction, method: ConsensusTxMethod |
return t('transactions.method.beaconPVSSReveal')
case ConsensusTxMethod.beaconVRFProve:
return t('transactions.method.beaconVRFProve')
case ConsensusTxMethod.consensusMeta:
return t('transactions.method.consensus.meta')
case ConsensusTxMethod.keymanagerPublishEphemeralSecret:
return t('transactions.method.keyManager.publishEphemeralSecret')
case ConsensusTxMethod.keymanagerPublishMasterSecret:
return t('transactions.method.keyManager.publishMasterSecret')
case ConsensusTxMethod.keymanagerUpdatePolicy:
return t('transactions.method.keyManager.updatePolicy')
case ConsensusTxMethod['keymanager/churpApply']:
return t('transactions.method.keyManager.churp.apply')
case ConsensusTxMethod['keymanager/churpConfirm']:
return t('transactions.method.keyManager.churp.confirm')
case ConsensusTxMethod['keymanager/churpCreate']:
return t('transactions.method.keyManager.churp.create')
case ConsensusTxMethod['keymanager/churpUpdate']:
return t('transactions.method.keyManager.churp.update')
case ConsensusTxMethod.registryDeregisterEntity:
return t('transactions.method.registryDeregisterEntity')
case ConsensusTxMethod.registryProveFreshness:
return t('transactions.method.registryProveFreshness')
case ConsensusTxMethod.registryUnfreezeNode:
return t('transactions.method.registryUnfreezeNode')
case ConsensusTxMethod.roothashEvidence:
return t('transactions.method.roothashEvidence')
case ConsensusTxMethod.roothashSubmitMsg:
return t('transactions.method.roothashSubmitMessage')
case ConsensusTxMethod.stakingBurn:
return t('transactions.method.stakingBurn')
case ConsensusTxMethod.vaultAuthorizeAction:
return t('transactions.method.vault.authorizeAction')
case ConsensusTxMethod.vaultCancelAction:
return t('transactions.method.vault.cancelAction')
case ConsensusTxMethod.vaultCreate:
return t('transactions.method.vault.create')
case undefined:
return t('common.missing')
default:
exhaustedTypeWarning('Unexpected consensus transaction method', method)
return method || t('common.unknown')
}
}

const knownConsensusTxMethods: ConsensusTxMethod[] = [
ConsensusTxMethod.stakingTransfer,
ConsensusTxMethod.stakingAddEscrow,
ConsensusTxMethod.stakingReclaimEscrow,
ConsensusTxMethod.stakingAmendCommissionSchedule,
// List of known consensus ts types, to offer in filter
// Please keep them in alphabetical order
const knownConsensusTxMethods = [
ConsensusTxMethod.stakingAllow,
ConsensusTxMethod.stakingAmendCommissionSchedule,
ConsensusTxMethod.governanceCastVote,
ConsensusTxMethod.stakingBurn,
ConsensusTxMethod.consensusMeta,
ConsensusTxMethod.stakingWithdraw,
ConsensusTxMethod.registryDeregisterEntity,
ConsensusTxMethod.roothashExecutorCommit,
ConsensusTxMethod.roothashExecutorProposerTimeout,
ConsensusTxMethod['keymanager/churpApply'],
ConsensusTxMethod['keymanager/churpConfirm'],
ConsensusTxMethod['keymanager/churpCreate'],
ConsensusTxMethod['keymanager/churpUpdate'],
ConsensusTxMethod.keymanagerPublishEphemeralSecret,
ConsensusTxMethod.keymanagerPublishMasterSecret,
ConsensusTxMethod.keymanagerUpdatePolicy,
ConsensusTxMethod.beaconPVSSCommit,
ConsensusTxMethod.beaconPVSSReveal,
ConsensusTxMethod.registryRegisterEntity,
ConsensusTxMethod.registryRegisterNode,
ConsensusTxMethod.registryRegisterRuntime,
ConsensusTxMethod.governanceCastVote,
ConsensusTxMethod.registryProveFreshness,
ConsensusTxMethod.registryUnfreezeNode,
ConsensusTxMethod.roothashEvidence,
ConsensusTxMethod.roothashSubmitMsg,
ConsensusTxMethod.stakingAddEscrow,
ConsensusTxMethod.stakingReclaimEscrow,
ConsensusTxMethod.governanceSubmitProposal,
ConsensusTxMethod.beaconPVSSCommit,
ConsensusTxMethod.beaconPVSSReveal,
ConsensusTxMethod.stakingTransfer,
ConsensusTxMethod.beaconVRFProve,
]
ConsensusTxMethod.vaultAuthorizeAction,
ConsensusTxMethod.vaultCancelAction,
ConsensusTxMethod.vaultCreate,
] satisfies ConsensusTxMethod[]

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const typeTestExhaustiveArray =
undefined as unknown as ConsensusTxMethod satisfies (typeof knownConsensusTxMethods)[number]

export const getConsensusTxMethodOptions = (t: TFunction): SelectOptionBase[] =>
knownConsensusTxMethods.map(
Expand Down
23 changes: 23 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,20 @@
"filterByType": "Filter by type",
"latest": "Latest Transactions",
"method": {
"stakingBurn": "Burn",
"stakingTransfer": "Transfer",
"stakingAddEscrow": "Start Delegate",
"stakingReclaimEscrow": "Start Undelegate",
"stakingAmendCommissionSchedule": "Amend Commission Schedule",
"stakingAllow": "Allowance Change",
"stakingWithdraw": "Continued Delegate",
"registryDeregisterEntity": "Deregister Entity",
"registryUnfreezeNode": "Registry: Unfreeze Node",
"roothashExecutorCommit": "Executor Commit",
"roothashEvidence": "RootHash Evidence",
"roothashSubmitMessage": "RootHash: Submit Message",
"roothashExecutorProposerTimeout": "Executor Proposer Timeout",
"registryProveFreshness": "Registry: Prove Freshness",
"registryRegisterEntity": "Register Entity",
"registryRegisterNode": "Register Node",
"registryRegisterRuntime": "Register Runtime",
Expand All @@ -445,18 +451,35 @@
"consensus": {
"deposit": "Consensus Deposit",
"delegate": "Consensus Delegate",
"meta": "Consensus Meta",
"undelegate": "Consensus Undelegate",
"withdraw": "Consensus Withdraw"
},
"evm": {
"call": "Contract Call",
"create": "Contract Creation"
},
"keyManager": {
"churp": {
"apply": "Key Manager: Churp Apply",
"confirm": "Key Manager: Churp Confirm",
"create": "Key Manager: Churp Create",
"update": "Key Manager: Churp Update"
},
"publishEphemeralSecret": "Key Manager: Publish Ephemeral Secret",
"publishMasterSecret": "Key Manager: Publish Master Secret",
"updatePolicy": "Key Manager: Update Policy"
},
"rofl": {
"create": "ROFL Create",
"register": "ROFL Register",
"remove": "ROFL Remove",
"update": "ROFL Update"
},
"vault": {
"authorizeAction": "Vault: Authorize Action",
"cancelAction": "Vault: Cancel Action",
"create": "Vault: Create"
}
}
},
Expand Down

0 comments on commit e6dcb06

Please sign in to comment.