From cce4d6484dbe097a768f1ac157c1eecc7aa4c76f Mon Sep 17 00:00:00 2001 From: aldin4u Date: Tue, 3 Feb 2026 12:31:17 +0000 Subject: [PATCH 1/4] fix: safeguard against getEtherspotProvider crash in delegated mode --- src/apps/perps/hooks/useHyperliquid.ts | 27 +++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/apps/perps/hooks/useHyperliquid.ts b/src/apps/perps/hooks/useHyperliquid.ts index 9793add8..850d9954 100644 --- a/src/apps/perps/hooks/useHyperliquid.ts +++ b/src/apps/perps/hooks/useHyperliquid.ts @@ -76,19 +76,24 @@ export function useHyperliquid() { transport: clientTransport ?? http(), }); isImported = true; + } else { } else { // 2. Fallback to Connected Wallet - const walletProvider = kit.getEtherspotProvider(); - const eoa = (await walletProvider.getSdk()).getEOAAddress() || null; - console.log('DEBUG: Wallet Provider EOA:', eoa); - - if (eoa && clientTransport) { - targetAddress = eoa; - client = createWalletClient({ - account: eoa as `0x${string}`, - chain: arbitrum, - transport: clientTransport, - }); + try { + const walletProvider = kit.getEtherspotProvider(); + const eoa = (await walletProvider.getSdk()).getEOAAddress() || null; + console.log('DEBUG: Wallet Provider EOA:', eoa); + + if (eoa && clientTransport) { + targetAddress = eoa; + client = createWalletClient({ + account: eoa as `0x${string}`, + chain: arbitrum, + transport: clientTransport, + }); + } + } catch (err) { + console.warn('Failed to get Etherspot provider or EOA (expected in delegatedEoa mode without imported account):', err); } } From 6885edd6fe8fae04e37452381e2f81a9c2d5be39 Mon Sep 17 00:00:00 2001 From: aldin4u Date: Tue, 3 Feb 2026 12:36:21 +0000 Subject: [PATCH 2/4] fix: remove duplicate else block causing build error --- src/apps/perps/hooks/useHyperliquid.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/perps/hooks/useHyperliquid.ts b/src/apps/perps/hooks/useHyperliquid.ts index 850d9954..0b9acabe 100644 --- a/src/apps/perps/hooks/useHyperliquid.ts +++ b/src/apps/perps/hooks/useHyperliquid.ts @@ -77,7 +77,7 @@ export function useHyperliquid() { }); isImported = true; } else { - } else { + // 2. Fallback to Connected Wallet try { const walletProvider = kit.getEtherspotProvider(); From 9adfc4787494f1c4baab5d2c04c028d66523bdc2 Mon Sep 17 00:00:00 2001 From: aldin4u Date: Tue, 3 Feb 2026 12:52:54 +0000 Subject: [PATCH 3/4] fix: resolve linting issues in useAlgoInsightsStats --- .../pillarx-app/hooks/useAlgoInsightsStats.ts | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 src/apps/pillarx-app/hooks/useAlgoInsightsStats.ts diff --git a/src/apps/pillarx-app/hooks/useAlgoInsightsStats.ts b/src/apps/pillarx-app/hooks/useAlgoInsightsStats.ts new file mode 100644 index 00000000..7be5523a --- /dev/null +++ b/src/apps/pillarx-app/hooks/useAlgoInsightsStats.ts @@ -0,0 +1,154 @@ +import { useMemo } from 'react'; +import { useTradingSignals } from '../../insights/hooks/useTradingSignals'; +import { TradingSignal as InsightSignal } from '../../insights/types'; + +export interface AlgoInsightsStats { + pnl1m: number; + pnl3m: number; + pnl6m: number; + riskLevel: string; + pnlStatus: { + winning: number; + losing: number; + neutral: number; + }; + cumulativePnl: { + '1w': { value: number; history: { timestamp: number; value: number }[] }; + '1m': { value: number; history: { timestamp: number; value: number }[] }; + '3m': { value: number; history: { timestamp: number; value: number }[] }; + '6m': { value: number; history: { timestamp: number; value: number }[] }; + }; +} + +export const useAlgoInsightsStats = () => { + const { signals, loading } = useTradingSignals({ enabled: true }); + + const stats = useMemo(() => { + if (loading || signals.length === 0) return null; + + // Helper to calculate PnL for a set of signals + const calculatePnL = (filterFn: (s: InsightSignal) => boolean) => { + return signals + .filter(filterFn) + .reduce((sum, s) => sum + (s.realized_pnl_percent || 0), 0); + }; + + const now = Date.now(); + const oneMonthAgo = now - 30 * 24 * 60 * 60 * 1000; + const threeMonthsAgo = now - 90 * 24 * 60 * 60 * 1000; + const sixMonthsAgo = now - 180 * 24 * 60 * 60 * 1000; + + // PnL metrics + const pnl1m = calculatePnL((s) => { + const closedAt = s.closed_at ? new Date(s.closed_at).getTime() : 0; + return closedAt > oneMonthAgo; + }); + + const pnl3m = calculatePnL((s) => { + const closedAt = s.closed_at ? new Date(s.closed_at).getTime() : 0; + return closedAt > threeMonthsAgo; + }); + + const pnl6m = calculatePnL((s) => { + const closedAt = s.closed_at ? new Date(s.closed_at).getTime() : 0; + return closedAt > sixMonthsAgo; + }); + + // PnL Status (Winning/Losing/Neutral) + const closedSignals = signals.filter( + (s) => + s.status === 'closed' || + s.status === 'completed' || + s.status === 'stopped' + ); + const totalClosed = closedSignals.length; + + let winning = 0; + let losing = 0; + let neutral = 0; + + if (totalClosed > 0) { + winning = + (closedSignals.filter((s) => (s.realized_pnl_percent || 0) > 0).length / + totalClosed) * + 100; + losing = + (closedSignals.filter((s) => (s.realized_pnl_percent || 0) < 0).length / + totalClosed) * + 100; + neutral = + (closedSignals.filter((s) => (s.realized_pnl_percent || 0) === 0) + .length / + totalClosed) * + 100; + } + + // Cumulative PnL History Generation + const generateHistory = (cutoffTime: number) => { + // Sort signals by close time + const relevantSignals = signals + .filter( + (s) => s.closed_at && new Date(s.closed_at).getTime() > cutoffTime + ) + .sort( + (a, b) => + new Date(a.closed_at!).getTime() - new Date(b.closed_at!).getTime() + ); + + let runningPnL = 0; + const history = relevantSignals.map((s) => { + runningPnL += s.realized_pnl_percent || 0; + return { + timestamp: new Date(s.closed_at!).getTime() / 1000, + value: runningPnL, + }; + }); + + // Ensure we have a starting point? Or just the trade history. + // If history is empty, return empty array + return history; + }; + + // For cumulative values in the object, we use the specific period totals calculated above + // but the history needs to be generated point-by-point. + + return { + pnl1m: Number(pnl1m.toFixed(2)), + pnl3m: Number(pnl3m.toFixed(2)), + pnl6m: Number(pnl6m.toFixed(2)), + riskLevel: 'Low Risk', // Placeholder logic + pnlStatus: { + winning: Number(winning.toFixed(1)), + losing: Number(losing.toFixed(1)), + neutral: Number(neutral.toFixed(1)), + }, + cumulativePnl: { + '1w': { + value: Number( + calculatePnL((s) => + s.closed_at + ? new Date(s.closed_at).getTime() > + now - 7 * 24 * 60 * 60 * 1000 + : false + ).toFixed(2) + ), + history: generateHistory(now - 7 * 24 * 60 * 60 * 1000), + }, + '1m': { + value: Number(pnl1m.toFixed(2)), + history: generateHistory(oneMonthAgo), + }, + '3m': { + value: Number(pnl3m.toFixed(2)), + history: generateHistory(threeMonthsAgo), + }, + '6m': { + value: Number(pnl6m.toFixed(2)), + history: generateHistory(sixMonthsAgo), + }, + }, + }; + }, [signals, loading]); + + return { stats, loading }; +}; From 0b8260f7541f5a508ab03bb9daab700a516450b7 Mon Sep 17 00:00:00 2001 From: aldin4u Date: Tue, 3 Feb 2026 13:48:58 +0000 Subject: [PATCH 4/4] fix: update test snapshots --- .../LeftColumnTokenMarketDataRow.test.tsx.snap | 4 ++-- .../TokensWithMarketDataTile.test.tsx.snap | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/apps/pillarx-app/components/TokenMarketDataRow/tests/__snapshots__/LeftColumnTokenMarketDataRow.test.tsx.snap b/src/apps/pillarx-app/components/TokenMarketDataRow/tests/__snapshots__/LeftColumnTokenMarketDataRow.test.tsx.snap index fab28c42..8bae6cfc 100644 --- a/src/apps/pillarx-app/components/TokenMarketDataRow/tests/__snapshots__/LeftColumnTokenMarketDataRow.test.tsx.snap +++ b/src/apps/pillarx-app/components/TokenMarketDataRow/tests/__snapshots__/LeftColumnTokenMarketDataRow.test.tsx.snap @@ -41,7 +41,7 @@ exports[` - ETH token row > renders and matches

- 9mo ago + 10mo ago

- ETH token row > renders and matches

- 9mo ago + 10mo ago

> renders and matches snapshot 1`] = `

- 9mo ago + 10mo ago

> renders and matches snapshot 1`] = `

- 9mo ago + 10mo ago

> renders and matches snapshot 1`] = `

- 9mo ago + 10mo ago

> renders and matches snapshot 1`] = `

- 9mo ago + 10mo ago

> renders and matches snapshot 1`] = `

- 9mo ago + 10mo ago

> renders and matches snapshot 1`] = `

- 9mo ago + 10mo ago

> renders and matches snapshot 1`] = `

- 9mo ago + 10mo ago

> renders and matches snapshot 1`] = `

- 9mo ago + 10mo ago