Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions frontends/web/src/routes/market/btcdirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import { useState, useEffect, useContext, useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { getBTCDirectInfo, TMarketAction } from '@/api/market';
import { getBTCDirectInfo, TBTCDirectInfoResponse, TMarketAction } from '@/api/market';
import { syncdone } from '@/api/accountsync';
import { parseExternalBtcAmount } from '@/api/coins';
import { AppContext } from '@/contexts/AppContext';
import { AccountCode, TAccount, proposeTx, sendTx, TTxInput } from '@/api/account';
Expand Down Expand Up @@ -48,7 +49,15 @@ export const BTCDirect = ({
const { isDarkMode } = useDarkmode();
const navigate = useNavigate();

const btcdirectInfo = useLoad(() => getBTCDirectInfo(action, code));
const [btcdirectInfo, setBtcdirectInfo] = useState<TBTCDirectInfoResponse>();
const fetchBTCDirectInfo = useCallback(async () => {
setBtcdirectInfo(await getBTCDirectInfo(action, code));
Comment on lines +53 to +54
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ignore stale BTCDirect info responses when refetching

fetchBTCDirectInfo writes every response directly into state, but this effect can create overlapping requests (the initial fetch plus the syncdone-triggered fetch). If the older request resolves last, it can overwrite a newer successful payload with stale data (for example, switching back to success: false after sync), which can leave the widget in the wrong state until another sync event occurs. Track request generation (or cancel/ignore outdated requests) before calling setBtcdirectInfo to ensure only the latest response is applied.

Useful? React with 👍 / 👎.

}, [action, code]);
// re-fetch btcdirectInfo in case account is not fully synced
useEffect(() => {
fetchBTCDirectInfo();
return syncdone(code, fetchBTCDirectInfo);
}, [code, fetchBTCDirectInfo]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const [blocking, setBlocking] = useState(false);

Expand Down
Loading