Skip to content

Commit c01b944

Browse files
committed
Update workflow icons and improve Alpaca order sync
Standardizes and updates workflow and agent icons across analysis, research, trading, and risk steps for better visual consistency. Refactors Alpaca order status synchronization in TradeHistoryTable to use a batch API, improves logging, and ensures more accurate status updates. Also enhances Discord linking logic in Profile page for reliability and user feedback.
1 parent 6dbb1f6 commit c01b944

File tree

6 files changed

+267
-136
lines changed

6 files changed

+267
-136
lines changed

src/components/RebalanceDetailModal.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Button } from "@/components/ui/button";
1212
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
1313
import {
1414
RefreshCw,
15+
RefreshCcw,
1516
Loader2,
1617
CheckCircle,
1718
Clock,
@@ -22,7 +23,10 @@ import {
2223
XCircle,
2324
X,
2425
ChevronUp,
25-
ChevronDown
26+
ChevronDown,
27+
ChartLine,
28+
Lightbulb,
29+
ChartColumn
2630
} from "lucide-react";
2731
import { formatDistanceToNow } from "date-fns";
2832
import { supabase } from "@/lib/supabase";
@@ -201,13 +205,13 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
201205

202206
// Determine status using centralized status system
203207
let status: RebalanceStatus = convertLegacyRebalanceStatus(rebalanceRequest.status);
204-
208+
205209
// If we're in legacy pending_trades state but have a rebalance plan (portfolio manager is done),
206210
// consider it as completed since the planning is complete
207211
if (rebalanceRequest.status === 'pending_trades' && rebalanceRequest.rebalance_plan) {
208212
status = REBALANCE_STATUS.COMPLETED;
209213
}
210-
214+
211215
const isRunning = isRebalanceActive(status);
212216
const isPendingApproval = false; // No longer using AWAITING_APPROVAL status
213217
const isCompleted = status === REBALANCE_STATUS.COMPLETED;
@@ -275,7 +279,7 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
275279
.select('*') // Select all fields including metadata
276280
.eq('rebalance_request_id', rebalanceId)
277281
.eq('user_id', user.id);
278-
282+
279283
// Store tradingActions for later use (even if empty)
280284
let tradingActionsData = tradingActions || [];
281285

@@ -368,6 +372,7 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
368372
id: 'threshold',
369373
title: 'Threshold Check',
370374
description: 'Evaluating portfolio drift against rebalance threshold',
375+
icon: ChartLine,
371376
status: thresholdStatus,
372377
completedAt: thresholdStep.data?.timestamp || thresholdStep.timestamp || thresholdStep.completedAt,
373378
insights: thresholdStep.data, // Add the insights data
@@ -446,6 +451,7 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
446451
id: 'opportunity',
447452
title: 'Opportunity Analysis',
448453
description: 'Scanning market for new investment opportunities',
454+
icon: Lightbulb,
449455
status: opportunityStatus,
450456
completedAt: opportunityStep.data?.timestamp || opportunityStep.timestamp || opportunityStep.completedAt,
451457
insights: insights, // Use the parsed insights
@@ -582,6 +588,7 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
582588
id: 'analysis',
583589
title: 'Stock Analysis',
584590
description: 'Analyzing individual stocks for rebalancing decisions',
591+
icon: ChartColumn,
585592
status: stockAnalysisStatus,
586593
agents: stockAnalyses.map((sa: any) => ({
587594
name: `${sa.ticker} Analysis`,
@@ -611,6 +618,7 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
611618
id: 'rebalance',
612619
title: 'Portfolio Manager',
613620
description: 'Calculating optimal portfolio rebalancing strategy and generating trade orders',
621+
icon: RefreshCcw,
614622
status: portfolioManagerStatus,
615623
completedAt: rebalanceAgentStep.data?.completedAt || portfolioManagerStep.data?.completedAt || rebalanceRequest.plan_generated_at
616624
});
@@ -654,7 +662,7 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
654662
opportunity_reasoning: rebalanceRequest.opportunity_reasoning,
655663

656664
relatedAnalyses: rebalanceAnalyses || [],
657-
665+
658666
// Include trading_actions data for proper status tracking
659667
trading_actions: tradingActionsData
660668
};
@@ -746,7 +754,7 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
746754
</Badge>
747755
)}
748756
</div>
749-
757+
750758
{/* Close button */}
751759
<Button
752760
size="sm"
@@ -798,23 +806,23 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
798806
if (collapsedCards.size === 0) {
799807
// Collapse all - need to get all card keys
800808
const allCardKeys = new Set<string>();
801-
809+
802810
// Add threshold card if it exists
803811
if (!rebalanceData?.skipThresholdCheck) {
804812
const thresholdStep = rebalanceData?.workflowSteps?.find((s: any) => s.id === 'threshold');
805813
if (thresholdStep?.insights) {
806814
allCardKeys.add('threshold');
807815
}
808816
}
809-
817+
810818
// Add opportunity card if it exists
811819
if (!rebalanceData?.skipOpportunityAgent) {
812820
const opportunityStep = rebalanceData?.workflowSteps?.find((s: any) => s.id === 'opportunity');
813821
if (opportunityStep?.insights || opportunityStep?.data) {
814822
allCardKeys.add('opportunity');
815823
}
816824
}
817-
825+
818826
// Add portfolio manager card if it exists
819827
const portfolioInsights =
820828
rebalanceData?.rebalance_plan?.portfolioManagerAnalysis ||
@@ -824,11 +832,11 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
824832
rebalanceData?.rebalance_plan?.agentInsights?.rebalanceAgent ||
825833
rebalanceData?.agentInsights?.portfolioManager ||
826834
rebalanceData?.agentInsights?.rebalanceAgent;
827-
835+
828836
if (portfolioInsights) {
829837
allCardKeys.add('portfolioManager');
830838
}
831-
839+
832840
setCollapsedCards(allCardKeys);
833841
} else {
834842
// Expand all
@@ -883,13 +891,13 @@ export default function RebalanceDetailModal({ rebalanceId, isOpen, onClose, reb
883891
/>
884892
</TabsContent>
885893

886-
<RebalanceWorkflowTab
894+
<RebalanceWorkflowTab
887895
workflowData={rebalanceData}
888896
onNavigateToInsight={handleNavigateToInsight}
889897
onOpenAnalysisModal={handleOpenAnalysisModal}
890898
/>
891899

892-
<RebalanceInsightsTab
900+
<RebalanceInsightsTab
893901
rebalanceData={rebalanceData}
894902
selectedAnalysis={selectedAnalysis}
895903
setSelectedAnalysis={setSelectedAnalysis}

0 commit comments

Comments
 (0)