Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/app-council/src/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import { useLocation } from 'react-router-dom';
import { registry } from '@polkadot/react-api';
import { Button } from '@polkadot/react-components';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';
import { createType } from '@polkadot/types';

import Candidates from './Candidates';
Expand All @@ -33,9 +33,9 @@ const NULL_INFO: DerivedElectionsInfo = {

export default function Overview ({ className }: Props): React.ReactElement<Props> {
const { api } = useApi();
const bestNumber = useStream<BlockNumber>(api.derive.chain.bestNumber, []);
const _electionsInfo = useStream<DerivedElectionsInfo>(api.derive.elections.info, []);
const allVotes = useStream<Record<string, AccountId[]>>(api.query.electionsPhragmen?.votesOf, [], {
const bestNumber = useCall<BlockNumber>(api.derive.chain.bestNumber, []);
const _electionsInfo = useCall<DerivedElectionsInfo>(api.derive.elections.info, []);
const allVotes = useCall<Record<string, AccountId[]>>(api.query.electionsPhragmen?.votesOf, [], {
transform: ([voters, casted]: [AccountId[], AccountId[][]]): Record<string, AccountId[]> =>
voters.reduce((result: Record<string, AccountId[]>, voter, index): Record<string, AccountId[]> => {
casted[index].forEach((candidate): void => {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-council/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Route, Switch } from 'react-router';
import { useLocation } from 'react-router-dom';
import styled from 'styled-components';
import { Tabs } from '@polkadot/react-components';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';

import Overview from './Overview';
import Motions from './Motions';
Expand All @@ -23,7 +23,7 @@ interface Props extends AppProps, BareProps, I18nProps {}
function App ({ basePath, className, t }: Props): React.ReactElement<Props> {
const { api } = useApi();
const { pathname } = useLocation();
const motions = useStream<Hash[]>(api.query.council.proposals, []);
const motions = useCall<Hash[]>(api.query.council.proposals, []);

return (
<main className={className}>
Expand Down
4 changes: 2 additions & 2 deletions packages/app-council/src/useCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import { Hash } from '@polkadot/types/interfaces';

import { useState, useEffect } from 'react';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';

export default function useCounter (): number {
const { api, isApiReady } = useApi();
const motions = useStream<Hash[]>(isApiReady ? api.query.council?.proposals : undefined, []);
const motions = useCall<Hash[]>(isApiReady ? api.query.council?.proposals : undefined, []);
const [counter, setCounter] = useState(0);

useEffect((): void => {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-democracy/src/Overview/DispatchEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AccountId, Balance, BlockNumber, Hash, Proposal, ReferendumIndex } from
import { ITuple } from '@polkadot/types/types';

import React, { useEffect, useState } from 'react';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';
import { Bytes, Option } from '@polkadot/types';
import { formatNumber } from '@polkadot/util';

Expand All @@ -22,7 +22,7 @@ interface Props extends I18nProps {

function DispatchEntry ({ blockNumber, hash, referendumIndex, t }: Props): React.ReactElement<Props> {
const { api } = useApi();
const preimage = useStream<Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>
const preimage = useCall<Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>
>(api.query.democracy.preimages, [hash]);
const [proposal, setProposal] = useState<Proposal | undefined>();

Expand Down
4 changes: 2 additions & 2 deletions packages/app-democracy/src/Overview/DispatchQueue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ITuple } from '@polkadot/types/types';

import React, { useState } from 'react';
import { Table } from '@polkadot/react-components';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';
import { Option, StorageKey, Vec } from '@polkadot/types';
import { u8aToHex } from '@polkadot/util';

Expand All @@ -18,7 +18,7 @@ import DispatchBlock from './DispatchBlock';
function DispatchQueue ({ className, t }: Props): React.ReactElement<Props> | null {
const { api } = useApi();
const [keyPrefix] = useState(u8aToHex(api.query.democracy.dispatchQueue.creator.iterKey));
const queued = useStream<[StorageKey, Option<Vec<Option<ITuple<[Hash, ReferendumIndex]>>>>
const queued = useCall<[StorageKey, Option<Vec<Option<ITuple<[Hash, ReferendumIndex]>>>>
][]>(api.query.democracy.dispatchQueue.entries as any, []);

if (!queued?.length) {
Expand Down
6 changes: 3 additions & 3 deletions packages/app-democracy/src/Overview/Externals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { I18nProps as Props } from '@polkadot/react-components/types';

import React, { useEffect, useState } from 'react';
import { AddressSmall, Table } from '@polkadot/react-components';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';
import { Bytes, Option } from '@polkadot/types';

Expand All @@ -17,10 +17,10 @@ import ProposalCell from './ProposalCell';

function Externals ({ className, t }: Props): React.ReactElement<Props> | null {
const { api } = useApi();
const external = useStream<Option<ITuple<[Hash, VoteThreshold]>>>(api.query.democracy.nextExternal, []);
const external = useCall<Option<ITuple<[Hash, VoteThreshold]>>>(api.query.democracy.nextExternal, []);
const [hash, setHash] = useState<Hash | null>(null);
const [expanded, setExpanded] = useState<{ at: BlockNumber; balance: Balance; proposer: AccountId; proposal: Proposal } | null>(null);
const preimage = useStream<Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>>(api.query.democracy.preimages, [hash]);
const preimage = useCall<Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>>(api.query.democracy.preimages, [hash]);

useEffect((): void => {
setHash(
Expand Down
4 changes: 2 additions & 2 deletions packages/app-democracy/src/Overview/Proposals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { I18nProps as Props } from '@polkadot/react-components/types';

import React from 'react';
import { Table } from '@polkadot/react-components';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';

import ProposalDisplay from './Proposal';
import translate from '../translate';

function Proposals ({ className, t }: Props): React.ReactElement<Props> {
const { api } = useApi();
const proposals = useStream<DeriveProposal[]>(api.derive.democracy.proposals, []);
const proposals = useCall<DeriveProposal[]>(api.derive.democracy.proposals, []);

return (
<div className={`proposalSection ${className}`}>
Expand Down
4 changes: 2 additions & 2 deletions packages/app-democracy/src/Overview/Referendums.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { I18nProps as Props } from '@polkadot/react-components/types';

import React from 'react';
import { Table } from '@polkadot/react-components';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';

import Referendum from './Referendum';
import translate from '../translate';

function Referendums ({ className, t }: Props): React.ReactElement<Props> {
const { api } = useApi();
const referendums = useStream<DerivedReferendum[]>(api.derive.democracy.referendums, []);
const referendums = useCall<DerivedReferendum[]>(api.derive.democracy.referendums, []);

return (
<div className={`proposalSection ${className}`}>
Expand Down
4 changes: 2 additions & 2 deletions packages/app-democracy/src/Overview/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { I18nProps } from '@polkadot/react-components/types';
import BN from 'bn.js';
import React from 'react';
import { SummaryBox, CardSummary } from '@polkadot/react-components';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';
import { withCalls } from '@polkadot/react-api';
import { formatNumber } from '@polkadot/util';

Expand All @@ -23,7 +23,7 @@ interface Props extends I18nProps {

function Summary (props: Props): React.ReactElement<Props> {
const { api } = useApi();
const activeProposals = useStream<any[]>(api.derive.democracy.proposals, []);
const activeProposals = useCall<any[]>(api.derive.democracy.proposals, []);

const {
chain_bestNumber,
Expand Down
6 changes: 3 additions & 3 deletions packages/app-democracy/src/useCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// of the Apache-2.0 license. See the LICENSE file for details.

import { useState, useEffect } from 'react';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';

export default function useCounter (): number {
const { api, isApiReady } = useApi();
const proposals = useStream<any[]>(isApiReady ? api.derive.democracy.proposals : undefined, []);
const referenda = useStream<any[]>(isApiReady ? api.derive.democracy.referendums : undefined, []);
const proposals = useCall<any[]>(isApiReady ? api.derive.democracy.proposals : undefined, []);
const referenda = useCall<any[]>(isApiReady ? api.derive.democracy.referendums : undefined, []);
const [counter, setCounter] = useState(0);

useEffect((): void => {
Expand Down
6 changes: 3 additions & 3 deletions packages/app-staking/src/Actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AccountId, StakingLedger } from '@polkadot/types/interfaces';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { Button, CardGrid } from '@polkadot/react-components';
import { useStream, useApi, useAccounts } from '@polkadot/react-hooks';
import { useCall, useApi, useAccounts } from '@polkadot/react-hooks';
import { AccountName } from '@polkadot/react-query';
import { Option } from '@polkadot/types';
import createOption from '@polkadot/ui-keyring/options/item';
Expand Down Expand Up @@ -50,8 +50,8 @@ function getStashes (allAccounts: string[], queryBonded?: Option<AccountId>[], q
function Actions ({ allStashes, className, isVisible, recentlyOnline, t }: Props): React.ReactElement<Props> {
const { api } = useApi();
const { allAccounts } = useAccounts();
const queryBonded = useStream<Option<AccountId>[]>(api.query.staking.bonded.multi as any, [allAccounts]);
const queryLedger = useStream<Option<StakingLedger>[]>(api.query.staking.ledger.multi as any, [allAccounts]);
const queryBonded = useCall<Option<AccountId>[]>(api.query.staking.bonded.multi as any, [allAccounts]);
const queryLedger = useCall<Option<StakingLedger>[]>(api.query.staking.ledger.multi as any, [allAccounts]);
const [isNewStakeOpen, setIsNewStateOpen] = useState(false);
const [foundStashes, setFoundStashes] = useState<[string, boolean][] | null>(null);
const [stashOptions, setStashOptions] = useState<KeyringSectionOption[]>([]);
Expand Down
4 changes: 2 additions & 2 deletions packages/app-staking/src/Overview/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import BN from 'bn.js';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { AddressMini, AddressSmall, Badge, Icon } from '@polkadot/react-components';
import { useStream, useApi } from '@polkadot/react-hooks';
import { useCall, useApi } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';

Expand Down Expand Up @@ -51,7 +51,7 @@ interface StakingState {
function Address ({ address, authorsMap, className, filter, hasQueries, isElected, isFavorite, lastAuthors, myAccounts, points, recentlyOnline, t, toggleFavorite, withNominations = true }: Props): React.ReactElement<Props> | null {
const { api } = useApi();
// FIXME Any horrors, caused by derive type mismatches
const stakingInfo = useStream<DerivedStaking>(api.derive.staking.info as any, [address]);
const stakingInfo = useCall<DerivedStaking>(api.derive.staking.info as any, [address]);
const [hasActivity, setHasActivity] = useState(true);
const [{ commission, hasNominators, isNominatorMe, nominators, stashId, stakeOwn, stakeOther, validatorPayment }, setStakingState] = useState<StakingState>({
hasNominators: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/app-staking/src/Targets/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { I18nProps } from '@polkadot/react-components/types';
import BN from 'bn.js';
import React, { useEffect, useState } from 'react';
import { SummaryBox, CardSummary } from '@polkadot/react-components';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';
import { formatBalance } from '@polkadot/util';

import translate from '../translate';
Expand All @@ -25,7 +25,7 @@ interface StakeInfo {

function Summary ({ lastReward, t, totalStaked }: Props): React.ReactElement<Props> {
const { api } = useApi();
const totalInsurance = useStream<Balance>(api.query.balances.totalIssuance, []);
const totalInsurance = useCall<Balance>(api.query.balances.totalIssuance, []);
const [{ percentage, staked }, setStakeInfo] = useState<StakeInfo>({ percentage: '-', staked: null });
const [total, setTotal] = useState<string | null>(null);

Expand Down
33 changes: 16 additions & 17 deletions packages/app-staking/src/Targets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { SessionRewards } from '../types';
import { ValidatorInfo } from './types';

import BN from 'bn.js';
import React, { useEffect, useRef, useState } from 'react';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { registry } from '@polkadot/react-api';
import { InputBalance, Table } from '@polkadot/react-components';
import { useAccounts, useApi, useDebounce, useFavorites, useStream } from '@polkadot/react-hooks';
import { useAccounts, useApi, useDebounce, useFavorites, useCall } from '@polkadot/react-hooks';
import { createType } from '@polkadot/types';

import { STORE_FAVS_BASE } from '../constants';
Expand Down Expand Up @@ -150,14 +150,23 @@ function Targets ({ className, sessionRewards, t }: Props): React.ReactElement<P
const { api } = useApi();
const { allAccounts } = useAccounts();
const [_amount, setAmount] = useState<BN | undefined>(new BN(1000));
const electedInfo = useStream<DerivedStakingElected>(api.derive.staking.electedInfo, []);
const electedInfo = useCall<DerivedStakingElected>(api.derive.staking.electedInfo, [], { isSingle: true });
const [favorites, toggleFavorite] = useFavorites(STORE_FAVS_BASE);
const [lastReward, setLastReward] = useState(new BN(0));
const lastBase = useRef<number>(0);
const [baseInfo, setBaseInfo] = useState<BaseInfo[]>([]);
const [baseInfo, setBaseInfo] = useState<BaseInfo[] | undefined>();
const [{ validators, totalStaked }, setWorkable] = useState<AllInfo>({ totalStaked: new BN(0), validators: [] });
const amount = useDebounce(_amount);

useEffect((): void => {
if (electedInfo) {
setBaseInfo(
electedInfo.info.map(({ accountId, stakers, validatorPrefs }) => ({
accountId, stakers, validatorPrefs
}))
);
}
}, [electedInfo]);

useEffect((): void => {
if (sessionRewards && sessionRewards.length) {
const lastRewardSession = sessionRewards.filter(({ reward }): boolean => reward.gtn(0));
Expand All @@ -171,19 +180,9 @@ function Targets ({ className, sessionRewards, t }: Props): React.ReactElement<P
}, [sessionRewards]);

useEffect((): void => {
if (electedInfo && lastBase.current !== electedInfo.info.length) {
lastBase.current = electedInfo.info.length;

setBaseInfo(
electedInfo.info.map(({ accountId, stakers, validatorPrefs }) => ({
accountId, stakers, validatorPrefs
}))
);
if (baseInfo) {
setWorkable(extractInfo(allAccounts, amount, baseInfo, favorites, lastReward));
}
}, [electedInfo]);

useEffect((): void => {
setWorkable(extractInfo(allAccounts, amount, baseInfo, favorites, lastReward));
}, [allAccounts, amount, baseInfo, favorites, lastReward]);

return (
Expand Down
8 changes: 4 additions & 4 deletions packages/app-staking/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import styled from 'styled-components';
import { Option } from '@polkadot/types';
import { HelpOverlay } from '@polkadot/react-components';
import Tabs from '@polkadot/react-components/Tabs';
import { useStream, useAccounts, useApi } from '@polkadot/react-hooks';
import { useCall, useAccounts, useApi } from '@polkadot/react-hooks';

import basicMd from './md/basic.md';
import Actions from './Actions';
Expand Down Expand Up @@ -45,12 +45,12 @@ function App ({ basePath, className, t }: Props): React.ReactElement<Props> {
const { hasAccounts } = useAccounts();
const { pathname } = useLocation();
const [next, setNext] = useState<string[]>([]);
const [allStashes, allControllers] = (useStream<[string[], string[]]>(api.derive.staking.controllers, [], {
const [allStashes, allControllers] = (useCall<[string[], string[]]>(api.derive.staking.controllers, [], {
defaultValue: EMPTY_ALL,
transform: transformStakingControllers
}) as [string[], string[]]);
const recentlyOnline = useStream<DerivedHeartbeats>(api.derive.imOnline.receivedHeartbeats, []);
const stakingOverview = useStream<DerivedStakingOverview>(api.derive.staking.overview, []);
const recentlyOnline = useCall<DerivedHeartbeats>(api.derive.imOnline.receivedHeartbeats, []);
const stakingOverview = useCall<DerivedStakingOverview>(api.derive.staking.overview, []);
const sessionRewards = useSessionRewards(MAX_SESSIONS);
const hasQueries = hasAccounts && !!(api.query.imOnline?.authoredBlocks);
const validators = stakingOverview?.validators;
Expand Down
6 changes: 3 additions & 3 deletions packages/app-staking/src/useBlockCounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { SessionIndex } from '@polkadot/types/interfaces';
import { SessionRewards } from './types';

import { useEffect, useState } from 'react';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';
import { u32 } from '@polkadot/types';

export default function useBlockCounts (accountId: string, sessionRewards: SessionRewards[]): u32[] {
const { api } = useApi();
const [counts, setCounts] = useState<u32[]>([]);
const [historic, setHistoric] = useState<u32[]>([]);
const sessionIndex = useStream<SessionIndex>(api.query.session.currentIndex, []);
const current = useStream<u32>(api.query.imOnline?.authoredBlocks, [sessionIndex, accountId]);
const sessionIndex = useCall<SessionIndex>(api.query.session.currentIndex, []);
const current = useCall<u32>(api.query.imOnline?.authoredBlocks, [sessionIndex, accountId]);

useEffect((): void => {
if (api.query.imOnline?.authoredBlocks && sessionRewards && sessionRewards.length) {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-sudo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ComponentProps } from './types';
import React, { useEffect, useState } from 'react';
import { Route, Switch } from 'react-router';
import { Icon, Tabs } from '@polkadot/react-components';
import { useStream, useAccounts, useApi } from '@polkadot/react-hooks';
import { useCall, useAccounts, useApi } from '@polkadot/react-hooks';

import SetKey from './SetKey';
import Sudo from './Sudo';
Expand All @@ -21,7 +21,7 @@ interface Props extends AppProps, I18nProps {

function App ({ basePath, t }: Props): React.ReactElement<Props> {
const { api } = useApi();
const sudoKey = useStream<string>(api.query.sudo.key, [], { transform: (k): string => k.toString() });
const sudoKey = useCall<string>(api.query.sudo.key, [], { transform: (k): string => k.toString() });
const { allAccounts } = useAccounts();
const [isMine, setIsMine] = useState(false);

Expand Down
4 changes: 2 additions & 2 deletions packages/app-tech-comm/src/Overview/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ComponentProps } from '../types';

import React from 'react';
import { SummaryBox, CardSummary } from '@polkadot/react-components';
import { useApi, useStream } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';
import { u32 } from '@polkadot/types';
import { formatNumber } from '@polkadot/util';

Expand All @@ -18,7 +18,7 @@ interface Props extends ComponentProps, I18nProps {}

function Summary ({ className, members, proposals, t }: Props): React.ReactElement<Props> {
const { api } = useApi();
const proposalCount = useStream<u32>(api.query.technicalCommittee.proposalCount, []);
const proposalCount = useCall<u32>(api.query.technicalCommittee.proposalCount, []);

return (
<SummaryBox className={className}>
Expand Down
Loading