Add useApiContext (#1890)

* Add useApiContext

* Add missing withApiContext import

* useCacheKey, rename headers

* Adjustment on sessionRewards naming

* Renames based on defacto standards
This commit is contained in:
Jaco Greeff 2019-11-15 10:51:12 +01:00 committed by GitHub
parent 999f7063af
commit c167227845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 205 additions and 179 deletions

View File

@ -7,9 +7,10 @@ import { AccountId } from '@polkadot/types/interfaces';
import { BareProps, I18nProps } from '@polkadot/react-components/types';
import BN from 'bn.js';
import React, { useContext } from 'react';
import { ApiContext, withCalls } from '@polkadot/react-api';
import React from 'react';
import { withCalls } from '@polkadot/react-api';
import { Bubble, IdentityIcon } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { formatBalance, formatNumber } from '@polkadot/util';
import translate from './translate';
@ -22,7 +23,7 @@ interface Props extends BareProps, I18nProps {
}
function SummaryBar ({ balances_totalIssuance, chain_bestNumber, chain_bestNumberLag, staking_validators }: Props): React.ReactElement<Props> {
const { api, systemChain, systemName, systemVersion } = useContext(ApiContext);
const { api, systemChain, systemName, systemVersion } = useApiContext();
return (
<summary>

View File

@ -9,11 +9,11 @@ import { KeypairType } from '@polkadot/util-crypto/types';
import { ModalProps } from '../types';
import FileSaver from 'file-saver';
import React, { useContext, useState } from 'react';
import React, { useState } from 'react';
import styled from 'styled-components';
import { DEV_PHRASE } from '@polkadot/keyring/defaults';
import { ApiContext } from '@polkadot/react-api';
import { AddressRow, Button, Dropdown, Input, InputAddress, Modal, Password } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import keyring from '@polkadot/ui-keyring';
import uiSettings from '@polkadot/ui-settings';
import { isHex, u8aToHex } from '@polkadot/util';
@ -151,7 +151,7 @@ function createAccount (suri: string, pairType: KeypairType, name: string, passw
}
function Create ({ className, onClose, onStatusChange, seed: propsSeed, t, type: propsType }: Props): React.ReactElement<Props> {
const { isDevelopment } = useContext(ApiContext);
const { isDevelopment } = useApiContext();
const [{ address, deriveError, derivePath, isSeedValid, pairType, seed, seedType }, setAddress] = useState<AddressState>(generateSeed(propsSeed, '', propsSeed ? 'raw' : 'bip', propsType));
const [isConfirmationOpen, setIsConfirmationOpen] = useState(false);
const [{ isNameValid, name }, setName] = useState({ isNameValid: false, name: '' });

View File

@ -8,12 +8,12 @@ import { DerivedFees } from '@polkadot/api-derive/types';
import { I18nProps } from '@polkadot/react-components/types';
import BN from 'bn.js';
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { Button, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { Available } from '@polkadot/react-query';
import Checks from '@polkadot/react-signer/Checks';
import { ApiContext } from '@polkadot/react-api';
import translate from '../translate';
@ -65,7 +65,7 @@ const ZERO = new BN(0);
// }
function Transfer ({ className, onClose, recipientId: propRecipientId, senderId: propSenderId, t }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [amount, setAmount] = useState<BN | undefined>(new BN(0));
const [extrinsic, setExtrinsic] = useState<SubmittableExtrinsic | null>(null);
const [hasAvailable, setHasAvailable] = useState(true);

View File

@ -6,10 +6,10 @@ import { Option } from '@polkadot/types';
import { BalanceOf, EthereumAddress } from '@polkadot/types/interfaces';
import { I18nProps } from '@polkadot/react-components/types';
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { ApiContext } from '@polkadot/react-api';
import { Button, Card } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';
import translate from './translate';
@ -21,7 +21,7 @@ interface Props extends I18nProps {
}
function Claim ({ button, className, ethereumAddress, t }: Props): React.ReactElement<Props> | null {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [claimValue, setClaimValue] = useState<BalanceOf | null>(null);
const [claimAddress, setClaimAddress] = useState<EthereumAddress | null>(null);
const [isBusy, setIsBusy] = useState(false);

View File

@ -7,10 +7,10 @@ import { ApiProps } from '@polkadot/react-api/types';
import { I18nProps } from '@polkadot/react-components/types';
import { Header } from '@polkadot/types/interfaces';
import React, { useContext, useEffect, useRef, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import styled from 'styled-components';
import { ApiContext } from '@polkadot/react-api';
import { CardSummary, IdentityIcon, SummaryBox } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';
import translate from './translate';
@ -204,7 +204,7 @@ function renderRows (rows: Row[]): React.ReactNode[] {
}
function Forks ({ className, t }: Props): React.ReactElement<Props> | null {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [tree, setTree] = useState<Link | null>(null);
const childrenRef = useRef<Map<string, string[]>>(new Map([['root', []]]));
const countRef = useRef({ numBlocks: 0, numForks: 0 });

View File

@ -5,9 +5,9 @@
import { I18nProps as Props } from '@polkadot/react-components/types';
import { Info } from './types';
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { ApiPromise } from '@polkadot/api';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import Extrinsics from '../BlockInfo/Extrinsics';
import Peers from './Peers';
@ -32,7 +32,7 @@ async function retrieveInfo (api: ApiPromise): Promise<Partial<Info>> {
}
function NodeInfo ({ t }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [info, setInfo] = useState<Partial<Info>>({});
const [nextRefresh, setNextRefresh] = useState(Date.now());

View File

@ -8,8 +8,8 @@ import { KeyedEvent } from './types';
import React, { useContext } from 'react';
import { Route, Switch } from 'react-router';
import styled from 'styled-components';
import { ApiContext } from '@polkadot/react-api';
import Tabs from '@polkadot/react-components/Tabs';
import { useApiContext } from '@polkadot/react-hooks';
import { BlockAuthorsContext, EventsContext } from '@polkadot/react-query';
import uiSettings from '@polkadot/ui-settings';
@ -24,7 +24,7 @@ interface Props extends AppProps, BareProps, I18nProps {
}
function ExplorerApp ({ basePath, className, t }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const { lastHeaders } = useContext(BlockAuthorsContext);
const events = useContext(EventsContext);

View File

@ -6,12 +6,13 @@ import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
import { I18nProps } from '@polkadot/react-components/types';
import BN from 'bn.js';
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { Button, InputAddress, InputBalance, TxButton, Dropdown } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { Available } from '@polkadot/react-query';
import Checks from '@polkadot/react-signer/Checks';
import { ApiContext, withMulti, withObservable } from '@polkadot/react-api';
import { withMulti, withObservable } from '@polkadot/react-api';
import assetRegistry, { AssetsSubjectInfo } from './assetsRegistry';
import translate from './translate';
@ -30,7 +31,7 @@ interface Option {
}
function Transfer ({ assets, className, onClose, recipientId: propRecipientId, senderId: propSenderId, t }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [assetId, setAssetId] = useState('0');
const [amount, setAmount] = useState<BN | undefined>(new BN(0));
const [extrinsic, setExtrinsic] = useState<SubmittableExtrinsic | null>(null);

View File

@ -7,13 +7,13 @@ import { KeyringInstance } from '@polkadot/keyring/types';
import { AppProps, I18nProps } from '@polkadot/react-components/types';
import { Log, LogType, Snippet } from './types';
import React, { useContext, useRef, useState, useEffect } from 'react';
import React, { useRef, useState, useEffect } from 'react';
import { withRouter, RouteComponentProps } from 'react-router';
import { Transition } from 'semantic-ui-react';
import snappy from 'snappyjs';
import styled from 'styled-components';
import { ApiContext } from '@polkadot/react-api';
import { Button, Dropdown, Editor } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import uiKeyring from '@polkadot/ui-keyring';
import * as types from '@polkadot/types';
import * as util from '@polkadot/util';
@ -90,7 +90,7 @@ function decodeBase64 (base64: string): Snippet {
// FIXME This... ladies & gentlemen, is a mess that should be untangled
function Playground ({ className, history, match: { params: { base64 } }, t }: Props): React.ReactElement<Props> {
const { api, isDevelopment } = useContext(ApiContext);
const { api, isDevelopment } = useApiContext();
const injectedRef = useRef<Injected | null>(null);
const [code, setCode] = useState('');
const [isAnimated, setIsAnimated] = useState(true);

View File

@ -4,9 +4,9 @@
import { I18nProps } from '@polkadot/react-components/types';
import React, { useContext, useState } from 'react';
import React, { useState } from 'react';
import { Button, InputAddress, Input, Modal, TxButton } from '@polkadot/react-components';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import ValidationSessionKey from './InputValidationSessionKey';
import translate from '../../translate';
@ -22,7 +22,7 @@ interface Props extends I18nProps {
const EMPTY_PROOF = new Uint8Array();
function SetSessionKey ({ controllerId, isOpen, onClose, sessionIds, stashId, t }: Props): React.ReactElement<Props> | null {
const { isSubstrateV2 } = useContext(ApiContext);
const { isSubstrateV2 } = useApiContext();
const [keysError, setKeysError] = useState<string | null>(null);
const [keys, setKeys] = useState<string | null>(
isSubstrateV2

View File

@ -8,11 +8,12 @@ import { I18nProps } from '@polkadot/react-components/types';
import { ValidatorFilter } from '../types';
import BN from 'bn.js';
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { ApiContext, withCalls, withMulti } from '@polkadot/react-api';
import { withCalls, withMulti } from '@polkadot/react-api';
import { AddressCard, AddressMini, Badge, Expander, Icon } from '@polkadot/react-components';
import { classes } from '@polkadot/react-components/util';
import { useApiContext } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';
import translate from '../translate';
@ -47,7 +48,7 @@ interface StakingState {
const WITH_VALIDATOR_PREFS = { validatorPayment: true };
function Address ({ address, authorsMap, className, defaultName, filter, isElected, isFavorite, lastAuthors, myAccounts, points, recentlyOnline, stakingInfo, t, toggleFavorite, withNominations = true }: Props): React.ReactElement<Props> | null {
const { api, isSubstrateV2 } = useContext(ApiContext);
const { api, isSubstrateV2 } = useApiContext();
const [extraInfo, setExtraInfo] = useState<[React.ReactNode, React.ReactNode][] | undefined>();
const [hasActivity, setHasActivity] = useState(true);
const [{ balanceOpts, controllerId, hasNominators, isNominatorMe, nominators, sessionId, stashId }, setStakingState] = useState<StakingState>({

View File

@ -7,10 +7,9 @@ import { I18nProps } from '@polkadot/react-components/types';
import { AccountId, EraPoints, Points } from '@polkadot/types/interfaces';
import { ValidatorFilter } from '../types';
import React, { useContext, useEffect, useState } from 'react';
import { ApiContext } from '@polkadot/react-api';
import React, { useEffect, useState } from 'react';
import { Columar, Column, Dropdown, FilterOverlay } from '@polkadot/react-components';
import { useFavorites } from '@polkadot/react-hooks';
import { useApiContext, useFavorites } from '@polkadot/react-hooks';
import keyring from '@polkadot/ui-keyring';
import { STORE_FAVS_BASE } from '../constants';
@ -57,7 +56,7 @@ function accountsToString (accounts: AccountId[]): string[] {
}
function CurrentList ({ authorsMap, lastAuthors, next, recentlyOnline, stakingOverview, t }: Props): React.ReactElement<Props> {
const { isSubstrateV2 } = useContext(ApiContext);
const { isSubstrateV2 } = useApiContext();
const [favorites, toggleFavorite] = useFavorites(STORE_FAVS_BASE);
const [filter, setFilter] = useState<ValidatorFilter>('all');
const [myAccounts] = useState(keyring.getAccounts().map(({ address }): string => address));

View File

@ -6,7 +6,7 @@ import { BareProps } from '@polkadot/react-components/types';
import { ComponentProps } from '../types';
import React, { useContext, useEffect, useState } from 'react';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import { BlockAuthorsContext } from '@polkadot/react-query';
import CurrentList from './CurrentList';
@ -15,7 +15,7 @@ import Summary from './Summary';
interface Props extends BareProps, ComponentProps {}
export default function Overview ({ allControllers, allStashes, className, recentlyOnline, stakingOverview }: Props): React.ReactElement<Props> {
const { isSubstrateV2 } = useContext(ApiContext);
const { isSubstrateV2 } = useApiContext();
const { byAuthor, lastBlockAuthors, lastBlockNumber } = useContext(BlockAuthorsContext);
const [next, setNext] = useState<string[]>([]);
const validators = stakingOverview && stakingOverview.validators;

View File

@ -7,11 +7,12 @@ import { Balance, BlockNumber, Hash, Exposure, SessionIndex } from '@polkadot/ty
import { SessionRewards, Slash } from '@polkadot/react-hooks/types';
import BN from 'bn.js';
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { Chart, Columar, Column } from '@polkadot/react-components';
import { toShortAddress } from '@polkadot/react-components/util';
import { ApiContext, withCalls } from '@polkadot/react-api';
import { withCalls } from '@polkadot/react-api';
import { getHistoric } from '@polkadot/react-api/util';
import { useApiContext } from '@polkadot/react-hooks';
import { formatBalance, formatNumber } from '@polkadot/util';
import { MAX_SESSIONS } from '../constants';
@ -21,7 +22,7 @@ interface Props extends I18nProps {
blockCounts?: BN[];
className?: string;
currentIndex: SessionIndex;
stakingRewards: SessionRewards[];
sessionRewards: SessionRewards[];
startNumber: BlockNumber;
validatorId: string;
}
@ -95,8 +96,8 @@ function extractEraSlash (validatorId: string, slashes: Slash[]): BN {
}, new BN(0));
}
function Validator ({ blockCounts, className, currentIndex, stakingRewards, startNumber, t, validatorId }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
function Validator ({ blockCounts, className, currentIndex, sessionRewards, startNumber, t, validatorId }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const [blocksLabels, setBlocksLabels] = useState<string[]>([]);
const [blocksChart, setBlocksChart] = useState<LineData | null>(null);
const [{ rewardsChart, rewardsLabels }, setRewardsInfo] = useState<{ rewardsChart: LineData | null; rewardsLabels: string[] }>({ rewardsChart: null, rewardsLabels: [] });
@ -124,7 +125,7 @@ function Validator ({ blockCounts, className, currentIndex, stakingRewards, star
const rewardsLabels: string[] = [];
const rewardsChart: LineData = [[]];
stakingRewards.forEach(({ sessionIndex, slashes }): void => {
sessionRewards.forEach(({ sessionIndex, slashes }): void => {
// this shows the start of the new era, however rewards are for previous
rewardsLabels.push(formatNumber(sessionIndex.subn(1)));
@ -135,7 +136,7 @@ function Validator ({ blockCounts, className, currentIndex, stakingRewards, star
});
setRewardsInfo({ rewardsChart, rewardsLabels });
}, [stakingRewards, validatorId]);
}, [sessionRewards, validatorId]);
useEffect((): void => {
setBlocksLabels(

View File

@ -47,7 +47,7 @@ interface Props extends I18nProps, ComponentProps, RouteComponentProps<{}> {
// />
// </Input>
function Query ({ bestNumber, className, stakingRewards, stakingOverview, match: { params: { value } }, t }: Props): React.ReactElement<Props> {
function Query ({ bestNumber, className, sessionRewards, stakingOverview, match: { params: { value } }, t }: Props): React.ReactElement<Props> {
const [startNumber, setStartNumber] = useState<BlockNumber | undefined>();
const [validatorId, setValidatorId] = useState<string | null>(value || null);
@ -82,7 +82,7 @@ function Query ({ bestNumber, className, stakingRewards, stakingOverview, match:
{value && startNumber && stakingOverview && (
<Validator
currentIndex={stakingOverview.currentIndex}
stakingRewards={stakingRewards}
sessionRewards={sessionRewards}
startNumber={startNumber}
validatorId={value}
/>

View File

@ -9,15 +9,15 @@ import { AccountId, BlockNumber } from '@polkadot/types/interfaces';
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import { ComponentProps } from './types';
import React, { useContext } from 'react';
import React from 'react';
import { Route, Switch } from 'react-router';
import { useRouteMatch } from 'react-router-dom';
import styled from 'styled-components';
import { Option } from '@polkadot/types';
import { HelpOverlay } from '@polkadot/react-components';
import Tabs from '@polkadot/react-components/Tabs';
import { ApiContext, withCalls, withMulti, withObservable } from '@polkadot/react-api';
import { useSessionSlashes } from '@polkadot/react-hooks';
import { withCalls, withMulti, withObservable } from '@polkadot/react-api';
import { useApiContext, useSessionRewards } from '@polkadot/react-hooks';
import accountObservable from '@polkadot/ui-keyring/observable/accounts';
import Accounts from './Actions/Accounts';
@ -39,8 +39,8 @@ const EMPY_ACCOUNTS: string[] = [];
const EMPTY_ALL: [string[], string[]] = [EMPY_ACCOUNTS, EMPY_ACCOUNTS];
function App ({ allAccounts, allStashesAndControllers: [allStashes, allControllers] = EMPTY_ALL, basePath, bestNumber, className, recentlyOnline, stakingOverview, t }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const stakingRewards = useSessionSlashes(MAX_SESSIONS);
const { api } = useApiContext();
const sessionRewards = useSessionRewards(MAX_SESSIONS);
const routeMatch = useRouteMatch({ path: basePath, strict: true });
const _renderComponent = (Component: React.ComponentType<ComponentProps>, className?: string): () => React.ReactNode => {
// eslint-disable-next-line react/display-name
@ -57,7 +57,7 @@ function App ({ allAccounts, allStashesAndControllers: [allStashes, allControlle
bestNumber={bestNumber}
className={className}
recentlyOnline={recentlyOnline}
stakingRewards={stakingRewards}
sessionRewards={sessionRewards}
stakingOverview={stakingOverview}
/>
);

View File

@ -16,7 +16,7 @@ export interface ComponentProps {
bestNumber?: BlockNumber;
className?: string;
recentlyOnline?: DerivedHeartbeats;
stakingRewards: SessionRewards[];
sessionRewards: SessionRewards[];
stakingOverview?: DerivedStakingOverview;
}

View File

@ -7,16 +7,16 @@ import { I18nProps } from '@polkadot/react-components/types';
import { ConstValue } from '@polkadot/react-components/InputConsts/types';
import { ComponentProps } from '../types';
import React, { useContext, useState } from 'react';
import { ApiContext } from '@polkadot/react-api';
import React, { useState } from 'react';
import { Button, InputConsts } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import translate from '../translate';
interface Props extends ComponentProps, I18nProps {}
function Consts ({ onAdd, t }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [defaultValue] = useState<ConstValue>((): ConstValue => {
const section = Object.keys(api.consts)[0];
const method = Object.keys(api.consts[section])[0];

View File

@ -7,11 +7,11 @@ import { I18nProps } from '@polkadot/react-components/types';
import { RawParams } from '@polkadot/react-params/types';
import { ComponentProps, StorageEntryPromise } from '../types';
import React, { useContext, useState } from 'react';
import React, { useState } from 'react';
import { getTypeDef } from '@polkadot/types';
import { Button, InputStorage } from '@polkadot/react-components';
import Params from '@polkadot/react-params';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import { isNull, isUndefined } from '@polkadot/util';
import translate from '../translate';
@ -32,7 +32,7 @@ function areParamsValid (values: RawParams): boolean {
}
function Modules ({ onAdd, t }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [{ defaultValues, isLinked, key, params }, setKey] = useState<{ defaultValues: RawParams | undefined | null; isLinked: boolean; key: StorageEntryPromise; params: ParamsType }>({ defaultValues: undefined, isLinked: false, key: api.query.timestamp.now, params: [] });
const [{ isValid, values }, setValues] = useState<{ isValid: boolean; values: RawParams }>({ isValid: true, values: [] });

View File

@ -5,10 +5,10 @@
import { I18nProps } from '@polkadot/react-components/types';
import { ComponentProps, QueryTypes, ParitalQueryTypes } from '../types';
import React, { useContext } from 'react';
import React from 'react';
import { Route, Switch } from 'react-router';
import { ApiContext } from '@polkadot/react-api';
import { Tabs } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import Consts from './Consts';
import Modules from './Modules';
@ -23,7 +23,7 @@ interface Props extends I18nProps {
let id = -1;
function Selection ({ basePath, onAdd, t }: Props): React.ReactElement<Props> {
const { isSubstrateV2 } = useContext(ApiContext);
const { isSubstrateV2 } = useApiContext();
const _onAdd = (query: ParitalQueryTypes): void => onAdd({ ...query, id: ++id });
const _renderComponent = (Component: React.ComponentType<ComponentProps>): () => React.ReactNode =>
// eslint-disable-next-line react/display-name

View File

@ -8,8 +8,8 @@ import React, { useContext } from 'react';
import { withRouter, RouteComponentProps } from 'react-router';
import styled from 'styled-components';
import routing from '@polkadot/apps-routing';
import { ApiContext } from '@polkadot/react-api';
import { StatusContext } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import Status from './Status';
import translate from '../translate';
@ -26,7 +26,7 @@ const unknown = {
};
function Content ({ className, location, t }: Props): React.ReactElement<Props> {
const { isApiConnected, isApiReady } = useContext(ApiContext);
const { isApiConnected, isApiReady } = useApiContext();
const { queueAction, stqueue, txqueue } = useContext(StatusContext);
const app = location.pathname.slice(1) || '';
const { Component, display: { needsApi }, name } = routing.routes.find((route): boolean =>

View File

@ -8,12 +8,13 @@ import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import { Route } from '@polkadot/apps-routing/types';
import { AccountId } from '@polkadot/types/interfaces';
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { NavLink } from 'react-router-dom';
import { ApiPromise } from '@polkadot/api';
import { Icon, Menu, Tooltip } from '@polkadot/react-components';
import accountObservable from '@polkadot/ui-keyring/observable/accounts';
import { ApiContext, withCalls, withMulti, withObservable } from '@polkadot/react-api';
import { withCalls, withMulti, withObservable } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import { isFunction } from '@polkadot/util';
import translate from '../translate';
@ -77,7 +78,7 @@ function checkVisible (name: string, { api, isApiReady, isApiConnected }: ApiPro
}
function Item ({ allAccounts, route: { Modal, display, i18n, icon, name }, t, isCollapsed, onClick, sudoKey }: Props): React.ReactElement<Props> | null {
const apiProps = useContext(ApiContext);
const apiProps = useApiContext();
const [hasAccounts, setHasAccounts] = useState(false);
const [hasSudo, setHasSudo] = useState(false);
const [isVisible, setIsVisible] = useState(false);

View File

@ -4,9 +4,9 @@
import { BareProps as Props } from '@polkadot/react-components/types';
import React, { useContext } from 'react';
import React from 'react';
import styled from 'styled-components';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import { NodeName, NodeVersion } from '@polkadot/react-query';
// eslint-disable-next-line @typescript-eslint/no-var-requires
@ -15,7 +15,7 @@ const pkgJson = require('../../package.json');
const uiInfo = `apps v${pkgJson.version}`;
function NodeInfo ({ className }: Props): React.ReactElement<Props> {
const { api, isApiReady } = useContext(ApiContext);
const { api, isApiReady } = useApiContext();
return (
<div className={className}>

View File

@ -7,12 +7,12 @@ import { SIDEBAR_MENU_THRESHOLD } from '../constants';
import './SideBar.css';
import React, { useContext, useState } from 'react';
import React, { useState } from 'react';
import styled from 'styled-components';
import { Responsive } from 'semantic-ui-react';
import routing from '@polkadot/apps-routing';
import { ApiContext } from '@polkadot/react-api';
import { Button, ChainImg, Icon, Menu, media } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { classes } from '@polkadot/react-components/util';
import { BestNumber, Chain } from '@polkadot/react-query';
@ -31,7 +31,7 @@ interface Props extends I18nProps {
}
function SideBar ({ className, collapse, handleResize, isCollapsed, toggleMenu, menuOpen }: Props): React.ReactElement<Props> {
const { api, isApiReady } = useContext(ApiContext);
const { api, isApiReady } = useApiContext();
const [modals, setModals] = useState<Record<string, boolean>>(
routing.routes.reduce((result: Record<string, boolean>, route): Record<string, boolean> => {
if (route && route.Modal) {

View File

@ -5,9 +5,9 @@
import { ApiProps } from '@polkadot/react-api/types';
import { I18nProps as Props } from '@polkadot/react-components/types';
import React, { useContext } from 'react';
import React from 'react';
import styled from 'styled-components';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import settings from '@polkadot/ui-settings';
import translate from '../translate';
@ -60,7 +60,7 @@ function ConnectOverlay ({ className, isApiConnected, t }: ApiProps & Props): Re
}
function Connecting (props: Props): React.ReactElement<Props> | null {
const api = useContext(ApiContext);
const api = useApiContext();
return ExtensionOverlay({ ...props, ...api }) || ConnectOverlay({ ...props, ...api });
}

View File

@ -2,9 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import React, { useContext } from 'react';
import React from 'react';
import styled from 'styled-components';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
// the imports here as a bit all-over, non-aphabetical - since we expect this to grow,
// rather organise based on type, grouping chains and nodes as opposed to location
@ -54,7 +54,7 @@ interface Props {
}
function ChainImg ({ className, logo = '', onClick }: Props): React.ReactElement<Props> {
const { systemChain, systemName } = useContext(ApiContext);
const { systemChain, systemName } = useApiContext();
const img = LOGOS[logo] || CHAINS[systemChain] || NODES[systemName] || EMPTY;
return (

View File

@ -4,8 +4,8 @@
import { I18nProps } from '@polkadot/react-components/types';
import React, { useContext } from 'react';
import { ApiContext } from '@polkadot/react-api';
import React from 'react';
import { useApiContext } from '@polkadot/react-hooks';
import translate from './translate';
import Toggle from './Toggle';
@ -17,7 +17,7 @@ interface Props extends I18nProps {
}
function ChainLock ({ genesisHash, onChange, t }: Props): React.ReactElement<Props> | null {
const { isDevelopment, api } = useContext(ApiContext);
const { isDevelopment, api } = useApiContext();
if (isDevelopment) {
return null;

View File

@ -7,7 +7,8 @@ import { IdentityProps } from '@polkadot/react-identicon/types';
import { I18nProps } from './types';
import React, { useContext, useEffect, useState } from 'react';
import { ApiContext, withCalls, withMulti } from '@polkadot/react-api';
import { withCalls, withMulti } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import BaseIdentityIcon from '@polkadot/react-identicon';
import uiSettings from '@polkadot/ui-settings';
@ -33,7 +34,7 @@ export function getIdentityTheme (systemName: string): 'empty' {
}
function IdentityIcon ({ className, onCopy, prefix, size, style, t, theme, validators, value }: Props): React.ReactElement<Props> {
const { systemName } = useContext(ApiContext);
const { systemName } = useApiContext();
const { queueAction } = useContext(StatusContext);
const [address, setAddress] = useState<string | undefined>();
const [isValidator, setIsValidator] = useState(false);

View File

@ -9,9 +9,9 @@ import { ConstValue, ConstValueBase } from './types';
import '../InputExtrinsic/InputExtrinsic.css';
import React, { useContext, useState } from 'react';
import React, { useState } from 'react';
import { ApiPromise } from '@polkadot/api';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import Labelled from '../Labelled';
import translate from '../translate';
@ -43,7 +43,7 @@ function getValue (api: ApiPromise, { method, section }: ConstValueBase): ConstV
}
function InputConsts ({ className, defaultValue, help, label, onChange, style, withLabel }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [optionsMethod, setOptionsMethod] = useState<DropdownOptions>(keyOptions(api, defaultValue.section));
const [optionsSection] = useState<DropdownOptions>(sectionOptions(api));
const [value, setValue] = useState<ConstValue>(getValue(api, defaultValue));

View File

@ -8,8 +8,8 @@ import { DropdownOptions } from '../util/types';
import './InputExtrinsic.css';
import React, { useContext, useState } from 'react';
import { ApiContext } from '@polkadot/react-api';
import React, { useState } from 'react';
import { useApiContext } from '@polkadot/react-hooks';
import Labelled from '../Labelled';
import translate from '../translate';
@ -30,7 +30,7 @@ interface Props extends I18nProps {
}
function InputExtrinsic ({ className, defaultValue, help, label, onChange, style, withLabel }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [optionsMethod, setOptionsMethod] = useState<DropdownOptions>(methodOptions(api, defaultValue.section));
const [optionsSection] = useState<DropdownOptions>(sectionOptions(api));
const [value, setValue] = useState<CallFunction>((): CallFunction => defaultValue);

View File

@ -10,9 +10,9 @@ import { I18nProps } from '../types';
import '../InputExtrinsic/InputExtrinsic.css';
import React, { useContext, useState } from 'react';
import React, { useState } from 'react';
import map from '@polkadot/jsonrpc';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import Labelled from '../Labelled';
import translate from '../translate';
@ -31,7 +31,7 @@ interface Props extends I18nProps {
}
function InputRpc ({ className, defaultValue, help, label, onChange, style, withLabel }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [optionsMethod, setOptionsMethod] = useState<DropdownOptions>(methodOptions(api, defaultValue.section));
const [optionsSection] = useState<DropdownOptions>(sectionOptions(api));
const [value, setValue] = useState<RpcMethod>((): RpcMethod => defaultValue);

View File

@ -6,9 +6,9 @@ import { DropdownOptions } from '../util/types';
import { BareProps } from '../types';
import { StorageEntryPromise } from './types';
import React, { useContext } from 'react';
import React from 'react';
import { ApiPromise } from '@polkadot/api';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import Dropdown from '../Dropdown';
import { classes } from '../util';
@ -29,7 +29,7 @@ function transform (api: ApiPromise, { value }: Props): (method: string) => Stor
}
export default function SelectKey (props: Props): React.ReactElement<Props> | null {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const { className, isError, onChange, options, style, value } = props;
if (!options.length) {

View File

@ -10,8 +10,8 @@ import { StorageEntryPromise } from './types';
import '../InputExtrinsic/InputExtrinsic.css';
import React, { useContext, useState } from 'react';
import { ApiContext } from '@polkadot/react-api';
import React, { useState } from 'react';
import { useApiContext } from '@polkadot/react-hooks';
import Labelled from '../Labelled';
import translate from '../translate';
@ -30,7 +30,7 @@ interface Props extends I18nProps {
}
function InputStorage ({ className, defaultValue, help, label, onChange, style, withLabel }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [optionsMethod, setOptionsMethod] = useState<DropdownOptions>(keyOptions(api, defaultValue.creator.section));
const [optionsSection] = useState<DropdownOptions>(sectionOptions(api));
const [value, setValue] = useState<StorageEntryPromise>((): StorageEntryPromise => defaultValue);

View File

@ -4,9 +4,9 @@
import { I18nProps } from './types';
import React, { useContext } from 'react';
import React from 'react';
import styled from 'styled-components';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import translate from './translate';
@ -34,7 +34,7 @@ const TYPES: Record<string, string> = {
};
function LinkPolkascan ({ className, data, t, type }: Props): React.ReactElement<Props> | null {
const { systemChain } = useContext(ApiContext);
const { systemChain } = useApiContext();
const extChain = CHAINS[systemChain];
const extType = TYPES[type];

View File

@ -5,13 +5,13 @@
import { SubmittableExtrinsicFunction } from '@polkadot/api/types';
import { Props } from '@polkadot/react-params/types';
import React, { useContext } from 'react';
import { ApiContext } from '@polkadot/react-api';
import React from 'react';
import { useApiContext } from '@polkadot/react-hooks';
import Extrinsic from './Extrinsic';
export default function Call ({ className, isDisabled, isError, label, onChange, onEnter, style, withLabel }: Props): React.ReactElement<Props> {
const { api, apiDefaultTx } = useContext(ApiContext);
const { api, apiDefaultTx } = useApiContext();
const defaultValue = ((): SubmittableExtrinsicFunction<'promise'> => {
try {

View File

@ -4,9 +4,9 @@
import { Props, RawParam } from '@polkadot/react-params/types';
import React, { useContext } from 'react';
import React from 'react';
import { createType } from '@polkadot/types';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import ExtrinsicDisplay from './Extrinsic';
@ -26,7 +26,7 @@ function onChange ({ onChange }: Props): (_: RawParam) => void {
}
export default function ProposalDisplay (props: Props): React.ReactElement<Props> {
const { apiDefaultTxSudo } = useContext(ApiContext);
const { apiDefaultTxSudo } = useApiContext();
const { className, isDisabled, isError, label, onEnter, style, withLabel } = props;
return (

View File

@ -5,9 +5,9 @@
import { TreasuryProposal as TreasuryProposalType } from '@polkadot/types/interfaces';
import { I18nProps } from '@polkadot/react-components/types';
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { InputAddress, Labelled, Static } from '@polkadot/react-components';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import { Option } from '@polkadot/types';
import { FormatBalance } from '@polkadot/react-query';
@ -26,7 +26,7 @@ interface Props extends I18nProps {
function TreasuryProposal ({ className, asInset, insetProps, onClick, proposal, proposalId, t }: Props): React.ReactElement<Props> | null {
const [stateProposal, setProposal] = useState<TreasuryProposalType | null>(null);
const { api } = useContext(ApiContext);
const { api } = useApiContext();
useEffect((): void => {
if (!proposal && proposalId) {

View File

@ -1,7 +1,8 @@
// Copyright 2017-2019 @polkadot/react-components authors & contributors
// Copyright 2017-2019 @polkadot/react-hooks authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
export { default as useDebounce } from './debounce';
export { default as useFavorites } from './favorites';
export { default as useSessionSlashes } from './sessionSlashes';
export { default as useApiContext } from './useApiContext';
export { default as useDebounce } from './useDebounce';
export { default as useFavorites } from './useFavorites';
export { default as useSessionRewards } from './useSessionRewards';

View File

@ -0,0 +1,12 @@
// Copyright 2017-2019 @polkadot/react-hooks authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiProps } from '@polkadot/react-api/types';
import { useContext } from 'react';
import { ApiContext } from '@polkadot/react-api';
export default function useApiContext (): ApiProps {
return useContext(ApiContext);
}

View File

@ -0,0 +1,17 @@
// Copyright 2017-2019 @polkadot/react-hooks authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import store from 'store';
import useApiContext from './useApiContext';
// create a chain-specific key for the local cache
export default function useCacheKey <T> (storageKeyBase: string): [(defaultValue?: T) => T | undefined, (value: T) => T] {
const { api, isDevelopment } = useApiContext();
const STORAGE_KEY = `${storageKeyBase}:${isDevelopment ? 'development' : api.genesisHash}`;
return [
(): T | undefined => store.get(STORAGE_KEY),
(value: T): T => store.set(STORAGE_KEY, value)
];
}

View File

@ -1,4 +1,4 @@
// Copyright 2017-2019 @polkadot/react-components authors & contributors
// Copyright 2017-2019 @polkadot/react-hooks authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

View File

@ -1,23 +1,22 @@
// Copyright 2017-2019 @polkadot/react-components authors & contributors
// Copyright 2017-2019 @polkadot/react-hooks authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { useContext, useState } from 'react';
import { useState } from 'react';
import store from 'store';
import { ApiContext } from '@polkadot/react-api';
import useCacheKey from './useCacheKey';
// hook for favorites with local storage
export default function useFavorites (storageKeyBase: string): [string[], (address: string) => void] {
const { api, isDevelopment } = useContext(ApiContext);
const keyName = `${storageKeyBase}:${isDevelopment ? 'development' : api.genesisHash}`;
const [getCache, setCache] = useCacheKey<string[]>(storageKeyBase);
// retrieve from the new style first, if not available, fallback to old-style
const [favorites, setFavorites] = useState<string[]>(store.get(keyName) || store.get(storageKeyBase, []));
const [favorites, setFavorites] = useState<string[]>(getCache() || store.get(storageKeyBase, []));
const _toggleFavorite = (address: string): void =>
setFavorites(
store.set(
keyName,
setCache(
favorites.includes(address)
? favorites.filter((accountId): boolean => address !== accountId)
: [...favorites, address]

View File

@ -1,4 +1,4 @@
// Copyright 2017-2019 @polkadot/react-components authors & contributors
// Copyright 2017-2019 @polkadot/react-hooks authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
@ -6,33 +6,29 @@ import { Balance, BlockNumber, EventRecord, Hash, Header } from '@polkadot/types
import { Slash, SessionRewards } from './types';
import BN from 'bn.js';
import { useContext, useEffect, useState } from 'react';
import store from 'store';
import { useEffect, useState } from 'react';
import { ApiPromise } from '@polkadot/api';
import { ApiContext } from '@polkadot/react-api';
import { createType } from '@polkadot/types';
import { bnMax, u8aToU8a } from '@polkadot/util';
interface SlashSer {
import useApiContext from './useApiContext';
import useCacheKey from './useCacheKey';
interface SerializedSlash {
accountId: string;
amount: string;
}
interface SessionResultSer {
interface Serialized {
blockHash: string;
blockNumber: string;
isEventsEmpty: boolean;
reward: string;
sessionIndex: string;
slashes: SlashSer[];
slashes: SerializedSlash[];
}
// assuming 4 hrs sessions, we grab results for 10 days
const MAX_SESSIONS = 10 * (24 / 4);
function getStorage (storageKey: string): SessionRewards[] {
const sessions: SessionResultSer[] = store.get(storageKey, []);
function fromJSON (sessions: Serialized[]): SessionRewards[] {
return sessions.map(({ blockHash, blockNumber, isEventsEmpty, reward, sessionIndex, slashes }): SessionRewards => ({
blockHash: createType('Hash', blockHash),
blockNumber: createType('BlockNumber', blockNumber),
@ -46,23 +42,18 @@ function getStorage (storageKey: string): SessionRewards[] {
}));
}
function setStorage (storageKey: string, sessions: SessionRewards[], maxSessions: number): SessionResultSer[] {
return store.set(
storageKey,
sessions
.map(({ blockHash, blockNumber, isEventsEmpty, reward, sessionIndex, slashes }): SessionResultSer => ({
blockHash: blockHash.toHex(),
blockNumber: blockNumber.toHex(),
isEventsEmpty,
reward: reward.toHex(),
sessionIndex: sessionIndex.toHex(),
slashes: slashes.map(({ accountId, amount }): SlashSer => ({
accountId: accountId.toString(),
amount: amount.toHex()
}))
}))
.slice(-maxSessions)
);
function toJSON (sessions: SessionRewards[], maxSessions: number): Serialized[] {
return sessions.map(({ blockHash, blockNumber, isEventsEmpty, reward, sessionIndex, slashes }): Serialized => ({
blockHash: blockHash.toHex(),
blockNumber: blockNumber.toHex(),
isEventsEmpty,
reward: reward.toHex(),
sessionIndex: sessionIndex.toHex(),
slashes: slashes.map(({ accountId, amount }): SerializedSlash => ({
accountId: accountId.toString(),
amount: amount.toHex()
}))
})).slice(-maxSessions);
}
function mergeResults (sessions: SessionRewards[], newSessions: SessionRewards[]): SessionRewards[] {
@ -90,7 +81,7 @@ async function loadSome (api: ApiPromise, fromHash: Hash, toHash: Hash): Promise
.then((records): EventRecord[] =>
records.filter(({ event: { section } }): boolean => section === 'staking')
)
.catch((): EventRecord[] => []) // undecodable may throw
.catch((): EventRecord[] => []) // may throw, update metadata for old
)
);
const slashes: Slash[][] = events.map((info): Slash[] =>
@ -117,10 +108,10 @@ async function loadSome (api: ApiPromise, fromHash: Hash, toHash: Hash): Promise
}));
}
export default function useSessionSlashes (maxSessions = MAX_SESSIONS): SessionRewards[] {
const { api } = useContext(ApiContext);
const STORAGE_KEY = `hooks:sessionSlashes:${api.genesisHash}`;
const [results, setResults] = useState<SessionRewards[]>(getStorage(STORAGE_KEY));
export default function useSessionRewards (maxSessions: number): SessionRewards[] {
const { api } = useApiContext();
const [getCache, setCache] = useCacheKey<Serialized[]>('hooks:sessionSlashes');
const [results, setResults] = useState<SessionRewards[]>(fromJSON(getCache() || []));
const [filtered, setFiltered] = useState<SessionRewards[]>([]);
useEffect((): void => {
@ -146,7 +137,7 @@ export default function useSessionSlashes (maxSessions = MAX_SESSIONS): SessionR
toNumber = fromNumber;
fromNumber = bnMax(toNumber.subn(count), new BN(1));
setStorage(STORAGE_KEY, workQueue, maxSessionsStore);
setCache(toJSON(workQueue, maxSessionsStore));
setResults(workQueue);
const lastNumber = workQueue[workQueue.length - 1]?.blockNumber;

View File

@ -2,9 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { HeaderExtended } from '@polkadot/api-derive';
import { ApiContext } from '@polkadot/react-api';
import { useApiContext } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';
interface Authors {
@ -25,7 +25,7 @@ const byAuthor: Record<string, string> = {};
const BlockAuthorsContext: React.Context<Authors> = React.createContext<Authors>({ byAuthor, lastHeaders: [] });
function BlockAuthors ({ children }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [state, setState] = useState<Authors>({ byAuthor, lastHeaders: [] });
useEffect((): void => {

View File

@ -5,8 +5,8 @@
import { BareProps } from '@polkadot/react-api/types';
import React, { useContext } from 'react';
import { ApiContext } from '@polkadot/react-api';
import React from 'react';
import { useApiContext } from '@polkadot/react-hooks';
interface Props extends BareProps {
children?: React.ReactNode;
@ -14,7 +14,7 @@ interface Props extends BareProps {
}
export default function Chain ({ children, className, label = '', style }: Props): React.ReactElement<Props> {
const { systemChain } = useContext(ApiContext);
const { systemChain } = useApiContext();
return (
<div

View File

@ -4,8 +4,8 @@
import { Codec } from '@polkadot/types/types';
import React, { useContext, useEffect, useState } from 'react';
import { ApiContext } from '@polkadot/react-api';
import React, { useEffect, useState } from 'react';
import { useApiContext } from '@polkadot/react-hooks';
import { EventRecord } from '@polkadot/types/interfaces';
import { stringToU8a } from '@polkadot/util';
import { xxhashAsHex } from '@polkadot/util-crypto';
@ -26,7 +26,7 @@ const MAX_EVENTS = 20;
const EventsContext: React.Context<Events> = React.createContext<Events>([]);
function Events ({ children }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [state, setState] = useState<Events>([]);
useEffect((): void => {

View File

@ -5,8 +5,8 @@
import { BareProps } from '@polkadot/react-api/types';
import React, { useContext } from 'react';
import { ApiContext } from '@polkadot/react-api';
import React from 'react';
import { useApiContext } from '@polkadot/react-hooks';
interface Props extends BareProps {
children?: React.ReactNode;
@ -14,7 +14,7 @@ interface Props extends BareProps {
}
export default function NodeName ({ children, className, label = '', style }: Props): React.ReactElement<Props> {
const { systemName } = useContext(ApiContext);
const { systemName } = useApiContext();
return (
<div

View File

@ -5,8 +5,8 @@
import { BareProps } from '@polkadot/react-api/types';
import React, { useContext } from 'react';
import { ApiContext } from '@polkadot/react-api';
import React from 'react';
import { useApiContext } from '@polkadot/react-hooks';
interface Props extends BareProps {
children?: React.ReactNode;
@ -14,7 +14,7 @@ interface Props extends BareProps {
}
export default function NodeVersion ({ children, className, label = '', style }: Props): React.ReactElement<Props> {
const { systemVersion } = useContext(ApiContext);
const { systemVersion } = useApiContext();
return (
<div

View File

@ -9,10 +9,11 @@ import { IExtrinsic } from '@polkadot/types/types';
import { ExtraFees } from './types';
import BN from 'bn.js';
import React, { useContext, useState, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import { Compact, UInt } from '@polkadot/types';
import { ApiContext, withCalls } from '@polkadot/react-api';
import { withCalls } from '@polkadot/react-api';
import { Icon } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { compactToU8a, formatBalance } from '@polkadot/util';
import translate from '../translate';
@ -64,7 +65,7 @@ export const calcTxLength = (extrinsic?: IExtrinsic | null, nonce?: BN, tip?: BN
};
export function FeeDisplay ({ accountId, balances_all = ZERO_BALANCE, balances_fees = ZERO_FEES_BALANCES, className, contract_fees = ZERO_FEES_CONTRACT, extrinsic, isSendable, onChange, t, tip }: Props): React.ReactElement<Props> | null {
const { api } = useContext(ApiContext);
const { api } = useApiContext();
const [state, setState] = useState<State>({
allFees: ZERO,
allTotal: ZERO,