import * as React from "react"; import Button from "@mui/material/Button"; import Dialog from "@mui/material/Dialog"; import ListItemText from "@mui/material/ListItemText"; import ListItemButton from "@mui/material/ListItemButton"; import List from "@mui/material/List"; import Divider from "@mui/material/Divider"; import AppBar from "@mui/material/AppBar"; import Toolbar from "@mui/material/Toolbar"; import IconButton from "@mui/material/IconButton"; import Typography from "@mui/material/Typography"; import CloseIcon from "@mui/icons-material/Close"; import ExpandLess from "@mui/icons-material/ExpandLess"; import ExpandMore from "@mui/icons-material/ExpandMore"; import Slide from "@mui/material/Slide"; import { TransitionProps } from "@mui/material/transitions"; import { Box, Collapse, Input, MenuItem, Select, SelectChangeEvent, Tab, Tabs, styled, } from "@mui/material"; import { AddGroupList } from "./AddGroupList"; import { UserListOfInvites } from "./UserListOfInvites"; import { CustomizedSnackbars } from "../Snackbar/Snackbar"; import { getFee } from "../../background"; import { MyContext, isMobile } from "../../App"; import { subscribeToEvent, unsubscribeFromEvent } from "../../utils/events"; export const Label = styled("label")( ({ theme }) => ` font-family: 'IBM Plex Sans', sans-serif; font-size: 14px; display: block; margin-bottom: 4px; font-weight: 400; ` ); const Transition = React.forwardRef(function Transition( props: TransitionProps & { children: React.ReactElement; }, ref: React.Ref ) { return ; }); export const AddGroup = ({ address, open, setOpen }) => { const {show, setTxList} = React.useContext(MyContext) const [tab, setTab] = React.useState("create"); const [openAdvance, setOpenAdvance] = React.useState(false); const [name, setName] = React.useState(""); const [description, setDescription] = React.useState(""); const [groupType, setGroupType] = React.useState("1"); const [approvalThreshold, setApprovalThreshold] = React.useState("40"); const [minBlock, setMinBlock] = React.useState("5"); const [maxBlock, setMaxBlock] = React.useState("21600"); const [value, setValue] = React.useState(0); const [openSnack, setOpenSnack] = React.useState(false); const [infoSnack, setInfoSnack] = React.useState(null); const handleChange = (event: React.SyntheticEvent, newValue: number) => { setValue(newValue); }; const handleClose = () => { setOpen(false); }; const handleChangeGroupType = (event: SelectChangeEvent) => { setGroupType(event.target.value as string); }; const handleChangeApprovalThreshold = (event: SelectChangeEvent) => { setApprovalThreshold(event.target.value as string); }; const handleChangeMinBlock = (event: SelectChangeEvent) => { setMinBlock(event.target.value as string); }; const handleChangeMaxBlock = (event: SelectChangeEvent) => { setMaxBlock(event.target.value as string); }; const handleCreateGroup = async () => { try { if(!name) throw new Error('Please provide a name') if(!description) throw new Error('Please provide a description') const fee = await getFee('CREATE_GROUP') await show({ message: "Would you like to perform an CREATE_GROUP transaction?" , publishFee: fee.fee + ' QORT' }) await new Promise((res, rej) => { window.sendMessage("createGroup", { groupName: name, groupDescription: description, groupType: +groupType, groupApprovalThreshold: +approvalThreshold, minBlock: +minBlock, maxBlock: +maxBlock, }) .then((response) => { if (!response?.error) { setInfoSnack({ type: "success", message: "Successfully created group. It may take a couple of minutes for the changes to propagate", }); setOpenSnack(true); setTxList((prev) => [ { ...response, type: 'created-group', label: `Created group ${name}: awaiting confirmation`, labelDone: `Created group ${name}: success!`, done: false, }, ...prev, ]); res(response); return; } rej({ message: response.error }); }) .catch((error) => { rej({ message: error.message || "An error occurred" }); }); }); } catch (error) { setInfoSnack({ type: "error", message: error?.message, }); setOpenSnack(true); } }; function CustomTabPanel(props: TabPanelProps) { const { children, value, index, ...other } = props; return ( ); } function a11yProps(index: number) { return { id: `simple-tab-${index}`, "aria-controls": `simple-tabpanel-${index}`, }; } const openGroupInvitesRequestFunc = ()=> { setValue(2) } React.useEffect(() => { subscribeToEvent("openGroupInvitesRequest", openGroupInvitesRequestFunc); return () => { unsubscribeFromEvent("openGroupInvitesRequest", openGroupInvitesRequestFunc); }; }, []); return ( Add Group {/* */} {value === 0 && ( setName(e.target.value)} /> setDescription(e.target.value)} /> setOpenAdvance((prev) => !prev)} > Advanced options {openAdvance ? : } )} {value === 1 && ( )} {value === 2 && ( )} ); };