Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: disconnect wallet #250

Merged
merged 9 commits into from
Aug 29, 2022
8 changes: 1 addition & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ import { ProposalTypes } from 'components/ProposalTypes';
import CreateProposalPage from 'Modules/Guilds/pages/CreateProposal';
import { LandingPage } from 'Modules/Guilds/pages/LandingPage';
import NotFound from 'Modules/Guilds/pages/NotFound';
import { Navigate, Route, Routes } from 'react-router-dom';
import { Route, Routes } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';
import { GuildsDarkTheme } from 'components/theme';
import CreateDiscussionPage from 'Modules/Guilds/pages/CreateDiscussion';
import { useNetwork } from 'wagmi';

const App = () => {
const {
chain: { network },
} = useNetwork();

return (
<ThemeProvider theme={GuildsDarkTheme}>
<TransactionsProvider>
Expand All @@ -29,7 +24,6 @@ const App = () => {
<Header />
<Container>
<Routes>
<Route path="/" element={<Navigate replace to={network} />} />
<Route path="/:chainName" element={<LandingPage />} />
<Route path="/:chainName/:guildId" element={<GuildsPage />} />
<Route
Expand Down
13 changes: 9 additions & 4 deletions src/Modules/Guilds/pages/NotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ import { IconButton } from 'components/primitives/Button';
import { Result, ResultState } from 'components/Result';
import { UnstyledLink } from 'components/primitives/Links';
import { FiArrowLeft } from 'react-icons/fi';
import { useTypedParams } from '../Hooks/useTypedParams';
dcrescimbeni marked this conversation as resolved.
Show resolved Hide resolved
import { useTranslation } from 'react-i18next';

const NotFound: React.FC = () => {
const { chainName } = useTypedParams();
const { t } = useTranslation();

return (
<Result
state={ResultState.ERROR}
title="That page doesn't exist."
subtitle="Make sure you typed the correct address."
title={t('pageNotExist')}
subtitle={t('makeSureCorrectAddress')}
extra={
<UnstyledLink to={`/`}>
<UnstyledLink to={`/${chainName}`}>
<IconButton iconLeft>
<FiArrowLeft /> Take me home
<FiArrowLeft /> {t('takeMeHome')}
</IconButton>
</UnstyledLink>
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { useNetwork } from 'wagmi';
import { NetworkButton } from '../NetworkButton';
import { WalletButton } from '../WalletButton';
import {
Expand All @@ -12,11 +13,15 @@ import {
const Header = () => {
const navigate = useNavigate();
const { t } = useTranslation();
const { chain } = useNetwork();

return (
<HeaderWrapper as="header">
<HeaderContainer>
<ClickableHeading onClick={() => navigate(`/`)} size={2}>
<ClickableHeading
onClick={() => navigate(`/${chain.network}`)}
size={2}
>
<strong>{t('guilds.guilds')}</strong>
</ClickableHeading>
<MenuItems>
Expand Down
16 changes: 7 additions & 9 deletions src/components/Web3Modals/EnsureReadOnlyConnection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { useEffect, useMemo } from 'react';
import { useAccount, useConnect, useNetwork } from 'wagmi';

const EnsureReadOnlyConnection = () => {
const { chains } = useNetwork();
const defaultChain = useMemo(() => {
const { chains, chain } = useNetwork();
const validChain = useMemo(() => {
if (chains?.length === 0) return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove this line, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good question.

I tinkered with it to get an answer, and it seems that its removal won't affect the connection.

Maybe @mprasanjith can chime in?


// Localhost is only available on development environments.
// const localhost = chains.find(chain => chain.id === 1337);
return chains[0];
}, [chains]);
if (!chain) return chains[0];
return chain;
}, [chains, chain]);

const { connector, isConnecting, isReconnecting } = useAccount();
const { connect, connectors } = useConnect();
Expand All @@ -22,7 +20,7 @@ const EnsureReadOnlyConnection = () => {
);
if (readOnlyConnector) {
console.log('Initiating read only connection');
connect({ connector: readOnlyConnector, chainId: defaultChain?.id });
connect({ connector: readOnlyConnector, chainId: validChain?.id });
}
}
}, [
Expand All @@ -31,7 +29,7 @@ const EnsureReadOnlyConnection = () => {
isReconnecting,
connector,
connectors,
defaultChain,
validChain,
]);

return null;
Expand Down
14 changes: 8 additions & 6 deletions src/contexts/Guilds/guildAvailability.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getNetworkById, getChainIcon } from 'utils';
import { useTypedParams } from 'Modules/Guilds/Hooks/useTypedParams';
import { useNetwork } from 'wagmi';
import useSwitchNetwork from 'hooks/Guilds/web3/useSwitchNetwork';
import { useTranslation } from 'react-i18next';

interface ContractAvailability {
[chainId: number]: boolean;
Expand All @@ -36,11 +37,12 @@ export const GuildAvailabilityContext =
// TODO: Refactor this to not use the MultichainContext.
// We should remove the MultichainContext as we no longer need it.
const GuildAvailabilityProvider = ({ children }) => {
const { guildId } = useTypedParams();
const { guildId, chainName } = useTypedParams();
const { providers: multichainProviders } = useContext(MultichainContext);
const [availability, setAvailability] = useState<ContractAvailability>({});
const { chain: currentChain } = useNetwork();
const { switchNetwork } = useSwitchNetwork();
const { t } = useTranslation();

const currentChainId = useMemo(() => currentChain?.id, [currentChain]);

Expand Down Expand Up @@ -84,11 +86,11 @@ const GuildAvailabilityProvider = ({ children }) => {
return (
<Result
state={ResultState.ERROR}
title="Guild not available."
title={t('guildNotAvailable')}
subtitle={
Object.values(availability).includes(true)
? 'This guild is not available on this network.'
: 'No guild exists on this address.'
? t('guildNotAvailableOnThisNetwork')
: t('noGuildInThisAddress')
}
extra={
Object.values(availability).includes(true) ? (
Expand Down Expand Up @@ -118,9 +120,9 @@ const GuildAvailabilityProvider = ({ children }) => {
</div>
</>
) : (
<UnstyledLink to={`/`}>
<UnstyledLink to={`/${chainName}`}>
<IconButton iconLeft>
<FiArrowLeft /> Take me home
<FiArrowLeft /> {t('takeMeHome')}
</IconButton>
</UnstyledLink>
)
Expand Down
8 changes: 7 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,11 @@
},
"none": "None",
"expandLinesOfCode": "Expand {{numLines}} lines of code",
"noGuildsRegistered": "No guilds registered on this network"
"noGuildsRegistered": "No guilds registered on this network",
"guildNotAvailable": "Guild not available",
"guildNotAvailableOnThisNetwork": "This guild is not available on this network",
"noGuildInThisAddress": "No guild exists on this address",
"takeMeHome": "Take me home",
"pageNotExist": "That page doesn't exist",
"makeSureCorrectAddress": "Make sure you typed the correct address"
}