/** * Deposit USDT Modal * Allows users to deposit USDT (TRC20 or Polkadot) to get wUSDT on Asset Hub */ import { useState, useEffect } from 'react'; import { X, Copy, CheckCircle, ExternalLink, AlertCircle, Loader2, History, Plus, } from 'lucide-react'; import { useTelegram } from '@/hooks/useTelegram'; import { supabase } from '@/lib/supabase'; type Network = 'trc20' | 'polkadot'; interface NetworkInfo { id: Network; name: string; description: string; address: string; explorer: string; icon: string; minAmount: number; confirmations: number; } const NETWORKS: NetworkInfo[] = [ { id: 'trc20', name: 'TRC20 (TRON)', description: 'USDT li ser tora TRON', address: import.meta.env.VITE_DEPOSIT_TRON_ADDRESS || '', explorer: 'https://tronscan.org/#/transaction/', icon: '🔴', minAmount: 10, confirmations: 20, }, { id: 'polkadot', name: 'Polkadot Asset Hub', description: 'USDT li ser Polkadot', address: import.meta.env.VITE_DEPOSIT_POLKADOT_ADDRESS || '', explorer: 'https://assethub-polkadot.subscan.io/extrinsic/', icon: '⚪', minAmount: 10, confirmations: 1, }, ]; interface Deposit { id: string; network: Network; amount: number; status: string; tx_hash: string | null; created_at: string; } interface Props { isOpen: boolean; onClose: () => void; userId: string | null; } export function DepositUSDTModal({ isOpen, onClose }: Props) { const { hapticImpact, showAlert } = useTelegram(); const [selectedNetwork, setSelectedNetwork] = useState('trc20'); const [depositCode, setDepositCode] = useState(''); const [copied, setCopied] = useState<'address' | 'memo' | null>(null); const [deposits, setDeposits] = useState([]); const [showHistory, setShowHistory] = useState(false); const [isLoading, setIsLoading] = useState(false); const network = NETWORKS.find((n) => n.id === selectedNetwork) || NETWORKS[0]; // Fetch user's deposit code via edge function useEffect(() => { const fetchDepositCode = async () => { if (!isOpen) return; const initData = window.Telegram?.WebApp?.initData; if (!initData) { setDepositCode('---'); return; } setIsLoading(true); try { const { data, error } = await supabase.functions.invoke('get-deposit-code', { body: { initData }, }); if (error) { console.error('Error fetching deposit code:', error); setDepositCode('---'); } else if (data?.code) { setDepositCode(data.code); } } catch (err) { console.error('Error fetching deposit code:', err); setDepositCode('---'); } finally { setIsLoading(false); } }; fetchDepositCode(); }, [isOpen]); // Fetch deposits history useEffect(() => { const fetchDeposits = async () => { if (!isOpen) return; const initData = window.Telegram?.WebApp?.initData; if (!initData) return; try { const { data, error } = await supabase.functions.invoke('get-deposits', { body: { initData }, }); if (!error && data?.deposits) { setDeposits(data.deposits as Deposit[]); } } catch { // Ignore - deposits history is optional } }; fetchDeposits(); }, [isOpen]); const copyToClipboard = async (text: string, type: 'address' | 'memo') => { try { await navigator.clipboard.writeText(text); setCopied(type); hapticImpact('light'); setTimeout(() => setCopied(null), 2000); } catch { showAlert('Kopî nekir'); } }; const getStatusColor = (status: string) => { switch (status) { case 'completed': return 'text-green-400'; case 'confirming': return 'text-yellow-400'; case 'failed': return 'text-red-400'; default: return 'text-muted-foreground'; } }; const getStatusText = (status: string) => { switch (status) { case 'pending': return 'Li benda'; case 'confirming': return 'Tê pejirandin'; case 'completed': return 'Qediya'; case 'failed': return 'Neserketî'; case 'expired': return 'Dema wê derbas bû'; default: return status; } }; if (!isOpen) return null; return (
{/* Header */}

USDT Depo Bike

Bo wUSDT li Asset Hub

{showHistory ? ( /* Deposit History */

Dîroka Depoyan

{deposits.length === 0 ? (

Hîn depo tune

) : ( deposits.map((deposit) => (
{deposit.network === 'trc20' ? '🔴' : '⚪'} {deposit.amount} USDT

{new Date(deposit.created_at).toLocaleDateString('ku')}

{getStatusText(deposit.status)}
{deposit.tx_hash && ( n.id === deposit.network)?.explorer}${deposit.tx_hash}`} target="_blank" rel="noopener noreferrer" className="text-xs text-blue-400 flex items-center gap-1 mt-2" > TX bibîne )}
)) )}
) : (
{/* Network Selection */}
{NETWORKS.map((net) => ( ))}
{/* Important Notice */}

Girîng!

  • Kêmtirîn: {network.minAmount} USDT
  • Memo/Not qada de koda xwe binivîse
  • Tenê USDT bişîne, tokenên din winda dibin
{/* Deposit Address */}
{/* Address */}
{network.address || 'Amade nîne'}
{/* Memo/Reference */}
{isLoading ? (
) : ( {depositCode || '---'} )}

⚠️ Vê kodê di memo/not de binivîse, wekî din depoya te nayê nas kirin!

{/* Steps */}

Çawa Depo Bikim?

  1. 1. Navnîşan û memo kopî bike
  2. 2. Di cîzdana xwe de ({network.name}) USDT bişîne navnîşana jorîn
  3. 3. MEMO qada de koda xwe binivîse!
  4. 4. Piştî {network.confirmations} pejirandinê, wUSDT dê li Asset Hub be
{/* Processing Time */}

Dema pêvajoyê: ~5-30 hûrdem li gorî torê

)}
); }