-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: partners carousel * fixup * feat(home): hero section * refactor: cleaner file structure * fix: formatting * fixup * fixup * feat: add reusable text component * rename carousel to ticker * fix: format * feat(home): technology section * fixup * fixup * feat(home): stats section * fixup * fixup * fix: hero image size * refine revalidation of stats * remove catch * fixup
- Loading branch information
Showing
9 changed files
with
190 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Text } from "../../_components/text"; | ||
import { StatBox } from "../../_components/stat-box"; | ||
|
||
import { getProtocolStats } from "../../_lib/scraper"; | ||
import { humanReadableNumber } from "../../_lib/format"; | ||
|
||
async function getFormattedStatsData() { | ||
const protocolStats = await getProtocolStats({ | ||
revalidate: 24 * 60 * 60, // Update once a day | ||
}); | ||
|
||
return { | ||
totalVolumeUsd: `$${humanReadableNumber(protocolStats.totalVolumeUsd)}`, | ||
totalDeposits: `${humanReadableNumber(protocolStats.totalDeposits)}`, | ||
avgFillTimeInMinutes: `${protocolStats.avgFillTimeInMinutes < 1 ? "<" : ""} ${Math.max( | ||
protocolStats.avgFillTimeInMinutes, | ||
1, | ||
)}m`, | ||
bridgeFee: "<$1", | ||
}; | ||
} | ||
|
||
export async function StatsSection() { | ||
const formattedStatsData = await getFormattedStatsData(); | ||
return ( | ||
<section className="container mx-auto flex flex-col gap-10 px-4 sm:gap-16"> | ||
<div className="flex flex-col items-center gap-4"> | ||
<Text variant="cap-case" className="text-aqua-100 md:text-center"> | ||
power in originality | ||
</Text> | ||
<Text variant="heading-2" className="text-center capitalize text-light-200"> | ||
Production ready <br /> | ||
Empirically Proven | ||
</Text> | ||
<Text className="max-w-xl text-center"> | ||
Across is the only cross-chain intents protocol in production today, enabling | ||
the fastest and lowest-cost interoperability solution without security | ||
tradeoffs. | ||
</Text> | ||
</div> | ||
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4"> | ||
<StatBox | ||
title="volume" | ||
value={formattedStatsData.totalVolumeUsd} | ||
titleClassName="text-teal-100" | ||
className="group-hover:border-teal-100" | ||
dividerClassName="group-hover:bg-teal-100/[.5]" | ||
/> | ||
<StatBox | ||
title="transaction" | ||
value={formattedStatsData.totalDeposits} | ||
titleClassName="text-orange-100" | ||
className="group-hover:border-orange-100" | ||
dividerClassName="group-hover:bg-orange-100/[.5]" | ||
/> | ||
<StatBox | ||
title="avg. fill time" | ||
value={formattedStatsData.avgFillTimeInMinutes} | ||
titleClassName="text-purple-100" | ||
className="group-hover:border-purple-100" | ||
dividerClassName="group-hover:bg-purple-100/[.5]" | ||
/> | ||
<StatBox | ||
title="bridge 1 eth" | ||
value={formattedStatsData.bridgeFee} | ||
titleClassName="text-aqua-100" | ||
className="group-hover:border-aqua-100" | ||
dividerClassName="group-hover:bg-aqua-100/[.5]" | ||
/> | ||
</div> | ||
</section> | ||
); | ||
} |
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 { ComponentProps } from "react"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
import { Text } from "./text"; | ||
|
||
type Props = ComponentProps<"div"> & { | ||
title: string; | ||
titleClassName: string; | ||
value: string; | ||
dividerClassName?: string; | ||
}; | ||
|
||
export function StatBox({ | ||
className, | ||
title, | ||
titleClassName, | ||
value, | ||
dividerClassName, | ||
...props | ||
}: Props) { | ||
return ( | ||
<div className="group"> | ||
<div | ||
className={twMerge( | ||
"group flex flex-col rounded-2xl border border-grey-600 px-4 pb-6 transition sm:pb-10", | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<div | ||
className={twMerge( | ||
"mb-6 h-1 w-11 self-center rounded-b-[12px] rounded-t-none bg-grey-600 sm:mb-10", | ||
dividerClassName, | ||
)} | ||
/> | ||
<Text variant="cap-case" className={twMerge("mb-2 text-center", titleClassName)}> | ||
{title} | ||
</Text> | ||
<Text variant="heading-3" className="text-center"> | ||
{value} | ||
</Text> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import numeral from "numeral"; | ||
|
||
/** | ||
* Formats a number into a human readable format | ||
* @param num The number to format | ||
* @returns A human readable format. I.e. 1000 -> 1K, 1001 -> 1K+ | ||
*/ | ||
export function humanReadableNumber(num: number, decimals = 0): string { | ||
if (num <= 0) return "0"; | ||
return ( | ||
numeral(num) | ||
.format(decimals <= 0 ? "0a" : `0.${"0".repeat(decimals)}a`) | ||
.toUpperCase() + "+" | ||
); | ||
} |
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,31 @@ | ||
type ProtocolStatsResponse = { | ||
totalDeposits: number; | ||
avgFillTime: number; | ||
totalVolumeUsd: number; | ||
}; | ||
|
||
type ProtocolStatsFormatted = ProtocolStatsResponse & { | ||
avgFillTimeInMinutes: number; | ||
}; | ||
|
||
export async function getProtocolStats( | ||
nextFetchRequestConfig?: NextFetchRequestConfig, | ||
): Promise<ProtocolStatsFormatted> { | ||
const response = await fetch(`https://public.api.across.to/deposits/stats`, { | ||
next: nextFetchRequestConfig, | ||
}); | ||
if (!response.ok) { | ||
throw new Error( | ||
`Failed to fetch protocol stats: ${response.status} ${response.statusText}`, | ||
); | ||
} | ||
const data = await response.json(); | ||
return formatResult(data); | ||
} | ||
|
||
function formatResult(data: ProtocolStatsResponse) { | ||
return { | ||
...data, | ||
avgFillTimeInMinutes: Math.floor(data.avgFillTime / 60), | ||
}; | ||
} |
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