Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemkaDev committed Nov 23, 2024
1 parent 57dc09d commit b445e5d
Show file tree
Hide file tree
Showing 9 changed files with 1,045 additions and 20 deletions.
371 changes: 363 additions & 8 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@radix-ui/react-navigation-menu": "^1.2.1",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.1",
"@radix-ui/react-toast": "^1.2.2",
"@radix-ui/react-tooltip": "^1.1.4",
"autoprefixer": "^10.4.19",
Expand All @@ -30,6 +31,7 @@
"react": "^18.3.1",
"react-device-detect": "^2.2.3",
"react-dom": "^18",
"recharts": "^2.13.3",
"tailwind-merge": "^1.12.0",
"tailwindcss": "^3.4.3",
"tailwindcss-animate": "^1.0.7"
Expand Down
4 changes: 4 additions & 0 deletions src/app/[locale]/page/desktop/Desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styles from "./desktop.module.css";
import {useTranslations} from "next-intl";
import { usePathname } from 'next/navigation';
import Link from "next/link";
import Crypto from '@/components/crypto/component';

const murecho = Murecho({subsets: ['latin', 'cyrillic']});

Expand Down Expand Up @@ -102,6 +103,9 @@ export default function Desktop() {
<img src="/main/community-image-3.png"
className={`${styles["community-image3"]} ${styles["community-image-right"]}`}/>
</section>
<section className={styles['main-container']}>
<Crypto />
</section>
</>
);
}
174 changes: 174 additions & 0 deletions src/components/crypto/component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
"use client";

import React, { useEffect, useState } from "react";
import { ethers } from "ethers";
import { AreaChart, Area, CartesianGrid, XAxis, Tooltip, Bar, BarChart } from "recharts";
import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from "@/components/ui/tabs";
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from "@/components/ui/card";

// Форматирование сложности
function formatHashrate(difficulty: bigint): string {
const units = ["H/s", "KH/s", "MH/s", "GH/s", "TH/s", "PH/s"];
let value = Number(difficulty);
let unitIndex = 0;

while (value >= 1000 && unitIndex < units.length - 1) {
value /= 1000;
unitIndex++;
}

return `${value.toFixed(2)} ${units[unitIndex]}`;
}

const BlockExplorer = () => {
const [blocks, setBlocks] = useState<any[]>([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
const fetchBlocks = async () => {
const provider = new ethers.JsonRpcProvider("https://pub1.aplocoin.com");
const currentBlockNumber = await provider.getBlockNumber();
const fetchedBlocks = [];

for (let i = 0; i < 50; i++) {
const blockNumber = currentBlockNumber - i;
const block = await provider.getBlock(blockNumber);
if (block) {
fetchedBlocks.push({
number: block.number,
difficulty: block.difficulty,
gasUsed: block.gasUsed.toString(),
transactions: block.transactions.length,
});
}
}
setBlocks(fetchedBlocks.reverse());
setLoading(false);
};

fetchBlocks();
}, []);

if (loading) {
return <div>Loading...</div>;
}

// Данные для графиков
const difficultyData = blocks.map((block) => ({
name: `#${block.number}`,
difficulty: Number(block.difficulty),
}));

const gasData = blocks.map((block) => ({
name: `#${block.number}`,
gasUsed: Number(block.gasUsed),
transactions: block.transactions,
}));

return (
<Tabs defaultValue="difficulty">
<TabsList>
<TabsTrigger value="difficulty">Сложность</TabsTrigger>
<TabsTrigger value="gas">Использование газа</TabsTrigger>
</TabsList>

{/* Вкладка сложности */}
<TabsContent value="difficulty">
<Card>
<CardHeader className="flex flex-col items-stretch space-y-0 border-b p-0 sm:flex-row">
<div className="flex flex-1 flex-col justify-center gap-1 px-6 py-5 sm:py-6">
<CardTitle>Сложность майнинга</CardTitle>

</div>
</CardHeader>
<CardContent className="px-2 sm:p-6">
<div className="aspect-auto h-[400px] w-full">
<BarChart
width={800}
height={400}
data={difficultyData}
margin={{
left: 12,
right: 12,
}}
onClick={(e) => {
if (e && e.activeLabel) {
const blockId = e.activeLabel.replace("#", "");
window.open(`https://explorer.aplocoin.com/block/${blockId}`);
}
}}
>
<CartesianGrid vertical={false} strokeDasharray="3 3" />
<XAxis
dataKey="name"
tickLine={false}
axisLine={false}
tickMargin={8}
minTickGap={32}
/>
<Tooltip
content={({ active, payload, label }) => {
if (active && payload && payload.length) {
return (
<div className="bg-background p-2 rounded-lg border">
<p>Блок: {label}</p>
<p>Сложность: {payload[0].value}</p>
</div>
);
}
return null;
}}
/>
<Bar
dataKey="difficulty"
fill="var(--primary)"
radius={[4, 4, 0, 0]}
/>
</BarChart>
</div>
</CardContent>
</Card>
</TabsContent>

{/* Вкладка газа */}
<TabsContent value="gas">
<Card>
<CardHeader>
<CardTitle>Использование газа и транзакции</CardTitle>
</CardHeader>
<CardContent>
<AreaChart
width={800}
height={400}
data={gasData}
onClick={(e) => {
if (e && e.activeLabel) {
const blockId = e.activeLabel.replace("#", "");
window.open(`https://explorer.aplocoin.com/block/${blockId}`);
}
}}
>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<Tooltip />
<Area type="monotone" dataKey="gasUsed" stroke="#82ca9d" fill="#82ca9d" />
<Area type="monotone" dataKey="transactions" stroke="#ffc658" fill="#ffc658" />
</AreaChart>
</CardContent>
</Card>
</TabsContent>
</Tabs>
);
};

export default BlockExplorer;
3 changes: 1 addition & 2 deletions src/components/navigation/DesktopNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import styles from "./desktop.module.css";
import LanguageSwitcher from "../language/LanguageSwitcher";
import { useTranslations } from "next-intl";
import { usePathname } from "next/navigation";
Expand Down Expand Up @@ -198,7 +197,7 @@ export default function DesktopNavigation() {
/>
</Link>
<div
className={`flex flex-row items-center ${styles[`${lang}-lang`]}`}
className={`flex flex-row items-center`}
>
<NavigationMenu>
<NavigationMenuList>
Expand Down
10 changes: 0 additions & 10 deletions src/components/navigation/desktop.module.css

This file was deleted.

76 changes: 76 additions & 0 deletions src/components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import * as React from "react"

import { cn } from "@/lib/utils"

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-xl border bg-card text-card-foreground shadow",
className
)}
{...props}
/>
))
Card.displayName = "Card"

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
))
CardHeader.displayName = "CardHeader"

const CardTitle = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("font-semibold leading-none tracking-tight", className)}
{...props}
/>
))
CardTitle.displayName = "CardTitle"

const CardDescription = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
CardDescription.displayName = "CardDescription"

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
))
CardContent.displayName = "CardContent"

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex items-center p-6 pt-0", className)}
{...props}
/>
))
CardFooter.displayName = "CardFooter"

export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
Loading

0 comments on commit b445e5d

Please sign in to comment.