Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ const PerpsMarketDetailsView: React.FC<PerpsMarketDetailsViewProps> = () => {
useState(false);
const [ohlcData, setOhlcData] = useState<OhlcData | null>(null);

// Track when position data has settled to avoid button flash (TAT-2236)
const [hasPositionSettled, setHasPositionSettled] = useState(false);

const { account } = usePerpsLiveAccount();

// Get real-time open orders via WebSocket
Expand Down Expand Up @@ -380,6 +383,19 @@ const PerpsMarketDetailsView: React.FC<PerpsMarketDetailsViewProps> = () => {
loadOnMount: true,
});

// Wait one frame after loading to avoid button flash (TAT-2236)
// This handles the gap between isLoadingPosition=false and existingPosition being populated
useEffect(() => {
if (isLoadingPosition) {
setHasPositionSettled(false);
} else {
const frame = requestAnimationFrame(() => {
setHasPositionSettled(true);
});
return () => cancelAnimationFrame(frame);
}
}, [isLoadingPosition]);

// Fetch order fills to get position opened timestamp
const { orderFills } = usePerpsOrderFills({
skipInitialFetch: false,
Expand Down Expand Up @@ -861,8 +877,8 @@ const PerpsMarketDetailsView: React.FC<PerpsMarketDetailsViewProps> = () => {

// Determine if any action buttons will be visible
const hasLongShortButtons = useMemo(
() => !isLoadingPosition && !hasZeroBalance,
[isLoadingPosition, hasZeroBalance],
() => !isLoadingPosition && !hasZeroBalance && hasPositionSettled,
[isLoadingPosition, hasZeroBalance, hasPositionSettled],
);

const hasAddFundsButton = useMemo(
Expand Down
Loading