fix: chat message alignment + auto-refresh for all P2P screens

- TradeChat: use authUserId for sender matching (fixes all messages
  appearing on left side instead of bubble alignment)
- BalanceCard: auto-refresh every 30s
- OfferList: auto-refresh every 15s
- MyOffers/MyTrades: auto-refresh every 15s when tab is active
This commit is contained in:
2026-02-27 02:11:53 +03:00
parent 4fbf60f940
commit b56760b22e
4 changed files with 10 additions and 4 deletions
+2
View File
@@ -43,6 +43,8 @@ export function BalanceCard({
useEffect(() => {
fetchBalances();
const interval = setInterval(fetchBalances, 30000);
return () => clearInterval(interval);
}, [fetchBalances]);
const handleRefresh = () => {
+2
View File
@@ -56,6 +56,8 @@ export function OfferList({ adType, onAcceptOffer }: OfferListProps) {
useEffect(() => {
fetchOffers(1);
const interval = setInterval(() => fetchOffers(1), 15000);
return () => clearInterval(interval);
}, [fetchOffers]);
const handleAccept = (offer: P2POffer) => {
+2 -4
View File
@@ -12,7 +12,7 @@ interface TradeChatProps {
}
export function TradeChat({ tradeId, onClose }: TradeChatProps) {
const { sessionToken, user } = useAuth();
const { sessionToken, authUserId } = useAuth();
const { t, isRTL } = useTranslation();
const { hapticImpact } = useTelegram();
@@ -23,8 +23,6 @@ export function TradeChat({ tradeId, onClose }: TradeChatProps) {
// eslint-disable-next-line no-undef
const messagesEndRef = useRef<HTMLDivElement>(null);
const userId = user?.id;
const fetchMessages = useCallback(async () => {
if (!sessionToken) return;
try {
@@ -97,7 +95,7 @@ export function TradeChat({ tradeId, onClose }: TradeChatProps) {
</div>
) : (
messages.map((msg) => {
const isOwn = msg.sender_id === userId;
const isOwn = msg.sender_id === authUserId;
const isSystem = msg.message_type === 'system';
return (
<div
+4
View File
@@ -99,8 +99,12 @@ export function P2PSection() {
useEffect(() => {
if (activeTab === 'myAds') {
fetchMyOffersFull();
const interval = setInterval(fetchMyOffersFull, 15000);
return () => clearInterval(interval);
} else if (activeTab === 'myTrades') {
fetchMyTrades();
const interval = setInterval(fetchMyTrades, 15000);
return () => clearInterval(interval);
}
}, [activeTab, fetchMyOffersFull, fetchMyTrades]);