ghost-portal/packages/react-components/src/ChainImg.tsx
Jaco Greeff c60ba8708a
Bumps w/ eslint (#2802)
* Bumps w/ eslint

* Additional

* Additional

* Additional

* Additional

* Remove style props

* Additional

* Additional

* Additional

* Additional (< 100)

* eslint passes, tsc next

* tsc fixes

* Update deps

* Update i18n
2020-05-24 19:41:14 +02:00

40 lines
1.2 KiB
TypeScript

// Copyright 2017-2020 @polkadot/apps 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, { useMemo } from 'react';
import styled from 'styled-components';
import { chainLogos, emptyLogo, namedLogos, nodeLogos } from '@polkadot/apps-config/ui/logos';
import { useApi } from '@polkadot/react-hooks';
interface Props {
className?: string;
logo?: keyof typeof namedLogos;
onClick?: () => any;
}
function sanitize (value?: string): string {
return value?.toLowerCase().replace('-', ' ') || '';
}
function ChainImg ({ className = '', logo, onClick }: Props): React.ReactElement<Props> {
const { systemChain, systemName } = useApi();
const img = useMemo((): string => {
return (namedLogos[logo || ''] || chainLogos[sanitize(systemChain)] || nodeLogos[sanitize(systemName)] || emptyLogo) as string;
}, [logo, systemChain, systemName]);
return (
<img
alt='chain logo'
className={className}
onClick={onClick}
src={img}
/>
);
}
export default React.memo(styled(ChainImg)`
border-radius: 50%;
box-sizing: border-box;
`);