-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add stacking dao amounts / month (#18)
- Loading branch information
Showing
14 changed files
with
208 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Protocol, protocolsInfo } from "@/lib/protocols"; | ||
import { Heading, IconButton, Text } from "@radix-ui/themes"; | ||
import { IconBrandX, IconWorld } from "@tabler/icons-react"; | ||
import Image from "next/image"; | ||
|
||
interface ProtocolInfoProps { | ||
protocol: Protocol; | ||
} | ||
|
||
export const ProtocolInfo = ({ protocol }: ProtocolInfoProps) => { | ||
const protocolInfo = protocolsInfo[protocol]; | ||
|
||
return ( | ||
<div className="flex items-start gap-5"> | ||
<Image | ||
className="rounded-full" | ||
src={`/protocols/${protocol}.png`} | ||
alt={`${protocol} logo`} | ||
width={50} | ||
height={50} | ||
priority | ||
/> | ||
<div> | ||
<Heading as="h1" size="5" color="gray" highContrast> | ||
{protocolInfo.name} | ||
</Heading> | ||
<Text className="mt-1" as="p" size="2" color="gray"> | ||
{protocolInfo.description} | ||
</Text> | ||
<div className="mt-2 space-x-2"> | ||
<IconButton size="1" variant="ghost" color="gray" asChild> | ||
<a href={protocolInfo.website} target="_blank" rel="noreferrer"> | ||
<IconWorld size={14} /> | ||
</a> | ||
</IconButton> | ||
<IconButton size="1" variant="ghost" color="gray" asChild> | ||
<a href={protocolInfo.x} target="_blank" rel="noreferrer"> | ||
<IconBrandX size={14} /> | ||
</a> | ||
</IconButton> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/components/Stats/stackingdao/DepositsWithdrawBarChart/DepositWithdrawBarChartClient.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"use client"; | ||
import { BarChart } from "@/components/ui/BarChart"; | ||
import { displayPrice } from "@/lib/currencies"; | ||
import { Card, Inset, Separator, Text } from "@radix-ui/themes"; | ||
|
||
interface DepositWithdrawBarChartClientProps { | ||
data: { | ||
date: string; | ||
withdrawals: number; | ||
deposits: number; | ||
}[]; | ||
} | ||
|
||
export const DepositWithdrawBarChartClient = ({ | ||
data, | ||
}: DepositWithdrawBarChartClientProps) => { | ||
return ( | ||
<Card size="2" className="mt-5"> | ||
<Text as="div" size="2" weight="medium" color="gray" highContrast> | ||
Deposits and Withdrawals in STX | ||
</Text> | ||
<Text className="mt-1" as="div" size="1" color="gray"> | ||
Amount of deposits and withdrawals made by users per month | ||
</Text> | ||
<Inset py="current" side="bottom"> | ||
<Separator size="4" /> | ||
</Inset> | ||
<BarChart | ||
className="mt-6 pr-3" | ||
data={data} | ||
index="date" | ||
categories={["deposits", "withdrawals"]} | ||
colors={["orange", "indigo"]} | ||
valueFormatter={(value) => displayPrice(value, 6)} | ||
/> | ||
</Card> | ||
); | ||
}; |
35 changes: 35 additions & 0 deletions
35
src/components/Stats/stackingdao/DepositsWithdrawBarChart/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { db } from "@/db/db"; | ||
import { transactionTable } from "@/db/schema"; | ||
import { eq, sql } from "drizzle-orm"; | ||
import { DepositWithdrawBarChartClient } from "./DepositWithdrawBarChartClient"; | ||
|
||
const getData = async () => { | ||
const query = db | ||
.select({ | ||
month: sql<string>`strftime('%Y-%m', timestamp, 'unixepoch') as month`, | ||
depositsAmount: sql<number>`sum(case when action = 'stackingdao-deposit' then json->>'outAmount' else 0 end) as depositsAmount`, | ||
withdrawalsAmount: sql<number>`sum(case when action = 'stackingdao-withdraw' then json->>'inAmount' else 0 end) as withdrawalsAmount`, | ||
}) | ||
.from(transactionTable) | ||
.where(eq(transactionTable.protocol, "stackingdao")) | ||
.groupBy(sql`month`); | ||
|
||
const stats = await query; | ||
return stats; | ||
}; | ||
|
||
export const DepositWithdrawBarChart = async () => { | ||
const stats = await getData(); | ||
|
||
const formattedData: { | ||
date: string; | ||
withdrawals: number; | ||
deposits: number; | ||
}[] = stats.map((d) => ({ | ||
date: d.month, | ||
withdrawals: d.withdrawalsAmount, | ||
deposits: d.depositsAmount, | ||
})); | ||
|
||
return <DepositWithdrawBarChartClient data={formattedData} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.