diff --git a/src/components/p2p/TradeView.tsx b/src/components/p2p/TradeView.tsx index d8ebac4..8d2c376 100644 --- a/src/components/p2p/TradeView.tsx +++ b/src/components/p2p/TradeView.tsx @@ -36,7 +36,7 @@ const STATUS_CONFIG: Record = { }; export function TradeView({ tradeId, onBack }: TradeViewProps) { - const { sessionToken, user } = useAuth(); + const { sessionToken, authUserId } = useAuth(); const { t, isRTL } = useTranslation(); const { hapticImpact, hapticNotification } = useTelegram(); @@ -47,9 +47,9 @@ export function TradeView({ tradeId, onBack }: TradeViewProps) { const [showDispute, setShowDispute] = useState(false); const [error, setError] = useState(''); - const userId = user?.id; - const isBuyer = trade?.buyer_id === userId; - const isSeller = trade?.seller_id === userId; + // authUserId = auth.users UUID (matches trade.buyer_id / trade.seller_id) + const isBuyer = trade?.buyer_id === authUserId; + const isSeller = trade?.seller_id === authUserId; const fetchTrade = useCallback(async () => { if (!sessionToken || !tradeId) return; diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index e14fe52..69ea1d7 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -12,6 +12,7 @@ import type { User } from '@/hooks/useSupabase'; interface AuthContextType { user: User | null; + authUserId: string | null; sessionToken: string | null; isLoading: boolean; isAuthenticated: boolean; @@ -49,6 +50,7 @@ function waitForInitData(maxAttempts = 25, intervalMs = 200): Promise(null); + const [authUserId, setAuthUserId] = useState(null); const [sessionToken, setSessionToken] = useState(null); const [isLoading, setIsLoading] = useState(true); const [authError, setAuthError] = useState(null); @@ -70,6 +72,7 @@ export function AuthProvider({ children }: { children: ReactNode }) { const result = await signInWithTelegram(initData); if (result?.user) { setUser(result.user); + setAuthUserId(result.auth_user_id || null); setAuthError(null); } else { setAuthError('No user returned from auth'); @@ -98,6 +101,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {