-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTradeForm.tsx
50 lines (43 loc) · 1.79 KB
/
TradeForm.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use client'
import { useTradeForm } from '@/lib/contexts/TradeFormContext'
import { Input } from '@/components/ui/input'
import { Button } from '@/components/ui/button'
interface TradeFormProps {
type: 'buy' | 'sell'
baseAsset?: string
quoteAsset?: string
}
export function TradeForm({ type, baseAsset, quoteAsset }: TradeFormProps) {
const { tradeForm, updateForm } = useTradeForm()
const formData = type === 'buy' ? tradeForm.buy : tradeForm.sell
const handlePriceChange = (e: React.ChangeEvent<HTMLInputElement>) => {
updateForm(type, 'price', e.target.value)
}
const handleAmountChange = (e: React.ChangeEvent<HTMLInputElement>) => {
updateForm(type, 'amount', e.target.value)
}
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
console.log(`${type} order:`, formData)
}
return (
<form onSubmit={handleSubmit} className="bg-card rounded-lg p-3 border">
<h2 className="text-lg font-bold mb-2">{type === 'buy' ? `Buy ${baseAsset}` : `Sell ${baseAsset}`}</h2>
<div className="space-y-4">
<div className="flex space-x-4">
<div className="flex-1">
<label className="text-sm text-muted-foreground">Price ({quoteAsset})</label>
<Input type="number" value={formData.price} onChange={handlePriceChange} className="mt-1" />
</div>
<div className="flex-1">
<label className="text-sm text-muted-foreground">Amount ({baseAsset})</label>
<Input type="number" value={formData.amount} onChange={handleAmountChange} className="mt-1" />
</div>
</div>
<Button type="submit" className="w-full" variant={type === 'buy' ? 'default' : 'destructive'}>
{type === 'buy' ? 'Buy' : 'Sell'} {baseAsset}
</Button>
</div>
</form>
)
}