From 617fea34ac2802a37e305af3d343cbaf70240eac Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 6 Mar 2020 14:40:18 +0100 Subject: [PATCH] Bump API (#2335) * Bump API * Cleanup staking Address render --- package.json | 8 +- packages/page-contracts/package.json | 2 +- .../page-staking/src/Overview/Address.tsx | 25 +--- .../page-staking/src/Overview/CurrentList.tsx | 24 +--- packages/react-api/package.json | 2 +- yarn.lock | 112 +++++++++--------- 6 files changed, 67 insertions(+), 106 deletions(-) diff --git a/package.json b/package.json index 88fdd99de3..ef35e30e10 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,11 @@ "packages/*" ], "resolutions": { - "@polkadot/api": "^1.5.0-beta.33", - "@polkadot/api-contract": "^1.5.0-beta.33", + "@polkadot/api": "^1.6.0-beta.1", + "@polkadot/api-contract": "^1.6.0-beta.1", "@polkadot/keyring": "^2.6.1", - "@polkadot/typegen": "^1.5.0-beta.33", - "@polkadot/types": "^1.5.0-beta.33", + "@polkadot/typegen": "^1.6.0-beta.1", + "@polkadot/types": "^1.6.0-beta.1", "@polkadot/util": "^2.6.1", "@polkadot/util-crypto": "^2.6.1", "babel-core": "^7.0.0-bridge.0", diff --git a/packages/page-contracts/package.json b/packages/page-contracts/package.json index 3d62dfbec3..6f857e13c7 100644 --- a/packages/page-contracts/package.json +++ b/packages/page-contracts/package.json @@ -12,6 +12,6 @@ "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.8.4", - "@polkadot/api-contract": "^1.5.0-beta.33" + "@polkadot/api-contract": "^1.6.0-beta.1" } } diff --git a/packages/page-staking/src/Overview/Address.tsx b/packages/page-staking/src/Overview/Address.tsx index 20f66c8868..bc2c1ea3a9 100644 --- a/packages/page-staking/src/Overview/Address.tsx +++ b/packages/page-staking/src/Overview/Address.tsx @@ -4,7 +4,6 @@ import { AccountId, Balance, RewardPoint } from '@polkadot/types/interfaces'; import { DeriveAccountInfo, DerivedStakingQuery, DerivedHeartbeatAuthor } from '@polkadot/api-derive/types'; -import { ValidatorFilter } from '../types'; import BN from 'bn.js'; import React, { useEffect, useState } from 'react'; @@ -21,7 +20,6 @@ interface Props { address: string; className?: string; defaultName: string; - filter: ValidatorFilter; filterName: string; hasQueries: boolean; heartbeat?: DerivedHeartbeatAuthor; @@ -39,8 +37,6 @@ interface Props { interface StakingState { commission?: string; controllerId?: string; - hasNominators: boolean; - isNominatorMe: boolean; nominators: [AccountId, Balance][]; sessionId?: string; stakeTotal?: BN; @@ -62,10 +58,6 @@ function expandInfo ({ controllerId, exposure, nextSessionIds, validatorPrefs }: ? `${(commission.toNumber() / 10000000).toFixed(2)}%` : undefined, controllerId: controllerId?.toString(), - hasNominators: nominators.length !== 0, - isNominatorMe: nominators.some(([who]): boolean => - myAccounts.includes(who.toString()) - ), nominators, sessionId: nextSessionIds && nextSessionIds[0]?.toString(), stakeOther, @@ -74,15 +66,6 @@ function expandInfo ({ controllerId, exposure, nextSessionIds, validatorPrefs }: }; } -function checkFilter (filter: string, hasNominators: boolean, isElected: boolean, isNominatorMe: boolean, heartbeat?: DerivedHeartbeatAuthor): boolean { - return (filter === 'hasNominators' && !hasNominators) || - (filter === 'noNominators' && hasNominators) || - (filter === 'hasWarnings' && heartbeat?.isOnline) || - (filter === 'noWarnings' && !heartbeat?.isOnline) || - (filter === 'iNominated' && !isNominatorMe) || - (filter === 'nextSet' && !isElected); -} - function checkVisibility (api: ApiPromise, address: string, filterName: string, info: DeriveAccountInfo | undefined): boolean { let isVisible = false; const filterLower = filterName.toLowerCase(); @@ -114,13 +97,12 @@ function checkVisibility (api: ApiPromise, address: string, filterName: string, return isVisible; } -export default function Address ({ address, className, filter, filterName, hasQueries, heartbeat, isAuthor, isElected, isFavorite, lastBlock, myAccounts, points, setNominators, toggleFavorite, withNominations }: Props): React.ReactElement | null { +export default function Address ({ address, className, filterName, hasQueries, heartbeat, isAuthor, isElected, isFavorite, lastBlock, myAccounts, points, setNominators, toggleFavorite, withNominations }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - // FIXME Any horrors, caused by derive type mismatches const info = useCall(api.derive.accounts.info as any, [address]); const stakingInfo = useCall(api.derive.staking.query as any, [address]); - const [{ commission, hasNominators, isNominatorMe, nominators, stakeOwn, stakeOther }, setStakingState] = useState({ hasNominators: false, isNominatorMe: false, nominators: [] }); + const [{ commission, nominators, stakeOwn, stakeOther }, setStakingState] = useState({ nominators: [] }); const [isExpanded, setIsExpanded] = useState(false); const [isVisible, setIsVisible] = useState(true); @@ -135,10 +117,9 @@ export default function Address ({ address, className, filter, filterName, hasQu useEffect((): void => { setIsVisible( - checkFilter(filter, hasNominators, isElected, isNominatorMe, heartbeat) || checkVisibility(api, address, filterName, info) ); - }, [filter, filterName, heartbeat, info, hasNominators, isNominatorMe]); + }, [address, filterName, info]); const _onFavorite = (): void => toggleFavorite(address); const _onQueryStats = (): void => { diff --git a/packages/page-staking/src/Overview/CurrentList.tsx b/packages/page-staking/src/Overview/CurrentList.tsx index 22771eb85b..44b035b684 100644 --- a/packages/page-staking/src/Overview/CurrentList.tsx +++ b/packages/page-staking/src/Overview/CurrentList.tsx @@ -4,11 +4,10 @@ import { DerivedHeartbeats, DerivedStakingOverview } from '@polkadot/api-derive/types'; import { AccountId } from '@polkadot/types/interfaces'; -import { ValidatorFilter } from '../types'; import { AddressDetails } from './types'; -import React, { useEffect, useMemo, useReducer, useState } from 'react'; -import { Dropdown, FilterOverlay, Input, Table } from '@polkadot/react-components'; +import React, { useEffect, useReducer, useState } from 'react'; +import { Input, Table } from '@polkadot/react-components'; import { useAccounts, useFavorites } from '@polkadot/react-hooks'; import { STORE_FAVS_BASE } from '../constants'; @@ -69,19 +68,9 @@ export default function CurrentList ({ authorsMap, hasQueries, isIntentions, isV const { t } = useTranslation(); const { allAccounts } = useAccounts(); const [favorites, toggleFavorite] = useFavorites(STORE_FAVS_BASE); - const [filter, setFilter] = useState('all'); const [{ allElected, elected, validators, waiting }, setFiltered] = useState<{ allElected: string[]; elected: AccountExtend[]; validators: AccountExtend[]; waiting: AccountExtend[] }>({ allElected: [], elected: [], validators: [], waiting: [] }); const [nameFilter, setNameFilter] = useState(''); const [addressDetails, dispatchDetails] = useReducer(reduceDetails, {}); - const filterOpts = useMemo(() => [ - { text: t('Show all validators and intentions'), value: 'all' }, - { text: t('Show only my nominations'), value: 'iNominated' }, - { text: t('Show only with nominators'), value: 'hasNominators' }, - { text: t('Show only without nominators'), value: 'noNominators' }, - { text: t('Show only with warnings'), value: 'hasWarnings' }, - { text: t('Show only without warnings'), value: 'noWarnings' }, - { text: t('Show only elected for next session'), value: 'nextSet' } - ], [t]); useEffect((): void => { if (isVisible && stakingOverview) { @@ -123,7 +112,6 @@ export default function CurrentList ({ authorsMap, hasQueries, isIntentions, isV
- - -