diff --git a/src/components/TokenSwap.tsx b/src/components/TokenSwap.tsx
index 0f9038de..37c12129 100644
--- a/src/components/TokenSwap.tsx
+++ b/src/components/TokenSwap.tsx
@@ -11,6 +11,8 @@ import { useWallet } from '@/contexts/WalletContext';
import { ASSET_IDS, formatBalance, parseAmount } from '@/lib/wallet';
import { useToast } from '@/hooks/use-toast';
import { KurdistanSun } from './KurdistanSun';
+import { PriceChart } from './trading/PriceChart';
+import { LimitOrders } from './trading/LimitOrders';
const TokenSwap = () => {
const { api, isApiReady, selectedAccount } = usePolkadot();
@@ -693,6 +695,15 @@ const TokenSwap = () => {
)}
+ {/* Price Chart */}
+ {exchangeRate > 0 && (
+
+ )}
+
Token Swap
@@ -876,6 +887,13 @@ const TokenSwap = () => {
)}
+
+ {/* Limit Orders Section */}
+
diff --git a/src/components/p2p/P2PMarket.tsx b/src/components/p2p/P2PMarket.tsx
index 6e810267..97130203 100644
--- a/src/components/p2p/P2PMarket.tsx
+++ b/src/components/p2p/P2PMarket.tsx
@@ -6,7 +6,7 @@ import { Label } from '@/components/ui/label';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Badge } from '@/components/ui/badge';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
-import { ArrowUpDown, Search, Filter, TrendingUp, TrendingDown, User, Shield, Clock, DollarSign, Plus, X, SlidersHorizontal } from 'lucide-react';
+import { ArrowUpDown, Search, Filter, TrendingUp, TrendingDown, User, Shield, Clock, DollarSign, Plus, X, SlidersHorizontal, Lock, CheckCircle, AlertCircle } from 'lucide-react';
import { useTranslation } from 'react-i18next';
interface P2POffer {
@@ -151,9 +151,34 @@ export const P2PMarket: React.FC = () => {
return 0;
});
+ // Escrow state
+ const [showEscrow, setShowEscrow] = useState(false);
+ const [escrowStep, setEscrowStep] = useState<'funding' | 'confirmation' | 'release'>('funding');
+ const [escrowOffer, setEscrowOffer] = useState
(null);
+
const handleTrade = (offer: P2POffer) => {
console.log('Initiating trade:', tradeAmount, offer.token, 'with', offer.seller.name);
- // Implement trade logic
+ setEscrowOffer(offer);
+ setShowEscrow(true);
+ setEscrowStep('funding');
+ };
+
+ const handleEscrowFund = () => {
+ console.log('Funding escrow with:', tradeAmount, escrowOffer?.token);
+ setEscrowStep('confirmation');
+ };
+
+ const handleEscrowConfirm = () => {
+ console.log('Confirming payment received');
+ setEscrowStep('release');
+ };
+
+ const handleEscrowRelease = () => {
+ console.log('Releasing escrow funds');
+ setShowEscrow(false);
+ setSelectedOffer(null);
+ setEscrowOffer(null);
+ setEscrowStep('funding');
};
return (
@@ -583,11 +608,189 @@ export const P2PMarket: React.FC = () => {
)}
+ {/* Escrow Modal (Binance P2P Escrow style) */}
+ {showEscrow && escrowOffer && (
+
+
+
+
+
+ Secure Escrow Trade
+
+ setShowEscrow(false)}>
+
+
+
+
+ Trade safely with escrow protection • {activeTab === 'buy' ? 'Buying' : 'Selling'} {escrowOffer.token}
+
+
+
+ {/* Escrow Steps Indicator */}
+
+ {[
+ { step: 'funding', label: 'Fund Escrow', icon: Lock },
+ { step: 'confirmation', label: 'Payment', icon: Clock },
+ { step: 'release', label: 'Complete', icon: CheckCircle }
+ ].map((item, idx) => (
+
+
idx ? 'bg-green-600' : 'bg-gray-700'
+ }`}>
+
+
+
{item.label}
+ {idx < 2 && (
+
idx ? 'bg-green-600' : 'bg-gray-700'
+ }`} style={{ left: `calc(${(idx + 1) * 33.33}% - 64px)` }}>
+ )}
+
+ ))}
+
+
+ {/* Trade Details Card */}
+
+ Trade Details
+
+
+ Seller
+ {escrowOffer.seller.name}
+
+
+ Amount
+ {tradeAmount} {escrowOffer.token}
+
+
+ Price per {escrowOffer.token}
+ ${escrowOffer.price}
+
+
+ Payment Method
+ {escrowOffer.paymentMethod}
+
+
+ Total
+
+ ${(parseFloat(tradeAmount || '0') * escrowOffer.price).toFixed(2)}
+
+
+
+
+
+ {/* Step Content */}
+ {escrowStep === 'funding' && (
+
+
+
+
+
+ Escrow Protection: Your funds will be held securely in smart contract escrow until both parties confirm the trade. This protects both buyer and seller.
+
+
+
+
+
+ 1. Fund the escrow with {tradeAmount} {escrowOffer.token}
+ 2. Wait for seller to provide payment details
+ 3. Complete payment via {escrowOffer.paymentMethod}
+ 4. Confirm payment to release escrow
+
+
+
+ Fund Escrow ({tradeAmount} {escrowOffer.token})
+
+
+ )}
+
+ {escrowStep === 'confirmation' && (
+
+
+
+
+
+ Waiting for Payment: Complete your {escrowOffer.paymentMethod} payment and click confirm when done. Do not release escrow until payment is verified!
+
+
+
+
+
+ Payment Instructions
+
+
• Payment Method: {escrowOffer.paymentMethod}
+
• Amount: ${(parseFloat(tradeAmount || '0') * escrowOffer.price).toFixed(2)}
+
• Time Limit: {escrowOffer.timeLimit} minutes
+
+
+
+
+ {
+ setShowEscrow(false);
+ setEscrowStep('funding');
+ }}
+ className="flex-1"
+ >
+ Cancel Trade
+
+
+ I've Made Payment
+
+
+
+ )}
+
+ {escrowStep === 'release' && (
+
+
+
+
+
+ Payment Confirmed: Your payment has been verified. The escrow will be released to the seller automatically.
+
+
+
+
+
+ Trade Summary
+
+
✅ Escrow Funded: {tradeAmount} {escrowOffer.token}
+
✅ Payment Sent: ${(parseFloat(tradeAmount || '0') * escrowOffer.price).toFixed(2)}
+
✅ Payment Verified
+
🎉 Trade Completed Successfully!
+
+
+
+
+ Close & Release Escrow
+
+
+ )}
+
+
+ Note: Smart contract escrow integration coming soon
+
+
+
+ )}
+
{/* Overlay */}
- {(showCreateOrder || selectedOffer) && (
+ {(showCreateOrder || selectedOffer || showEscrow) && (
{
setShowCreateOrder(false);
setSelectedOffer(null);
+ setShowEscrow(false);
}}>
)}
diff --git a/src/components/trading/LimitOrders.tsx b/src/components/trading/LimitOrders.tsx
new file mode 100644
index 00000000..4b7aaa10
--- /dev/null
+++ b/src/components/trading/LimitOrders.tsx
@@ -0,0 +1,306 @@
+import React, { useState } from 'react';
+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
+import { Button } from '@/components/ui/button';
+import { Input } from '@/components/ui/input';
+import { Label } from '@/components/ui/label';
+import { Badge } from '@/components/ui/badge';
+import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
+import { X, Clock, CheckCircle, AlertCircle } from 'lucide-react';
+
+interface LimitOrder {
+ id: string;
+ type: 'buy' | 'sell';
+ fromToken: string;
+ toToken: string;
+ fromAmount: number;
+ limitPrice: number;
+ currentPrice: number;
+ status: 'pending' | 'filled' | 'cancelled' | 'expired';
+ createdAt: number;
+ expiresAt: number;
+}
+
+interface LimitOrdersProps {
+ fromToken: string;
+ toToken: string;
+ currentPrice: number;
+ onCreateOrder?: (order: Omit