Skip to content

Commit

Permalink
Merge pull request #24 from InvArch/gabriel-fix_claim_issue
Browse files Browse the repository at this point in the history
Fixed claim issue
  • Loading branch information
arrudagates authored Aug 19, 2023
2 parents 86c9e9c + d5b30bd commit 8b2e9f8
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/routes/staking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ const Staking = () => {
};

if (info.stakes.length > 0) {
const unclaimedEarliest = info.stakes[0].era;
const unclaimedEarliest = info.stakes.reduce((p, v) => p.era < v.era ? p : v).era;

if (parseInt(unclaimedEarliest) < currentStakingEra) {
if (parseInt(unclaimedEarliest) < currentStakingEra) {
const unclaimed = unclaimedEras;

const cores = unclaimed.cores.filter((value) => {
Expand Down Expand Up @@ -294,7 +294,7 @@ const Staking = () => {
}));
}

const latestInfo = info.stakes.at(-1);
const latestInfo = info.stakes.at(-1);

if (!latestInfo) {
return;
Expand Down Expand Up @@ -469,7 +469,12 @@ const Staking = () => {
staked: BigNumber;
}[] = [];

for (const stakingCore of stakingCores) {
let newUnclaimedCores: {
cores: { coreId: number; earliestEra: number }[];
total: number;
} = { cores: [], total: 0 };

for (const stakingCore of stakingCores) {
const generalStakerInfo =
await api.query.ocifStaking.generalStakerInfo(
stakingCore.key,
Expand All @@ -484,9 +489,7 @@ const Staking = () => {
const unclaimedEarliest = info.stakes[0].era;

if (parseInt(unclaimedEarliest) < currentStakingEra) {
const unclaimed = unclaimedEras;

const cores = unclaimed.cores.filter((value) => {
const cores = newUnclaimedCores.cores.filter((value) => {
return value.coreId != stakingCore.key;
});

Expand All @@ -495,15 +498,13 @@ const Staking = () => {
earliestEra: parseInt(unclaimedEarliest),
});

let total = unclaimed.total;
let total = newUnclaimedCores.total;

if (currentStakingEra - parseInt(unclaimedEarliest) > total) {
if (currentStakingEra - parseInt(unclaimedEarliest) > total) {
total = currentStakingEra - parseInt(unclaimedEarliest);
}
setUnclaimedEras({
cores,
total,
});

newUnclaimedCores = { cores, total };
}

const latestInfo = info.stakes.at(-1);
Expand All @@ -520,7 +521,9 @@ const Staking = () => {
}
}

setUserStakedInfo(userStakedInfo);
setUnclaimedEras(newUnclaimedCores);

setUserStakedInfo(userStakedInfo);

const totalUserStaked = userStakedInfo.reduce(
(acc, cur) => acc.plus(cur.staked),
Expand Down Expand Up @@ -598,14 +601,19 @@ const Staking = () => {

for (let i = 0; i < currentStakingEra - core.earliestEra; i += 1) {
batch.push(api.tx.ocifStaking.stakerClaimRewards(core.coreId));
console.log("pushed core: ", core.coreId);
}
}

await api.tx.utility.batch(batch).signAndSend(
selectedAccount.address,
{ signer: injector.signer },
getSignAndSendCallback({
onInvalid: () => {
console.log("batch: ", batch);
console.log("uniqueCores: ", uniqueCores);
console.log("unclaimedEras: ", unclaimedEras)

await api.tx.utility.batch(batch).signAndSend(
selectedAccount.address,
{ signer: injector.signer },
getSignAndSendCallback({
onInvalid: () => {
toast.dismiss();

toast.error("Invalid transaction");
Expand Down

1 comment on commit 8b2e9f8

@vercel
Copy link

@vercel vercel bot commented on 8b2e9f8 Aug 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.