import { useConnect } from "thirdweb/react";
import { createWallet, injectedProvider } from "thirdweb/wallets";
import { shortenAddress } from "thirdweb/utils";
function App() {
const account = useActiveAccount();
const wallet = useActiveWallet();
const { connect, isConnecting, error, cancelConnection } = useConnect();
const { disconnect } = useDisconnect();
if (account) {
return (
<div>
<p>Connected: {shortenAddress(account.address)} </p>
{wallet && (
<button onClick={() => disconnect(wallet)}>Disconnect</button>
)}
</div>
);
}
return (
<button
onClick={() =>
connect(async () => {
// 500+ wallets supported with id autocomplete
const wallet = createWallet("io.metamask");
const isInstalled = !!injectedProvider("io.metamask");
await wallet.connect({
client,
...(isInstalled
? {}
: {
walletConnect: {
// if not installed, show qr modal
showQrModal: true,
onCancel: () => {
cancelConnection();
},
},
}),
});
return wallet;
})
}
>
Connect MetaMask
</button>
);
}