Staking counter does not display last claimed (#2413)

This commit is contained in:
Jaco Greeff 2020-03-18 09:36:39 +01:00 committed by GitHub
parent 791a787350
commit 0aab9fd809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,18 +25,18 @@ function useNextPayouts (onlyLatest?: boolean): [string, BN][] | undefined {
const [nextPayouts, setNextPayouts] = useState<[string, BN][] | undefined>();
useEffect((): void => {
if (stashIds) {
if (onlyLatest) {
indexes && setNextPayouts(
stashIds.map((stashId) => [stashId, indexes.activeEra.subn(1)])
);
} else if (allInfo) {
setNextPayouts(
allInfo
.map(({ stakingLedger }, index) => [stashIds[index], stakingLedger?.lastReward?.unwrapOr(new BN(-1)).addn(1)])
.filter((value): value is [string, EraIndex] => !!value[1])
);
}
if (stashIds && allInfo && indexes) {
const prevEra = indexes.activeEra.subn(1);
const lastPayouts = allInfo
.map(({ stakingLedger }, index) => [stashIds[index], stakingLedger?.lastReward?.unwrapOr(new BN(-1)).addn(1)])
.filter((value): value is [string, EraIndex] => !!value[1])
.filter(([, era]) => era.lt(prevEra));
setNextPayouts(
onlyLatest
? lastPayouts.map(([stashId]) => [stashId, indexes.activeEra.subn(1)])
: lastPayouts
);
}
}, [allInfo, indexes, onlyLatest, stashIds]);
@ -44,6 +44,8 @@ function useNextPayouts (onlyLatest?: boolean): [string, BN][] | undefined {
}
function getRewards ([thesePayouts, theseRewards]: [[string, EraIndex][], DeriveStakerReward[][]], nextPayouts: [string, BN][]): OwnRewards {
console.error(JSON.stringify(theseRewards));
const allRewards = theseRewards.reduce((result: Record<string, DeriveStakerReward[]>, rewards, index): Record<string, DeriveStakerReward[]> => {
const [stashId] = thesePayouts[index];
const nextPayout = nextPayouts.find(([thisId]) => thisId === stashId);