// Copyright 2017-2019 @polkadot/react-components 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 { I18nProps } from './types'; import React from 'react'; import styled from 'styled-components'; import { useApi } from '@polkadot/react-hooks'; import translate from './translate'; export type LinkTypes = 'address' | 'block' | 'extrinsic'; interface Props extends I18nProps { className?: string; data: string; type: LinkTypes; } const BASE = 'https://polkascan.io/pre/'; const CHAINS: Record = { Alexander: 'alexander', Kusama: 'kusama-cc1', // old name via W3F nodes 'Kusama CC1': 'kusama-cc1', 'Kusama CC2': 'kusama-cc2', 'Kusama CC3': 'kusama-cc3' }; const TYPES: Record = { address: '/module/account/', block: '/system/block/', extrinsic: '/system/extrinsic/' }; function LinkPolkascan ({ className, data, t, type }: Props): React.ReactElement | null { const { systemChain } = useApi(); const extChain = CHAINS[systemChain]; const extType = TYPES[type]; if (!extChain || !extType) { return null; } return (
{t('View this {{type}} on Polkascan.io', { replace: { type } })}
); } export default translate( styled(LinkPolkascan)` margin-top: 1rem; text-align: right; ` );