-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoinsMarketStats.tsx
157 lines (153 loc) · 5.39 KB
/
CoinsMarketStats.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import Image from "next/image";
import { useAppSelector } from "../../redux/store";
import { ChevronUpIcon } from "../icons/ChevronUpIcon";
import { ChevronDownIcon } from "../icons/ChevronDownIcon";
import { Progress } from "../components/ui/progress";
import formatNumber from "../../app/utils/formatNumber";
import TableGraph from "./TableGraph";
import { TableCell, TableRow } from "./ui/table";
type Coin = {
id: string;
image: string;
symbol: string;
current_price: number;
price_change_percentage_1h_in_currency: number;
price_change_percentage_24h_in_currency: number;
price_change_percentage_7d_in_currency: number;
total_volume: number;
market_cap: number;
circulating_supply: number;
total_supply: number;
sparkline_in_7d: SparklineIn7d;
};
type SparklineIn7d = {
price: number[];
};
type CoinsMarketStatsProps = {
coin: Coin;
index: number;
};
export default function CoinsMarketStats({
coin,
index,
}: CoinsMarketStatsProps) {
const currencySymbol = useAppSelector(
(state) => state.currency.currentCurrency.symbol
);
return (
<>
<tr className="bg-transparent h-2"></tr>
<TableRow className="dark:bg-[#191925] bg-white border-0">
<TableCell className="dark:text-white text-[#232336] text-base font-medium leading-6 rounded-tl-xl rounded-bl-xl">
{index + 1}
</TableCell>
<TableCell>
<div className="flex items-center gap-4">
<Image src={coin.image} alt={coin.id} width={32} height={32} />
<>
<span className="dark:text-white text-[#232336] text-base font-medium capitalize leading-6">
{coin.id}
</span>
<span className="dark:text-white text-[#232336] text-base font-medium leading-6 uppercase">
({coin.symbol})
</span>
</>
</div>
</TableCell>
<TableCell className="dark:text-white text-[#232336] text-base font-medium leading-6">
{currencySymbol}
{coin.current_price}
</TableCell>
<TableCell>
<div className="flex items-center gap-[6px]">
{coin.price_change_percentage_1h_in_currency > 0 ? (
<ChevronUpIcon />
) : (
<ChevronDownIcon />
)}
<span
className={`text-base font-medium leading-6 ${
coin.price_change_percentage_1h_in_currency > 0
? "text-[#00F0E2]"
: "text-[#FD2263]"
}`}
>{`${Math.abs(coin.price_change_percentage_1h_in_currency).toFixed(
2
)}%`}</span>
</div>
</TableCell>
<TableCell>
<div className="flex items-center gap-[6px]">
{coin.price_change_percentage_24h_in_currency > 0 ? (
<ChevronUpIcon />
) : (
<ChevronDownIcon />
)}
<span
className={`text-base font-medium leading-6 ${
coin.price_change_percentage_24h_in_currency > 0
? "text-[#00F0E2]"
: "text-[#FD2263]"
}`}
>{`${Math.abs(coin.price_change_percentage_24h_in_currency).toFixed(
2
)}%`}</span>
</div>
</TableCell>
<TableCell>
<div className="flex items-center gap-[6px]">
{coin.price_change_percentage_7d_in_currency > 0 ? (
<ChevronUpIcon />
) : (
<ChevronDownIcon />
)}
<span
className={`text-base font-medium leading-6 ${
coin.price_change_percentage_7d_in_currency > 0
? "text-[#00F0E2]"
: "text-[#FD2263]"
}`}
>{`${Math.abs(coin.price_change_percentage_7d_in_currency).toFixed(
2
)}%`}</span>
</div>
</TableCell>
<TableCell className="dark:text-white text-[#232336] text-base font-medium leading-6">
<div className="flex justify-between">
<span className="text-xs font-normal">
{currencySymbol}
{formatNumber(coin.total_volume)}
</span>
<span className="text-xs font-normal">
{currencySymbol}
{formatNumber(coin.market_cap)}
</span>
</div>
<Progress
className="w-full h-[6px] bg-gray-500"
value={(coin.total_volume / coin.market_cap) * 100}
indicator="bg-[#F7931A]"
/>
</TableCell>
<TableCell className="dark:text-white text-[#232336] text-base font-medium leading-6">
<div className="flex justify-between">
<span className="text-xs font-normal">
{formatNumber(coin.circulating_supply)}
</span>
<span className="text-xs font-normal">
{formatNumber(coin.total_supply)}
</span>
</div>
<Progress
className="w-full h-[6px] bg-gray-500"
value={(coin.circulating_supply / coin.total_supply) * 100}
indicator="bg-[#F7931A]"
/>
</TableCell>
<TableCell className="dark:text-white text-[#232336] text-base font-medium leading-6 rounded-tr-xl rounded-br-xl">
<TableGraph sparklineIn7Days={coin.sparkline_in_7d.price} />
</TableCell>
</TableRow>
</>
);
}