From a6d2dcaf725bc8112575e596983a884dcd8c8b85 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 15 Oct 2019 10:07:54 +0200 Subject: [PATCH] Expose and use StatusContext (#1725) --- .../src/Actions/Account/InjectKeys.tsx | 5 ++- packages/apps/src/Content/index.tsx | 36 +++++++++---------- packages/react-components/src/CopyButton.tsx | 4 +-- .../react-components/src/Status/index.tsx | 4 +-- packages/react-components/src/index.tsx | 2 +- packages/react-signer/src/index.tsx | 4 +-- 6 files changed, 25 insertions(+), 30 deletions(-) diff --git a/packages/app-staking/src/Actions/Account/InjectKeys.tsx b/packages/app-staking/src/Actions/Account/InjectKeys.tsx index e3386b3fe5..fde36a3ae8 100644 --- a/packages/app-staking/src/Actions/Account/InjectKeys.tsx +++ b/packages/app-staking/src/Actions/Account/InjectKeys.tsx @@ -6,8 +6,7 @@ import { I18nProps } from '@polkadot/react-components/types'; import { KeypairType } from '@polkadot/util-crypto/types'; import React, { useContext, useEffect, useState } from 'react'; -import { Button, Dropdown, Icon, Input, Modal } from '@polkadot/react-components'; -import { QueueContext } from '@polkadot/react-components/Status'; +import { Button, Dropdown, Icon, Input, Modal, StatusContext } from '@polkadot/react-components'; import keyring from '@polkadot/ui-keyring'; import { assert, u8aToHex } from '@polkadot/util'; import { keyExtractSuri, mnemonicValidate } from '@polkadot/util-crypto'; @@ -30,7 +29,7 @@ const CRYPTO_MAP: Record = { const EMPTY_KEY = '0x'; function InjectKeys ({ isOpen = true, onClose, t }: Props): React.ReactElement | null { - const { queueRpc } = useContext(QueueContext); + const { queueRpc } = useContext(StatusContext); // this needs to align with what is set as the first value in `type` const [crypto, setCrypto] = useState('sr25519'); const [publicKey, setPublicKey] = useState(EMPTY_KEY); diff --git a/packages/apps/src/Content/index.tsx b/packages/apps/src/Content/index.tsx index 0f5292d437..e6f2a9dfd0 100644 --- a/packages/apps/src/Content/index.tsx +++ b/packages/apps/src/Content/index.tsx @@ -4,14 +4,13 @@ import { I18nProps } from '@polkadot/react-components/types'; import { ApiProps } from '@polkadot/react-api/types'; -import { QueueProps } from '@polkadot/react-components/Status/types'; -import React from 'react'; +import React, { useContext } from 'react'; import { withRouter, RouteComponentProps } from 'react-router'; import styled from 'styled-components'; import routing from '@polkadot/apps-routing'; import { withCalls, withMulti } from '@polkadot/react-api'; -import { QueueConsumer } from '@polkadot/react-components/Status/Context'; +import { StatusContext } from '@polkadot/react-components'; import Status from './Status'; import translate from '../translate'; @@ -27,7 +26,8 @@ const unknown = { name: '' }; -function Content ({ isApiConnected, isApiReady, className, location, t, i18n }: Props): React.ReactElement { +function Content ({ isApiConnected, isApiReady, className, location, t }: Props): React.ReactElement { + const { queueAction, stqueue, txqueue } = useContext(StatusContext); const app = location.pathname.slice(1) || ''; const { Component, display: { needsApi }, name } = routing.routes.find((route): boolean => !!(route && app.startsWith(route.name)) @@ -38,22 +38,18 @@ function Content ({ isApiConnected, isApiReady, className, location, t, i18n }: {needsApi && (!isApiReady || !isApiConnected) ?
{t('Waiting for API to be connected and ready.')}
: ( - - {({ queueAction, stqueue, txqueue }: QueueProps): React.ReactNode => ( - <> - - - - )} - + <> + + + ) } diff --git a/packages/react-components/src/CopyButton.tsx b/packages/react-components/src/CopyButton.tsx index f1f548dd31..9a35ee7592 100644 --- a/packages/react-components/src/CopyButton.tsx +++ b/packages/react-components/src/CopyButton.tsx @@ -7,7 +7,7 @@ import { BareProps, I18nProps } from './types'; import React, { useContext } from 'react'; import CopyToClipboard from 'react-copy-to-clipboard'; -import QueueContext from './Status/Context'; +import StatusContext from './Status/Context'; import Button from './Button'; import translate from './translate'; import styled from 'styled-components'; @@ -20,7 +20,7 @@ interface Props extends BareProps, I18nProps { } function CopyButton ({ children, className, icon = 'copy', isAddress = false, t, value }: Props): React.ReactElement { - const { queueAction } = useContext(QueueContext); + const { queueAction } = useContext(StatusContext); const _onCopy = (): void => { isAddress && queueAction && queueAction({ diff --git a/packages/react-components/src/Status/index.tsx b/packages/react-components/src/Status/index.tsx index aea516d390..61952f6926 100644 --- a/packages/react-components/src/Status/index.tsx +++ b/packages/react-components/src/Status/index.tsx @@ -14,10 +14,10 @@ import Button from '../Button'; import Icon from '../Icon'; import translate from '../translate'; import { classes } from '../util'; -import QueueContext from './Context'; +import StatusContext from './Context'; import { STATUS_COMPLETE } from './constants'; -export { QueueContext }; +export { StatusContext }; interface Props extends I18nProps { stqueue?: QueueStatus[]; diff --git a/packages/react-components/src/index.tsx b/packages/react-components/src/index.tsx index 37250e8303..816912b6e2 100644 --- a/packages/react-components/src/index.tsx +++ b/packages/react-components/src/index.tsx @@ -63,7 +63,7 @@ export { default as ProposedAction } from './ProposedAction'; export { default as OnlineStatus } from './OnlineStatus'; export { default as Row } from './Row'; export { default as Static } from './Static'; -export { default as Status } from './Status'; +export { default as Status, StatusContext } from './Status'; export { default as SummaryBox } from './SummaryBox'; export { default as Tabs } from './Tabs'; export { default as Toggle } from './Toggle'; diff --git a/packages/react-signer/src/index.tsx b/packages/react-signer/src/index.tsx index 0d6902096e..6cf56857cb 100644 --- a/packages/react-signer/src/index.tsx +++ b/packages/react-signer/src/index.tsx @@ -7,7 +7,7 @@ import { BareProps } from '@polkadot/react-components/types'; import './index.css'; import React, { useContext } from 'react'; -import QueueContext from '@polkadot/react-components/Status/Context'; +import { StatusContext } from '@polkadot/react-components'; import Modal from './Modal'; @@ -16,7 +16,7 @@ interface Props extends BareProps { } export default function Signer ({ children, className, style }: Props): React.ReactElement { - const { txqueue, queueSetTxStatus } = useContext(QueueContext); + const { txqueue, queueSetTxStatus } = useContext(StatusContext); return ( <>