Skip to content

Commit

Permalink
Merge pull request #1321 from kleros/fix(web,subgraph)/stakes-balance…
Browse files Browse the repository at this point in the history
…s-bug

fix(web,subgraph): fix staking balances bug
  • Loading branch information
alcercu authored Nov 8, 2023
2 parents fd9862b + d279014 commit 347cbcd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions subgraph/src/entities/JurorTokensPerCourt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function updateJurorStake(jurorAddress: string, courtID: string, contract
const jurorBalance = contract.getJurorBalance(Address.fromString(jurorAddress), BigInt.fromString(courtID));
const previousStake = jurorTokens.staked;
const previousTotalStake = juror.totalStake;
jurorTokens.staked = jurorBalance.value0;
jurorTokens.staked = jurorBalance.value2;
jurorTokens.locked = jurorBalance.value1;
jurorTokens.save();
const stakeDelta = getDelta(previousStake, jurorTokens.staked);
Expand All @@ -47,7 +47,7 @@ export function updateJurorStake(jurorAddress: string, courtID: string, contract
court.stake = court.stake.plus(stakeDelta);
updateStakedPNK(stakeDelta, timestamp);
const activeJurorsDelta = getActivityDelta(previousTotalStake, newTotalStake);
const stakedJurorsDelta = getActivityDelta(previousStake, jurorBalance.value0);
const stakedJurorsDelta = getActivityDelta(previousStake, jurorBalance.value2);
court.numberStakedJurors = court.numberStakedJurors.plus(stakedJurorsDelta);
updateActiveJurors(activeJurorsDelta, timestamp);
juror.save();
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Popup/Description/StakeWithdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const StakeWithdraw: React.FC<IStakeWithdraw> = ({ pnkStaked, courtName, isStake

<TotalStakeContainer>
<StyledKlerosLogo /> <MyStakeContainer>My Stake:</MyStakeContainer>{" "}
<AmountContainer>{`${formatUnits(jurorBalance?.[0] ?? BigInt(0), 18)} PNK`} </AmountContainer>
<AmountContainer>{`${formatUnits(jurorBalance?.[2] ?? BigInt(0), 18)} PNK`} </AmountContainer>
</TotalStakeContainer>
</Container>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
args: [address, id],
watch: true,
});
const parsedStake = formatPNK(jurorBalance?.[0] || 0n, 0, true);
const parsedStake = formatPNK(jurorBalance?.[2] || 0n, 0, true);
const isStaking = action === ActionType.stake;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const useCalculateJurorOdds = (
return "0.00%";
}

return bigIntRatioToPercentage(jurorBalance[0], BigInt(stakedByAllJurors));
return bigIntRatioToPercentage(jurorBalance[2], BigInt(stakedByAllJurors));
}, [jurorBalance, stakedByAllJurors, loading]);
};

Expand All @@ -78,10 +78,10 @@ const JurorBalanceDisplay = () => {
const [previousStakedByAllJurors, setPreviousStakedByAllJurors] = useState<bigint | undefined>(undefined);

useEffect(() => {
if (previousJurorBalance !== undefined && jurorBalance?.[0] !== previousJurorBalance) {
if (previousJurorBalance !== undefined && jurorBalance?.[2] !== previousJurorBalance) {
setLoading(true);
}
setPreviousJurorBalance(jurorBalance?.[0]);
setPreviousJurorBalance(jurorBalance?.[2]);
}, [jurorBalance, previousJurorBalance]);

useEffect(() => {
Expand All @@ -99,7 +99,7 @@ const JurorBalanceDisplay = () => {
{
icon: PNKIcon,
name: "My Stake",
value: `${format(jurorBalance?.[0])} PNK`,
value: `${format(jurorBalance?.[2])} PNK`,
},
{
icon: LockerIcon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
if (isAllowance) {
return parsedAmount;
} else if (isStaking) {
return jurorBalance[0] + parsedAmount;
return jurorBalance[2] + parsedAmount;
} else {
return jurorBalance[0] - parsedAmount;
return jurorBalance[2] - parsedAmount;
}
}
return 0n;
Expand Down Expand Up @@ -121,7 +121,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
},
[ActionType.withdraw]: {
text: "Withdraw",
checkDisabled: () => !jurorBalance || parsedAmount > jurorBalance[0],
checkDisabled: () => !jurorBalance || parsedAmount > jurorBalance[2],
onClick: handleStake,
},
};
Expand Down

0 comments on commit 347cbcd

Please sign in to comment.