* Use .js imports in src * Additional * Additional * Additional * Additional * Additional * Additional * Additional * Additional * Additional * Additional * Additional * Additional * Additional * Add WP extension aliases * Bump dev * Additional * Additional * Adjust extensionAlias order
69 lines
1.5 KiB
TypeScript
69 lines
1.5 KiB
TypeScript
// Copyright 2017-2023 @polkadot/app-staking authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { BN } from '@polkadot/util';
|
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
import { useParaEndpoints } from '@polkadot/react-hooks';
|
|
|
|
import ChainImg from './ChainImg.js';
|
|
import { styled } from './styled.js';
|
|
|
|
interface Props {
|
|
className?: string;
|
|
id: BN;
|
|
}
|
|
|
|
function ParaLink ({ className, id }: Props): React.ReactElement<Props> | null {
|
|
const endpoints = useParaEndpoints(id);
|
|
const links = useMemo(
|
|
() => endpoints.filter(({ isDisabled, isUnreachable }) => !isDisabled && !isUnreachable),
|
|
[endpoints]
|
|
);
|
|
|
|
if (!endpoints.length) {
|
|
return null;
|
|
}
|
|
|
|
const { text, ui, value } = links.length
|
|
? links[links.length - 1]
|
|
: endpoints[0];
|
|
|
|
return (
|
|
<StyledDiv className={className}>
|
|
<ChainImg
|
|
isInline
|
|
logo={ui.logo || 'empty'}
|
|
withoutHl
|
|
/>
|
|
{links.length
|
|
? (
|
|
<a
|
|
className='chainAlign'
|
|
href={`${window.location.origin}${window.location.pathname}?rpc=${encodeURIComponent(value)}`}
|
|
>{text}</a>
|
|
)
|
|
: text
|
|
}
|
|
</StyledDiv>
|
|
);
|
|
}
|
|
|
|
const StyledDiv = styled.div`
|
|
vertical-align: middle;
|
|
white-space: nowrap;
|
|
|
|
a.chainAlign {
|
|
display: inline-block;
|
|
height: 24px;
|
|
line-height: 24px;
|
|
max-width: 10em;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
vertical-align: middle;
|
|
}
|
|
`;
|
|
|
|
export default React.memo(ParaLink);
|