Claim banner on accounts (#2834)

* Claim banner on accounts

* Banner

* red background

* typo
This commit is contained in:
Jaco Greeff 2020-05-27 16:18:52 +02:00 committed by GitHub
parent ea0a0b3ff1
commit 88abae4682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 108 additions and 47 deletions

View File

@ -2,59 +2,21 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { detect } from 'detect-browser';
import React from 'react';
import styled from 'styled-components';
import { availableExtensions } from '@polkadot/apps-config/extensions';
import { isWeb3Injected } from '@polkadot/extension-dapp';
import { stringUpperFirst } from '@polkadot/util';
import { useTranslation } from '../translate';
// it would have been really good to import this from detect, however... not exported
type Browser = 'chrome' | 'firefox';
interface Props {
children: React.ReactNode;
className?: string;
type: 'warning' | 'error';
}
const browserInfo = detect();
const browserName: Browser | null = (browserInfo && (browserInfo.name as Browser)) || null;
const isSupported = browserName && Object.keys(availableExtensions).includes(browserName);
function Banner ({ className }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
if (isWeb3Injected || !isSupported || !browserName) {
return null;
}
function Banner ({ children, className = '', type }: Props): React.ReactElement<Props> | null {
return (
<div className={className}>
<div className={`${className} ${type}`}>
<div className='box'>
<div className='info'>
<p>{t<string>('It is recommended that you create/store your accounts securely and externally from the app. On {{yourBrowser}} the following browser extensions are available for use -', {
replace: {
yourBrowser: stringUpperFirst(browserName)
}
})}</p>
<ul>{availableExtensions[browserName].map(({ desc, link, name }): React.ReactNode => (
<li key={name}>
<a
href={link}
rel='noopener noreferrer'
target='_blank'
>
{name}
</a> ({t(desc)})
</li>
))
}</ul>
<p>{t<string>('Accounts injected from any of these extensions will appear in this application and be available for use. The above list is updated as more extensions with external signing capability become available.')}&nbsp;<a
href='https://github.com/polkadot-js/extension'
rel='noopener noreferrer'
target='_blank'
>{t<string>('Learn more...')}</a></p>
{children}
</div>
</div>
</div>
@ -64,9 +26,24 @@ function Banner ({ className }: Props): React.ReactElement<Props> | null {
export default React.memo(styled(Banner)`
padding: 0 0.5rem 0.5rem;
&.error {
.box {
background: #fdd;
border-left-color: #9f3a38;
color: #9f3a38;
}
}
&.warning {
.box {
background: #fff6e5;
border-left-color: darkorange;
}
}
.box {
background: #fff6e5;
border-left: 0.25rem solid darkorange;
border-left-style: solid;
border-left-width: 0.25rem;
border-radius: 0 0.25rem 0.25rem 0;
box-sizing: border-box;
padding: 1rem 1.5rem;

View File

@ -0,0 +1,26 @@
// Copyright 2017-2020 @polkadot/app-accounts 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 React from 'react';
import useClaimCounter from '@polkadot/app-claims/useCounter'; // exceptionally CRAP idea
import { useTranslation } from '../translate';
import Banner from './Banner';
function BannerExtension (): React.ReactElement | null {
const claimCount = useClaimCounter();
const { t } = useTranslation();
if (!claimCount) {
return null;
}
return (
<Banner type='error'>
<p>{t<string>('You have {{claimCount}} accounts that need attestations. Use the Claim Tokens app on the left navigation bar to complete the process. Until you do, your balances for those accounts will not be reflected.', { replace: { claimCount } })}</p>
</Banner>
);
}
export default React.memo(BannerExtension);

View File

@ -0,0 +1,56 @@
// Copyright 2017-2020 @polkadot/app-accounts 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 { detect } from 'detect-browser';
import React from 'react';
import { availableExtensions } from '@polkadot/apps-config/extensions';
import { isWeb3Injected } from '@polkadot/extension-dapp';
import { stringUpperFirst } from '@polkadot/util';
import { useTranslation } from '../translate';
import Banner from './Banner';
// it would have been really good to import this from detect, however... not exported
type Browser = 'chrome' | 'firefox';
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 {
const { t } = useTranslation();
if (isWeb3Injected || !isSupported || !browserName) {
return null;
}
return (
<Banner type='warning'>
<p>{t<string>('It is recommended that you create/store your accounts securely and externally from the app. On {{yourBrowser}} the following browser extensions are available for use -', {
replace: {
yourBrowser: stringUpperFirst(browserName)
}
})}</p>
<ul>{availableExtensions[browserName].map(({ desc, link, name }): React.ReactNode => (
<li key={name}>
<a
href={link}
rel='noopener noreferrer'
target='_blank'
>
{name}
</a> ({t(desc)})
</li>
))
}</ul>
<p>{t<string>('Accounts injected from any of these extensions will appear in this application and be available for use. The above list is updated as more extensions with external signing capability become available.')}&nbsp;<a
href='https://github.com/polkadot-js/extension'
rel='noopener noreferrer'
target='_blank'
>{t<string>('Learn more...')}</a></p>
</Banner>
);
}
export default React.memo(BannerExtension);

View File

@ -22,7 +22,8 @@ import ImportModal from './modals/Import';
import Multisig from './modals/MultisigCreate';
import QrModal from './modals/Qr';
import Account from './Account';
import Banner from './Banner';
import BannerClaims from './BannerClaims';
import BannerExtension from './BannerExtension';
interface Balances {
accounts: Record<string, BN>;
@ -159,7 +160,8 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
return (
<div className={className}>
<Banner />
<BannerExtension />
<BannerClaims />
{isCreateOpen && (
<CreateModal
onClose={toggleCreate}