Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
72 changes: 71 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^13.5.0",
"react-router-dom": "^7.18.2",
"recharts": "^2.8.0",
"zod": "^4.3.6"
},
Expand Down
84 changes: 84 additions & 0 deletions frontend/src/components/WalletPicker.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, screen, cleanup, fireEvent, waitFor } from '@testing-library/react'
import { WalletPicker } from './WalletPicker'

const mockWalletManager = vi.hoisted(() => ({
connect: vi.fn(),
disconnect: vi.fn(),
getWalletType: vi.fn(),
getPublicKey: vi.fn(),
}))

vi.mock('../utils/walletManager', () => ({
walletManager: mockWalletManager,
}))

vi.mock('../lib/wallet', () => ({
SUPPORTED_WALLETS: [
{ name: 'Freighter', type: 'freighter', installUrl: 'https://www.freighter.app/' },
{ name: 'Rabet', type: 'rabet', installUrl: 'https://rabet.io/' },
{ name: 'xBull', type: 'xbull', installUrl: 'https://xbull.app/' },
{ name: 'LOBSTR', type: 'lobstr', installUrl: 'https://lobstr.co/' },
{ name: 'WalletConnect', type: 'walletconnect', installUrl: 'https://walletconnect.com/' },
],
getLastUsedWallet: vi.fn(() => null),
setLastUsedWallet: vi.fn(),
clearLastUsedWallet: vi.fn(),
}))

describe('WalletPicker', () => {
let mockOnConnect: (publicKey: string, walletType: string) => void
let mockOnError: (error: string) => void

beforeEach(() => {
cleanup()
vi.restoreAllMocks()

mockOnConnect = vi.fn()
mockOnError = vi.fn()

mockWalletManager.getWalletType.mockReturnValue(null)
})

afterEach(() => {
cleanup()
})

it('renders all supported wallet options', () => {
render(<WalletPicker onConnect={mockOnConnect} onError={mockOnError} />)

expect(screen.getByText('Freighter')).toBeTruthy()
expect(screen.getByText('Rabet')).toBeTruthy()
expect(screen.getByText('xBull')).toBeTruthy()
expect(screen.getByText('LOBSTR')).toBeTruthy()
expect(screen.getByText('WalletConnect')).toBeTruthy()
})

it('detects Lobstr as installed when window.lobstr is available', () => {
window.lobstr = {} as any
render(<WalletPicker onConnect={mockOnConnect} onError={mockOnError} />)
expect(screen.getByText('Installed')).toBeTruthy()
delete (window as any).lobstr
})

it('calls walletManager.connect with lobstr when Lobstr is clicked', async () => {
window.lobstr = {} as any
const testPublicKey = 'GAlobstrtest1234567890abcdef1234567890abcdef1234567890abcdef'
mockWalletManager.connect.mockResolvedValue(testPublicKey)

render(<WalletPicker onConnect={mockOnConnect} onError={mockOnError} />)

const lobstrButton = screen.getByText('LOBSTR').closest('button')
expect(lobstrButton).toBeTruthy()

fireEvent.click(lobstrButton!)

await waitFor(() => {
expect(mockWalletManager.connect).toHaveBeenCalledWith('lobstr')
expect(mockOnConnect).toHaveBeenCalledWith(testPublicKey, 'LOBSTR')
expect(mockOnError).not.toHaveBeenCalled()
})

delete (window as any).lobstr
})
})
2 changes: 1 addition & 1 deletion frontend/src/components/WalletPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const WalletPicker: React.FC<WalletPickerProps> = ({ onConnect, onError,
case 'freighter': return !!window.freighter
case 'rabet': return !!window.rabet
case 'xbull': return !!window.xBull
case 'lobstr': return false // LOBSTR is usually mobile or extension
case 'lobstr': return !!window.lobstr
case 'walletconnect': return false // Requires QR flow
default: return false
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/Compare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Compare: React.FC<PortfolioCompareProps> = ({ onNavigate, publicKey }) =>
const togglePortfolio = (portfolioId: string) => {
if (selectedPortfolioIds.includes(portfolioId)) {
setSelectedPortfolioIds(prev => prev.filter(id => id !== portfolioId))
} else if (selectedPortfolioIds.length < 3) {
} else if (selectedPortfolioIds.length < 5) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Cap URL-initialized selections as well.

Line 41 only limits clicks. ?portfolios=a,b,c,d,e,f initializes six IDs at Lines 20-23, displays 6/5, and sends all six to usePortfolioCompare.

Proposed fix
 const COLORS = ['`#3B82F6`', '`#10B981`', '`#F59E0B`', '`#EF4444`', '`#8B5CF6`', '`#EC4899`']
+const MAX_SELECTED_PORTFOLIOS = 5

 const [selectedPortfolioIds, setSelectedPortfolioIds] = useState<string[]>(() => {
   const params = searchParams.get('portfolios')
-  return params ? params.split(',') : []
+  return [...new Set(params?.split(',').filter((id) => id.length > 0) ?? [])]
+    .slice(0, MAX_SELECTED_PORTFOLIOS)
 })

-    } else if (selectedPortfolioIds.length < 5) {
+    } else if (selectedPortfolioIds.length < MAX_SELECTED_PORTFOLIOS) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if (selectedPortfolioIds.length < 5) {
} else if (selectedPortfolioIds.length < MAX_SELECTED_PORTFOLIOS) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/pages/Compare.tsx` at line 41, Cap portfolio IDs initialized
from the URL to five before they are stored or passed to usePortfolioCompare.
Update the URL parsing/initialization logic near the selectedPortfolioIds setup,
while preserving the existing selectedPortfolioIds.length click guard and
ensuring the displayed count cannot exceed 5.

setSelectedPortfolioIds(prev => [...prev, portfolioId])
}
}
Expand Down Expand Up @@ -101,7 +101,7 @@ const Compare: React.FC<PortfolioCompareProps> = ({ onNavigate, publicKey }) =>
</div>
</div>
<div className="text-sm text-gray-600 dark:text-gray-400">
{selectedPortfolioIds.length}/3 {t('compare.selectPortfolios')}
{selectedPortfolioIds.length}/5 {t('compare.selectPortfolios')}
</div>
</div>

Expand Down Expand Up @@ -142,7 +142,7 @@ const Compare: React.FC<PortfolioCompareProps> = ({ onNavigate, publicKey }) =>
<div className="space-y-6">
<div className="bg-white dark:bg-gray-800 rounded-xl p-6 shadow-sm">
<h2 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">{t('compare.allocation')}</h2>
<div className={`grid gap-6 ${selectedPortfolioIds.length === 2 ? 'grid-cols-1 md:grid-cols-2' : 'grid-cols-1 md:grid-cols-3'}`}>
<div className={`grid gap-6 ${selectedPortfolioIds.length <= 2 ? 'grid-cols-1 md:grid-cols-2' : 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3'}`}>
{selectedPortfolios.map((portfolio, index) => {
const allocationData = getAllocationData(portfolio)
return (
Expand Down
Loading
Loading