Skip to content

Commit

Permalink
Merge pull request #154 from migalabs/dev
Browse files Browse the repository at this point in the history
Release 2.1.0
  • Loading branch information
IuriPons authored Dec 17, 2023
2 parents bf53e5b + 41c326d commit 52d23c6
Show file tree
Hide file tree
Showing 47 changed files with 2,155 additions and 244 deletions.
3 changes: 2 additions & 1 deletion packages/client/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NEXT_PUBLIC_URL_API=
NEXT_PUBLIC_GOOGLE_ANALYTICS=
NEXT_PUBLIC_TAG_MANAGER=
NEXT_PUBLIC_TAG_MANAGER=
URL_API=
246 changes: 246 additions & 0 deletions packages/client/components/layouts/Blocks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
import React, { useState, useRef, useContext, useEffect } from 'react';
import { useRouter } from 'next/router';

// Axios
import axiosClient from '../../config/axios';

// Contexts
import ThemeModeContext from '../../contexts/theme-mode/ThemeModeContext';

// Components
import LinkBlock from '../ui/LinkBlock';
import LinkSlot from '../ui/LinkSlot';

// Types
import { BlockEL } from '../../types';

// Props
type Props = {
blocks: BlockEL[];
};

const Blocks = ({ blocks }: Props) => {
// Theme Mode Context
const { themeMode } = useContext(ThemeModeContext) ?? {};

// Router
const router = useRouter();
const { network } = router.query;

// Refs
const containerRef = useRef<HTMLInputElement>(null);

// States
const [desktopView, setDesktopView] = useState(true);
const [blockGenesis, setBlockGenesis] = useState(0);

useEffect(() => {
setDesktopView(window !== undefined && window.innerWidth > 768);

if (network && blockGenesis == 0) {
getBlockGenesis(network as string);
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const handleMouseMove = (e: any) => {
if (containerRef.current) {
const x = e.pageX;
const limit = 0.15;

if (x < containerRef.current.clientWidth * limit) {
containerRef.current.scrollLeft -= 10;
} else if (x > containerRef.current.clientWidth * (1 - limit)) {
containerRef.current.scrollLeft += 10;
}
}
};

const getBlockGenesis = async (network: string) => {
try {
const genesisBlock = await axiosClient.get(`/api/networks/block/genesis`, {
params: {
network,
},
});

setBlockGenesis(genesisBlock.data.block_genesis);
} catch (error) {
console.log(error);
}
};

//View blocks table desktop
const getContentBlocksDesktop = () => {
const titles = ['Block Number', 'Slot', 'Datetime', 'Transactions'];
return (
<div
ref={containerRef}
className='flex flex-col overflow-x-scroll overflow-y-hidden scrollbar-thin my-4'
onMouseMove={handleMouseMove}
>
<div>
<div
className='font-semibold flex gap-4 py-3 text-center items-center flex-row justify-around text-[16px]'
style={{
color: themeMode?.darkMode ? 'var(--white)' : 'var(--darkGray)',
}}
>
{titles.map((title, index) => (
<p key={index} className='w-[20%]'>
{title}
</p>
))}
</div>

{blocks.map(element => (
<div
className='flex gap-4 py-3 text-center font-medium items-center flex-row justify-around text-[16px] rounded-md border-2 border-white my-2'
style={{
backgroundColor: themeMode?.darkMode
? 'var(--bgFairDarkMode)'
: 'var(--bgMainLightMode)',
boxShadow: themeMode?.darkMode
? 'var(--boxShadowCardDark)'
: 'var(--boxShadowCardLight)',
color: themeMode?.darkMode ? 'var(--white)' : 'var(--black)',
}}
key={element.f_slot}
>
<div
className='w-[20%] md:hover:underline underline-offset-4 decoration-2'
style={{ color: themeMode?.darkMode ? 'var(--purple)' : 'var(--darkPurple)' }}
>
<LinkBlock block={element.f_el_block_number} mxAuto />
</div>

<div
className='w-[20%] md:hover:underline underline-offset-4 decoration-2'
style={{ color: themeMode?.darkMode ? 'var(--purple)' : 'var(--darkPurple)' }}
>
<LinkSlot slot={element.f_slot} mxAuto />
</div>

<p className='w-[20%]'>
{new Date(blockGenesis + Number(element.f_slot) * 12000).toLocaleString('ja-JP')}
</p>

<p className='w-[20%]'>{(element.f_el_transactions ?? 0).toLocaleString()}</p>
</div>
))}

{blocks.length === 0 && (
<div className='flex justify-center p-2'>
<p className='uppercase text-[16px]'>No blocks</p>
</div>
)}
</div>
</div>
);
};
//View blocks table mobile
const getContentBlocksMobile = () => {
return (
<div
className='flex flex-col gap-2 font-medium text-[14px] my-4'
style={{
color: themeMode?.darkMode ? 'var(--white)' : 'var(--black)',
}}
>
{blocks.map(block => (
<div
className='flex flex-row py-2 px-2 border-2 border-white rounded-md'
style={{
backgroundColor: themeMode?.darkMode ? 'var(--bgFairDarkMode)' : 'var(--bgMainLightMode)',
boxShadow: themeMode?.darkMode ? 'var(--boxShadowCardDark)' : 'var(--boxShadowCardLight)',
color: themeMode?.darkMode ? 'var(--white)' : 'var(--black)',
}}
key={block.f_slot}
>
<div className='flex flex-col mx-auto w-10/12'>
<div className='flex flex-row items-center justify-between py-1'>
<p
className='font-semibold'
style={{
color: themeMode?.darkMode ? 'var(--white)' : 'var(--darkGray)',
}}
>
Block number:
</p>
<LinkBlock block={block.f_el_block_number} />
</div>

<div className='flex flex-row items-center justify-between py-1'>
<p
className='font-semibold'
style={{
color: themeMode?.darkMode ? 'var(--white)' : 'var(--darkGray)',
}}
>
Slot:
</p>
<LinkSlot slot={block.f_slot} />
</div>

<div className='flex flex-row items-center justify-between py-1'>
<p
className='font-semibold'
style={{
color: themeMode?.darkMode ? 'var(--white)' : 'var(--darkGray)',
}}
>
Datetime:
</p>
<div className='flex flex-row gap-2 py-1'>
<p>
{new Date(blockGenesis + Number(block.f_slot) * 12000).toLocaleDateString(
'ja-JP',
{
year: 'numeric',
month: 'numeric',
day: 'numeric',
}
)}
</p>
<p>
{new Date(blockGenesis + Number(block.f_slot) * 12000).toLocaleTimeString(
'ja-JP',
{
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
}
)}
</p>
</div>
</div>

<div className='flex flex-row items-center justify-between'>
<p
className='font-semibold'
style={{
color: themeMode?.darkMode ? 'var(--white)' : 'var(--darkGray)',
}}
>
Transactions:
</p>
<p>{(block.f_el_transactions ?? 0).toLocaleString()}</p>
</div>
</div>
</div>
))}

{blocks.length === 0 && (
<div className='flex justify-center p-2'>
<p className='uppercase text-[14px]'>No blocks</p>
</div>
)}
</div>
);
};

return <div>{desktopView ? getContentBlocksDesktop() : getContentBlocksMobile()}</div>;
};

export default Blocks;
26 changes: 13 additions & 13 deletions packages/client/components/layouts/Statitstics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,14 @@ const Statitstics = ({ showCalculatingEpochs }: Props) => {
title='Target'
color='#343434'
backgroundColor='#f5f5f5'
percent={1 - epoch.f_missing_target / epoch.f_num_vals}
percent={1 - epoch.f_missing_target / epoch.f_num_active_vals}
tooltipColor='orange'
tooltipContent={
<>
<span>
Missing Target: {epoch.f_missing_target?.toLocaleString()}
</span>
<span>Attestations: {epoch.f_num_vals?.toLocaleString()}</span>
<span>Attestations: {epoch.f_num_active_vals?.toLocaleString()}</span>
</>
}
widthTooltip={220}
Expand All @@ -601,14 +601,14 @@ const Statitstics = ({ showCalculatingEpochs }: Props) => {
title='Source'
color='#343434'
backgroundColor='#f5f5f5'
percent={1 - epoch.f_missing_source / epoch.f_num_vals}
percent={1 - epoch.f_missing_source / epoch.f_num_active_vals}
tooltipColor='blue'
tooltipContent={
<>
<span>
Missing Source: {epoch.f_missing_source?.toLocaleString()}
</span>
<span>Attestations: {epoch.f_num_vals?.toLocaleString()}</span>
<span>Attestations: {epoch.f_num_active_vals?.toLocaleString()}</span>
</>
}
widthTooltip={220}
Expand All @@ -619,12 +619,12 @@ const Statitstics = ({ showCalculatingEpochs }: Props) => {
title='Head'
color='#343434'
backgroundColor='#f5f5f5'
percent={1 - epoch.f_missing_head / epoch.f_num_vals}
percent={1 - epoch.f_missing_head / epoch.f_num_active_vals}
tooltipColor='purple'
tooltipContent={
<>
<span>Missing Head: {epoch.f_missing_head?.toLocaleString()}</span>
<span>Attestations: {epoch.f_num_vals?.toLocaleString()}</span>
<span>Attestations: {epoch.f_num_active_vals?.toLocaleString()}</span>
</>
}
widthTooltip={220}
Expand Down Expand Up @@ -823,12 +823,12 @@ const Statitstics = ({ showCalculatingEpochs }: Props) => {
title='Target'
color='#343434'
backgroundColor='#f5f5f5'
percent={1 - epoch.f_missing_target / epoch.f_num_vals}
percent={1 - epoch.f_missing_target / epoch.f_num_active_vals}
tooltipColor='orange'
tooltipContent={
<>
<span>Missing Target: {epoch.f_missing_target?.toLocaleString()}</span>
<span>Attestations: {epoch.f_num_vals?.toLocaleString()}</span>
<span>Attestations: {epoch.f_num_active_vals?.toLocaleString()}</span>
</>
}
widthTooltip={220}
Expand All @@ -838,12 +838,12 @@ const Statitstics = ({ showCalculatingEpochs }: Props) => {
title='Source'
color='#343434'
backgroundColor='#f5f5f5'
percent={1 - epoch.f_missing_source / epoch.f_num_vals}
percent={1 - epoch.f_missing_source / epoch.f_num_active_vals}
tooltipColor='blue'
tooltipContent={
<>
<span>Missing Source: {epoch.f_missing_source?.toLocaleString()}</span>
<span>Attestations: {epoch.f_num_vals?.toLocaleString()}</span>
<span>Attestations: {epoch.f_num_active_vals?.toLocaleString()}</span>
</>
}
widthTooltip={220}
Expand All @@ -853,12 +853,12 @@ const Statitstics = ({ showCalculatingEpochs }: Props) => {
title='Head'
color='#343434'
backgroundColor='#f5f5f5'
percent={1 - epoch.f_missing_head / epoch.f_num_vals}
percent={1 - epoch.f_missing_head / epoch.f_num_active_vals}
tooltipColor='purple'
tooltipContent={
<>
<span>Missing Head: {epoch.f_missing_head?.toLocaleString()}</span>
<span>Attestations: {epoch.f_num_vals?.toLocaleString()}</span>
<span>Attestations: {epoch.f_num_active_vals?.toLocaleString()}</span>
</>
}
widthTooltip={220}
Expand Down Expand Up @@ -902,7 +902,7 @@ const Statitstics = ({ showCalculatingEpochs }: Props) => {
title='Attesting/Total active'
color='#343434'
backgroundColor='#f5f5f5'
percent={epoch.f_num_att_vals / epoch.f_num_vals}
percent={epoch.f_num_att_vals / epoch.f_num_active_vals}
tooltipColor='bluedark'
tooltipContent={
<>
Expand Down
Loading

0 comments on commit 52d23c6

Please sign in to comment.