-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
apps/flame-defi/app/earn/components/MarketSummary/MarketSummary.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,11 @@ | ||
import { MarketSummaryCard } from "./MarketSummaryCard"; | ||
|
||
export const MarketSummary = () => { | ||
return ( | ||
<div className="flex flex-col gap-2 md:flex-row"> | ||
{/* TODO: Use fetched values. */} | ||
<MarketSummaryCard label="Total Deposits" value={75000} /> | ||
<MarketSummaryCard label="Total Borrow" value={1000000} /> | ||
</div> | ||
); | ||
}; |
65 changes: 65 additions & 0 deletions
65
apps/flame-defi/app/earn/components/MarketSummary/MarketSummaryCard.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,65 @@ | ||
import { Skeleton } from "@repo/ui/shadcn-primitives"; | ||
import Big from "big.js"; | ||
import React, { useEffect, useState } from "react"; | ||
import { FormattedNumber } from "react-intl"; | ||
import { Card } from "../Card"; | ||
|
||
interface MarketSummaryCardProps { | ||
label: React.ReactNode; | ||
value: number; | ||
} | ||
|
||
export const MarketSummaryCard = ({ label, value }: MarketSummaryCardProps) => { | ||
const [count, setCount] = useState<number | null>(null); | ||
|
||
useEffect(() => { | ||
let isMounted = true; | ||
|
||
const counter = (minimum: number, maximum: number) => { | ||
for (let count = minimum; count <= maximum; count++) { | ||
setTimeout(() => { | ||
if (isMounted) { | ||
setCount(count); | ||
} | ||
}, 5000); | ||
} | ||
}; | ||
|
||
const minimum = value - 10000; | ||
counter(minimum < 0 ? 0 : minimum, value); | ||
|
||
return () => { | ||
isMounted = false; | ||
}; | ||
}, [value]); | ||
|
||
return ( | ||
<Card className="flex flex-col rounded-xl p-5 space-y-1"> | ||
<span className="text-xs/3 text-grey-light">{label}</span> | ||
|
||
<div className="relative"> | ||
{/* Reserve space for animation to prevent card size increasing with counter value. */} | ||
<span className="text-3xl/8 font-dot opacity-0"> | ||
<FormattedNumber | ||
value={+new Big(value).toFixed()} | ||
style="currency" | ||
currency="USD" | ||
maximumFractionDigits={0} | ||
/> | ||
</span> | ||
<span className="text-3xl/8 font-dot w-full absolute top-0 left-0"> | ||
<Skeleton isLoading={count === null}> | ||
<span> | ||
<FormattedNumber | ||
value={+new Big(count ?? 0).toFixed()} | ||
style="currency" | ||
currency="USD" | ||
maximumFractionDigits={0} | ||
/> | ||
</span> | ||
</Skeleton> | ||
</span> | ||
</div> | ||
</Card> | ||
); | ||
}; |
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 @@ | ||
export { MarketSummary } from "./MarketSummary"; |
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