mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
78 lines
1.8 KiB
TypeScript
78 lines
1.8 KiB
TypeScript
import React from 'react';
|
|
|
|
import { route } from 'nextjs/routes';
|
|
|
|
import { useMultichainContext } from 'lib/contexts/multichain';
|
|
import * as EntityBase from 'ui/shared/entities/base/components';
|
|
|
|
import { distributeEntityProps } from '../base/utils';
|
|
|
|
type LinkProps = EntityBase.LinkBaseProps & Partial<Pick<EntityProps, 'number'>>;
|
|
|
|
const Link = ((props: LinkProps) => {
|
|
const defaultHref = route(
|
|
{ pathname: '/block/[height_or_hash]', query: { height_or_hash: String(props.number) } },
|
|
{ chain: props.chain, external: props.external },
|
|
);
|
|
|
|
return (
|
|
<EntityBase.Link
|
|
{ ...props }
|
|
href={ props.href ?? defaultHref }
|
|
>
|
|
{ props.children }
|
|
</EntityBase.Link>
|
|
);
|
|
});
|
|
|
|
const Icon = (props: EntityBase.IconBaseProps) => {
|
|
return (
|
|
<EntityBase.Icon
|
|
{ ...props }
|
|
name={ 'name' in props ? props.name : 'flashblock' }
|
|
/>
|
|
);
|
|
};
|
|
|
|
type ContentProps = Omit<EntityBase.ContentBaseProps, 'text'> & Pick<EntityProps, 'number' | 'index'>;
|
|
|
|
const Content = ((props: ContentProps) => {
|
|
return (
|
|
<EntityBase.Content
|
|
{ ...props }
|
|
text={ `${ props.number } #${ props.index }` }
|
|
truncation="none"
|
|
/>
|
|
);
|
|
});
|
|
|
|
const Container = EntityBase.Container;
|
|
|
|
export interface EntityProps extends EntityBase.EntityBaseProps {
|
|
number: number;
|
|
index: number;
|
|
}
|
|
|
|
const FlashblockEntity = (props: EntityProps) => {
|
|
const multichainContext = useMultichainContext();
|
|
const partsProps = distributeEntityProps(props);
|
|
|
|
const content = <Content { ...partsProps.content }/>;
|
|
|
|
return (
|
|
<Container { ...partsProps.container }>
|
|
<Icon { ...partsProps.icon }/>
|
|
{ props.noLink ? content : <Link { ...partsProps.link } chain={ multichainContext?.chain }>{ content }</Link> }
|
|
</Container>
|
|
);
|
|
};
|
|
|
|
export default React.memo(FlashblockEntity);
|
|
|
|
export {
|
|
Container,
|
|
Link,
|
|
Icon,
|
|
Content,
|
|
};
|