Skip to content

fix(web,subgraph): fix staking balances bug #1321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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