diff --git a/packages/page-staking/src/Actions/Account/ListNominees.tsx b/packages/page-staking/src/Actions/Account/ListNominees.tsx index 478325fef3..c23d1f646c 100644 --- a/packages/page-staking/src/Actions/Account/ListNominees.tsx +++ b/packages/page-staking/src/Actions/Account/ListNominees.tsx @@ -1,9 +1,11 @@ // Copyright 2017-2020 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 -import React from 'react'; +import BN from 'bn.js'; +import React, { useMemo } from 'react'; +import { DeriveEraExposure, DeriveSessionProgress } from '@polkadot/api-derive/types'; import { AddressMini, Expander } from '@polkadot/react-components'; -import { useApi } from '@polkadot/react-hooks'; +import { useApi, useCall } from '@polkadot/react-hooks'; import { useTranslation } from '../../translate'; import useInactives from '../useInactives'; @@ -17,6 +19,29 @@ function ListNominees ({ nominating, stashId }: Props): React.ReactElement(api.query.staking && api.derive.session?.progress); + const eraExposure = useCall(api.query.staking.erasStakers && api.derive.staking.eraExposure, [sessionInfo?.activeEra]); + const nomBalanceMap: Record = useMemo(() => { + const res: Record = {}; + + if (nomsActive && eraExposure) { + // for every active nominee + nomsActive.forEach((nom) => { + // cycle through its nominator to find our current stash + eraExposure.validators?.[nom].others.some((o) => { + if (o.who.eq(stashId)) { + res[nom] = o.value.toBn(); + + return true; + } + + return false; + }); + }); + } + + return res; + }, [eraExposure, nomsActive, stashId]); const max = api.consts.staking?.maxNominatorRewardedPerValidator?.toString(); @@ -44,9 +69,10 @@ function ListNominees ({ nominating, stashId }: Props): React.ReactElement {nomsActive.map((nomineeId, index): React.ReactNode => ( ))}