Skip to content

Commit

Permalink
Merge pull request #983 from Koniverse/issue-932
Browse files Browse the repository at this point in the history
[Issue-932]: Update showing staking account on the Staking detail screen
  • Loading branch information
nguyenduythuc authored Aug 25, 2023
2 parents bb71733 + 8a41d98 commit 7d3460b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
32 changes: 32 additions & 0 deletions src/hooks/screen/Staking/useGetAccountsByStaking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { StakingType } from '@subwallet/extension-base/background/KoniTypes';
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { RootState } from 'stores/index';
import { findAccountByAddress } from 'utils/account';
import { AccountJson } from '@subwallet/extension-base/background/types';

export default function useGetAccountsByStaking(chain: string, stakingType: StakingType): AccountJson[] {
const stakingItems = useSelector((state: RootState) => state.staking.stakingMap);
const accounts = useSelector((state: RootState) => state.accountState.accounts);

return useMemo(() => {
const accountInfos: AccountJson[] = [];

stakingItems.forEach(stakingItem => {
if (stakingItem.chain === chain && stakingItem.type === stakingType) {
accountInfos.push({ address: stakingItem.address });
}
});

accountInfos.forEach(accountInfo => {
const accountJson = findAccountByAddress(accounts, accountInfo.address);

if (accountJson) {
accountInfo.name = accountJson.name;
accountInfo.type = accountJson.type;
}
});

return accountInfos;
}, [accounts, chain, stakingItems, stakingType]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import i18n from 'utils/i18n/i18n';
import { CustomToast } from 'components/design-system-ui/toast';
import { SWModalRefProps } from 'components/design-system-ui/modal/ModalBaseV2';
import StakingActionModal from 'screens/Home/Staking/StakingDetail/StakingActionModal';
import useGetAccountsByStaking from 'hooks/screen/Staking/useGetAccountsByStaking';

interface Props {
nominatorMetadata?: NominatorMetadata;
Expand Down Expand Up @@ -104,7 +105,7 @@ export const StakingDetailModal = ({
: i18n.header.poolDetails;
const theme = useSubWalletTheme().swThemes;
const [seeMore, setSeeMore] = useState<boolean>(false);
const { accounts, currentAccount } = useSelector((state: RootState) => state.accountState);
const { currentAccount } = useSelector((state: RootState) => state.accountState);
const toastRef = useRef<ToastContainer>(null);
const onClickFooterButton = usePreCheckReadOnly(toastRef, currentAccount?.address);
const chainInfo = useFetchChainInfo(staking.chain);
Expand All @@ -117,6 +118,10 @@ export const StakingDetailModal = ({
pooled: i18n.filterOptions.pooled,
};
const modalRef = useRef<SWModalRefProps>(null);
const stakingAccounts = useGetAccountsByStaking(
nominatorMetadata?.chain || '',
nominatorMetadata?.type || StakingType.NOMINATED,
);

const onCloseDetailModal = useCallback(() => modalRef?.current?.close(), []);

Expand Down Expand Up @@ -319,7 +324,7 @@ export const StakingDetailModal = ({
<MetaInfo.AccountGroup
label={i18n.inputLabel.account}
content={nominatorMetadata?.address === 'ALL' ? i18n.common.allAccounts : ''}
addresses={accounts.map(acc => acc.address)}
addresses={stakingAccounts.map(acc => acc.address)}
/>
) : (
<MetaInfo.Account
Expand Down

0 comments on commit 7d3460b

Please sign in to comment.