feat: enterprise multi-account vault - eliminate all hardcoded accounts, persistent vault api, 1-click account switcher drawer
This commit is contained in:
+100
-8
@@ -11,6 +11,7 @@ import { TitanOrderTerminal } from "@/components/execution/TitanOrderTerminal";
|
||||
import { AuraAgenticCopilot } from "@/components/agentic/AuraAgenticCopilot";
|
||||
import { SecurityGate } from "@/components/auth/SecurityGate";
|
||||
import { TradePosition } from "@/components/positions/ActiveTradesTable";
|
||||
import { AccountVaultModal, MT5AccountVaultItem } from "@/components/broker/AccountVaultModal";
|
||||
import { useExnessWebSocket } from "@/hooks/useExnessWebSocket";
|
||||
import { KeyRound, Layers } from "lucide-react";
|
||||
import { soundFX } from "@/lib/soundEffects";
|
||||
@@ -26,6 +27,11 @@ export default function TitanQuantTerminalPage() {
|
||||
orderType: "BUY" | "SELL";
|
||||
} | null>(null);
|
||||
|
||||
// Dynamic Multi-Account Vault State
|
||||
const [accounts, setAccounts] = useState<MT5AccountVaultItem[]>([]);
|
||||
const [activeAccount, setActiveAccount] = useState<MT5AccountVaultItem | null>(null);
|
||||
const [showVaultModal, setShowVaultModal] = useState(false);
|
||||
|
||||
const [apiBaseUrl, setApiBaseUrl] = useState(() => {
|
||||
if (typeof window !== "undefined") {
|
||||
if (window.location.hostname === "localhost" && window.location.port === "3000") {
|
||||
@@ -53,7 +59,7 @@ export default function TitanQuantTerminalPage() {
|
||||
const [positions, setPositions] = useState<TradePosition[]>([]);
|
||||
const [showConnectModal, setShowConnectModal] = useState(false);
|
||||
|
||||
// Exness Credential Inputs
|
||||
// Exness Credential Inputs (for direct connection modal fallback)
|
||||
const [exnessAccount, setExnessAccount] = useState("425437997");
|
||||
const [exnessPassword, setExnessPassword] = useState("");
|
||||
const [exnessServer, setExnessServer] = useState("Exness-MT5Real15");
|
||||
@@ -89,6 +95,74 @@ export default function TitanQuantTerminalPage() {
|
||||
setIsUnlocked(false);
|
||||
};
|
||||
|
||||
// Fetch Accounts from Persistent Vault
|
||||
const fetchAccounts = async () => {
|
||||
try {
|
||||
const res = await fetch(`${apiBaseUrl}/api/v1/broker/accounts`);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
setAccounts(data.accounts || []);
|
||||
if (data.active_account) {
|
||||
setActiveAccount(data.active_account);
|
||||
setExnessAccount(String(data.active_account.account_id));
|
||||
setExnessServer(data.active_account.server);
|
||||
} else if (data.accounts && data.accounts.length > 0) {
|
||||
setActiveAccount(data.accounts[0]);
|
||||
setExnessAccount(String(data.accounts[0].account_id));
|
||||
setExnessServer(data.accounts[0].server);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Error loading account vault:", err);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchAccounts();
|
||||
}, [apiBaseUrl]);
|
||||
|
||||
// Account Switcher Handler
|
||||
const handleSwitchAccount = async (accountId: number) => {
|
||||
try {
|
||||
const res = await fetch(`${apiBaseUrl}/api/v1/broker/accounts/switch`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ account_id: accountId }),
|
||||
});
|
||||
if (res.ok) {
|
||||
await fetchAccounts();
|
||||
}
|
||||
} catch (err: any) {
|
||||
alert(`Account switch failed: ${err.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
// Add Account Handler
|
||||
const handleAddAccount = async (newAcc: { name: string; account_id: number; server: string; password: string }) => {
|
||||
const res = await fetch(`${apiBaseUrl}/api/v1/broker/accounts`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(newAcc),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json();
|
||||
throw new Error(data.detail || "Failed to register account");
|
||||
}
|
||||
await fetchAccounts();
|
||||
};
|
||||
|
||||
// Delete Account Handler
|
||||
const handleDeleteAccount = async (accountId: number) => {
|
||||
const res = await fetch(`${apiBaseUrl}/api/v1/broker/accounts/${accountId}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json();
|
||||
throw new Error(data.detail || "Failed to delete account");
|
||||
}
|
||||
await fetchAccounts();
|
||||
};
|
||||
|
||||
// Fetch Confluence Analysis
|
||||
const fetchAnalysis = async () => {
|
||||
try {
|
||||
@@ -199,6 +273,7 @@ export default function TitanQuantTerminalPage() {
|
||||
soundFX.playUnlock();
|
||||
alert("🟢 Exness Account Connected Successfully!");
|
||||
setShowConnectModal(false);
|
||||
fetchAccounts();
|
||||
} else {
|
||||
soundFX.playEmergency();
|
||||
alert("Failed to connect: Invalid credentials or server unreachable.");
|
||||
@@ -216,7 +291,7 @@ export default function TitanQuantTerminalPage() {
|
||||
|
||||
return (
|
||||
<main className="flex flex-col min-h-screen bg-[#04080f] text-gray-100 select-none">
|
||||
{/* 1. Global Institutional Top HUD (Single-Tier, No Wrap) */}
|
||||
{/* 1. Global Institutional Top HUD with Dynamic Account Switcher */}
|
||||
<TitanHeader
|
||||
telemetry={packet?.telemetry || null}
|
||||
ping={ping}
|
||||
@@ -226,6 +301,12 @@ export default function TitanQuantTerminalPage() {
|
||||
onLockTerminal={handleLockTerminal}
|
||||
activeWorkspaceMode={workspaceMode}
|
||||
onChangeWorkspaceMode={setWorkspaceMode}
|
||||
activeAccount={activeAccount ? {
|
||||
account_id: activeAccount.account_id,
|
||||
server: activeAccount.server,
|
||||
name: activeAccount.name
|
||||
} : null}
|
||||
onOpenAccountVault={() => setShowVaultModal(true)}
|
||||
/>
|
||||
|
||||
{/* 2. Dynamic Institutional Workspace (Pro, Focus, or Agentic Cockpit) */}
|
||||
@@ -250,7 +331,7 @@ export default function TitanQuantTerminalPage() {
|
||||
</aside>
|
||||
)}
|
||||
|
||||
{/* Center Stage: TradingView Advanced Chart & Cockpit Dock */}
|
||||
{/* Center Stage: Dual-Engine Charting Stage & Cockpit Dock */}
|
||||
<section
|
||||
className={`flex flex-col gap-2.5 ${
|
||||
workspaceMode === "focus"
|
||||
@@ -265,11 +346,11 @@ export default function TitanQuantTerminalPage() {
|
||||
timeframe={activeTimeframe}
|
||||
onSelectTimeframe={(tf) => setActiveTimeframe(tf)}
|
||||
liveTick={packet?.tick || null}
|
||||
onOpenConnectModal={() => setShowConnectModal(true)}
|
||||
onOpenConnectModal={() => setShowVaultModal(true)}
|
||||
isTheaterMode={workspaceMode === "focus"}
|
||||
onToggleTheaterMode={() => setWorkspaceMode(workspaceMode === "focus" ? "pro" : "focus")}
|
||||
exnessAccount={exnessAccount}
|
||||
exnessServer={exnessServer}
|
||||
exnessAccount={activeAccount ? String(activeAccount.account_id) : exnessAccount}
|
||||
exnessServer={activeAccount ? activeAccount.server : exnessServer}
|
||||
/>
|
||||
|
||||
{/* Lower 4-Tab Analytical Cockpit Dock */}
|
||||
@@ -295,7 +376,7 @@ export default function TitanQuantTerminalPage() {
|
||||
workspaceMode === "agentic" ? "xl:col-span-5" : "xl:col-span-3"
|
||||
}`}
|
||||
>
|
||||
{/* Hermes Agentic Copilot HUD (Always visible in Pro & Agentic mode) */}
|
||||
{/* Hermes Agentic Copilot HUD */}
|
||||
<div className="shrink-0">
|
||||
<AuraAgenticCopilot
|
||||
confluence={confluence}
|
||||
@@ -325,7 +406,18 @@ export default function TitanQuantTerminalPage() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Connect Broker Modal */}
|
||||
{/* Multi-Account Vault Modal */}
|
||||
<AccountVaultModal
|
||||
isOpen={showVaultModal}
|
||||
onClose={() => setShowVaultModal(false)}
|
||||
accounts={accounts}
|
||||
activeAccount={activeAccount}
|
||||
onSwitchAccount={handleSwitchAccount}
|
||||
onAddAccount={handleAddAccount}
|
||||
onDeleteAccount={handleDeleteAccount}
|
||||
/>
|
||||
|
||||
{/* Connect Broker Modal Fallback */}
|
||||
{showConnectModal && (
|
||||
<div className="fixed inset-0 z-50 bg-black/80 backdrop-blur-sm flex items-center justify-center p-4">
|
||||
<div className="bg-[#091222] border border-[#14233d] rounded-2xl max-w-md w-full p-6 shadow-2xl font-mono">
|
||||
|
||||
Reference in New Issue
Block a user