diff --git a/src/modules/etherlink/explorer/index.tsx b/src/modules/etherlink/explorer/index.tsx index 18e5db9b..4c68fb57 100644 --- a/src/modules/etherlink/explorer/index.tsx +++ b/src/modules/etherlink/explorer/index.tsx @@ -1,9 +1,6 @@ import React, { useContext, useState } from "react" import { Grid, Typography, useTheme, useMediaQuery } from "@material-ui/core" -import { useDAO } from "services/services/dao/hooks/useDAO" -import { useEtherlinkDAOID } from "./router" - import { SmallButton } from "../../common/SmallButton" import SettingsIcon from "@mui/icons-material/Settings" @@ -18,13 +15,10 @@ import { EvmDaoStatsRow } from "../components/EvmDaoStatsRow" import { EvmDaoSettingModal } from "../components/EvmDaoSettingsModal" export const EtherlinkDAOOverview: React.FC = () => { - const daoId = useEtherlinkDAOID() - const { data, cycleInfo, ledger } = useDAO(daoId) const { daoSelected } = useContext(EtherlinkContext) const theme = useTheme() const isExtraSmall = useMediaQuery(theme.breakpoints.down("xs")) - const symbol = (daoSelected && daoSelected?.token?.toUpperCase()) || "Unknown" const name = daoSelected && daoSelected?.name const description = daoSelected && daoSelected?.description diff --git a/src/modules/explorer/components/NavigationMenu.tsx b/src/modules/explorer/components/NavigationMenu.tsx index dfdb95f7..70b552ed 100644 --- a/src/modules/explorer/components/NavigationMenu.tsx +++ b/src/modules/explorer/components/NavigationMenu.tsx @@ -281,6 +281,8 @@ export const NavigationMenu: React.FC<{ disableMobileMenu?: boolean }> = ({ disa } }, [account, dao, daoId, etherlinkDaoId, etherlinkDaoSelected]) + if (location.pathname === "/explorer/daos" || location.pathname === "/explorer/daos/") return null + return !isMobileSmall || disableMobileMenu ? ( void } +const useEtherlinkDao = ({ network }: { network: string }) => { + const selectedDaoIdRef = useRef(null) + + const firebaseRootCollection = useMemo(() => { + if (network === "etherlink_mainnet") { + return "daosEtherlink-Mainnet" + } + if (network === "etherlink_testnet") { + return "daosEtherlink-Testnet" + } + return undefined + }, [network]) + + const [isLoadingDaos, setIsLoadingDaos] = useState(true) + const [isLoadingDaoProposals, setIsLoadingDaoProposals] = useState(true) + + const [daoData, setDaoData] = useState([]) + const [daoSelected, setDaoSelected] = useState({}) + const [daoProposals, setDaoProposals] = useState([]) + const [daoProposalSelected, setDaoProposalSelected] = useState({}) + const [daoMembers, setDaoMembers] = useState([]) + const { data: firestoreData, loading, fetchCollection } = useFirestoreStore() + + useEffect(() => { + if (firebaseRootCollection) { + fetchCollection(firebaseRootCollection).then((data: any) => { + setIsLoadingDaos(false) + }) + } + }, [fetchCollection, firebaseRootCollection]) + + useEffect(() => { + console.log("Firestore Data", firestoreData) + if (!firebaseRootCollection) return + if (firestoreData?.[firebaseRootCollection]) { + setDaoData(firestoreData[firebaseRootCollection]) + } + const daoProposalKey = `${firebaseRootCollection}/${daoSelected.id}/proposals` + if (firestoreData?.[daoProposalKey]) { + setDaoProposals( + firestoreData[daoProposalKey] + ?.sort((a: any, b: any) => b.createdAt - a.createdAt) + .map(firebaseProposal => { + return { + ...firebaseProposal, + status: getStatusByHistory(firebaseProposal.statusHistory) + } + }) + ) + } + const daoMembersKey = `${firebaseRootCollection}/${daoSelected.id}/members` + if (firestoreData?.[daoMembersKey]) { + setDaoMembers(firestoreData[daoMembersKey]) + } + }, [daoSelected.id, firebaseRootCollection, firestoreData]) + + useEffect(() => { + if (daoSelected.id && firebaseRootCollection) { + fetchCollection(`${firebaseRootCollection}/${daoSelected.id}/proposals`) + fetchCollection(`${firebaseRootCollection}/${daoSelected.id}/members`) + } + }, [daoSelected, fetchCollection, firebaseRootCollection]) + + return { + daos: daoData, + daoSelected, + daoProposals, + daoProposalSelected, + daoMembers, + selectDaoProposal: (proposalId: string) => { + const proposal = daoProposals.find((proposal: any) => proposal.id === proposalId) + if (proposal) { + setDaoProposalSelected(proposal) + } + }, + selectDao: (daoId: string) => { + const dao = daoData.find(dao => dao.id === daoId) + if (dao) { + setDaoSelected(dao) + selectedDaoIdRef.current = daoId + } + }, + isLoadingDaos, + isLoadingDaoProposals + } +} + // TODO: @ashutoshpw, handle more statuus and move to utils const getStatusByHistory = (history: { active: number; executable: number; passed: number; pending: number }) => { const statuses = Object.keys(history) @@ -65,6 +152,7 @@ export const EtherlinkProvider: React.FC<{ children: ReactNode }> = ({ children const { connect } = useWagmiConnect() const { address, isConnected, chain, isDisconnected, status } = useWagmiAccount() + console.log("SIWE Data", status) // console.log("SIWE Data", data, status, error, isSignedIn, isReady, isRejected, isLoading) const etherlinkNetwork = useMemo(() => { @@ -77,78 +165,24 @@ export const EtherlinkProvider: React.FC<{ children: ReactNode }> = ({ children return "unknown" }, [chain?.name]) - const firebaseRootCollection = useMemo(() => { - if (etherlinkNetwork === "etherlink_mainnet") { - return "daosEtherlink-Mainnet" - } - if (etherlinkNetwork === "etherlink_testnet") { - return "daosEtherlink-Testnet" - } - return undefined - }, [etherlinkNetwork]) + const { + daos, + isLoadingDaos, + daoSelected, + daoProposals, + isLoadingDaoProposals, + daoProposalSelected, + daoMembers, + selectDaoProposal, + selectDao + } = useEtherlinkDao({ + network: etherlinkNetwork + }) console.log("Etherlink Network", etherlinkNetwork) - - // useEffect(() => { - // console.log(tezosNetwork) - // modal.switchNetwork(etherlinkTestnet as unknown as CaipNetwork) - // }, [tezosNetwork]) - console.log("Wagmi Chain", chain, status) console.log("Wagmi Address", address) - const [isLoadingDaos, setIsLoadingDaos] = useState(true) - const [isLoadingDaoProposals, setIsLoadingDaoProposals] = useState(true) - - const selectedDaoIdRef = useRef(null) - const [daoData, setDaoData] = useState([]) - const [daoSelected, setDaoSelected] = useState({}) - const [daoProposals, setDaoProposals] = useState([]) - const [daoProposalSelected, setDaoProposalSelected] = useState({}) - const [daoMembers, setDaoMembers] = useState([]) - const { data: firestoreData, loading, fetchCollection } = useFirestoreStore() - - console.log({ firestoreData }) - - useEffect(() => { - if (firebaseRootCollection) { - fetchCollection(firebaseRootCollection).then((data: any) => { - setIsLoadingDaos(false) - }) - } - }, [fetchCollection, firebaseRootCollection]) - - useEffect(() => { - if (!firebaseRootCollection) return - if (firestoreData?.[firebaseRootCollection]) { - setDaoData(firestoreData[firebaseRootCollection]) - } - const daoProposalKey = `${firebaseRootCollection}/${daoSelected.id}/proposals` - if (firestoreData?.[daoProposalKey]) { - setDaoProposals( - firestoreData[daoProposalKey] - ?.sort((a: any, b: any) => b.createdAt - a.createdAt) - .map(firebaseProposal => { - return { - ...firebaseProposal, - status: getStatusByHistory(firebaseProposal.statusHistory) - } - }) - ) - } - const daoMembersKey = `${firebaseRootCollection}/${daoSelected.id}/members` - if (firestoreData?.[daoMembersKey]) { - setDaoMembers(firestoreData[daoMembersKey]) - } - }, [daoSelected.id, firebaseRootCollection, firestoreData]) - - useEffect(() => { - if (daoSelected.id && firebaseRootCollection) { - fetchCollection(`${firebaseRootCollection}/${daoSelected.id}/proposals`) - fetchCollection(`${firebaseRootCollection}/${daoSelected.id}/members`) - } - }, [daoSelected, fetchCollection, firebaseRootCollection]) - return ( = ({ children setOpen(true) // connect({ config: wagmiConfig }) }, - daos: daoData, + daos, isLoadingDaos, - isLoadingDaoProposals: false, - daoSelected: daoSelected, - daoProposals: daoProposals, - daoProposalSelected: daoProposalSelected, - daoMembers: daoMembers, - selectDaoProposal: (proposalId: string) => { - const proposal = daoProposals.find((proposal: any) => proposal.id === proposalId) - if (proposal) { - setDaoProposalSelected(proposal) - // fetchCollection(`daosEtherlink-Testnet/${daoSelected.id}/proposals/${proposalId}`) - } - }, - selectDao: (daoId: string) => { - const dao = daoData.find(dao => dao.id === daoId) - // alert(`dao:${daoId}`) - if (dao) { - setDaoSelected(dao) - selectedDaoIdRef.current = daoId - } - }, + isLoadingDaoProposals, + daoSelected, + daoProposals, + daoProposalSelected, + daoMembers, + selectDaoProposal, + selectDao, disconnect: () => disconnectEtherlink(wagmiConfig), switchToNetwork: (network: string) => { const networkId = network === "etherlink_mainnet" ? etherlink.id : etherlinkTestnet.id