Skip to content

Commit 8ddb422

Browse files
sktbrdclaude
andauthored
fix(home): esconde "Powered by Morpheus" até a subnet bater 100k MOR (#232)
A faixa "community × community / Back Gnars" aparecia na home desde já, adiantando (spoiler) o reveal que só deve rolar quando a subnet atingir a meta (SUBNET_GOAL_MOR = 100k). Agora o componente é async e lê o total stakeado on-chain (subnetsData(id).deposited, igual ao hook useGnarsSubnet); renderiza null abaixo da meta. Fail-closed: se a leitura on-chain falhar, esconde em vez de revelar. Envolto em <Suspense fallback={null}> pra não bloquear o shell da home (que é ISR, revalidate=300). Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c3da3ed commit 8ddb422

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

src/app/[locale]/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ export default async function Home({ params }: { params: Promise<{ locale: strin
9696
</div>
9797
</section>
9898

99-
{/* Community × community — Gnars is a Morpheus Builder */}
100-
<PoweredByMorpheus />
99+
{/* Community × community — Gnars is a Morpheus Builder (gated on the subnet goal) */}
100+
<Suspense fallback={null}>
101+
<PoweredByMorpheus />
102+
</Suspense>
101103

102104
{/* Dashboard Grid */}
103105
<div className="flex flex-1 flex-col gap-6 py-8">

src/components/home/PoweredByMorpheus.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import Image from "next/image";
22
import { Link } from "@/i18n/navigation";
3+
import { getGnarsSubnetTotalStaked } from "@/lib/morpheus-builder";
4+
import { SUBNET_GOAL_MOR } from "@/lib/stake-milestones";
35

46
// "Powered by Morpheus" homepage strip — signals the Gnars × Morpheus
57
// community-to-community partnership, with the colored Morpheus mark, and links
68
// to the subnet staking flow. Morpheus green (#2be58b / emerald) accents.
7-
export function PoweredByMorpheus() {
9+
//
10+
// Gated: only surfaces once the subnet actually clears its goal (SUBNET_GOAL_MOR).
11+
// Before that it's a spoiler, so we render nothing. Fails closed — if the
12+
// on-chain read errors we hide it rather than reveal it prematurely.
13+
export async function PoweredByMorpheus() {
14+
let totalStaked = 0;
15+
try {
16+
totalStaked = await getGnarsSubnetTotalStaked();
17+
} catch {
18+
return null;
19+
}
20+
if (totalStaked < SUBNET_GOAL_MOR) return null;
21+
822
return (
923
<section className="mx-auto w-full max-w-6xl px-4">
1024
<Link

src/lib/morpheus-builder.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
// staker's principal is theirs, withdrawable after a 7-day lock. All values
77
// below were read on-chain from BuildersV4 before hardcoding.
88

9-
import { getAddress, type Address } from "viem";
9+
import { createPublicClient, fallback, formatUnits, getAddress, http, type Address } from "viem";
10+
import { base } from "viem/chains";
1011

1112
/** BuildersV4 (ERC1967 proxy) on Base. */
1213
export const BUILDERS = getAddress("0x42BB446eAE6dca7723a9eBdb81EA88aFe77eF4B9");
@@ -68,4 +69,20 @@ export type GnarsSubnetPosition = {
6869

6970
export const GNARS_SUBNET = { id: GNARS_SUBNET_ID, admin: getAddress("0x8Bf5941d27176242745B716251943Ae4892a3C26") } as const;
7071

72+
/**
73+
* Total MOR staked into the Gnars subnet, read on-chain (server-safe).
74+
* Mirrors the `useGnarsSubnet` hook: `subnetsData(id).deposited`, 18 decimals.
75+
* Used to gate the homepage "Powered by Morpheus" reveal behind the goal.
76+
*/
77+
export async function getGnarsSubnetTotalStaked(): Promise<number> {
78+
const client = createPublicClient({ chain: base, transport: fallback(BASE_RPCS.map((u) => http(u))) });
79+
const data = await client.readContract({
80+
address: BUILDERS,
81+
abi: buildersAbi,
82+
functionName: "subnetsData",
83+
args: [GNARS_SUBNET_ID],
84+
});
85+
return Number(formatUnits(data[1], MOR_DECIMALS));
86+
}
87+
7188
export type { Address };

0 commit comments

Comments
 (0)