Staking counter does not display last claimed (#2413)
This commit is contained in:
parent
791a787350
commit
0aab9fd809
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user