Skip to content

Commit

Permalink
feat: change other values when changing user role and owned amount
Browse files Browse the repository at this point in the history
  • Loading branch information
VmMad committed Nov 22, 2023
1 parent 28c2770 commit 69b8c22
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/components/ManaCalculator/hooks/useManaState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ export function useGivenManaState(
setState({
...state,
userType: value,
[getStakedOrDelegated(value)]: state.heldTokens,
...(value === UserType.VALIDATOR
? {
validator: {
...state.validator,
attractedNewDelegatedStake: state.heldTokens,
},
}
: {}),
});
}

Expand All @@ -162,7 +171,27 @@ export function useGivenManaState(
}

function handleOwnHoldChange(value: number) {
setState({ ...state, heldTokens: value });
setState({
...state,
...getDerivedValuesFromHeldTokens(value),
});
}

function getDerivedValuesFromHeldTokens(
heldTokens: number,
): Partial<ManaCalculatorProps> {
return {
heldTokens,
[getStakedOrDelegated(state.userType)]: heldTokens,
...(state.userType === UserType.VALIDATOR
? {
validator: {
...state.validator,
attractedNewDelegatedStake: heldTokens,
},
}
: {}),
};
}

const congestionAmount = getNetworkCongestion(
Expand Down

0 comments on commit 69b8c22

Please sign in to comment.