Skip to content

Commit

Permalink
L1-63: Fix payout always showing as unclaimed
Browse files Browse the repository at this point in the history
  • Loading branch information
youPickItUp committed Oct 30, 2024
1 parent 94bf282 commit 2ccb13e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
36 changes: 28 additions & 8 deletions .yarn/patches/@polkadot-api-derive-npm-13.2.1-19d2cc1087.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
diff --git a/cjs/staking/query.js b/cjs/staking/query.js
index 24826c714d1c6609d65ec379c385e9331e9e30cf..bb28bdbf59b6a0d73563b36e634df9cf2fc645e7 100644
index 24826c714d1c6609d65ec379c385e9331e9e30cf..5db6fbf9f97269e5812d11843ba2e36a59186eaf 100644
--- a/cjs/staking/query.js
+++ b/cjs/staking/query.js
@@ -58,7 +58,7 @@ function filterRewards(stashIds, eras, claimedRewards, stakersOverview) {
@@ -54,11 +54,17 @@ function filterRewards(stashIds, eras, claimedRewards, stakersOverview) {
? era
: -1;
}
+ // There is an migration period of 84 eras, where historical validators are still kept under `erasStakers`,
+ // but rewards are getting stored under `claimedRewards`. At least one page needs to be claimed.
+ if (rewardsPerEra && rewardsPerEra.has(era) && (!overviewPerEra || !overviewPerEra.has(era))) {
+ const rewards = rewardsPerEra.get(era);
+ return rewards.length > 0 ? era : -1;
+ }
return -1;
});
});
}
Expand All @@ -11,7 +21,7 @@ index 24826c714d1c6609d65ec379c385e9331e9e30cf..bb28bdbf59b6a0d73563b36e634df9cf
return {
accountId: stashId,
claimedRewardsEras: filterClaimedRewards(api, claimedRewards),
@@ -72,8 +72,9 @@ function parseDetails(api, stashId, controllerIdOpt, nominatorsOpt, rewardDestin
@@ -72,8 +78,9 @@ function parseDetails(api, stashId, controllerIdOpt, nominatorsOpt, rewardDestin
rewardDestination: rewardDestinationCompat(rewardDestinationOpts),
stakingLedger: stakingLedgerOpt.unwrapOrDefault(),
stashId,
Expand All @@ -23,7 +33,7 @@ index 24826c714d1c6609d65ec379c385e9331e9e30cf..bb28bdbf59b6a0d73563b36e634df9cf
}
function getLedgers(api, optIds, { withLedger = false }) {
const ids = optIds
@@ -133,11 +134,26 @@ function getStashInfo(api, stashIds, activeEra, { withClaimedRewardsEras, withCo
@@ -133,11 +140,26 @@ function getStashInfo(api, stashIds, activeEra, { withClaimedRewardsEras, withCo
: (0, rxjs_1.of)(stashIds.map(() => emptyClaimedRewards)),
withExposureErasStakersLegacy && api.query.staking.erasStakers
? (0, rxjs_1.combineLatest)(stashIds.map((s) => api.query.staking.erasStakers(activeEra, s)))
Expand Down Expand Up @@ -80,10 +90,20 @@ index 5d74f9b00630b7cbfe1fbab5cf584b18465be262..d346ec1979d17f2a56e639ce59146946
(0, rxjs_1.map)((keys) => [...new Set(keys.map(({ args: [, accountId] }) => accountId.toString()))].map((a) => api.registry.createType('AccountId', a))))
: api.query.staking['currentElected']());
diff --git a/staking/query.js b/staking/query.js
index f9448e7b554df170c96971eccbe0c3c94f0fd695..342d569897e25dc40f9fdf7815f6dcf2e174772c 100644
index f9448e7b554df170c96971eccbe0c3c94f0fd695..3f1d4d12ed078e742ced53fbe845c7ba840da673 100644
--- a/staking/query.js
+++ b/staking/query.js
@@ -54,7 +54,7 @@ function filterRewards(stashIds, eras, claimedRewards, stakersOverview) {
@@ -50,11 +50,17 @@ function filterRewards(stashIds, eras, claimedRewards, stakersOverview) {
? era
: -1;
}
+ // There is an migration period of 84 eras, where historical validators are still kept under `erasStakers`,
+ // but rewards are getting stored under `claimedRewards`. At least one page needs to be claimed.
+ if (rewardsPerEra && rewardsPerEra.has(era) && (!overviewPerEra || !overviewPerEra.has(era))) {
+ const rewards = rewardsPerEra.get(era);
+ return rewards.length > 0 ? era : -1;
+ }
return -1;
});
});
}
Expand All @@ -92,7 +112,7 @@ index f9448e7b554df170c96971eccbe0c3c94f0fd695..342d569897e25dc40f9fdf7815f6dcf2
return {
accountId: stashId,
claimedRewardsEras: filterClaimedRewards(api, claimedRewards),
@@ -68,8 +68,9 @@ function parseDetails(api, stashId, controllerIdOpt, nominatorsOpt, rewardDestin
@@ -68,8 +74,9 @@ function parseDetails(api, stashId, controllerIdOpt, nominatorsOpt, rewardDestin
rewardDestination: rewardDestinationCompat(rewardDestinationOpts),
stakingLedger: stakingLedgerOpt.unwrapOrDefault(),
stashId,
Expand All @@ -104,7 +124,7 @@ index f9448e7b554df170c96971eccbe0c3c94f0fd695..342d569897e25dc40f9fdf7815f6dcf2
}
function getLedgers(api, optIds, { withLedger = false }) {
const ids = optIds
@@ -129,11 +130,26 @@ function getStashInfo(api, stashIds, activeEra, { withClaimedRewardsEras, withCo
@@ -129,11 +136,26 @@ function getStashInfo(api, stashIds, activeEra, { withClaimedRewardsEras, withCo
: of(stashIds.map(() => emptyClaimedRewards)),
withExposureErasStakersLegacy && api.query.staking.erasStakers
? combineLatest(stashIds.map((s) => api.query.staking.erasStakers(activeEra, s)))
Expand Down
2 changes: 1 addition & 1 deletion packages/react-hooks/src/useOwnEraRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const OPT_REWARDS = { withParams: true };
function getLegacyRewards (ledger: PalletStakingStakingLedger, claimedRewardsEras?: Vec<u32>): u32[] {
const legacyRewards = ledger.legacyClaimedRewards || (ledger as unknown as { claimedRewards: u32[] }).claimedRewards || [];

return legacyRewards.concat(claimedRewardsEras?.toArray() || []);
return legacyRewards.concat((claimedRewardsEras?.toArray() || []).reverse());
}

function getRewards ([[stashIds], available]: [[string[]], DeriveStakerReward[][]]): State {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ __metadata:

"@polkadot/api-derive@patch:@polkadot/api-derive@npm%3A13.2.1#~/.yarn/patches/@polkadot-api-derive-npm-13.2.1-19d2cc1087.patch":
version: 13.2.1
resolution: "@polkadot/api-derive@patch:@polkadot/api-derive@npm%3A13.2.1#~/.yarn/patches/@polkadot-api-derive-npm-13.2.1-19d2cc1087.patch::version=13.2.1&hash=973d32"
resolution: "@polkadot/api-derive@patch:@polkadot/api-derive@npm%3A13.2.1#~/.yarn/patches/@polkadot-api-derive-npm-13.2.1-19d2cc1087.patch::version=13.2.1&hash=619873"
dependencies:
"@polkadot/api": "npm:13.2.1"
"@polkadot/api-augment": "npm:13.2.1"
Expand All @@ -1416,7 +1416,7 @@ __metadata:
"@polkadot/util-crypto": "npm:^13.1.1"
rxjs: "npm:^7.8.1"
tslib: "npm:^2.7.0"
checksum: 10/56d381b8c5b0fb51dc45ce859615bbe1d2b10e001f142d35cd7a9657a6ff1b9f9429e57a8ac62a67d309676ad2dea0988f382fdcf9f02592675e309f72ab644c
checksum: 10/40534ce86a54ea71ab5193bb16b27a4a05abbc58151793cfbb1b1a7ee978ed3a083b47226231a28abb5de50f2a84b70d5bbeed9199768e9e718eb71a8da11059
languageName: node
linkType: hard

Expand Down

0 comments on commit 2ccb13e

Please sign in to comment.