Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"react-hook-form": "^7.71.1",
"react-markdown": "^10.1.0",
"tailwind-merge": "^2.2.0",
"zod": "^4.3.5"
"zod": "^4.3.5",
"swr": "^2.2.0"
},
"devDependencies": {
"@playwright/test": "^1.58.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/frontend/src/app/api/config/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NextResponse } from 'next/server'

export async function GET() {
// Return a mock config. In production this should proxy the real backend.
const config = {
feePercent: 1.5,
}

return NextResponse.json(config)
}
7 changes: 5 additions & 2 deletions packages/frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "./globals.css";
import { Inter } from "next/font/google";
import { WalletProvider } from "@/components/WalletContext";
import { PlatformConfigProvider } from "@/contexts/PlatformConfigContext";
import { NavBar } from "@/components/NavBar";

const inter = Inter({ subsets: ["latin"] });
Expand All @@ -24,8 +25,10 @@ export default function RootLayout({
the live wallet address and passes it to NotificationBell.
*/}
<WalletProvider>
<NavBar />
<main>{children}</main>
<PlatformConfigProvider>
<NavBar />
<main>{children}</main>
</PlatformConfigProvider>
</WalletProvider>
</body>
</html>
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { useWalletContext } from "./WalletContext";
import { ConnectButton } from "./ConnectButton";
import { NotificationBell } from "./NotificationBell";
import { TrendingUp } from "lucide-react";
import { usePlatformConfig } from "@/contexts/PlatformConfigContext";

export function NavBar() {
const { publicKey } = useWalletContext();
const { config } = usePlatformConfig();

return (
<nav
Expand All @@ -32,6 +34,9 @@ export function NavBar() {
</div>

<div className="flex items-center gap-4">
{config && (
<div className="text-sm text-gray-300 mr-4">Fee: {config.feePercent}%</div>
)}
{publicKey && <NotificationBell userId={publicKey} />}
<ConnectButton />
</div>
Expand Down
37 changes: 37 additions & 0 deletions packages/frontend/src/contexts/PlatformConfigContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use client";

import React, { createContext, useContext } from "react";
import useSWR from "swr";
import { Config } from "@/types/config";

const fetcher = (url: string) => fetch(url).then((res) => res.json());

interface PlatformConfigContextValue {
config?: Config;
isLoading: boolean;
error?: any;
}

const PlatformConfigContext = createContext<PlatformConfigContextValue>({
config: undefined,
isLoading: true,
error: undefined,
});

export const PlatformConfigProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const { data, error, isLoading } = useSWR<Config>("/api/config", fetcher, {
revalidateOnFocus: false,
});

return (
<PlatformConfigContext.Provider value={{ config: data, isLoading, error }}>
{children}
</PlatformConfigContext.Provider>
);
};

export const usePlatformConfig = () => useContext(PlatformConfigContext);

export default PlatformConfigContext;
4 changes: 4 additions & 0 deletions packages/frontend/src/types/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Config {
feePercent: number; // expressed as a percentage (e.g., 1.5)
[key: string]: any;
}
Loading
Loading