Skip to content

Commit

Permalink
Fixed Navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshpw committed Dec 10, 2024
1 parent 748fc1f commit 7d4ec46
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 94 deletions.
6 changes: 0 additions & 6 deletions src/modules/etherlink/explorer/index.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/modules/explorer/components/NavigationMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? (
<Container container>
<InnerContainer
Expand Down
197 changes: 109 additions & 88 deletions src/services/wagmi/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,93 @@ interface EtherlinkType {
disconnect: () => void
}

const useEtherlinkDao = ({ network }: { network: string }) => {
const selectedDaoIdRef = useRef<string | null>(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<any[]>([])
const [daoSelected, setDaoSelected] = useState<any>({})
const [daoProposals, setDaoProposals] = useState<any[]>([])
const [daoProposalSelected, setDaoProposalSelected] = useState<any>({})
const [daoMembers, setDaoMembers] = useState<any[]>([])
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)
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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<string | null>(null)
const [daoData, setDaoData] = useState<any[]>([])
const [daoSelected, setDaoSelected] = useState<any>({})
const [daoProposals, setDaoProposals] = useState<any[]>([])
const [daoProposalSelected, setDaoProposalSelected] = useState<any>({})
const [daoMembers, setDaoMembers] = useState<any[]>([])
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 (
<EtherlinkContext.Provider
value={{
Expand All @@ -163,28 +197,15 @@ export const EtherlinkProvider: React.FC<{ children: ReactNode }> = ({ 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
Expand Down

0 comments on commit 7d4ec46

Please sign in to comment.