Skip to content

Commit

Permalink
Merge pull request #4180 from JoinColony/fix/4158-return-stakes
Browse files Browse the repository at this point in the history
Fix: Ensure you can reclaim your stakes even if you staked the losing side
  • Loading branch information
rumzledz authored Jan 29, 2025
2 parents e769d17 + 50b16cf commit 35cab01
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/redux/sagas/motions/claimMotionRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ function* claimMotionRewards({
throw new Error('Could not retrieve motion from database');
}

const userRewards = motionData.stakerRewards.find(
const userStakes = motionData.usersStakes.find(
({ address }) => address === userAddress,
);

if (!userRewards) {
throw new Error('Could not find rewards for given user address');
if (!userStakes) {
throw new Error('Could not find stakes for given user address');
}

const {
rewards: { yay, nay },
} = userRewards;
const { stakes } = userStakes ?? {};
const yayStake = stakes?.raw.yay;
const nayStake = stakes?.raw.nay;

const hasYayClaim = !BigNumber.from(yay).isZero();
const hasNayClaim = !BigNumber.from(nay).isZero();
const hasYayStake = !BigNumber.from(yayStake).isZero();
const hasNayStake = !BigNumber.from(nayStake).isZero();

if (!hasYayClaim && !hasNayClaim) {
if (!hasYayStake && !hasNayStake) {
throw new Error('A motion with claims needs to be provided');
}

Expand All @@ -89,7 +89,7 @@ function* claimMotionRewards({
const channels: { [id: string]: ChannelDefinition } = yield call(
createTransactionChannels,
meta.id,
[...(hasYayClaim ? [YAY_ID] : []), ...(hasNayClaim ? [NAY_ID] : [])],
[...(hasYayStake ? [YAY_ID] : []), ...(hasNayStake ? [NAY_ID] : [])],
);

const BATCH_KEY = 'claimMotionRewards';
Expand Down

0 comments on commit 35cab01

Please sign in to comment.