Skip to content
Merged
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
129 changes: 80 additions & 49 deletions src/app/profile/[address]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { getFullUserProfile } from "../../../../lib/actions";
import { truncateAddress } from "../../../../lib/utils";
import { formatPrice, formatSupply } from "../../../../lib/format";
import { getTokenPrice, mcv2BondAbi, erc20Abi, type TokenPriceInfo, get24hPriceChange, getTokenTVL } from "../../../../lib/price";

Check warning on line 14 in src/app/profile/[address]/page.tsx

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

'TokenPriceInfo' is defined but never used
import { browserClient } from "../../../../lib/rpc";
import type { FarcasterProfile } from "../../../../lib/farcaster";
import type { AgentMetadata } from "../../../../lib/contracts/erc8004";
Expand Down Expand Up @@ -133,7 +133,7 @@
if (r <= 0) clearInterval(interval);
}, 1000);
return () => clearInterval(interval);
}, [dbUser?.steemhunt_fetched_at]);

Check warning on line 136 in src/app/profile/[address]/page.tsx

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

React Hook useEffect has a missing dependency: 'COOLDOWN_MS'. Either include it or remove the dependency array

const onCooldown = cooldownRemaining > 0;

Expand Down Expand Up @@ -667,7 +667,7 @@
});

// Claimable royalties (own profile only)
const { data: royaltyInfo } = useQuery({

Check warning on line 670 in src/app/profile/[address]/page.tsx

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

'royaltyInfo' is assigned a value but never used
queryKey: ["profile-royalties", address],
queryFn: async () => {
const [balance, claimed] = await browserClient.readContract({
Expand Down Expand Up @@ -824,7 +824,7 @@
}) {
const tokenAddr = storyline.token_address as Address;

const { data: priceInfo } = useQuery({

Check warning on line 827 in src/app/profile/[address]/page.tsx

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

'priceInfo' is assigned a value but never used
queryKey: ["profile-story-price", storyline.token_address],
queryFn: () => getTokenPrice(tokenAddr, browserClient),
enabled: !!storyline.token_address,
Expand Down Expand Up @@ -1094,7 +1094,7 @@

const DONATION_PAGE_SIZE = 10;

function ProfileDonationHistory({ storylineId }: { storylineId: number }) {

Check warning on line 1097 in src/app/profile/[address]/page.tsx

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

'ProfileDonationHistory' is defined but never used
const { data: plotUsd } = usePlotUsdPrice();
const {
data,
Expand Down Expand Up @@ -1376,7 +1376,7 @@
const {
data: donationPages,
isLoading: donGivenLoading,
isFetchingNextPage: donFetchingNext,

Check warning on line 1379 in src/app/profile/[address]/page.tsx

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

'donFetchingNext' is assigned a value but never used
fetchNextPage: donFetchNext,
hasNextPage: donHasNext,
} = useInfiniteQuery({
Expand Down Expand Up @@ -1441,39 +1441,47 @@

const totalValue = holdings?.reduce((sum, h) => sum + h.value, BigInt(0)) ?? BigInt(0);
const reserveDecimals = holdings && holdings.length > 0 ? holdings[0].reserveDecimals : 18;
const bestPick = holdings && holdings.length > 0
? holdings.reduce((best, h) =>
(h.priceChange ?? -Infinity) > (best.priceChange ?? -Infinity) ? h : best
)
: null;
const totalDonated = donationsGiven.reduce((sum, d) => sum + BigInt(d.amount), BigInt(0));

// Compute portfolio-level cost basis % change (only if all holdings have entry prices)
const portfolioCostPct = (() => {
if (!holdings || holdings.length === 0 || plotUsd == null) return null;
if (holdings.some(h => h.entryPrice === null || h.entryPrice <= 0)) return null;
let totalCurrentUsd = 0;
let totalCostUsd = 0;
for (const h of holdings) {
const currentPrice = Number(formatUnits(h.price, 18));
const balanceNum = Number(formatUnits(h.balance, 18));
totalCurrentUsd += currentPrice * balanceNum * plotUsd;
totalCostUsd += h.entryPrice! * balanceNum * plotUsd;
}
if (totalCostUsd === 0) return null;
return ((totalCurrentUsd - totalCostUsd) / totalCostUsd) * 100;
})();

return (
<div className="mt-6 space-y-4">
{/* Portfolio summary */}
{hasHoldings && (
<>
<p className="text-muted text-[10px] uppercase tracking-wider">Portfolio</p>
<div className="border-border rounded border px-4 py-3 text-xs">
<div className="grid grid-cols-2 sm:grid-cols-4 gap-2">
<div className="border-border rounded border px-2 py-1.5 text-center">
<div className="text-foreground text-sm font-bold">{formatPrice(formatUnits(totalValue, reserveDecimals))}</div>
<div className="text-muted text-[9px]">{RESERVE_LABEL}</div>
</div>
<div className="grid grid-cols-2 gap-2">
<div className="border-border rounded border px-2 py-1.5 text-center">
<div className="text-foreground text-sm font-bold">{plotUsd ? formatUsdValue(Number(formatUnits(totalValue, reserveDecimals)) * plotUsd) : "—"}</div>
<div className="text-muted text-[9px]">USD</div>
<div className="text-foreground text-sm font-bold leading-tight">
{plotUsd ? formatUsdValue(Number(formatUnits(totalValue, reserveDecimals)) * plotUsd) : "—"}
{portfolioCostPct !== null && (
<span className={`ml-1 text-xs font-medium ${portfolioCostPct >= 0 ? "text-accent" : "text-error"}`}>
{portfolioCostPct >= 0 ? "+" : ""}{portfolioCostPct.toFixed(1)}%
</span>
)}
</div>
<div className="text-muted text-[9px]">Value</div>
</div>
<div className="border-border rounded border px-2 py-1.5 text-center">
<div className="text-foreground text-sm font-bold">{holdings!.length}</div>
<div className="text-muted text-[9px]">Holdings</div>
</div>
<div className="border-border rounded border px-2 py-1.5 text-center">
<div className={`text-sm font-bold ${bestPick && bestPick.priceChange !== null ? (bestPick.priceChange >= 0 ? "text-accent" : "text-error") : "text-foreground"}`}>
{bestPick && bestPick.priceChange !== null ? `${bestPick.priceChange >= 0 ? "+" : ""}${bestPick.priceChange.toFixed(1)}%` : "—"}
</div>
<div className="text-muted text-[9px]">Best 24h</div>
</div>
</div>
</div>
</>
Expand Down Expand Up @@ -1527,11 +1535,16 @@
<div className="border-border rounded border px-2 py-1.5 text-center">
<div className="text-foreground text-sm font-bold leading-tight">
{plotUsd ? formatUsdValue(Number(formatUnits(h.value, h.reserveDecimals)) * plotUsd) : "—"}
{h.priceChange !== null && (
<span className={`ml-1 text-xs font-medium ${h.priceChange >= 0 ? "text-accent" : "text-error"}`}>
{h.priceChange >= 0 ? "+" : ""}{h.priceChange.toFixed(1)}%
</span>
)}
{(() => {
if (h.entryPrice == null || h.entryPrice <= 0 || plotUsd == null) return null;
const currentPrice = Number(formatUnits(h.price, 18));
const costPct = ((currentPrice - h.entryPrice) / h.entryPrice) * 100;
return (
<span className={`ml-1 text-xs font-medium ${costPct >= 0 ? "text-accent" : "text-error"}`}>
{costPct >= 0 ? "+" : ""}{costPct.toFixed(1)}%
</span>
);
})()}
</div>
<div className="text-muted text-[9px]">Value</div>
</div>
Expand All @@ -1540,33 +1553,9 @@
<div className="text-foreground text-sm font-bold">{formatCompact(Number(formatUnits(h.balance, 18)))}</div>
<div className="text-muted text-[9px]">Balance</div>
</div>
{/* PnL */}
<div className="border-border rounded border px-2 py-1.5 text-center">
{h.entryPrice !== null && h.entryPrice > 0 && plotUsd != null ? (() => {
const currentPrice = Number(formatUnits(h.price, 18));
const balanceNum = Number(formatUnits(h.balance, 18));
const pnlUsd = (currentPrice - h.entryPrice) * balanceNum * plotUsd;
const pnlPct = ((currentPrice - h.entryPrice) / h.entryPrice) * 100;
const isPositive = pnlUsd >= 0;
return (
<div className={`text-sm font-bold leading-tight ${isPositive ? "text-accent" : "text-error"}`}>
{isPositive ? "+" : "-"}{formatUsdValue(Math.abs(pnlUsd))}
<span className="ml-1 text-xs">{isPositive ? "+" : ""}{pnlPct.toFixed(1)}%</span>
</div>
);
})() : (
<div className="text-foreground text-sm font-bold">—</div>
)}
<div className="text-muted text-[9px]">PnL</div>
</div>
{/* First Traded */}
<div className="border-border rounded border px-2 py-1.5 text-center">
<div className="text-foreground text-sm font-bold">
{h.firstTraded ? new Date(h.firstTraded).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" }) : "—"}
</div>
<div className="text-muted text-[9px]">First Traded</div>
</div>
</div>
{/* Recent transactions */}
<HoldingRecentTrades address={address} storylineId={h.storyline.storyline_id} plotUsd={plotUsd} />
</div>
</div>
</div>
Expand All @@ -1579,6 +1568,48 @@
);
}

// ---------------------------------------------------------------------------
// Holding Recent Trades — last 5 transactions for a specific story token
// ---------------------------------------------------------------------------

function HoldingRecentTrades({ address, storylineId, plotUsd }: { address: string; storylineId: number; plotUsd?: number | null }) {
const { data: trades, isLoading } = useQuery({
queryKey: ["holding-recent-trades", address, storylineId],
queryFn: async () => {
if (!supabase) return [];
const { data } = await supabase
.from("trade_history")
.select("event_type, reserve_amount, block_timestamp")
.eq("user_address", address)
.eq("storyline_id", storylineId)
.eq("contract_address", MCV2_BOND.toLowerCase())
.order("block_timestamp", { ascending: false })
.limit(5);
return data ?? [];
},
staleTime: 60000,
});

if (isLoading || !trades || trades.length === 0) return null;

return (
<div className="mt-2 space-y-1">
{trades.map((t, i) => {
const isBuy = t.event_type === "mint";
const date = new Date(t.block_timestamp).toLocaleDateString("en-US", { month: "short", day: "numeric" });
const amount = plotUsd != null ? formatUsdValue(t.reserve_amount * plotUsd) : `${formatPrice(t.reserve_amount)} ${RESERVE_LABEL}`;
return (
<div key={i} className="flex items-center justify-between text-[10px]">
<span className={isBuy ? "text-accent" : "text-error"}>{isBuy ? "Buy" : "Sell"}</span>
<span className="text-foreground">{amount}</span>
<span className="text-muted">{date}</span>
</div>
);
})}
</div>
);
}

// ---------------------------------------------------------------------------
// Portfolio Trading History — paginated trades
// ---------------------------------------------------------------------------
Expand Down
Loading