added ability to add exchanges and a custom delete exchange dialog

This commit is contained in:
Boki 2025-06-18 09:41:25 -04:00
parent 0bec1eca83
commit 1d299e52d4
8 changed files with 550 additions and 16 deletions

View file

@ -3,16 +3,21 @@ import {
CheckCircleIcon,
ExclamationTriangleIcon,
XMarkIcon,
PlusIcon,
} from '@heroicons/react/24/outline';
import { useEffect, useState } from 'react';
import { ExchangesTable } from './components/ExchangesTable';
import { AddExchangeDialog } from './components/AddExchangeDialog';
import { useExchanges } from './hooks/useExchanges';
export function ExchangesPage() {
const { createExchange } = useExchanges();
const [syncing, setSyncing] = useState(false);
const [syncStatus, setSyncStatus] = useState<{
type: 'success' | 'error' | null;
message: string;
}>({ type: null, message: '' });
const [showAddDialog, setShowAddDialog] = useState(false);
// Auto-dismiss success messages after 5 seconds
useEffect(() => {
@ -54,14 +59,23 @@ export function ExchangesPage() {
Configure and manage master exchanges with their data sources and providers.
</p>
</div>
<button
onClick={handleSync}
disabled={syncing}
className="inline-flex items-center gap-2 px-4 py-2 bg-primary-500 text-white rounded-lg hover:bg-primary-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
>
<ArrowPathIcon className={`h-4 w-4 ${syncing ? 'animate-spin' : ''}`} />
{syncing ? 'Syncing...' : 'Sync Exchanges'}
</button>
<div className="flex items-center gap-2">
<button
onClick={() => setShowAddDialog(true)}
className="inline-flex items-center gap-2 px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors"
>
<PlusIcon className="h-4 w-4" />
Add Exchange
</button>
<button
onClick={handleSync}
disabled={syncing}
className="inline-flex items-center gap-2 px-4 py-2 bg-primary-500 text-white rounded-lg hover:bg-primary-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
>
<ArrowPathIcon className={`h-4 w-4 ${syncing ? 'animate-spin' : ''}`} />
{syncing ? 'Syncing...' : 'Sync Exchanges'}
</button>
</div>
</div>
{syncing && (
@ -108,6 +122,26 @@ export function ExchangesPage() {
<div className="flex-1 min-h-0">
<ExchangesTable />
</div>
<AddExchangeDialog
isOpen={showAddDialog}
onClose={() => setShowAddDialog(false)}
onCreateExchange={async (exchangeRequest) => {
try {
await createExchange(exchangeRequest);
setShowAddDialog(false);
setSyncStatus({
type: 'success',
message: `Exchange "${exchangeRequest.code}" created successfully!`,
});
} catch (error) {
setSyncStatus({
type: 'error',
message: error instanceof Error ? error.message : 'Failed to create exchange',
});
}
}}
/>
</div>
);
}