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

Remove network enforcing screen #118

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,4 @@ module.exports = {
APP_VERSION: pkg.version,
COMMIT_HASH: commitHash,
},
webpack: (config) => {
// RainbowKit related dependencies
config.externals.push("pino-pretty", "lokijs", "encoding");
return config;
},
};
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"react": "^18",
"react-dom": "^18",
"ts-pattern": "^5.0.8",
"viem": "^2.9.16",
"viem": "^2.9.18",
"wagmi": "^2.5.12",
"zod": "^3.22.4"
},
Expand Down
17 changes: 6 additions & 11 deletions frontend/src/app/contracts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,15 @@ function AccountDetails() {
<Card
action={match({ address })
.with({ address: P.string }, () => {
const getWethAction = {
const receiveWeth = {
label: "Receive WETH",
onClick: tapCollTokenFaucet,
};
return isApproved ? getWethAction : [
{
label: "Approve ∞",
title: "Approve Liquity to transfer WETH on your behalf",
onClick: () => {
approve();
},
},
getWethAction,
];
return isApproved ? receiveWeth : [{
label: "Approve ∞",
title: "Approve Liquity to transfer WETH on your behalf",
onClick: approve,
}, receiveWeth];
})
.otherwise(() => ({
label: "Connect Wallet",
Expand Down
1 change: 0 additions & 1 deletion frontend/src/comps/AboutModal/AboutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function AboutModal({ children }: { children: ReactNode }) {
<AboutModalContext.Provider
value={{
open: () => {
console.log(visible);
setVisible(true);
},
close: () => setVisible(false),
Expand Down
74 changes: 6 additions & 68 deletions frontend/src/comps/Ethereum/Ethereum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,86 +6,28 @@ import type { Chain } from "wagmi/chains";

import { useConfig } from "@/src/comps/Config/Config";
import { WALLET_CONNECT_PROJECT_ID } from "@/src/env";
import { css } from "@/styled-system/css";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ConnectKitProvider, getDefaultConfig } from "connectkit";
import { ConnectKitProvider, getDefaultConfig as getDefaultConnectKitConfig } from "connectkit";
import { useMemo } from "react";
import { createConfig, http, useChainId, useSwitchChain, WagmiProvider } from "wagmi";
import { mainnet } from "wagmi/chains";
import { createConfig, http, WagmiProvider } from "wagmi";

const queryClient = new QueryClient();

export function Ethereum({ children }: { children: ReactNode }) {
const wagmiConfig = useWagmiConfig();

return (
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<ConnectKitProvider>
<EnforceChain>
{children}
</EnforceChain>
Comment on lines -25 to -27
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this yesterday because I couldn’t solve a mysterious wagmi runtime error happening only with Chromium (but not Chrome with the exact same version 🤨), but it got solved today after resetting it: it was probably caused by one of the flags I had activated.

{children}
</ConnectKitProvider>
</QueryClientProvider>
</WagmiProvider>
);
}

function EnforceChain({ children }: { children: ReactNode }) {
const currentChainId = useChainId();
const { chains: [chain], switchChain } = useSwitchChain();

if (!currentChainId || chain.id === currentChainId) {
return children;
}

return (
<div
className={css({
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
gap: 16,
height: "100vh",
})}
>
<p>
Please switch to the {chain.name} network.
</p>
<button
onClick={() => {
switchChain({ chainId: chain.id });
}}
className={css({
height: 40,
padding: "8px 16px",
color: "white",
fontSize: 14,
background: "blue",
borderRadius: 20,
cursor: "pointer",
whiteSpace: "nowrap",
_disabled: {
background: "rain",
cursor: "not-allowed",
},
_active: {
_enabled: {
translate: "0 1px",
},
},
})}
>
Switch to {chain.name}
</button>
</div>
);
}

function useWagmiConfig() {
const { config } = useConfig();

return useMemo(() => {
const chain = createChain({
id: config.chainId,
Expand All @@ -97,19 +39,15 @@ function useWagmiConfig() {
contractEnsResolver: config.chainContractEnsResolver,
contractMulticall: config.chainContractMulticall,
});

const configParams = getDefaultConfig({
return createConfig(getDefaultConnectKitConfig({
appName: "Liquity v2",
chains: [chain, mainnet],
chains: [chain],
transports: {
[mainnet.id]: http(mainnet.rpcUrls.default.http[0]),
[chain.id]: http(config.chainRpcUrl),
},
ssr: true,
walletConnectProjectId: WALLET_CONNECT_PROJECT_ID,
});

return createConfig(configParams);
}));
}, [config]);
}

Expand Down
49 changes: 27 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.