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
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { NextResponse } from "next/server";
import { headers } from "next/headers";

// Proxies the backend's single unified GET /transaction/history?type=plan|bot|all
// endpoint. Kept server-side because API_BASE_URL is a server-only env var and
// the backend isn't set up for direct browser CORS. Response is passed through
// as-is (no reshaping) — callers unwrap the `plan`/`bot` fields themselves.
export async function GET(request: Request) {
try {
// Get authorization header
const headersList = await headers();
const authorization = headersList.get("authorization");

Expand All @@ -17,20 +20,18 @@ export async function GET(request: Request) {
);
}

// Extract token from "Bearer <token>" format
const token = authorization.startsWith("Bearer ") ? authorization.slice(7) : authorization;

// Get pagination parameters from URL
const url = new URL(request.url);
const limit = url.searchParams.get("limit") || "100";
const offset = url.searchParams.get("offset") || "0";
const type = url.searchParams.get("type") || "all";
const page = url.searchParams.get("page") || "1";
const limit = url.searchParams.get("limit") || "10";

// Build API URL with pagination parameters
const apiUrl = new URL(`${process.env.API_BASE_URL}/transaction/bot-history`);
const apiUrl = new URL(`${process.env.API_BASE_URL}/transaction/history`);
apiUrl.searchParams.set("type", type);
apiUrl.searchParams.set("page", page);
apiUrl.searchParams.set("limit", limit);
apiUrl.searchParams.set("offset", offset);

// Make request to external API to get current user's bot (sats send/receive) transactions
const response = await fetch(apiUrl.toString(), {
method: "GET",
headers: {
Expand All @@ -44,18 +45,17 @@ export async function GET(request: Request) {
const errorData = await response.text();
return NextResponse.json(
{
error: "Failed to fetch bot transactions",
error: "Failed to fetch transaction history",
message: errorData || `HTTP ${response.status}: ${response.statusText}`,
},
{ status: response.status }
);
}

const data = await response.json();

return NextResponse.json(data);
} catch (error) {
console.error("❌ Error fetching bot transactions:", error);
console.error("❌ Error fetching transaction history:", error);
return NextResponse.json(
{
error: "Internal server error",
Expand Down
81 changes: 0 additions & 81 deletions src/app/api/transaction/list/route.ts

This file was deleted.

21 changes: 6 additions & 15 deletions src/app/dashboard/activity/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { ActivitySearchBar } from "@/components/dashboard/activity/ActivitySearc
import { ActivityTabs } from "@/components/dashboard/activity/ActivityTabs";
import { ActivityGroup } from "@/components/dashboard/activity/ActivityGroup";
import { ActivitySkeleton } from "@/components/dashboard/activity/ActivitySkeleton";
import { useTransactionHistory } from "@/hooks/query/useTransactionHistory";
import { useBotTransactionHistory } from "@/hooks/query/useBotTransactionHistory";
import { useTransactionHistory, useBotTransactionHistory } from "@/hooks/query/useTransactionHistory";
import {
ACTIVITY_TITLE,
getActivityCategory,
Expand All @@ -17,9 +16,6 @@ import {
} from "@/lib/activity";
import { useStore } from "@/lib/store";

// Tipjar/faucet/gift and tasks have no backend endpoint yet.
const COMING_SOON_CATEGORIES: ActivityCategory[] = ["tasks"];

export default function ActivityPage() {
const { balanceVisible, toggleBalanceVisible } = useStore();
const [search, setSearch] = useState("");
Expand All @@ -36,8 +32,8 @@ export default function ActivityPage() {
[dca.transactions, botHistory.transactions]
);

const showDca = category !== "transactions";
const showBotHistory = category === "transactions";
const showDca = category === "all" || category === "plans";
const showBotHistory = category === "all" || category === "transactions";
const isLoading =
(showDca && dca.isLoading) || (showBotHistory && botHistory.isLoading);
const hasNextPage = (showDca && dca.hasNextPage) || (showBotHistory && botHistory.hasNextPage);
Expand All @@ -47,14 +43,10 @@ export default function ActivityPage() {
if (showBotHistory && botHistory.hasNextPage) botHistory.fetchNextPage();
};

const comingSoon = COMING_SOON_CATEGORIES.includes(category);

const groups = useMemo(() => {
if (comingSoon) return [];

const filtered = activity.filter((item) => {
const itemCategory = getActivityCategory(item.type);
if (category === "all" ? itemCategory === "transactions" : itemCategory !== category) {
if (category !== "all" && itemCategory !== category) {
return false;
}
if (!search.trim()) return true;
Expand All @@ -80,7 +72,7 @@ export default function ActivityPage() {
}

return Array.from(byDay.entries());
}, [activity, comingSoon, search, category]);
}, [activity, search, category]);

return (
<div className="flex w-full flex-col gap-5">
Expand All @@ -89,14 +81,13 @@ export default function ActivityPage() {
onChange={setSearch}
visible={balanceVisible}
onToggleVisible={toggleBalanceVisible}
disabled
/>

<ActivityTabs value={category} onChange={setCategory} />

{isLoading ? (
<ActivitySkeleton />
) : comingSoon ? (
<p className="py-8 text-center text-[14px] text-[#64748b]">Coming soon.</p>
) : groups.length === 0 ? (
<p className="py-8 text-center text-[14px] text-[#64748b]">No activity found.</p>
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/components/dashboard/activity/ActivityRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function ActivityRow({ item, visible }: ActivityRowProps) {
</span>
}
after={
<div className="flex items-center gap-0.5">
<div className="flex shrink-0 items-center gap-0.5">
<div className="flex flex-col items-end gap-0.5">
<p
className={`text-right text-[14px] leading-4 ${
Expand Down
24 changes: 20 additions & 4 deletions src/components/dashboard/activity/ActivitySearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,47 @@ import { IconButton } from "@telegram-apps/telegram-ui";
import { Funnel } from "lucide-react";
import { SearchField } from "@/components/ui/search-field";
import { VisibleToggle } from "@/components/ui/visible-toggle";
import { cn } from "@/lib/cn";

export interface ActivitySearchBarProps {
value: string;
onChange: (value: string) => void;
visible: boolean;
onToggleVisible: () => void;
disabled?: boolean;
}

export function ActivitySearchBar({
value,
onChange,
visible,
onToggleVisible,
disabled = false,
}: ActivitySearchBarProps) {
return (
<div className="flex w-full items-center gap-2">
<SearchField className="flex-1" value={value} onChange={(e) => onChange(e.target.value)} />
<SearchField
className={cn("flex-1", disabled && "opacity-50 cursor-not-allowed")}
value={value}
onChange={(e) => onChange(e.target.value)}
disabled={disabled}
/>
<IconButton
mode="gray"
size="m"
disabled={disabled}
className={cn(
"bg-white! dark:bg-[#0B0F14]!",
disabled && "opacity-50 cursor-not-allowed"
)}
>
<Funnel size={18} strokeWidth={1.75} className="text-[#111821] dark:text-[#f1f5f9]" />
</IconButton>
<VisibleToggle
visible={visible}
onToggle={onToggleVisible}
className="bg-white! dark:bg-[#0B0F14]!"
/>
<IconButton mode="gray" size="m" className="bg-white! dark:bg-[#0B0F14]!">
<Funnel size={18} strokeWidth={1.75} className="text-[#111821] dark:text-[#f1f5f9]" />
</IconButton>
</div>
);
}
3 changes: 1 addition & 2 deletions src/components/dashboard/activity/ActivityTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import type { ActivityCategory } from "@/lib/activity";

const TABS: { value: ActivityCategory; label: string }[] = [
{ value: "all", label: "All Activities" },
{ value: "transactions", label: "Transactions" },
{ value: "tasks", label: "Tasks" },
{ value: "plans", label: "Plans" },
{ value: "transactions", label: "Transactions" },
];

export interface ActivityTabsProps {
Expand Down
75 changes: 0 additions & 75 deletions src/hooks/query/useBotTransactionHistory.ts

This file was deleted.

Loading