Skip to content

Commit

Permalink
exclude a validator on role changes
Browse files Browse the repository at this point in the history
  • Loading branch information
VmMad committed Nov 30, 2023
1 parent 88bd75b commit b644826
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/components/ManaCalculator/actions/calculateManaRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ export function calculateManaRewards(
totalTargetReward = targetReward(initialEpoch, supply, generationPerSlot);
}

const lockedStake: number[] = validators.map(
const filteredValidators = validators.filter(
(validator) => !validator.excluded,
);

const lockedStake: number[] = filteredValidators.map(
(validator) => validator.lockedStake,
);
const fixedCosts: number[] = validators.map(
const fixedCosts: number[] = filteredValidators.map(
(validator) => validator.fixedCost,
);
const performance: number[] = validators.map(
const performance: number[] = filteredValidators.map(
(validator) => validator.performanceFactor,
);
const delegatedStake: number[] = validators.map(
const delegatedStake: number[] = filteredValidators.map(
(validator) => validator.delegatedStake,
);

Expand All @@ -55,7 +59,7 @@ export function calculateManaRewards(
validatorParameters.attractedDelegatedStakeFromOtherPools *
delegatedStake.reduce((a, b) => a + b, 0),
);
for (let i = 0; i < validators.length; i++) {
for (let i = 0; i < filteredValidators.length; i++) {
delegatedStake[i] *=
1 - validatorParameters.attractedDelegatedStakeFromOtherPools;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ export function AdvancedSettingsValidator() {
</div>
<div className='col col--1'></div>
</div>
{state.validators.map((validator, i) => (
<div className='row row--centered' key={i}>
<ValidatorCard validator={validator} id={i} />
</div>
))}
{state.validators
.filter(({ excluded }) => !excluded)
.map((validator, i) => (
<div className='row row--centered' key={i}>
<ValidatorCard validator={validator} id={i} />
</div>
))}
</div>
<button
className='button button--block mana-calculator__button '
Expand Down
7 changes: 7 additions & 0 deletions src/components/ManaCalculator/hooks/useManaState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,16 @@ export function useGivenManaState(
}

function handleUserChange(value: UserType) {
const validators = [...state.validators];
if (value === UserType.VALIDATOR) {
validators[0].excluded = true;
} else {
validators[0].excluded = false;
}
setState({
...state,
userType: value,
validators,
});
}

Expand Down
1 change: 1 addition & 0 deletions src/components/ManaCalculator/types/validator.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface ValidatorProps {
delegatedStake: number;
performanceFactor: number;
fixedCost: number;
excluded?: boolean;
}

export interface ValidatorParameters {
Expand Down

0 comments on commit b644826

Please sign in to comment.