diff --git a/packages/page-staking/src/Payouts/PayButton.tsx b/packages/page-staking/src/Payouts/PayButton.tsx index 2e9432005156..e411244b8c82 100644 --- a/packages/page-staking/src/Payouts/PayButton.tsx +++ b/packages/page-staking/src/Payouts/PayButton.tsx @@ -39,13 +39,25 @@ function createExtrinsics (api: ApiPromise, payout: PayoutValidator | PayoutVali if (!Array.isArray(payout)) { const { eras, validatorId } = payout; + if (eras.every((e) => e.isClaimed)) { + return null; + } + return eras.length === 1 ? [api.tx.staking.payoutStakers(validatorId, eras[0].era)] : createStream(api, eras.map((era): SinglePayout => ({ era: era.era, validatorId }))); } else if (payout.length === 1) { + if (payout[0].eras.every((e) => e.isClaimed)) { + return null; + } + return createExtrinsics(api, payout[0]); } + if (!payout.some((p) => p.eras.some((e) => !e.isClaimed))) { + return null; + } + return createStream(api, payout.reduce((payouts: SinglePayout[], { eras, validatorId }): SinglePayout[] => { eras.forEach(({ era }): void => { payouts.push({ era, validatorId }); @@ -76,7 +88,7 @@ function PayButton ({ className, isAll, isDisabled, payout }: Props): React.Reac ); }, [api, payout]); - const isPayoutEmpty = !payout || (Array.isArray(payout) && payout.length === 0); + const isPayoutEmpty = !payout || (Array.isArray(payout) && !payout.some((p) => p.eras.some((e) => !e.isClaimed))) || (Array.isArray(payout) && payout.length === 0); return ( <> diff --git a/packages/page-staking/src/Payouts/Stash.tsx b/packages/page-staking/src/Payouts/Stash.tsx index 16902f7794f0..724c1aa3da88 100644 --- a/packages/page-staking/src/Payouts/Stash.tsx +++ b/packages/page-staking/src/Payouts/Stash.tsx @@ -30,7 +30,7 @@ function Stash ({ className = '', historyDepth, payout: { available, rewards, st useEffect((): void => { rewards && setEraInfo({ - eraStr: createErasString(rewards.map(({ era }) => era)), + eraStr: createErasString(rewards.filter(({ isClaimed }) => !isClaimed).map(({ era }) => era)), oldestEra: rewards[0]?.era }); }, [rewards]); diff --git a/packages/page-staking/src/Payouts/Validator.tsx b/packages/page-staking/src/Payouts/Validator.tsx index 729000dcdfae..5849bc53717a 100644 --- a/packages/page-staking/src/Payouts/Validator.tsx +++ b/packages/page-staking/src/Payouts/Validator.tsx @@ -29,7 +29,7 @@ interface State { } function extractState (payout: PayoutValidator): State { - const eraStr = createErasString(payout.eras.map(({ era }) => era)); + const eraStr = createErasString(payout.eras.filter(({ isClaimed }) => !isClaimed).map(({ era }) => era)); const nominators = payout.eras.reduce((nominators: Record, { stashes }): Record => { Object.entries(stashes).forEach(([stashId, value]): void => { if (nominators[stashId]) { diff --git a/packages/page-staking/src/Payouts/index.tsx b/packages/page-staking/src/Payouts/index.tsx index 760ad72844e6..83efa05e49c6 100644 --- a/packages/page-staking/src/Payouts/index.tsx +++ b/packages/page-staking/src/Payouts/index.tsx @@ -60,6 +60,7 @@ function groupByValidator (allRewards: Record): Pa } else { entry.eras.push({ era: reward.era, + isClaimed: reward.isClaimed, stashes: { [stashId]: value } }); } @@ -71,6 +72,7 @@ function groupByValidator (allRewards: Record): Pa available: value, eras: [{ era: reward.era, + isClaimed: reward.isClaimed, stashes: { [stashId]: value } }], total, @@ -97,6 +99,7 @@ function extractStashes (allRewards: Record): Payo stashId })) .filter(({ available }) => !available.isZero()) + .filter(({ rewards }) => rewards.some((r) => !r.isClaimed)) .sort((a, b) => b.available.cmp(a.available)); } @@ -270,7 +273,7 @@ function Payouts ({ className = '', historyDepth, isInElection, ownPools, ownVal /> ))} - {(myStashesIndex === 1) && !isLoadingRewards && validators && (validators.length !== 0) && ( + {(myStashesIndex === 1) && !isLoadingRewards && validators && (validators.length !== 0) && validators.filter(({ eras }) => eras.some((e) => !e.isClaimed)).length > 0 && ( ; + isClaimed: boolean; } export interface PayoutValidator { diff --git a/packages/react-hooks/src/useOwnEraRewards.ts b/packages/react-hooks/src/useOwnEraRewards.ts index d6c6b096eedb..c396d7964bc2 100644 --- a/packages/react-hooks/src/useOwnEraRewards.ts +++ b/packages/react-hooks/src/useOwnEraRewards.ts @@ -87,7 +87,6 @@ function getValRewards (api: ApiPromise, validatorEras: ValidatorWithEras[], era allRewards[stashId].push({ era, eraReward: eraRewards.eraReward, - // Place holder for https://github.com/polkadot-js/apps/pull/11035 isClaimed: false, isEmpty: false, isValidator: true,