This commit is contained in:
2025-12-04 13:38:58 -05:00
parent 4a1b5bfc24
commit ab663e7d2b
7 changed files with 365 additions and 29 deletions

View File

@@ -33,6 +33,14 @@ export function initDatabase() {
)
`);
// Create settings table for custom AUEC amount
db.exec(`
CREATE TABLE IF NOT EXISTS settings (
key TEXT PRIMARY KEY,
value TEXT NOT NULL
)
`);
console.log('Database initialized at:', dbPath);
}
@@ -80,6 +88,26 @@ export function deleteAlert(id: string): void {
stmt.run(id);
}
export function getCustomAuecAmount(): number | null {
if (!db) throw new Error('Database not initialized');
const stmt = db.prepare('SELECT value FROM settings WHERE key = ?');
const row = stmt.get('customAuecAmount') as any;
return row ? parseFloat(row.value) : null;
}
export function setCustomAuecAmount(amount: number): void {
if (!db) throw new Error('Database not initialized');
const stmt = db.prepare(`
INSERT OR REPLACE INTO settings (key, value)
VALUES (?, ?)
`);
stmt.run('customAuecAmount', amount.toString());
}
export function closeDatabase(): void {
if (db) {
db.close();

View File

@@ -53,6 +53,8 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
try { ipcMain.removeHandler('alerts:add'); } catch (e) { /* ignore */ }
try { ipcMain.removeHandler('alerts:update'); } catch (e) { /* ignore */ }
try { ipcMain.removeHandler('alerts:delete'); } catch (e) { /* ignore */ }
try { ipcMain.removeHandler('settings:getCustomAuecAmount'); } catch (e) { /* ignore */ }
try { ipcMain.removeHandler('settings:setCustomAuecAmount'); } catch (e) { /* ignore */ }
// IPC handlers for renderer requests
ipcMain.handle('ws:connect', async () => {
@@ -155,6 +157,26 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
}
});
// Custom AUEC amount handlers
ipcMain.handle('settings:getCustomAuecAmount', async () => {
try {
return db.getCustomAuecAmount();
} catch (error) {
console.error('Failed to get custom AUEC amount:', error);
return null;
}
});
ipcMain.handle('settings:setCustomAuecAmount', async (_event, amount: number) => {
try {
db.setCustomAuecAmount(amount);
return { success: true };
} catch (error) {
console.error('Failed to set custom AUEC amount:', error);
return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
}
});
// Auto-connect on startup
wsClient.connect();
}
@@ -181,6 +203,8 @@ export function cleanupIpcHandlers(): void {
ipcMain.removeHandler('alerts:add');
ipcMain.removeHandler('alerts:update');
ipcMain.removeHandler('alerts:delete');
ipcMain.removeHandler('settings:getCustomAuecAmount');
ipcMain.removeHandler('settings:setCustomAuecAmount');
} catch (error) {
// Handlers may not exist, ignore
}

View File

@@ -52,6 +52,10 @@ export function App() {
const [alertNotification, setAlertNotification] = useState<AlertNotification | null>(null);
const alertAudioRef = useRef<HTMLAudioElement | null>(null);
// Custom AUEC Amount State
const [customAuecAmount, setCustomAuecAmount] = useState<number | null>(null);
const [customAuecInput, setCustomAuecInput] = useState('');
// Load alerts from database on mount
useEffect(() => {
const loadAlerts = async () => {
@@ -65,6 +69,22 @@ export function App() {
loadAlerts();
}, []);
// Load custom AUEC amount from database on mount
useEffect(() => {
const loadCustomAmount = async () => {
try {
const amount = await window.electron.ipcRenderer.invoke('settings:getCustomAuecAmount');
if (amount) {
setCustomAuecAmount(amount);
setCustomAuecInput(amount.toString());
}
} catch (error) {
console.error('Failed to load custom AUEC amount:', error);
}
};
loadCustomAmount();
}, []);
// Fetch initial data on mount
useEffect(() => {
fetchInitialData();
@@ -374,6 +394,21 @@ export function App() {
}
};
const saveCustomAuecAmount = async () => {
const amount = parseFloat(customAuecInput);
if (isNaN(amount) || amount <= 0) {
alert('Please enter a valid AUEC amount');
return;
}
try {
await window.electron.ipcRenderer.invoke('settings:setCustomAuecAmount', amount);
setCustomAuecAmount(amount);
} catch (error) {
console.error('Failed to save custom AUEC amount:', error);
}
};
const dismissNotification = () => {
setAlertNotification(null);
};
@@ -769,7 +804,41 @@ export function App() {
{latestPrice && (
<div style={{ backgroundColor: '#1a1f3a', padding: '20px', borderRadius: '8px' }}>
<h2 style={{ margin: '0 0 15px 0' }}>Current Listings ({latestPrice.allPrices.length})</h2>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '15px' }}>
<h2 style={{ margin: 0 }}>Current Listings ({latestPrice.allPrices.length})</h2>
<div style={{ display: 'flex', gap: '10px', alignItems: 'center' }}>
<input
type="number"
placeholder="Enter AUEC amount"
value={customAuecInput}
onChange={(e) => setCustomAuecInput(e.target.value)}
style={{
padding: '8px 12px',
backgroundColor: '#0a0e27',
border: '1px solid #2a2f4a',
borderRadius: '4px',
color: '#fff',
fontSize: '14px',
width: '180px',
}}
/>
<button
onClick={saveCustomAuecAmount}
style={{
padding: '8px 16px',
backgroundColor: '#50e3c2',
color: '#0a0e27',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
fontWeight: 'bold',
fontSize: '14px',
}}
>
Set Amount
</button>
</div>
</div>
<div style={{
overflowX: 'auto',
overflowY: 'auto',
@@ -783,18 +852,30 @@ export function App() {
<th style={{ textAlign: 'left', padding: '12px', color: '#888', fontWeight: 'normal' }}>Platform</th>
<th style={{ textAlign: 'left', padding: '12px', color: '#888', fontWeight: 'normal' }}>Seller</th>
<th style={{ textAlign: 'right', padding: '12px', color: '#888', fontWeight: 'normal' }}>Price/1M AUEC</th>
{customAuecAmount && (
<th style={{ textAlign: 'right', padding: '12px', color: '#888', fontWeight: 'normal' }}>
Price for {(customAuecAmount / 1000000).toLocaleString()}M AUEC
</th>
)}
</tr>
</thead>
<tbody>
{latestPrice.allPrices.map((price) => (
<tr key={price.id} style={{ borderBottom: '1px solid #2a2f4a' }}>
<td style={{ padding: '12px' }}>{price.platform}</td>
<td style={{ padding: '12px' }}>{price.sellerName}</td>
<td style={{ textAlign: 'right', padding: '12px', color: '#50e3c2', fontWeight: 'bold' }}>
${price.pricePerMillion.toFixed(9)}
</td>
</tr>
))}
{[...latestPrice.allPrices]
.sort((a, b) => a.pricePerMillion - b.pricePerMillion)
.map((price) => (
<tr key={price.id} style={{ borderBottom: '1px solid #2a2f4a' }}>
<td style={{ padding: '12px' }}>{price.platform}</td>
<td style={{ padding: '12px' }}>{price.sellerName}</td>
<td style={{ textAlign: 'right', padding: '12px', color: '#50e3c2', fontWeight: 'bold' }}>
${price.pricePerMillion.toFixed(9)}
</td>
{customAuecAmount && (
<td style={{ textAlign: 'right', padding: '12px', color: '#50e3c2', fontWeight: 'bold' }}>
${((price.pricePerMillion * customAuecAmount) / 1000000).toFixed(2)}
</td>
)}
</tr>
))}
</tbody>
</table>
</div>