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

A0-2318: Update the no-extension warning #77

Merged
merged 5 commits into from
Aug 11, 2023
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
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ module.exports = {
// this seems very broken atm, false positives
'@typescript-eslint/unbound-method': 'off',
'header/header' : 'off',
'react/jsx-newline': 'off',
}
};
48 changes: 43 additions & 5 deletions packages/page-accounts/src/Accounts/BannerExtension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

import { detect } from 'detect-browser';
import React, { useRef } from 'react';
import React from 'react';
import { Trans } from 'react-i18next';

import useExtensionCounter from '@polkadot/app-settings/useCounter';
import { availableExtensions } from '@polkadot/apps-config';
import { isWeb3Injected } from '@polkadot/extension-dapp';
import { onlyOnWeb } from '@polkadot/react-api/hoc';
import { styled } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';

import { useTranslation } from '../translate.js';
Expand All @@ -21,11 +22,10 @@ const browserInfo = detect();
const browserName: Browser | null = (browserInfo && (browserInfo.name as Browser)) || null;
const isSupported = browserName && Object.keys(availableExtensions).includes(browserName);

function BannerExtension (): React.ReactElement | null {
function ExtensionWarning (): React.ReactElement | null {
const { t } = useTranslation();
const { hasInjectedAccounts } = useApi();
const upgradableCount = useExtensionCounter();
const phishing = useRef<string>(t<string>('Since some extensions, such as the polkadot-js extension, protects you against all community reported phishing sites, there are valid reasons to use them for additional protection, even if you are not storing accounts in it.'));

if (!isSupported || !browserName || !isWeb3Injected) {
return null;
Expand Down Expand Up @@ -53,10 +53,48 @@ function BannerExtension (): React.ReactElement | null {
return (
<Banner type='warning'>
<p>{t<string>('One or more extensions are detected in your browser, however no accounts have been injected.')}</p>
<p>{t<string>('Ensure that the extension has accounts, some accounts are visible globally and available for this chain and that you gave the application permission to access accounts from the extension to use them.')}</p>
<p>{phishing.current}</p>
<p>
{t<string>('Ensure that:')}
<SafetyInfoList>
<li>{t<string>('the extension has accounts,')}</li>
<li>{t<string>('at least one account is available for this chain,')}</li>
<li>{t<string>('the extension allows azero.dev to access accounts')}</li>
</SafetyInfoList>
</p>
</Banner>
);
}

function BannerExtension () {
const { t } = useTranslation();

return (
<>
<ExtensionWarning />
<Banner type='warning'>
<p>
{t<string>('For extra protection, consider using the')}
&nbsp;
<a
href='https://chrome.google.com/webstore/detail/threatslayer/mgcmocglffknmbhhfjihifeldhghihpj'
rel='noreferrer'
target='_blank'
>
Threat Slayer
</a>
&nbsp;
{t<string>('extension which protects you from dangerous websites in real-time.')}
</p>

</Banner>
</>
);
}

export default onlyOnWeb(React.memo(BannerExtension));

const SafetyInfoList = styled.ul`
margin-block: 0;
padding-left: 20px;
list-style-type: '- ';
`;