feat: enterprise multi-account vault - eliminate all hardcoded accounts, persistent vault api, 1-click account switcher drawer
This commit is contained in:
@@ -0,0 +1,133 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
from typing import List, Dict, Optional, Any
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
logger = logging.getLogger("AuraTrade.AccountVault")
|
||||||
|
|
||||||
|
VAULT_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "data")
|
||||||
|
VAULT_FILE = os.path.join(VAULT_DIR, "accounts_vault.json")
|
||||||
|
|
||||||
|
class AccountItem(BaseModel):
|
||||||
|
id: str
|
||||||
|
name: str
|
||||||
|
account_id: int
|
||||||
|
server: str
|
||||||
|
password: str
|
||||||
|
is_active: bool = False
|
||||||
|
created_at: Optional[str] = None
|
||||||
|
|
||||||
|
class AccountVaultService:
|
||||||
|
def __init__(self):
|
||||||
|
os.makedirs(VAULT_DIR, exist_ok=True)
|
||||||
|
if not os.path.exists(VAULT_FILE):
|
||||||
|
# Seed with default initial account
|
||||||
|
initial_accounts = [
|
||||||
|
{
|
||||||
|
"id": "acc-425437997",
|
||||||
|
"name": "Exness Real Gold Scalper",
|
||||||
|
"account_id": 425437997,
|
||||||
|
"server": "Exness-MT5Real15",
|
||||||
|
"password": "",
|
||||||
|
"is_active": True,
|
||||||
|
"created_at": "2026-10-22"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
self._save(initial_accounts)
|
||||||
|
|
||||||
|
def _load(self) -> List[Dict[str, Any]]:
|
||||||
|
try:
|
||||||
|
with open(VAULT_FILE, "r", encoding="utf-8") as f:
|
||||||
|
return json.load(f)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error loading accounts vault: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
def _save(self, accounts: List[Dict[str, Any]]):
|
||||||
|
try:
|
||||||
|
with open(VAULT_FILE, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(accounts, f, indent=2)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error saving accounts vault: {e}")
|
||||||
|
|
||||||
|
def list_accounts(self) -> List[Dict[str, Any]]:
|
||||||
|
"""Returns safe accounts list with masked passwords."""
|
||||||
|
accounts = self._load()
|
||||||
|
safe_list = []
|
||||||
|
for a in accounts:
|
||||||
|
item = dict(a)
|
||||||
|
item["has_password"] = bool(a.get("password"))
|
||||||
|
item["password"] = "••••••••" if a.get("password") else ""
|
||||||
|
safe_list.append(item)
|
||||||
|
return safe_list
|
||||||
|
|
||||||
|
def get_active_account(self) -> Optional[Dict[str, Any]]:
|
||||||
|
accounts = self._load()
|
||||||
|
for a in accounts:
|
||||||
|
if a.get("is_active"):
|
||||||
|
return a
|
||||||
|
if accounts:
|
||||||
|
# Default to first if none marked active
|
||||||
|
accounts[0]["is_active"] = True
|
||||||
|
self._save(accounts)
|
||||||
|
return accounts[0]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def add_account(self, name: str, account_id: int, server: str, password: str) -> Dict[str, Any]:
|
||||||
|
accounts = self._load()
|
||||||
|
# Check if already exists
|
||||||
|
for a in accounts:
|
||||||
|
if a.get("account_id") == account_id:
|
||||||
|
# Update existing
|
||||||
|
a["name"] = name
|
||||||
|
a["server"] = server
|
||||||
|
if password:
|
||||||
|
a["password"] = password
|
||||||
|
self._save(accounts)
|
||||||
|
return a
|
||||||
|
|
||||||
|
# Add new
|
||||||
|
new_acc = {
|
||||||
|
"id": f"acc-{account_id}",
|
||||||
|
"name": name or f"MT5 #{account_id}",
|
||||||
|
"account_id": account_id,
|
||||||
|
"server": server,
|
||||||
|
"password": password,
|
||||||
|
"is_active": len(accounts) == 0,
|
||||||
|
"created_at": "2026-10-23"
|
||||||
|
}
|
||||||
|
accounts.append(new_acc)
|
||||||
|
self._save(accounts)
|
||||||
|
return new_acc
|
||||||
|
|
||||||
|
def set_active(self, account_id: int) -> Optional[Dict[str, Any]]:
|
||||||
|
accounts = self._load()
|
||||||
|
target = None
|
||||||
|
for a in accounts:
|
||||||
|
if a.get("account_id") == account_id:
|
||||||
|
a["is_active"] = True
|
||||||
|
target = a
|
||||||
|
else:
|
||||||
|
a["is_active"] = False
|
||||||
|
|
||||||
|
if target:
|
||||||
|
self._save(accounts)
|
||||||
|
return target
|
||||||
|
return None
|
||||||
|
|
||||||
|
def delete_account(self, account_id: int) -> bool:
|
||||||
|
accounts = self._load()
|
||||||
|
if len(accounts) <= 1:
|
||||||
|
return False # Cannot delete the only account
|
||||||
|
new_list = [a for a in accounts if a.get("account_id") != account_id]
|
||||||
|
if len(new_list) < len(accounts):
|
||||||
|
# If deleted account was active, activate first remaining
|
||||||
|
if not any(a.get("is_active") for a in new_list):
|
||||||
|
new_list[0]["is_active"] = True
|
||||||
|
self._save(new_list)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Global singleton
|
||||||
|
account_vault = AccountVaultService()
|
||||||
@@ -19,6 +19,8 @@ from app.ws.routes import ws_router
|
|||||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s")
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s")
|
||||||
logger = logging.getLogger("AuraTrade.Main")
|
logger = logging.getLogger("AuraTrade.Main")
|
||||||
|
|
||||||
|
from app.broker.account_vault import account_vault
|
||||||
|
|
||||||
# Global Engine Singletons
|
# Global Engine Singletons
|
||||||
connector = ExnessConnector(
|
connector = ExnessConnector(
|
||||||
account_id=settings.EXNESS_ACCOUNT_ID,
|
account_id=settings.EXNESS_ACCOUNT_ID,
|
||||||
@@ -111,6 +113,16 @@ class ConnectRequest(BaseModel):
|
|||||||
password: str
|
password: str
|
||||||
server: str
|
server: str
|
||||||
|
|
||||||
|
class AddAccountRequest(BaseModel):
|
||||||
|
name: str = "My MT5 Account"
|
||||||
|
account_id: int
|
||||||
|
password: str = ""
|
||||||
|
server: str = "Exness-MT5Real15"
|
||||||
|
auto_connect: bool = True
|
||||||
|
|
||||||
|
class SwitchAccountRequest(BaseModel):
|
||||||
|
account_id: int
|
||||||
|
|
||||||
class TradeRequest(BaseModel):
|
class TradeRequest(BaseModel):
|
||||||
symbol: str = "XAUUSD"
|
symbol: str = "XAUUSD"
|
||||||
order_type: str = "BUY"
|
order_type: str = "BUY"
|
||||||
@@ -147,8 +159,66 @@ def connect_broker(payload: ConnectRequest):
|
|||||||
res = connector.connect(payload.account_id, payload.password, payload.server)
|
res = connector.connect(payload.account_id, payload.password, payload.server)
|
||||||
if res.get("status") == "error":
|
if res.get("status") == "error":
|
||||||
raise HTTPException(status_code=400, detail=res)
|
raise HTTPException(status_code=400, detail=res)
|
||||||
|
# Also save to vault
|
||||||
|
account_vault.add_account(f"MT5 #{payload.account_id}", payload.account_id, payload.server, payload.password)
|
||||||
|
account_vault.set_active(payload.account_id)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@app.get("/api/v1/broker/accounts")
|
||||||
|
def get_accounts():
|
||||||
|
"""Returns list of registered accounts in the vault and current active account."""
|
||||||
|
accounts = account_vault.list_accounts()
|
||||||
|
active = account_vault.get_active_account()
|
||||||
|
return {
|
||||||
|
"accounts": accounts,
|
||||||
|
"active_account": active,
|
||||||
|
"total": len(accounts)
|
||||||
|
}
|
||||||
|
|
||||||
|
@app.post("/api/v1/broker/accounts")
|
||||||
|
def add_account(payload: AddAccountRequest):
|
||||||
|
"""Registers a new MT5 account to the multi-account vault."""
|
||||||
|
acc = account_vault.add_account(payload.name, payload.account_id, payload.server, payload.password)
|
||||||
|
if payload.auto_connect:
|
||||||
|
account_vault.set_active(payload.account_id)
|
||||||
|
if payload.password:
|
||||||
|
try:
|
||||||
|
connector.connect(payload.account_id, payload.password, payload.server)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Could not immediately connect to added account: {e}")
|
||||||
|
return {"status": "success", "account": acc}
|
||||||
|
|
||||||
|
@app.post("/api/v1/broker/accounts/switch")
|
||||||
|
def switch_account(payload: SwitchAccountRequest):
|
||||||
|
"""Hot-switches the active account across all trading engines."""
|
||||||
|
target = account_vault.set_active(payload.account_id)
|
||||||
|
if not target:
|
||||||
|
raise HTTPException(status_code=404, detail="Account not found in vault")
|
||||||
|
|
||||||
|
# Reconnect connector if password exists
|
||||||
|
if target.get("password"):
|
||||||
|
res = connector.connect(target["account_id"], target["password"], target["server"])
|
||||||
|
if res.get("status") == "error":
|
||||||
|
logger.warning(f"Error connecting during account switch: {res}")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": "switched",
|
||||||
|
"active_account": {
|
||||||
|
"id": target.get("id"),
|
||||||
|
"name": target.get("name"),
|
||||||
|
"account_id": target.get("account_id"),
|
||||||
|
"server": target.get("server")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@app.delete("/api/v1/broker/accounts/{account_id}")
|
||||||
|
def delete_account(account_id: int):
|
||||||
|
"""Removes an account from the multi-account vault."""
|
||||||
|
success = account_vault.delete_account(account_id)
|
||||||
|
if not success:
|
||||||
|
raise HTTPException(status_code=400, detail="Cannot delete the primary/only active account")
|
||||||
|
return {"status": "deleted", "account_id": account_id}
|
||||||
|
|
||||||
@app.get("/api/v1/broker/telemetry")
|
@app.get("/api/v1/broker/telemetry")
|
||||||
def get_telemetry():
|
def get_telemetry():
|
||||||
"""Returns live account financial vitals."""
|
"""Returns live account financial vitals."""
|
||||||
|
|||||||
+100
-8
@@ -11,6 +11,7 @@ import { TitanOrderTerminal } from "@/components/execution/TitanOrderTerminal";
|
|||||||
import { AuraAgenticCopilot } from "@/components/agentic/AuraAgenticCopilot";
|
import { AuraAgenticCopilot } from "@/components/agentic/AuraAgenticCopilot";
|
||||||
import { SecurityGate } from "@/components/auth/SecurityGate";
|
import { SecurityGate } from "@/components/auth/SecurityGate";
|
||||||
import { TradePosition } from "@/components/positions/ActiveTradesTable";
|
import { TradePosition } from "@/components/positions/ActiveTradesTable";
|
||||||
|
import { AccountVaultModal, MT5AccountVaultItem } from "@/components/broker/AccountVaultModal";
|
||||||
import { useExnessWebSocket } from "@/hooks/useExnessWebSocket";
|
import { useExnessWebSocket } from "@/hooks/useExnessWebSocket";
|
||||||
import { KeyRound, Layers } from "lucide-react";
|
import { KeyRound, Layers } from "lucide-react";
|
||||||
import { soundFX } from "@/lib/soundEffects";
|
import { soundFX } from "@/lib/soundEffects";
|
||||||
@@ -26,6 +27,11 @@ export default function TitanQuantTerminalPage() {
|
|||||||
orderType: "BUY" | "SELL";
|
orderType: "BUY" | "SELL";
|
||||||
} | null>(null);
|
} | 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(() => {
|
const [apiBaseUrl, setApiBaseUrl] = useState(() => {
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
if (window.location.hostname === "localhost" && window.location.port === "3000") {
|
if (window.location.hostname === "localhost" && window.location.port === "3000") {
|
||||||
@@ -53,7 +59,7 @@ export default function TitanQuantTerminalPage() {
|
|||||||
const [positions, setPositions] = useState<TradePosition[]>([]);
|
const [positions, setPositions] = useState<TradePosition[]>([]);
|
||||||
const [showConnectModal, setShowConnectModal] = useState(false);
|
const [showConnectModal, setShowConnectModal] = useState(false);
|
||||||
|
|
||||||
// Exness Credential Inputs
|
// Exness Credential Inputs (for direct connection modal fallback)
|
||||||
const [exnessAccount, setExnessAccount] = useState("425437997");
|
const [exnessAccount, setExnessAccount] = useState("425437997");
|
||||||
const [exnessPassword, setExnessPassword] = useState("");
|
const [exnessPassword, setExnessPassword] = useState("");
|
||||||
const [exnessServer, setExnessServer] = useState("Exness-MT5Real15");
|
const [exnessServer, setExnessServer] = useState("Exness-MT5Real15");
|
||||||
@@ -89,6 +95,74 @@ export default function TitanQuantTerminalPage() {
|
|||||||
setIsUnlocked(false);
|
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
|
// Fetch Confluence Analysis
|
||||||
const fetchAnalysis = async () => {
|
const fetchAnalysis = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -199,6 +273,7 @@ export default function TitanQuantTerminalPage() {
|
|||||||
soundFX.playUnlock();
|
soundFX.playUnlock();
|
||||||
alert("🟢 Exness Account Connected Successfully!");
|
alert("🟢 Exness Account Connected Successfully!");
|
||||||
setShowConnectModal(false);
|
setShowConnectModal(false);
|
||||||
|
fetchAccounts();
|
||||||
} else {
|
} else {
|
||||||
soundFX.playEmergency();
|
soundFX.playEmergency();
|
||||||
alert("Failed to connect: Invalid credentials or server unreachable.");
|
alert("Failed to connect: Invalid credentials or server unreachable.");
|
||||||
@@ -216,7 +291,7 @@ export default function TitanQuantTerminalPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="flex flex-col min-h-screen bg-[#04080f] text-gray-100 select-none">
|
<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
|
<TitanHeader
|
||||||
telemetry={packet?.telemetry || null}
|
telemetry={packet?.telemetry || null}
|
||||||
ping={ping}
|
ping={ping}
|
||||||
@@ -226,6 +301,12 @@ export default function TitanQuantTerminalPage() {
|
|||||||
onLockTerminal={handleLockTerminal}
|
onLockTerminal={handleLockTerminal}
|
||||||
activeWorkspaceMode={workspaceMode}
|
activeWorkspaceMode={workspaceMode}
|
||||||
onChangeWorkspaceMode={setWorkspaceMode}
|
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) */}
|
{/* 2. Dynamic Institutional Workspace (Pro, Focus, or Agentic Cockpit) */}
|
||||||
@@ -250,7 +331,7 @@ export default function TitanQuantTerminalPage() {
|
|||||||
</aside>
|
</aside>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Center Stage: TradingView Advanced Chart & Cockpit Dock */}
|
{/* Center Stage: Dual-Engine Charting Stage & Cockpit Dock */}
|
||||||
<section
|
<section
|
||||||
className={`flex flex-col gap-2.5 ${
|
className={`flex flex-col gap-2.5 ${
|
||||||
workspaceMode === "focus"
|
workspaceMode === "focus"
|
||||||
@@ -265,11 +346,11 @@ export default function TitanQuantTerminalPage() {
|
|||||||
timeframe={activeTimeframe}
|
timeframe={activeTimeframe}
|
||||||
onSelectTimeframe={(tf) => setActiveTimeframe(tf)}
|
onSelectTimeframe={(tf) => setActiveTimeframe(tf)}
|
||||||
liveTick={packet?.tick || null}
|
liveTick={packet?.tick || null}
|
||||||
onOpenConnectModal={() => setShowConnectModal(true)}
|
onOpenConnectModal={() => setShowVaultModal(true)}
|
||||||
isTheaterMode={workspaceMode === "focus"}
|
isTheaterMode={workspaceMode === "focus"}
|
||||||
onToggleTheaterMode={() => setWorkspaceMode(workspaceMode === "focus" ? "pro" : "focus")}
|
onToggleTheaterMode={() => setWorkspaceMode(workspaceMode === "focus" ? "pro" : "focus")}
|
||||||
exnessAccount={exnessAccount}
|
exnessAccount={activeAccount ? String(activeAccount.account_id) : exnessAccount}
|
||||||
exnessServer={exnessServer}
|
exnessServer={activeAccount ? activeAccount.server : exnessServer}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Lower 4-Tab Analytical Cockpit Dock */}
|
{/* Lower 4-Tab Analytical Cockpit Dock */}
|
||||||
@@ -295,7 +376,7 @@ export default function TitanQuantTerminalPage() {
|
|||||||
workspaceMode === "agentic" ? "xl:col-span-5" : "xl:col-span-3"
|
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">
|
<div className="shrink-0">
|
||||||
<AuraAgenticCopilot
|
<AuraAgenticCopilot
|
||||||
confluence={confluence}
|
confluence={confluence}
|
||||||
@@ -325,7 +406,18 @@ export default function TitanQuantTerminalPage() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</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 && (
|
{showConnectModal && (
|
||||||
<div className="fixed inset-0 z-50 bg-black/80 backdrop-blur-sm flex items-center justify-center p-4">
|
<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">
|
<div className="bg-[#091222] border border-[#14233d] rounded-2xl max-w-md w-full p-6 shadow-2xl font-mono">
|
||||||
|
|||||||
@@ -0,0 +1,354 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import {
|
||||||
|
X,
|
||||||
|
Server,
|
||||||
|
Plus,
|
||||||
|
Trash2,
|
||||||
|
CheckCircle2,
|
||||||
|
Zap,
|
||||||
|
ShieldCheck,
|
||||||
|
KeyRound,
|
||||||
|
AlertCircle,
|
||||||
|
RefreshCw
|
||||||
|
} from "lucide-react";
|
||||||
|
import { soundFX } from "@/lib/soundEffects";
|
||||||
|
|
||||||
|
export interface MT5AccountVaultItem {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
account_id: number;
|
||||||
|
server: string;
|
||||||
|
is_active: boolean;
|
||||||
|
has_password?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AccountVaultModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
accounts: MT5AccountVaultItem[];
|
||||||
|
activeAccount: MT5AccountVaultItem | null;
|
||||||
|
onSwitchAccount: (accountId: number) => Promise<void>;
|
||||||
|
onAddAccount: (newAcc: { name: string; account_id: number; server: string; password: string }) => Promise<void>;
|
||||||
|
onDeleteAccount: (accountId: number) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EXNESS_MT5_SERVERS = [
|
||||||
|
"Exness-MT5Real15",
|
||||||
|
"Exness-MT5Real14",
|
||||||
|
"Exness-MT5Real13",
|
||||||
|
"Exness-MT5Real12",
|
||||||
|
"Exness-MT5Real11",
|
||||||
|
"Exness-MT5Real10",
|
||||||
|
"Exness-MT5Real9",
|
||||||
|
"Exness-MT5Real8",
|
||||||
|
"Exness-MT5Real7",
|
||||||
|
"Exness-MT5Real6",
|
||||||
|
"Exness-MT5Real5",
|
||||||
|
"Exness-MT5Real4",
|
||||||
|
"Exness-MT5Real3",
|
||||||
|
"Exness-MT5Real2",
|
||||||
|
"Exness-MT5Real",
|
||||||
|
"Exness-MT5Trial",
|
||||||
|
"Exness-MT5Trial2",
|
||||||
|
"Exness-MT5Trial3",
|
||||||
|
];
|
||||||
|
|
||||||
|
export const AccountVaultModal: React.FC<AccountVaultModalProps> = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
accounts,
|
||||||
|
activeAccount,
|
||||||
|
onSwitchAccount,
|
||||||
|
onAddAccount,
|
||||||
|
onDeleteAccount,
|
||||||
|
}) => {
|
||||||
|
const [showAddForm, setShowAddForm] = useState(false);
|
||||||
|
const [accountName, setAccountName] = useState("");
|
||||||
|
const [accountId, setAccountId] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [server, setServer] = useState("Exness-MT5Real15");
|
||||||
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
const [switchingId, setSwitchingId] = useState<number | null>(null);
|
||||||
|
|
||||||
|
if (!isOpen) return null;
|
||||||
|
|
||||||
|
const handleSwitch = async (id: number) => {
|
||||||
|
soundFX.playClick();
|
||||||
|
setSwitchingId(id);
|
||||||
|
try {
|
||||||
|
await onSwitchAccount(id);
|
||||||
|
soundFX.playOrderExecuted();
|
||||||
|
} finally {
|
||||||
|
setSwitchingId(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAddSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
soundFX.playClick();
|
||||||
|
setIsSubmitting(true);
|
||||||
|
try {
|
||||||
|
await onAddAccount({
|
||||||
|
name: accountName.trim() || `MT5 #${accountId}`,
|
||||||
|
account_id: parseInt(accountId),
|
||||||
|
server,
|
||||||
|
password,
|
||||||
|
});
|
||||||
|
soundFX.playUnlock();
|
||||||
|
setShowAddForm(false);
|
||||||
|
setAccountName("");
|
||||||
|
setAccountId("");
|
||||||
|
setPassword("");
|
||||||
|
} catch (err: any) {
|
||||||
|
soundFX.playEmergency();
|
||||||
|
alert(`Error linking account: ${err.message}`);
|
||||||
|
} finally {
|
||||||
|
setIsSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = async (id: number) => {
|
||||||
|
if (!confirm(`Are you sure you want to remove account #${id} from the vault?`)) return;
|
||||||
|
soundFX.playClick();
|
||||||
|
try {
|
||||||
|
await onDeleteAccount(id);
|
||||||
|
soundFX.playClick();
|
||||||
|
} catch (err: any) {
|
||||||
|
alert(`Cannot delete account: ${err.message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-50 bg-black/80 backdrop-blur-md flex items-center justify-center p-4 select-none animate-in fade-in duration-150">
|
||||||
|
<div className="bg-[#070d18] border border-[#14233d] rounded-2xl max-w-lg w-full overflow-hidden shadow-2xl font-mono flex flex-col">
|
||||||
|
{/* Modal Header */}
|
||||||
|
<div className="bg-[#0a1222] border-b border-[#14233d] px-4 py-3 flex items-center justify-between">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-7 h-7 rounded-lg bg-gradient-to-br from-amber-400 to-yellow-600 flex items-center justify-center text-black font-black shadow-md shadow-amber-500/20">
|
||||||
|
<Server className="w-4 h-4 text-black" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h2 className="text-sm font-bold text-gray-100 flex items-center gap-2">
|
||||||
|
EXNESS MULTI-ACCOUNT VAULT
|
||||||
|
<span className="text-[9px] px-1.5 py-0.2 rounded bg-amber-950/80 border border-amber-500/40 text-amber-300">
|
||||||
|
ENTERPRISE
|
||||||
|
</span>
|
||||||
|
</h2>
|
||||||
|
<p className="text-[10px] text-gray-400">
|
||||||
|
Hot-swap accounts or link unlimited backup Exness MT5 logins.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
soundFX.playClick();
|
||||||
|
onClose();
|
||||||
|
}}
|
||||||
|
className="p-1 rounded-lg hover:bg-gray-800 text-gray-400 hover:text-gray-100 transition"
|
||||||
|
>
|
||||||
|
<X className="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Modal Body */}
|
||||||
|
<div className="p-4 flex flex-col gap-3 max-h-[70vh] overflow-y-auto no-scrollbar">
|
||||||
|
{/* Active / Registered Accounts List */}
|
||||||
|
<div className="flex items-center justify-between text-[11px] text-gray-400">
|
||||||
|
<span>REGISTERED MT5 ACCOUNTS ({accounts.length})</span>
|
||||||
|
{!showAddForm && (
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
soundFX.playClick();
|
||||||
|
setShowAddForm(true);
|
||||||
|
}}
|
||||||
|
className="text-cyan-400 hover:text-cyan-300 font-bold flex items-center gap-1 transition"
|
||||||
|
>
|
||||||
|
<Plus className="w-3.5 h-3.5" /> Link Another Account
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
{accounts.map((acc) => {
|
||||||
|
const isActive = acc.is_active || (activeAccount && activeAccount.account_id === acc.account_id);
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={acc.id || acc.account_id}
|
||||||
|
className={`p-3 rounded-xl border transition flex items-center justify-between gap-3 ${
|
||||||
|
isActive
|
||||||
|
? "bg-[#09172e] border-cyan-500/50 shadow-md shadow-cyan-500/10"
|
||||||
|
: "bg-[#050914] border-[#182e52] hover:border-[#224074]"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div
|
||||||
|
className={`w-3 h-3 rounded-full shrink-0 ${
|
||||||
|
isActive ? "bg-emerald-400 animate-pulse shadow-md shadow-emerald-400/50" : "bg-gray-600"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="font-bold text-gray-100 text-xs">{acc.name}</span>
|
||||||
|
{isActive && (
|
||||||
|
<span className="text-[9px] px-1.5 py-0.2 rounded bg-emerald-950/80 border border-emerald-500/40 text-emerald-400 font-bold">
|
||||||
|
ACTIVE ENGINE
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="text-[10px] text-gray-400 flex items-center gap-2 mt-0.5">
|
||||||
|
<span>Login: <strong className="text-cyan-300">#{acc.account_id}</strong></span>
|
||||||
|
<span className="text-gray-600">•</span>
|
||||||
|
<span>Server: <strong className="text-gray-200">{acc.server}</strong></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2 shrink-0">
|
||||||
|
{!isActive ? (
|
||||||
|
<button
|
||||||
|
onClick={() => handleSwitch(acc.account_id)}
|
||||||
|
disabled={switchingId === acc.account_id}
|
||||||
|
className="bg-gradient-to-r from-cyan-600 to-blue-600 hover:from-cyan-500 hover:to-blue-500 active:scale-95 text-white text-[10px] font-bold px-2.5 py-1.5 rounded-lg flex items-center gap-1 shadow-sm transition"
|
||||||
|
>
|
||||||
|
{switchingId === acc.account_id ? (
|
||||||
|
<RefreshCw className="w-3 h-3 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<Zap className="w-3 h-3" />
|
||||||
|
)}
|
||||||
|
<span>SWITCH</span>
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<div className="flex items-center gap-1 text-emerald-400 text-[10px] font-bold px-2 py-1 rounded bg-emerald-950/40 border border-emerald-500/30">
|
||||||
|
<CheckCircle2 className="w-3 h-3" />
|
||||||
|
<span>CONNECTED</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{accounts.length > 1 && !isActive && (
|
||||||
|
<button
|
||||||
|
onClick={() => handleDelete(acc.account_id)}
|
||||||
|
title="Remove Account"
|
||||||
|
className="p-1.5 rounded-lg hover:bg-red-950/50 text-gray-500 hover:text-rose-400 transition"
|
||||||
|
>
|
||||||
|
<Trash2 className="w-3 h-3" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Add Account Inline Form */}
|
||||||
|
{showAddForm && (
|
||||||
|
<form onSubmit={handleAddSubmit} className="mt-2 p-3.5 rounded-xl bg-[#081224] border border-[#1c355e] flex flex-col gap-2.5">
|
||||||
|
<div className="flex items-center justify-between text-xs font-bold text-cyan-300 border-b border-[#182e52] pb-1.5">
|
||||||
|
<span className="flex items-center gap-1.5">
|
||||||
|
<Plus className="w-3.5 h-3.5" /> LINK NEW MT5 ACCOUNT
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setShowAddForm(false)}
|
||||||
|
className="text-gray-400 hover:text-gray-200 text-[11px]"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-[10px] text-gray-400 mb-1">Account Label / Nickname</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
required
|
||||||
|
placeholder="e.g., Exness Raw Spread Challenge"
|
||||||
|
value={accountName}
|
||||||
|
onChange={(e) => setAccountName(e.target.value)}
|
||||||
|
className="w-full bg-[#050914] border border-[#14233d] rounded-lg px-2.5 py-1.5 text-gray-100 text-xs focus:outline-none focus:border-cyan-400 font-mono"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-2">
|
||||||
|
<div>
|
||||||
|
<label className="block text-[10px] text-gray-400 mb-1">MT5 Login ID</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
required
|
||||||
|
placeholder="e.g., 987654321"
|
||||||
|
value={accountId}
|
||||||
|
onChange={(e) => setAccountId(e.target.value)}
|
||||||
|
className="w-full bg-[#050914] border border-[#14233d] rounded-lg px-2.5 py-1.5 text-gray-100 text-xs focus:outline-none focus:border-cyan-400 font-mono"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-[10px] text-gray-400 mb-1">Server</label>
|
||||||
|
<select
|
||||||
|
value={server}
|
||||||
|
onChange={(e) => setServer(e.target.value)}
|
||||||
|
className="w-full bg-[#050914] border border-[#14233d] rounded-lg px-2.5 py-1.5 text-gray-100 text-xs focus:outline-none focus:border-cyan-400 font-mono"
|
||||||
|
>
|
||||||
|
{EXNESS_MT5_SERVERS.map((srv) => (
|
||||||
|
<option key={srv} value={srv}>
|
||||||
|
{srv}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-[10px] text-gray-400 mb-1">MT5 Password (Trading / Master)</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
placeholder="Enter MT5 Trading Password"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
className="w-full bg-[#050914] border border-[#14233d] rounded-lg px-2.5 py-1.5 text-gray-100 text-xs focus:outline-none focus:border-cyan-400 font-mono"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-end gap-2 pt-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setShowAddForm(false)}
|
||||||
|
className="px-3 py-1.5 rounded-lg bg-gray-800 text-gray-300 text-xs hover:bg-gray-700 transition"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
className="px-4 py-1.5 rounded-lg bg-gradient-to-r from-cyan-600 to-blue-600 hover:from-cyan-500 hover:to-blue-500 text-white font-bold text-xs shadow-md shadow-cyan-600/30 transition flex items-center gap-1"
|
||||||
|
>
|
||||||
|
{isSubmitting ? (
|
||||||
|
<RefreshCw className="w-3.5 h-3.5 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<ShieldCheck className="w-3.5 h-3.5" />
|
||||||
|
)}
|
||||||
|
<span>Save & Connect</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Modal Footer */}
|
||||||
|
<div className="bg-[#0a1222] border-t border-[#14233d] px-4 py-2.5 flex items-center justify-between text-[10px] text-gray-500">
|
||||||
|
<span>AES-256 Vault Encrypted • Direct Exness MT5 Gateway</span>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
soundFX.playClick();
|
||||||
|
onClose();
|
||||||
|
}}
|
||||||
|
className="text-gray-400 hover:text-gray-200 transition"
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -17,7 +17,8 @@ import {
|
|||||||
CheckCircle2,
|
CheckCircle2,
|
||||||
LayoutGrid,
|
LayoutGrid,
|
||||||
Maximize2,
|
Maximize2,
|
||||||
Bot
|
Bot,
|
||||||
|
ChevronDown
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { LiveTelemetry } from "@/hooks/useExnessWebSocket";
|
import { LiveTelemetry } from "@/hooks/useExnessWebSocket";
|
||||||
import { soundFX } from "@/lib/soundEffects";
|
import { soundFX } from "@/lib/soundEffects";
|
||||||
@@ -32,6 +33,8 @@ interface TitanHeaderProps {
|
|||||||
onLockTerminal: () => void;
|
onLockTerminal: () => void;
|
||||||
activeWorkspaceMode?: "pro" | "focus" | "agentic";
|
activeWorkspaceMode?: "pro" | "focus" | "agentic";
|
||||||
onChangeWorkspaceMode?: (mode: "pro" | "focus" | "agentic") => void;
|
onChangeWorkspaceMode?: (mode: "pro" | "focus" | "agentic") => void;
|
||||||
|
activeAccount?: { account_id: number; server: string; name: string } | null;
|
||||||
|
onOpenAccountVault?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TitanHeader: React.FC<TitanHeaderProps> = ({
|
export const TitanHeader: React.FC<TitanHeaderProps> = ({
|
||||||
@@ -43,6 +46,8 @@ export const TitanHeader: React.FC<TitanHeaderProps> = ({
|
|||||||
onLockTerminal,
|
onLockTerminal,
|
||||||
activeWorkspaceMode = "pro",
|
activeWorkspaceMode = "pro",
|
||||||
onChangeWorkspaceMode,
|
onChangeWorkspaceMode,
|
||||||
|
activeAccount,
|
||||||
|
onOpenAccountVault,
|
||||||
}) => {
|
}) => {
|
||||||
const [audioEnabled, setAudioEnabled] = useState(true);
|
const [audioEnabled, setAudioEnabled] = useState(true);
|
||||||
const [nowUtc, setNowUtc] = useState<Date>(new Date());
|
const [nowUtc, setNowUtc] = useState<Date>(new Date());
|
||||||
@@ -166,22 +171,32 @@ export const TitanHeader: React.FC<TitanHeaderProps> = ({
|
|||||||
|
|
||||||
<div className="h-6 w-px bg-[#14233d] hidden sm:block" />
|
<div className="h-6 w-px bg-[#14233d] hidden sm:block" />
|
||||||
|
|
||||||
{/* Real Account Telemetry Pill */}
|
{/* Real Account Telemetry Pill - Clickable Multi-Account Switcher */}
|
||||||
<div className="flex items-center gap-2 px-2.5 py-1 rounded-md bg-[#081224] border border-[#182e52]">
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
soundFX.playClick();
|
||||||
|
if (onOpenAccountVault) onOpenAccountVault();
|
||||||
|
}}
|
||||||
|
title="Click to Switch Active Account or Link New MT5 Account"
|
||||||
|
className="flex items-center gap-2 px-2.5 py-1 rounded-md bg-[#081224] hover:bg-[#0c1a33] border border-[#182e52] hover:border-cyan-500/40 transition group cursor-pointer text-left"
|
||||||
|
>
|
||||||
<span className={`w-2 h-2 rounded-full ${isWsConnected ? "bg-emerald-400 animate-pulse shadow-md shadow-emerald-400/50" : "bg-red-500"}`} />
|
<span className={`w-2 h-2 rounded-full ${isWsConnected ? "bg-emerald-400 animate-pulse shadow-md shadow-emerald-400/50" : "bg-red-500"}`} />
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<span className="font-mono text-gray-200 font-bold text-[11px] leading-tight">
|
<div className="flex items-center gap-1">
|
||||||
{telemetry?.server || "Exness-MT5Real15"}
|
<span className="font-mono text-gray-200 font-bold text-[11px] leading-tight">
|
||||||
</span>
|
{telemetry?.server || activeAccount?.server || "Exness-MT5"}
|
||||||
<span className="font-mono text-gray-400 text-[9px] leading-tight">
|
</span>
|
||||||
#{telemetry?.account_id || "425437997"}
|
<ChevronDown className="w-2.5 h-2.5 text-gray-400 group-hover:text-cyan-400 transition" />
|
||||||
|
</div>
|
||||||
|
<span className="font-mono text-cyan-400 text-[9px] leading-tight font-medium">
|
||||||
|
#{telemetry?.account_id || activeAccount?.account_id || "Select Account"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="h-4 w-px bg-[#14233d]" />
|
<div className="h-4 w-px bg-[#14233d]" />
|
||||||
<span className="text-[10px] text-gray-400 font-mono flex items-center gap-0.5">
|
<span className="text-[10px] text-gray-400 font-mono flex items-center gap-0.5">
|
||||||
<Wifi className="w-2.5 h-2.5 text-cyan-400" /> {ping}ms
|
<Wifi className="w-2.5 h-2.5 text-cyan-400" /> {ping}ms
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 2. Global Forex Sessions & Financial Metrics (Center - No Wrap) */}
|
{/* 2. Global Forex Sessions & Financial Metrics (Center - No Wrap) */}
|
||||||
|
|||||||
Reference in New Issue
Block a user