Skip to content
Open
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
95 changes: 95 additions & 0 deletions src/app/api/strategy/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { NextRequest, NextResponse } from "next/server";
import {
parseStrategyKind,
StrategyKind,
StrategyPreference,
StrategyUpdatePayload,
} from "@/lib/strategies";

// In-memory store for the demo/fallback path.
// Resets on server restart; the client layer mirrors to localStorage for persistence.
let mockPreference: StrategyKind | null = null;

function resolveEndpoint(baseUrl: string, path: string): string {
const normalizedBase = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
return new URL(normalizedPath, normalizedBase).toString();
}

export async function GET(request: NextRequest) {
const apiBaseUrl = process.env.NEUROWEALTH_API_BASE_URL;
const strategyPath =
process.env.NEUROWEALTH_STRATEGY_PATH ?? "/strategy/preference";

if (apiBaseUrl) {
try {
const res = await fetch(resolveEndpoint(apiBaseUrl, strategyPath), {
cache: "no-store",
headers: { Accept: "application/json" },
});

if (res.ok) {
const data = (await res.json()) as StrategyPreference;
return NextResponse.json(data, {
headers: { "Cache-Control": "no-store" },
});
}
} catch {
// fall through to mock
}
}

// Provide the in-memory default. Clients may override via localStorage.
const body: StrategyPreference = { strategy: mockPreference };
return NextResponse.json(body, {
headers: { "Cache-Control": "no-store" },
});
}

export async function PUT(request: NextRequest) {
const apiBaseUrl = process.env.NEUROWEALTH_API_BASE_URL;
const strategyPath =
process.env.NEUROWEALTH_STRATEGY_PATH ?? "/strategy/preference";

const payload = (await request.json()) as Partial<StrategyUpdatePayload>;
const strategy = parseStrategyKind(payload.strategy ?? null);

if (!strategy) {
return NextResponse.json(
{ message: "Invalid strategy value. Must be conservative, balanced, or growth." },
{ status: 422 },
);
}

if (apiBaseUrl) {
try {
const res = await fetch(resolveEndpoint(apiBaseUrl, strategyPath), {
method: "PUT",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ strategy }),
cache: "no-store",
});

const text = await res.text();
return new NextResponse(text, {
status: res.status,
headers: {
"Content-Type": res.headers.get("Content-Type") ?? "application/json",
"Cache-Control": "no-store",
},
});
} catch {
// fall through to mock
}
}

// Mock: persist in memory and respond with the updated preference.
mockPreference = strategy;
const body: StrategyPreference = { strategy };
return NextResponse.json(body, {
headers: { "Cache-Control": "no-store" },
});
}
34 changes: 34 additions & 0 deletions src/app/api/transaction-history/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { NextRequest, NextResponse } from "next/server";
import {
filterAndPaginateHistory,
parseHistoryKind,
parseHistoryStatus,
TransactionHistoryFilter,
} from "@/lib/transaction-history";

export function GET(req: NextRequest) {
const params = req.nextUrl.searchParams;

const kind = parseHistoryKind(params.get("kind"));
const status = parseHistoryStatus(params.get("status"));
const dateFrom = params.get("dateFrom") ?? "";
const dateTo = params.get("dateTo") ?? "";
const page = Math.max(1, parseInt(params.get("page") ?? "1", 10) || 1);
const pageSize = Math.min(
50,
Math.max(1, parseInt(params.get("pageSize") ?? "10", 10) || 10),
);

const filter: TransactionHistoryFilter = {
kind,
status,
dateFrom,
dateTo,
page,
pageSize,
};

const result = filterAndPaginateHistory(filter);

return NextResponse.json(result);
}
7 changes: 6 additions & 1 deletion src/app/dashboard/history/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"use client";

import { TransactionHistory } from "@/components/transactions/TransactionHistory";
import { ProtectedRoute } from "@/components/auth/ProtectedRoute";
import { Suspense, useState } from "react";
import { useState, useEffect } from "react";
import { useSearchParams } from "next/navigation";
import { Clock, AlertTriangle, Loader2 } from "lucide-react";
import { EmptyState } from "@/components/ui/EmptyState";
import { TableSkeleton } from "@/components/ui/Skeleton";
import { useSandbox } from "@/contexts/SandboxContext";


export default function HistoryPage() {
const searchParams = useSearchParams();
const { getCurrentScenario, isSandboxMode } = useSandbox();
Expand Down Expand Up @@ -98,7 +102,6 @@ export default function HistoryPage() {
</div>
);
}

return (
<div className="px-6 pt-8">
<div className="flex items-center justify-between pb-4">
Expand Down Expand Up @@ -137,6 +140,8 @@ export default function HistoryPage() {
</div>
</div>
</div>
<TransactionHistory />

</div>
);
}
3 changes: 3 additions & 0 deletions src/app/dashboard/strategy/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { CheckCircle, Shield, TrendingUp, Zap } from "lucide-react";
import StrategyLoading from "./loading";
import { cn } from "@/lib/utils";
import type { Strategy } from "@/types";
import { StrategySelector } from "@/components/strategies/StrategySelector";


export const metadata = { title: "Strategy — NeuroWealth" };

Expand Down Expand Up @@ -146,6 +148,7 @@ export default function StrategyPage() {
return (
<Suspense fallback={<StrategyLoading />}>
<StrategyContent />
<StrategySelector />
</Suspense>
);
}
Loading
Loading