Skip to content

Commit

Permalink
Switch network to DAO network if opened by url (#372)
Browse files Browse the repository at this point in the history
Signed-off-by: Manank Patni <manank321@gmail.com>
  • Loading branch information
Man-Jain authored Nov 14, 2022
1 parent d6b9119 commit 2d2e892
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/modules/explorer/components/NetworkSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const NetworkSheet: React.FC<Props> = props => {
onClick={() => {
props.onClose()
changeNetwork(networkOption)
window.location.href = "/explorer"
}}
>
<Grid container justifyContent="center" alignItems="center" style={{ gap: 8 }}>
Expand Down
7 changes: 4 additions & 3 deletions src/modules/explorer/pages/DAO/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { User } from "modules/explorer/pages/User"
import React, { useContext, useEffect, useState } from "react"
import { useHistory } from "react-router"
import { Redirect, Route, RouteProps, Switch, useParams, useRouteMatch } from "react-router-dom"
import { Network } from "services/beacon"
import { useTezos } from "services/beacon/hooks/useTezos"
import { useDAO } from "services/indexer/dao/hooks/useDAO"
import { Navbar } from "../../components/Toolbar"
Expand Down Expand Up @@ -43,7 +44,7 @@ enum DAOState {

const DAORouteContent: React.FC = ({ children }) => {
const daoId = useDAOID()
const { tezos, network } = useTezos()
const { tezos, network, changeNetwork } = useTezos()
const { data, error } = useDAO(daoId)
const [state, setState] = useState<DAOState>(DAOState.FOUND)
const history = useHistory()
Expand All @@ -63,9 +64,9 @@ const DAORouteContent: React.FC = ({ children }) => {

useEffect(() => {
if (history && data && data.data.network.toLowerCase() !== network.toLowerCase()) {
history.push("/explorer")
changeNetwork(data.data.network.toLowerCase() as Network)
}
}, [data, history, network])
}, [data, history, network, changeNetwork])

return (
<>
Expand Down
1 change: 1 addition & 0 deletions src/services/beacon/hooks/useTezos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const useTezos = (): WalletConnectReturn => {
await connect(newNetwork)
}
queryClient.resetQueries()
location.reload()
},
account,
network
Expand Down

0 comments on commit 2d2e892

Please sign in to comment.