Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s/useApiContext/useApi/ #1900

Merged
merged 1 commit into from
Nov 16, 2019
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
4 changes: 2 additions & 2 deletions packages/app-123code/src/SummaryBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import BN from 'bn.js';
import React from 'react';
import { withCalls } from '@polkadot/react-api';
import { Bubble, IdentityIcon } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';
import { formatBalance, formatNumber } from '@polkadot/util';

import translate from './translate';
Expand All @@ -23,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 } = useApiContext();
const { api, systemChain, systemName, systemVersion } = useApi();

return (
<summary>
Expand Down
4 changes: 2 additions & 2 deletions packages/app-accounts/src/modals/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import React, { useState } from 'react';
import styled from 'styled-components';
import { DEV_PHRASE } from '@polkadot/keyring/defaults';
import { AddressRow, Button, Dropdown, Input, InputAddress, Modal, Password } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';
import keyring from '@polkadot/ui-keyring';
import uiSettings from '@polkadot/ui-settings';
import { isHex, u8aToHex } from '@polkadot/util';
Expand Down Expand Up @@ -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 } = useApiContext();
const { isDevelopment } = useApi();
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: '' });
Expand Down
4 changes: 2 additions & 2 deletions packages/app-accounts/src/modals/Transfer.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 { Button, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';
import { Available } from '@polkadot/react-query';
import Checks from '@polkadot/react-signer/Checks';

Expand Down Expand Up @@ -65,7 +65,7 @@ const ZERO = new BN(0);
// }

function Transfer ({ className, onClose, recipientId: propRecipientId, senderId: propSenderId, t }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const { api } = useApi();
const [amount, setAmount] = useState<BN | undefined>(new BN(0));
const [extrinsic, setExtrinsic] = useState<SubmittableExtrinsic | null>(null);
const [hasAvailable, setHasAvailable] = useState(true);
Expand Down
4 changes: 2 additions & 2 deletions packages/app-claims/src/Claim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { I18nProps } from '@polkadot/react-components/types';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { Button, Card } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';

import translate from './translate';
Expand All @@ -21,7 +21,7 @@ interface Props extends I18nProps {
}

function Claim ({ button, className, ethereumAddress, t }: Props): React.ReactElement<Props> | null {
const { api } = useApiContext();
const { api } = useApi();
const [claimValue, setClaimValue] = useState<BalanceOf | null>(null);
const [claimAddress, setClaimAddress] = useState<EthereumAddress | null>(null);
const [isBusy, setIsBusy] = useState(false);
Expand Down
4 changes: 2 additions & 2 deletions packages/app-explorer/src/Forks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Header } from '@polkadot/types/interfaces';
import React, { useEffect, useRef, useState } from 'react';
import styled from 'styled-components';
import { CardSummary, IdentityIcon, SummaryBox } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';

import translate from './translate';
Expand Down Expand Up @@ -204,7 +204,7 @@ function renderRows (rows: Row[]): React.ReactNode[] {
}

function Forks ({ className, t }: Props): React.ReactElement<Props> | null {
const { api } = useApiContext();
const { api } = useApi();
const [tree, setTree] = useState<Link | null>(null);
const childrenRef = useRef<Map<string, string[]>>(new Map([['root', []]]));
const countRef = useRef({ numBlocks: 0, numForks: 0 });
Expand Down
4 changes: 2 additions & 2 deletions packages/app-explorer/src/NodeInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Info } from './types';

import React, { useEffect, useState } from 'react';
import { ApiPromise } from '@polkadot/api';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';

import Extrinsics from '../BlockInfo/Extrinsics';
import Peers from './Peers';
Expand All @@ -32,7 +32,7 @@ async function retrieveInfo (api: ApiPromise): Promise<Partial<Info>> {
}

function NodeInfo ({ t }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const { api } = useApi();
const [info, setInfo] = useState<Partial<Info>>({});
const [nextRefresh, setNextRefresh] = useState(Date.now());

Expand Down
4 changes: 2 additions & 2 deletions packages/app-explorer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { useContext } from 'react';
import { Route, Switch } from 'react-router';
import styled from 'styled-components';
import Tabs from '@polkadot/react-components/Tabs';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';
import { BlockAuthorsContext, EventsContext } from '@polkadot/react-query';
import uiSettings from '@polkadot/ui-settings';

Expand All @@ -24,7 +24,7 @@ interface Props extends AppProps, BareProps, I18nProps {
}

function ExplorerApp ({ basePath, className, t }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const { api } = useApi();
const { lastHeaders } = useContext(BlockAuthorsContext);
const events = useContext(EventsContext);

Expand Down
4 changes: 2 additions & 2 deletions packages/app-generic-asset/src/Transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import BN from 'bn.js';
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 { useApi } from '@polkadot/react-hooks';
import { Available } from '@polkadot/react-query';
import Checks from '@polkadot/react-signer/Checks';
import { withMulti, withObservable } from '@polkadot/react-api';
Expand All @@ -31,7 +31,7 @@ interface Option {
}

function Transfer ({ assets, className, onClose, recipientId: propRecipientId, senderId: propSenderId, t }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const { api } = useApi();
const [assetId, setAssetId] = useState('0');
const [amount, setAmount] = useState<BN | undefined>(new BN(0));
const [extrinsic, setExtrinsic] = useState<SubmittableExtrinsic | null>(null);
Expand Down
4 changes: 2 additions & 2 deletions packages/app-js/src/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Transition } from 'semantic-ui-react';
import snappy from 'snappyjs';
import styled from 'styled-components';
import { Button, Dropdown, Editor } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';
import uiKeyring from '@polkadot/ui-keyring';
import * as types from '@polkadot/types';
import * as util from '@polkadot/util';
Expand Down Expand Up @@ -80,7 +80,7 @@ function decodeBase64 (base64: string): Snippet {

// FIXME This... ladies & gentlemen, is a mess that should be untangled
function Playground ({ className, t }: Props): React.ReactElement<Props> {
const { api, isDevelopment } = useApiContext();
const { api, isDevelopment } = useApi();
const history = useHistory();
const { base64 } = useParams();
const injectedRef = useRef<Injected | null>(null);
Expand Down
4 changes: 2 additions & 2 deletions packages/app-staking/src/Actions/Account/SetSessionKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { I18nProps } from '@polkadot/react-components/types';

import React, { useState } from 'react';
import { Button, InputAddress, Input, Modal, TxButton } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';

import ValidationSessionKey from './InputValidationSessionKey';
import translate from '../../translate';
Expand All @@ -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 } = useApiContext();
const { isSubstrateV2 } = useApi();
const [keysError, setKeysError] = useState<string | null>(null);
const [keys, setKeys] = useState<string | null>(
isSubstrateV2
Expand Down
4 changes: 2 additions & 2 deletions packages/app-staking/src/Actions/Accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ComponentProps } from '../types';
import React, { useState } from 'react';
import styled from 'styled-components';
import { Button, CardGrid } from '@polkadot/react-components';
import { trackStream, useApiContext } from '@polkadot/react-hooks';
import { trackStream, useApi } 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 @@ -45,7 +45,7 @@ function getMyStashes (allAccounts: string[], queryBonded?: Option<AccountId>[],
}

function Accounts ({ allAccounts, allStashes, className, recentlyOnline, t }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const { api } = useApi();
const queryBonded = trackStream<Option<AccountId>[]>(api.query.staking.bonded.multi as any, [allAccounts]);
const queryLedger = trackStream<Option<StakingLedger>[]>(api.query.staking.ledger.multi as any, [allAccounts]);
const [isNewStakeOpen, setIsNewStateOpen] = useState(false);
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 @@ -12,7 +12,7 @@ import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { AddressCard, AddressMini, Badge, Expander, Icon } from '@polkadot/react-components';
import { classes } from '@polkadot/react-components/util';
import { trackStream, useApiContext } from '@polkadot/react-hooks';
import { trackStream, useApi } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';

import translate from '../translate';
Expand Down Expand Up @@ -47,7 +47,7 @@ interface StakingState {
const WITH_VALIDATOR_PREFS = { validatorPayment: true };

function Address ({ address, authorsMap, className, defaultName, filter, hasQueries, isElected, isFavorite, lastAuthors, myAccounts, points, recentlyOnline, t, toggleFavorite, withNominations = true }: Props): React.ReactElement<Props> | null {
const { api, isSubstrateV2 } = useApiContext();
const { api, isSubstrateV2 } = useApi();
// FIXME Any horrors, caused by derive type mismatches
const stakingInfo = trackStream<DerivedStaking>(api.derive.staking.info as any, [address]);
const [extraInfo, setExtraInfo] = useState<[React.ReactNode, React.ReactNode][] | undefined>();
Expand Down
4 changes: 2 additions & 2 deletions packages/app-staking/src/Overview/CurrentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ValidatorFilter } from '../types';

import React, { useEffect, useState } from 'react';
import { Columar, Column, Dropdown, FilterOverlay } from '@polkadot/react-components';
import { useApiContext, useFavorites } from '@polkadot/react-hooks';
import { useApi, useFavorites } from '@polkadot/react-hooks';
import keyring from '@polkadot/ui-keyring';

import { STORE_FAVS_BASE } from '../constants';
Expand Down Expand Up @@ -57,7 +57,7 @@ function accountsToString (accounts: AccountId[]): string[] {
}

function CurrentList ({ authorsMap, hasQueries, lastAuthors, next, recentlyOnline, stakingOverview, t }: Props): React.ReactElement<Props> {
const { isSubstrateV2 } = useApiContext();
const { isSubstrateV2 } = useApi();
const [favorites, toggleFavorite] = useFavorites(STORE_FAVS_BASE);
const [filter, setFilter] = useState<ValidatorFilter>('all');
const [myAccounts] = useState(keyring.getAccounts().map(({ address }): string => address));
Expand Down
4 changes: 2 additions & 2 deletions packages/app-staking/src/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BareProps } from '@polkadot/react-components/types';
import { ComponentProps } from '../types';

import React, { useContext, useEffect, useState } from 'react';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';
import { BlockAuthorsContext } from '@polkadot/react-query';

import CurrentList from './CurrentList';
Expand All @@ -15,7 +15,7 @@ import Summary from './Summary';
interface Props extends BareProps, ComponentProps {}

export default function Overview ({ allControllers, hasQueries, allStashes, className, recentlyOnline, stakingOverview }: Props): React.ReactElement<Props> {
const { isSubstrateV2 } = useApiContext();
const { isSubstrateV2 } = useApi();
const { byAuthor, lastBlockAuthors, lastBlockNumber } = useContext(BlockAuthorsContext);
const [next, setNext] = useState<string[]>([]);
const validators = stakingOverview && stakingOverview.validators;
Expand Down
4 changes: 2 additions & 2 deletions packages/app-staking/src/Query/Validator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, { useEffect, useState } from 'react';
import { Chart, Columar, Column } from '@polkadot/react-components';
import { toShortAddress } from '@polkadot/react-components/util';
import { getHistoric } from '@polkadot/react-api/util';
import { trackStream, useApiContext } from '@polkadot/react-hooks';
import { trackStream, useApi } from '@polkadot/react-hooks';
import { u32 } from '@polkadot/types';
import { formatBalance, formatNumber } from '@polkadot/util';

Expand Down Expand Up @@ -91,7 +91,7 @@ function extractEraSlash (validatorId: string, slashes: Slash[]): BN {
}

function Validator ({ className, sessionRewards, t, validatorId }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const { api } = useApi();
// FIXME There is something seriously wrong in these two with "any" horrors
const blockCounts = trackStream<u32[]>(api.query.imOnline?.authoredBlocks?.multi as any, [sessionRewards, validatorId], {
paramMap: ([sessionRewards, validatorId]: [SessionRewards[], string]): any =>
Expand Down
4 changes: 2 additions & 2 deletions packages/app-staking/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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 { trackStream, useAccounts, useApiContext, useSessionRewards } from '@polkadot/react-hooks';
import { trackStream, useAccounts, useApi, useSessionRewards } from '@polkadot/react-hooks';

import Accounts from './Actions/Accounts';
import basicMd from './md/basic.md';
Expand All @@ -39,7 +39,7 @@ function transformStakingControllers ([stashes, controllers]: [AccountId[], Opti
}

function App ({ basePath, className, t }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const { api } = useApi();
const { allAccounts, hasAccounts } = useAccounts();
const stakingControllers = trackStream<[string[], string[]]>(api.derive.staking.controllers, [], { transform: transformStakingControllers });
const bestNumber = trackStream<BlockNumber>(api.derive.chain.bestNumber, []);
Expand Down
4 changes: 2 additions & 2 deletions packages/app-storage/src/Selection/Consts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { ComponentProps } from '../types';

import React, { useState } from 'react';
import { Button, InputConsts } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';

import translate from '../translate';

interface Props extends ComponentProps, I18nProps {}

function Consts ({ onAdd, t }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const { api } = useApi();
const [defaultValue] = useState<ConstValue>((): ConstValue => {
const section = Object.keys(api.consts)[0];
const method = Object.keys(api.consts[section])[0];
Expand Down
4 changes: 2 additions & 2 deletions packages/app-storage/src/Selection/Modules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, { useState } from 'react';
import { getTypeDef } from '@polkadot/types';
import { Button, InputStorage } from '@polkadot/react-components';
import Params from '@polkadot/react-params';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';
import { isNull, isUndefined } from '@polkadot/util';

import translate from '../translate';
Expand All @@ -32,7 +32,7 @@ function areParamsValid (values: RawParams): boolean {
}

function Modules ({ onAdd, t }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const { api } = useApi();
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: [] });

Expand Down
4 changes: 2 additions & 2 deletions packages/app-storage/src/Selection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ComponentProps, QueryTypes, ParitalQueryTypes } from '../types';
import React from 'react';
import { Route, Switch } from 'react-router';
import { Tabs } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';

import Consts from './Consts';
import Modules from './Modules';
Expand All @@ -23,7 +23,7 @@ interface Props extends I18nProps {
let id = -1;

function Selection ({ basePath, onAdd, t }: Props): React.ReactElement<Props> {
const { isSubstrateV2 } = useApiContext();
const { isSubstrateV2 } = useApi();
const _onAdd = (query: ParitalQueryTypes): void => onAdd({ ...query, id: ++id });
const _renderComponent = (Component: React.ComponentType<ComponentProps>): () => React.ReactNode =>
// eslint-disable-next-line react/display-name
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 { trackStream, useAccounts, useApiContext } from '@polkadot/react-hooks';
import { trackStream, useAccounts, useApi } from '@polkadot/react-hooks';

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

function App ({ basePath, t }: Props): React.ReactElement<Props> {
const { api } = useApiContext();
const { api } = useApi();
const sudoKey = trackStream<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/apps/src/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useLocation } from 'react-router-dom';
import styled from 'styled-components';
import routing from '@polkadot/apps-routing';
import { StatusContext } from '@polkadot/react-components';
import { useApiContext } from '@polkadot/react-hooks';
import { useApi } from '@polkadot/react-hooks';

import Status from './Status';
import translate from '../translate';
Expand All @@ -25,7 +25,7 @@ const unknown = {

function Content ({ className, t }: Props): React.ReactElement<Props> {
const location = useLocation();
const { isApiConnected, isApiReady } = useApiContext();
const { isApiConnected, isApiReady } = useApi();
const { queueAction, stqueue, txqueue } = useContext(StatusContext);
const app = location.pathname.slice(1) || '';
const { Component, display: { needsApi }, name } = routing.routes.find((route): boolean =>
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/src/SideBar/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { NavLink } from 'react-router-dom';
import { ApiPromise } from '@polkadot/api';
import { Icon, Menu, Tooltip } from '@polkadot/react-components';
import { withCalls, withMulti } from '@polkadot/react-api';
import { useAccounts, useApiContext } from '@polkadot/react-hooks';
import { useAccounts, useApi } from '@polkadot/react-hooks';
import { isFunction } from '@polkadot/util';

import translate from '../translate';
Expand Down Expand Up @@ -76,7 +76,7 @@ function checkVisible (name: string, { api, isApiReady, isApiConnected }: ApiPro

function Item ({ route: { Modal, display, i18n, icon, name }, t, isCollapsed, onClick, sudoKey }: Props): React.ReactElement<Props> | null {
const { allAccounts, hasAccounts } = useAccounts();
const apiProps = useApiContext();
const apiProps = useApi();
const [hasSudo, setHasSudo] = useState(false);
const [isVisible, setIsVisible] = useState(false);

Expand Down
Loading