Skip to content

Commit

Permalink
refactor: some minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Dec 30, 2024
1 parent 13d2cad commit b3caf1c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

/* eslint-disable react/jsx-max-props-per-line */

import type { ApiPromise } from '@polkadot/api';
import type { BN } from '@polkadot/util';
import type { PoolFilter, PoolInfo } from '../../../../util/types';

import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { FilterAltOutlined as FilterIcon, MoreVert as MoreVertIcon, SearchOff as SearchOffIcon, SearchOutlined as SearchOutlinedIcon } from '@mui/icons-material';
import { Divider, FormControlLabel, Grid, LinearProgress, Radio, type SxProps, type Theme, Typography, useTheme } from '@mui/material';
import React, { useCallback, useRef, useState } from 'react';

import { ApiPromise } from '@polkadot/api';
import Filters from '@polkadot/extension-polkagate/src/popup/staking/pool/stake/joinPool/partials/Filters';
import { BN } from '@polkadot/util';

import { InputFilter, Progress, ShowBalance } from '../../../../components';
import { useInfo, useStakingConsts, useTranslation } from '../../../../hooks';
import PoolMoreInfo from '../../../../popup/staking/partial/PoolMoreInfo';
import { DEFAULT_POOL_FILTERS } from '../../../../util/constants';
import type { PoolFilter, PoolInfo } from '../../../../util/types';

interface Props {
api?: ApiPromise;
Expand All @@ -37,7 +38,7 @@ interface Props {
setSearchedPools: React.Dispatch<React.SetStateAction<PoolInfo[] | null | undefined>>;
}

export default function PoolsTable({ address, setSearchedPools, api, numberOfFetchedPools, totalNumberOfPools, pools, poolsToShow, filteredPools, setFilteredPools, selected, setSelected, minHeight, maxHeight = window.innerHeight / 2.4, style }: Props): React.ReactElement {
export default function PoolsTable ({ address, api, filteredPools, maxHeight = window.innerHeight / 2.4, minHeight, numberOfFetchedPools, pools, poolsToShow, selected, setFilteredPools, setSearchedPools, setSelected, style, totalNumberOfPools }: Props): React.ReactElement {
const { t } = useTranslation();
const ref = useRef(null);
const { chain, decimal, token } = useInfo(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { BN } from '@polkadot/util';

import { useApi, useToken } from '.';

export default function useMinToReceiveRewardsInSolo(address: string): BN | undefined {
export default function useMinToReceiveRewardsInSolo (address: string): BN | undefined {
const api = useApi(address);
const token = useToken(address);
const tokenFromApi = api && api.registry.chainTokens[0];
const tokenFromApi = api?.registry.chainTokens[0];

const [min, setMin] = useState<BN | undefined>();

Expand All @@ -20,7 +20,7 @@ export default function useMinToReceiveRewardsInSolo(address: string): BN | unde
return setMin(undefined);
}

api.query.staking.minimumActiveStake().then((min) => {
api.query['staking']['minimumActiveStake']().then((min) => {
setMin(new BN(min.toString()));
}).catch(console.error);
}, [api, token, tokenFromApi]);
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-polkagate/src/hooks/usePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type { MyPoolInfo } from '../util/types';
import { useCallback, useContext, useEffect, useState } from 'react';

import { FetchingContext } from '../components';
import { AUTO_MODE } from '../util/constants';
import { isHexToBn } from '../util/utils';
import { useInfo } from '.';
import { AUTO_MODE } from '../util/constants';

export default function usePool (address?: AccountId | string, id?: number, refresh?: boolean, pool?: MyPoolInfo): MyPoolInfo | null | undefined {
const { decimal: currentDecimal, endpoint, formatted, token: currentToken } = useInfo(address);
Expand Down
13 changes: 6 additions & 7 deletions packages/extension-polkagate/src/hooks/usePools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
// @ts-nocheck

import type { ApiPromise } from '@polkadot/api';
import type { DeriveStakingAccount } from '@polkadot/api-derive/types';
import type { Codec } from '@polkadot/types/types';
import type { PoolInfo } from '../util/types';

import { useCallback, useEffect, useState } from 'react';

import { ApiPromise } from '@polkadot/api';

import getPoolAccounts from '../util/getPoolAccounts';
import { useApi } from '.';

Expand All @@ -34,13 +33,13 @@ const handleInfo = (info: [Codec, Codec, Codec, DeriveStakingAccount][], lastBat
}
})?.filter((f) => f !== undefined);

type UsePools = {
interface UsePools {
incrementalPools: PoolInfo[] | null | undefined;
numberOfFetchedPools: number;
totalNumberOfPools: number | undefined;
}

export default function usePools(address: string): UsePools {
export default function usePools (address: string): UsePools {
const api = useApi(address);

const [totalNumberOfPools, setTotalNumberOfPools] = useState<number | undefined>();
Expand Down Expand Up @@ -83,9 +82,9 @@ export default function usePools(address: string): UsePools {
const { stashId } = getPoolAccounts(api, poolId);

queries.push(Promise.all([
api.query.nominationPools.metadata(poolId),
api.query['nominationPools']['metadata'](poolId),
api.query['nominationPools']['bondedPools'](poolId),
api.query.nominationPools.rewardPools(poolId),
api.query['nominationPools']['rewardPools'](poolId),
api.derive.staking.account(stashId)
]));
}
Expand All @@ -102,7 +101,7 @@ export default function usePools(address: string): UsePools {
}, []);

useEffect(() => {
api && getPools(api);
api && getPools(api).catch(console.error);
}, [api, getPools]);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function getStakingConsts (endpoint) {

return {
bondingDuration,
eraIndex: Number(currentEraIndex?.toString(), '0'),
eraIndex: Number(currentEraIndex?.toString() || '0'),
existentialDeposit,
maxNominations,
maxNominatorRewardedPerValidator,
Expand Down

0 comments on commit b3caf1c

Please sign in to comment.