-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FinalizationCommitteeParameters Update
- Loading branch information
Showing
14 changed files
with
387 additions
and
1 deletion.
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
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
36 changes: 36 additions & 0 deletions
36
.../multisig/updates/FinalizationCommitteeParameters/FinalizationCommitteeParametersShow.tsx
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,36 @@ | ||
import React from 'react'; | ||
import { RewardFractionField } from '../common/RewardFractionField/RewardFractionField'; | ||
import { fieldDisplays } from './util'; | ||
import Label from '~/components/Label'; | ||
import { FinalizationCommitteeParameters } from '~/utils/types'; | ||
|
||
interface PoolParametersShowProps { | ||
parameters: FinalizationCommitteeParameters; | ||
title: string; | ||
} | ||
|
||
export default function ShowFinalizationCommitteeParameters({ | ||
parameters: { | ||
minFinalizers, | ||
maxFinalizers, | ||
relativeStakeThresholdFraction, | ||
}, | ||
title, | ||
}: PoolParametersShowProps): JSX.Element { | ||
return ( | ||
<section className="mB40"> | ||
<h3>{title}</h3> | ||
<div> | ||
<Label className="mB5">{fieldDisplays.minFinalizers}:</Label> | ||
<div className="body3 mono mB10">{minFinalizers}</div> | ||
<Label className="mB5">{fieldDisplays.maxFinalizers}:</Label> | ||
<div className="body3 mono mB10">{maxFinalizers}</div> | ||
<RewardFractionField | ||
label={fieldDisplays.relativeStakeThresholdFraction} | ||
value={relativeStakeThresholdFraction} | ||
disabled | ||
/> | ||
</div> | ||
</section> | ||
); | ||
} |
45 changes: 45 additions & 0 deletions
45
.../multisig/updates/FinalizationCommitteeParameters/FinalizationCommitteeParametersView.tsx
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,45 @@ | ||
import React from 'react'; | ||
import { isChainParametersV0, isChainParametersV1 } from '@concordium/web-sdk'; | ||
import Loading from '~/cross-app-components/Loading'; | ||
import { FinalizationCommitteeParameters } from '~/utils/types'; | ||
import withChainData, { ChainData } from '~/utils/withChainData'; | ||
import ShowFinalizationCommitteeParameters from './FinalizationCommitteeParametersShow'; | ||
import { getCurrentFinalizationCommitteeParameters } from './util'; | ||
|
||
interface Props extends ChainData { | ||
finalizationCommitteeParameters: FinalizationCommitteeParameters; | ||
} | ||
|
||
/** | ||
* Displays an overview of a baker stake threshold. | ||
*/ | ||
export default withChainData(function FinalizationCommitteeParametersView({ | ||
finalizationCommitteeParameters, | ||
chainParameters, | ||
}: Props) { | ||
if (!chainParameters) { | ||
return <Loading inline />; | ||
} | ||
|
||
if ( | ||
isChainParametersV0(chainParameters) || | ||
isChainParametersV1(chainParameters) | ||
) { | ||
throw new Error('Connected node used outdated chainParameters format'); | ||
} | ||
|
||
const current = getCurrentFinalizationCommitteeParameters(chainParameters); | ||
|
||
return ( | ||
<> | ||
<ShowFinalizationCommitteeParameters | ||
parameters={current} | ||
title="Current finalization committee parameters" | ||
/> | ||
<ShowFinalizationCommitteeParameters | ||
parameters={finalizationCommitteeParameters} | ||
title="New finalization committee parameters" | ||
/> | ||
</> | ||
); | ||
}); |
92 changes: 92 additions & 0 deletions
92
...ultisig/updates/FinalizationCommitteeParameters/UpdateFinalizationCommitteeParameters.tsx
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,92 @@ | ||
import React from 'react'; | ||
import { isChainParametersV0, isChainParametersV1 } from '@concordium/web-sdk'; | ||
import { EqualRecord } from '~/utils/types'; | ||
import { UpdateProps } from '~/utils/transactionTypes'; | ||
import Form from '~/components/Form/'; | ||
import { mustBeAnInteger, requiredMessage, enterHere } from '../common/util'; | ||
import { | ||
FinalizationCommitteeParametersFields, | ||
fieldDisplays, | ||
getCurrentFinalizationCommitteeParameters, | ||
} from './util'; | ||
import ShowFinalizationCommitteeParameters from './FinalizationCommitteeParametersShow'; | ||
import { FormRewardFractionField as FractionFieldForm } from '../common/RewardFractionField/RewardFractionField'; | ||
|
||
const fieldNames: EqualRecord<FinalizationCommitteeParametersFields> = { | ||
minFinalizers: 'minFinalizers', | ||
maxFinalizers: 'maxFinalizers', | ||
relativeStakeThresholdFraction: 'relativeStakeThresholdFraction', | ||
}; | ||
|
||
const UINT32_MAX = 2 ** 32 - 1; // UInt32 upper bound | ||
|
||
const validationRules = (name: string) => ({ | ||
required: requiredMessage(name), | ||
min: { | ||
value: 1, | ||
message: `${name} must be positive`, | ||
}, | ||
max: { | ||
value: UINT32_MAX, | ||
message: `${name} may not exceed ${UINT32_MAX}`, | ||
}, | ||
validate: { | ||
mustBeAnInteger, | ||
}, | ||
}); | ||
|
||
/** | ||
* Component for creating an update block energy limit transaction. | ||
*/ | ||
export default function UpdateFinalizationCommitteeParametersFields({ | ||
defaults, | ||
chainParameters, | ||
}: UpdateProps): JSX.Element | null { | ||
if ( | ||
isChainParametersV0(chainParameters) || | ||
isChainParametersV1(chainParameters) | ||
) { | ||
throw new Error('Connected node used outdated chainParameters format'); | ||
} | ||
|
||
const current = getCurrentFinalizationCommitteeParameters(chainParameters); | ||
|
||
return ( | ||
<div> | ||
<ShowFinalizationCommitteeParameters | ||
parameters={current} | ||
title="Current finalization committee parameters" | ||
/> | ||
<h3>New finalization committee parameters</h3> | ||
<Form.Input | ||
className="body2 mB5" | ||
name={fieldNames.minFinalizers} | ||
defaultValue={ | ||
defaults.minFinalizers || current.minFinalizers.toString() | ||
} | ||
label={`New ${fieldDisplays.minFinalizers}`} | ||
placeholder={enterHere(fieldDisplays.minFinalizers)} | ||
rules={validationRules(fieldDisplays.minFinalizers)} | ||
/> | ||
<Form.Input | ||
className="body2" | ||
name={fieldNames.maxFinalizers} | ||
defaultValue={ | ||
defaults.maxFinalizers || current.maxFinalizers.toString() | ||
} | ||
label={`New ${fieldDisplays.maxFinalizers}`} | ||
placeholder={enterHere(fieldDisplays.maxFinalizers)} | ||
rules={validationRules(fieldDisplays.maxFinalizers)} | ||
/> | ||
<FractionFieldForm | ||
label={fieldDisplays.relativeStakeThresholdFraction} | ||
name={fieldNames.relativeStakeThresholdFraction} | ||
className="mV20" | ||
defaultValue={ | ||
defaults.relativeStakeThresholdFraction || | ||
current.relativeStakeThresholdFraction.toString() | ||
} | ||
/> | ||
</div> | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
app/pages/multisig/updates/FinalizationCommitteeParameters/util.ts
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,26 @@ | ||
import { ChainParametersV2 } from '@concordium/common-sdk'; | ||
import updateConstants from '~/constants/updateConstants.json'; | ||
|
||
export interface FinalizationCommitteeParametersFields { | ||
minFinalizers: number; | ||
maxFinalizers: number; | ||
relativeStakeThresholdFraction: number; | ||
} | ||
|
||
export const fieldDisplays = { | ||
minFinalizers: 'Minimum number of finalizers', | ||
maxFinalizers: 'Maximum number of finalizers', | ||
relativeStakeThresholdFraction: 'Relative stake threshold fraction', | ||
}; | ||
|
||
export function getCurrentFinalizationCommitteeParameters( | ||
chainParameters: ChainParametersV2 | ||
): FinalizationCommitteeParametersFields { | ||
return { | ||
relativeStakeThresholdFraction: | ||
chainParameters.finalizerRelativeStakeThreshold * | ||
updateConstants.rewardFractionResolution, | ||
minFinalizers: chainParameters.minimumFinalizers, | ||
maxFinalizers: chainParameters.maximumFinalizers, | ||
}; | ||
} |
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
Oops, something went wrong.