diff --git a/packages/apps/src/overlays/Accounts.tsx b/packages/apps/src/overlays/Accounts.tsx index f15c66decc81..64340ed2db31 100644 --- a/packages/apps/src/overlays/Accounts.tsx +++ b/packages/apps/src/overlays/Accounts.tsx @@ -4,7 +4,6 @@ import React, { useState } from 'react'; import { Link } from 'react-router-dom'; -import styled from 'styled-components'; import { useAccounts, useApi } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; @@ -14,7 +13,7 @@ interface Props { className?: string; } -function Accounts ({ className }: Props): React.ReactElement | null { +export default function Accounts ({ className }: Props): React.ReactElement | null { const { t } = useTranslation(); const { hasAccounts } = useAccounts(); const { isApiReady } = useApi(); @@ -30,6 +29,7 @@ function Accounts ({ className }: Props): React.ReactElement | null {

{t("You don't have any accounts. Some features are currently hidden and will only become available once you have accounts.")}

@@ -43,9 +43,3 @@ function Accounts ({ className }: Props): React.ReactElement | null { ); } - -export default styled(Accounts)` - background: #fff6cb; - border-color: #e7c000; - color: #6b5900; -`; diff --git a/packages/apps/src/overlays/Base.tsx b/packages/apps/src/overlays/Base.tsx index 3dbad2da3e5c..1a6049b7feba 100644 --- a/packages/apps/src/overlays/Base.tsx +++ b/packages/apps/src/overlays/Base.tsx @@ -10,9 +10,10 @@ interface Props { children: React.ReactNode; className?: string; icon: string; + type: 'error' | 'info'; } -function BaseOverlay ({ children, className, icon }: Props): React.ReactElement | null { +function BaseOverlay ({ children, className, icon, type }: Props): React.ReactElement | null { const [isHidden, setIsHidden] = useState(false); if (isHidden) { @@ -22,7 +23,7 @@ function BaseOverlay ({ children, className, icon }: Props): React.ReactElement< const _onClose = (): void => setIsHidden(true); return ( -

+
| null { +export default function Connecting ({ className }: Props): React.ReactElement | null { const { t } = useTranslation(); const { isApiConnected, isWaitingInjected } = useApi(); @@ -28,33 +27,27 @@ function Connecting ({ className }: Props): React.ReactElement | null {
{t('Waiting for authorization from the extension. Please open the installed extension and approve or reject access.')}
); + } else if (!isApiConnected) { + return ( + +
{t('You are not connected to a node. Ensure that your node is running and that the Websocket endpoint is reachable.')}
+ { + isWs && !isWsLocal && isHttps + ?
{t('You are connecting from a secure location to an insecure WebSocket ({{wsUrl}}). Due to browser mixed-content security policies this connection type is not allowed. Change the RPC service to a secure \'wss\' endpoint.', { replace: { wsUrl } })}
+ : undefined + } +
+ ); } - if (isApiConnected) { - return null; - } - - return ( - -
{t('You are not connected to a node. Ensure that your node is running and that the Websocket endpoint is reachable.')}
- { - isWs && !isWsLocal && isHttps - ?
{t('You are connecting from a secure location to an insecure WebSocket ({{wsUrl}}). Due to browser mixed-content security policies this connection type is not allowed. Change the RPC service to a secure \'wss\' endpoint.', { replace: { wsUrl } })}
- : undefined - } -
- ); + return null; } - -export default styled(Connecting)` - background: #ffe6e6; - border-color: #c00; - color: #4d0000; -`; diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 25873989ffbe..f1f677d40b09 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -113,6 +113,7 @@ async function loadOnReady (api: ApiPromise): Promise { export default function Api ({ children, queuePayload, queueSetTxStatus, url }: Props): React.ReactElement | null { const [state, setState] = useState({ isApiReady: false } as Partial as State); const [isApiConnected, setIsApiConnected] = useState(false); + const [isApiLoading, setIsApiLoading] = useState(true); const [isWaitingInjected, setIsWaitingInjected] = useState(isWeb3Injected); // initial initialization @@ -135,11 +136,13 @@ export default function Api ({ children, queuePayload, queueSetTxStatus, url }: injectedPromise .then((): void => setIsWaitingInjected(false)) .catch((error: Error) => console.error(error)); + + setIsApiLoading(false); }, []); return api ? ( - + {children} ) diff --git a/packages/react-api/src/types.ts b/packages/react-api/src/types.ts index c7cbe40becb9..3be76df67d71 100644 --- a/packages/react-api/src/types.ts +++ b/packages/react-api/src/types.ts @@ -30,6 +30,7 @@ export interface ApiProps extends ApiState { api: ApiPromise; isWaitingInjected: boolean; isApiConnected: boolean; + isApiLoading: boolean; } export interface OnChangeCbObs {