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

Many terrible experiments to install web3modal #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
60 changes: 60 additions & 0 deletions app/dc/connect-web3-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ethers } from "ethers";
import Web3Modal from "web3modal";
import { useEffect, useState } from "react";

const INFURA_ID = "709bb38868e74ec589d302a96b94450b";

/**
* This because of infinite pain. AMA
*/
const providerOptions =
typeof window !== "undefined"
? {
walletconnect: {
package: window.WalletConnectProvider, // required
options: {
infuraId: INFURA_ID,
},
},
}
: {};

async function connectWallet(web3Modal) {
const instance = await web3Modal.connect();
const provider = new ethers.providers.Web3Provider(instance);
const signer = provider.getSigner();
console.log(signer, provider);
}

export default function ConnectWallet() {
let [web3Modal, setWeb3Modal] = useState();

useEffect(() => {
let w3m;
try {
w3m = new Web3Modal({
disableInjectedProvider: true,
network: "mainnet", // optional
cacheProvider: false, // optional
providerOptions, // required
});
} catch (e) {
debugger;
console.error(e);
}

// TODO: While testing
// w3m.clearCachedProvider();

setWeb3Modal(w3m);
}, []);

return (
<div
className="box bg-pink-300 p-4 inline-block rounded"
onClick={() => connectWallet(web3Modal)}
>
Connecccct Wallet
</div>
);
}
3 changes: 3 additions & 0 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Header from "~/components/header";
import SendEth from "~/components/send-eth";
import { DappContext } from "./contexts/dapp-context";
import { useDappContext } from "./hooks/useDappContext";
import ConnectWeb3Modal from "~/dc/connect-web3-modal";

export const meta: MetaFunction = () => ({
charset: "utf-8",
Expand All @@ -28,6 +29,7 @@ export default function App() {
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<ConnectWeb3Modal />
<Header />
{/* How do we connect */}
{dappContextData && (
Expand All @@ -37,6 +39,7 @@ export default function App() {
</DappContext.Provider>
)}
<ScrollRestoration />
<script src="web3modal.js" />
<Scripts />
<LiveReload />
</body>
Expand Down
Loading