|
1 | | -import { BalanceChart } from "@/components/BalanceChart" |
2 | 1 | import { Breadcrumbs } from "@/components/Breadcrumbs" |
3 | 2 | import { PageTitle } from "@/components/PageTitle" |
| 3 | +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" |
| 4 | +import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts" |
| 5 | +import { type ChartConfig, ChartContainer, ChartLegend, ChartLegendContent } from "@/components/ui/chart" |
| 6 | +import { PropsWithChildren, Suspense } from "react" |
| 7 | +import { Skeleton } from "@/components/ui/skeleton" |
| 8 | +import { BalancesResponse, fetchBalances } from "@/lib/api" |
| 9 | +import { useSuspenseQuery } from "@tanstack/react-query" |
| 10 | + |
| 11 | +function Loader() { |
| 12 | + return ( |
| 13 | + <div className="flex gap-2 py-2"> |
| 14 | + <Skeleton className="flex-1 h-32 rounded-lg" /> |
| 15 | + <Skeleton className="flex-1 h-32 rounded-lg" /> |
| 16 | + <Skeleton className="flex-1 h-32 rounded-lg" /> |
| 17 | + <Skeleton className="flex-1 h-32 rounded-lg" /> |
| 18 | + </div> |
| 19 | + ) |
| 20 | +} |
| 21 | + |
| 22 | +export function BitcoinBalanceChart() { |
| 23 | + const config = { |
| 24 | + bitcoin: { |
| 25 | + label: "Bitcoin", |
| 26 | + color: "#2563eb", |
| 27 | + }, |
| 28 | + } satisfies ChartConfig |
| 29 | + |
| 30 | + const data = [ |
| 31 | + { month: "January", bitcoin: 186 }, |
| 32 | + { month: "February", bitcoin: 305 }, |
| 33 | + { month: "March", bitcoin: 237 }, |
| 34 | + { month: "April", bitcoin: 73 }, |
| 35 | + { month: "May", bitcoin: 209 }, |
| 36 | + { month: "June", bitcoin: 214 }, |
| 37 | + { month: "July", bitcoin: 21 }, |
| 38 | + { month: "August", bitcoin: 32 }, |
| 39 | + { month: "September", bitcoin: 0 }, |
| 40 | + { month: "October", bitcoin: 0 }, |
| 41 | + { month: "November", bitcoin: 0 }, |
| 42 | + { month: "December", bitcoin: 0 }, |
| 43 | + ] |
| 44 | + |
| 45 | + return ( |
| 46 | + <ChartContainer config={config} className="min-h-[200px] w-full"> |
| 47 | + <BarChart accessibilityLayer data={data}> |
| 48 | + <CartesianGrid vertical={false} /> |
| 49 | + <XAxis |
| 50 | + dataKey="month" |
| 51 | + tickLine={false} |
| 52 | + tickMargin={10} |
| 53 | + axisLine={false} |
| 54 | + tickFormatter={(value: string) => value.slice(0, 3)} |
| 55 | + /> |
| 56 | + <YAxis dataKey="bitcoin" tickLine={false} tickMargin={10} axisLine={false} /> |
| 57 | + <Bar dataKey="bitcoin" fill="var(--color-bitcoin)" radius={4} /> |
| 58 | + <ChartLegend content={<ChartLegendContent />} /> |
| 59 | + </BarChart> |
| 60 | + </ChartContainer> |
| 61 | + ) |
| 62 | +} |
| 63 | + |
| 64 | +export function OtherBalanceChart() { |
| 65 | + const config = { |
| 66 | + eIOU: { |
| 67 | + label: "e-IOU", |
| 68 | + color: "#911198", |
| 69 | + }, |
| 70 | + credit: { |
| 71 | + label: "Credit token", |
| 72 | + color: "#e9d4ff", |
| 73 | + }, |
| 74 | + debit: { |
| 75 | + label: "Debit token", |
| 76 | + color: "#c27aff", |
| 77 | + }, |
| 78 | + } satisfies ChartConfig |
| 79 | + |
| 80 | + const data = [ |
| 81 | + { month: "January", credit: 121, debit: 0 }, |
| 82 | + { month: "February", credit: 231, debit: 0 }, |
| 83 | + { month: "March", credit: 321, debit: 51 }, |
| 84 | + { month: "April", credit: 603, debit: 186 }, |
| 85 | + { month: "May", credit: 583, debit: 486 }, |
| 86 | + { month: "June", credit: 893, debit: 359 }, |
| 87 | + { month: "July", credit: 1023, debit: 192 }, |
| 88 | + { month: "August", credit: 2023, debit: 521 }, |
| 89 | + { month: "September", credit: 1821, debit: 789 }, |
| 90 | + { month: "October", credit: 1782, debit: 1232 }, |
| 91 | + { month: "November", credit: 0, debit: 0 }, |
| 92 | + { month: "December", credit: 0, debit: 0 }, |
| 93 | + ] |
| 94 | + |
| 95 | + return ( |
| 96 | + <ChartContainer config={config} className="min-h-[200px] w-full"> |
| 97 | + <BarChart accessibilityLayer data={data}> |
| 98 | + <CartesianGrid vertical={false} /> |
| 99 | + <XAxis |
| 100 | + dataKey="month" |
| 101 | + tickLine={false} |
| 102 | + tickMargin={10} |
| 103 | + axisLine={false} |
| 104 | + tickFormatter={(value: string) => value.slice(0, 3)} |
| 105 | + /> |
| 106 | + <YAxis dataKey="credit" tickLine={false} tickMargin={10} axisLine={false} /> |
| 107 | + <YAxis dataKey="debit" tickLine={false} tickMargin={10} axisLine={false} /> |
| 108 | + <Bar dataKey="credit" fill="var(--color-credit)" radius={4} /> |
| 109 | + <Bar dataKey="debit" fill="var(--color-debit)" radius={4} /> |
| 110 | + <ChartLegend content={<ChartLegendContent />} /> |
| 111 | + </BarChart> |
| 112 | + </ChartContainer> |
| 113 | + ) |
| 114 | +} |
| 115 | + |
| 116 | +export function BalanceText({ value, children }: PropsWithChildren<{ value: BalancesResponse["bitcoin"] }>) { |
| 117 | + return ( |
| 118 | + <> |
| 119 | + <h3 className="scroll-m-20 text-2xl font-extrabold tracking-tight"> |
| 120 | + {value.value} {value.currency} |
| 121 | + </h3> |
| 122 | + {children} |
| 123 | + </> |
| 124 | + ) |
| 125 | +} |
| 126 | + |
| 127 | +function PageBody() { |
| 128 | + const { data } = useSuspenseQuery({ |
| 129 | + queryKey: ["balances"], |
| 130 | + queryFn: fetchBalances, |
| 131 | + }) |
| 132 | + |
| 133 | + return ( |
| 134 | + <> |
| 135 | + <div className="flex items-center gap-2 my-2"> |
| 136 | + <Card className="flex-1 bg-indigo-100 self-stretch"> |
| 137 | + <CardHeader> |
| 138 | + <CardTitle>Bitcoin balance</CardTitle> |
| 139 | + </CardHeader> |
| 140 | + <CardContent> |
| 141 | + <BalanceText value={data.bitcoin} /> |
| 142 | + </CardContent> |
| 143 | + </Card> |
| 144 | + <Card className="flex-1 bg-orange-100 self-stretch"> |
| 145 | + <CardHeader> |
| 146 | + <CardTitle>e-IOU balance</CardTitle> |
| 147 | + </CardHeader> |
| 148 | + <CardContent> |
| 149 | + <BalanceText value={data.eiou} /> |
| 150 | + </CardContent> |
| 151 | + </Card> |
| 152 | + <Card className="flex-1 bg-purple-200 self-stretch"> |
| 153 | + <CardHeader> |
| 154 | + <CardTitle>Credit token balance</CardTitle> |
| 155 | + </CardHeader> |
| 156 | + <CardContent> |
| 157 | + <BalanceText value={data.credit} /> |
| 158 | + </CardContent> |
| 159 | + </Card> |
| 160 | + <Card className="flex-1 bg-purple-400 self-stretch"> |
| 161 | + <CardHeader> |
| 162 | + <CardTitle>Debit token balance</CardTitle> |
| 163 | + </CardHeader> |
| 164 | + <CardContent> |
| 165 | + <BalanceText value={data.debit} /> |
| 166 | + </CardContent> |
| 167 | + </Card> |
| 168 | + </div> |
| 169 | + |
| 170 | + <div className="flex items-center gap-2 hidden"> |
| 171 | + <Card className="flex-1 max-h-[500px] py-4"> |
| 172 | + <BitcoinBalanceChart /> |
| 173 | + </Card> |
| 174 | + <Card className="flex-1 max-h-[500px] py-4"> |
| 175 | + <OtherBalanceChart /> |
| 176 | + </Card> |
| 177 | + </div> |
| 178 | + |
| 179 | + <pre className="text-sm bg-accent text-accent-foreground rounded-lg p-2 my-2"> |
| 180 | + {JSON.stringify(data, null, 2)} |
| 181 | + </pre> |
| 182 | + </> |
| 183 | + ) |
| 184 | +} |
4 | 185 |
|
5 | 186 | export default function BalancesPage() { |
6 | 187 | return ( |
7 | 188 | <> |
8 | 189 | <Breadcrumbs>Balances</Breadcrumbs> |
9 | 190 | <PageTitle>Balances</PageTitle> |
10 | 191 |
|
11 | | - <div className="flex max-h-[500px] max-w-[320px] py-4"> |
12 | | - <BalanceChart /> |
13 | | - </div> |
| 192 | + <Suspense fallback={<Loader />}> |
| 193 | + <PageBody /> |
| 194 | + </Suspense> |
14 | 195 | </> |
15 | 196 | ) |
16 | 197 | } |
0 commit comments