import { useCallback, useContext, useEffect, useState } from 'react';
import {
Popover,
Button,
Box,
CircularProgress,
useTheme,
} from '@mui/material';
import { executeEvent } from '../utils/events';
import { MyContext } from '../App';
import { useAtom } from 'jotai';
import { isRunningPublicNodeAtom } from '../atoms/global';
export const WrapperUserAction = ({ children, address, name, disabled }) => {
const theme = useTheme();
const [isRunningPublicNode] = useAtom(isRunningPublicNodeAtom);
const [anchorEl, setAnchorEl] = useState(null);
// Handle child element click to open Popover
const handleChildClick = (event) => {
event.stopPropagation(); // Prevent parent onClick from firing
setAnchorEl(event.currentTarget);
};
// Handle closing the Popover
const handleClose = useCallback(() => {
setAnchorEl(null);
}, []);
// Determine if the popover is open
const open = Boolean(anchorEl);
const id = open ? address || name : undefined;
if (disabled) {
return children;
}
return (
<>
{/* Render the child without altering dimensions */}
{children}
{/* Popover */}
{open && (
event.stopPropagation(), // Stop propagation inside popover
},
}}
>
{/* Option 1: Message */}
{/* Option 2: Send QORT */}
{!isRunningPublicNode && (
)}
)}
>
);
};
const BlockUser = ({ address, name, handleClose }) => {
const [isAlreadyBlocked, setIsAlreadyBlocked] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const { isUserBlocked, addToBlockList, removeBlockFromList } =
useContext(MyContext);
const theme = useTheme();
useEffect(() => {
if (!address) return;
setIsAlreadyBlocked(isUserBlocked(address, name));
}, [address, setIsAlreadyBlocked, isUserBlocked, name]);
return (
);
};