Skip to content

Commit

Permalink
Fix for Back to community (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshpw authored Sep 11, 2024
1 parent a7aaf3f commit ca1780a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ yarn-error.log*

.idea
.env.example
.cosine
.cosine
bun.lockb
75 changes: 39 additions & 36 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"
import { CommunityCreator } from "modules/lite/creator"
import { hexStringToBytes } from "services/utils/utils"
import { HistoryLengthProvider } from "modules/explorer/context/HistoryLength"

const queryClient = new QueryClient({
defaultOptions: {
Expand Down Expand Up @@ -101,47 +102,49 @@ const App: React.FC = () => {
<LocalizationProvider dateAdapter={AdapterDayjs}>
<Box bgcolor="primary.dark" position="absolute" width="100%">
<Router>
<ScrollToTop />
<Switch>
<Route path="/creator">
<CreatorProvider>
<ThemeProvider theme={legacyTheme}>
<DAOCreatorRouter />
</ThemeProvider>
</CreatorProvider>
{/* <WarningFooter
<HistoryLengthProvider>
<ScrollToTop />
<Switch>
<Route path="/creator">
<CreatorProvider>
<ThemeProvider theme={legacyTheme}>
<DAOCreatorRouter />
</ThemeProvider>
</CreatorProvider>
{/* <WarningFooter
text={
"The Homebase contract can't transfer FA1.2 tokens. Please make sure any and all tokens you send to the DAO treasury are implementing the FA2 standard."
}
/> */}
</Route>
<Route path="/lite">
<ThemeProvider theme={legacyTheme}>
<CommunityCreator />
</ThemeProvider>
</Route>
<Route path="/explorer">
<TZKTSubscriptionsProvider>
<DAOExplorerRouter />
</TZKTSubscriptionsProvider>
</Route>
<Route path="/lite">
<ThemeProvider theme={legacyTheme}>
<CommunityCreator />
</ThemeProvider>
</Route>
<Route path="/explorer">
<TZKTSubscriptionsProvider>
<DAOExplorerRouter />
</TZKTSubscriptionsProvider>

{window.location.href.indexOf(HUMANITEZ_DAO) !== -1 ? (
<>
{/* Special case for this DAO which was created before FA1.2 fix was created for the smart contract */}
<WarningFooter
text={
"The Homebase contract can't transfer FA1.2 tokens. Please make sure any and all tokens you send to the DAO treasury are implementing the FA2 standard."
}
/>
</>
) : null}
<ExplorerFooter></ExplorerFooter>
</Route>
<Route path="/faq">
<FAQ />
</Route>
<Redirect to="/explorer" />
</Switch>
{window.location.href.indexOf(HUMANITEZ_DAO) !== -1 ? (
<>
{/* Special case for this DAO which was created before FA1.2 fix was created for the smart contract */}
<WarningFooter
text={
"The Homebase contract can't transfer FA1.2 tokens. Please make sure any and all tokens you send to the DAO treasury are implementing the FA2 standard."
}
/>
</>
) : null}
<ExplorerFooter></ExplorerFooter>
</Route>
<Route path="/faq">
<FAQ />
</Route>
<Redirect to="/explorer" />
</Switch>
</HistoryLengthProvider>
</Router>
</Box>
</LocalizationProvider>
Expand Down
25 changes: 25 additions & 0 deletions src/modules/explorer/context/HistoryLength/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { createContext, useContext, useState, useEffect } from "react"
import { useHistory, useLocation } from "react-router-dom"

const HistoryLengthContext = createContext<number>(0)

export const useHistoryLength = () => useContext(HistoryLengthContext)

export const HistoryLengthProvider: React.FC = ({ children }) => {
const [historyLength, setHistoryLength] = useState(1)
const history = useHistory()
const location = useLocation()

useEffect(() => {
console.log({ history })
if (history && (history.action === "PUSH" || history.action === "REPLACE")) {
setHistoryLength(prevLength => prevLength + 1)
}
}, [history, location])

useEffect(() => {
console.log({ historyLength })
}, [historyLength])

return <HistoryLengthContext.Provider value={historyLength}>{children}</HistoryLengthContext.Provider>
}
14 changes: 12 additions & 2 deletions src/modules/lite/explorer/pages/ProposalDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useTokenVoteWeight } from "services/contracts/token/hooks/useTokenVoteW
import BigNumber from "bignumber.js"
import { ArrowBackIosOutlined } from "@material-ui/icons"
import { useIsMember } from "../../hooks/useIsMember"
import { useHistoryLength } from "modules/explorer/context/HistoryLength"

const PageContainer = styled("div")({
marginBottom: 50,
Expand Down Expand Up @@ -54,8 +55,9 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
}>()

const theme = useTheme()
const historyLength = useHistoryLength()
const isMobileSmall = useMediaQuery(theme.breakpoints.down("sm"))
const { state } = useLocation<{ poll: Poll; choices: Choice[]; daoId: string }>()
const { state, pathname } = useLocation<{ poll: Poll; choices: Choice[]; daoId: string }>()
const navigate = useHistory()
const { data: dao } = useDAO(state?.daoId)
const { account, wallet } = useTezos()
Expand All @@ -73,6 +75,14 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
const isMember = useIsMember(network, community?.tokenAddress || "", account)

const votingPower = poll?.isXTZ ? voteWeight?.votingXTZWeight : voteWeight?.votingWeight
const navigateToDao = () => {
if (historyLength > 1) {
navigate.goBack()
} else {
const daoUrl = pathname?.replace(`proposal/${proposalId}`, "")
navigate.push(daoUrl)
}
}

useEffect(() => {
// refetch()
Expand Down Expand Up @@ -142,7 +152,7 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
<Grid
container
style={{ gap: 15, cursor: "pointer", marginBottom: 23 }}
onClick={() => navigate.goBack()}
onClick={() => navigateToDao()}
alignItems="center"
>
<ArrowBackIosOutlined color="secondary" />
Expand Down

0 comments on commit ca1780a

Please sign in to comment.