Skip to content

Commit

Permalink
Remove network enforcing screen (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre authored Apr 16, 2024
1 parent 7bf8503 commit c17f4af
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 108 deletions.
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>
{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.

0 comments on commit c17f4af

Please sign in to comment.