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

Wallet Connect Fixes #2396

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 14 additions & 9 deletions lib/state/wallet-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,12 @@ const chains = Object.values(requiredNamespaces)
.map((namespace) => namespace.chains)
.flat();

if (!WC_PROJECT_ID) {
throw new Error("Missing WalletConnect project ID");
}

const modal = new WalletConnectModal({
projectId: WC_PROJECT_ID,
chains,
});
let provider;
let modal;

const provider = await UniversalProvider.init(walletConnectParams);
const setProvider = async () => {
provider = await UniversalProvider.init(walletConnectParams);
};

export class WalletConnect implements Wallet {
extensionName = "walletconnect";
Expand All @@ -65,6 +61,15 @@ export class WalletConnect implements Wallet {
onModalOpen?: () => void;
onModalClose?: () => void;
} = {}) {
if (!WC_PROJECT_ID) return;

setProvider();

modal = new WalletConnectModal({
projectId: WC_PROJECT_ID,
chains,
});

modal.subscribeModal((state) => {
state.open ? onModalOpen?.() : onModalClose?.();
});
Expand Down
3 changes: 2 additions & 1 deletion lib/state/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { web3AuthWalletInstance } from "./util/web3auth-config";
import { WalletConnect } from "./wallet-connect";

const DAPP_NAME = "zeitgeist";
const WC_PROJECT_ID = process.env.NEXT_PUBLIC_WC_PROJECT_ID;

export type UseWallet = WalletState & {
/**
Expand Down Expand Up @@ -222,7 +223,7 @@ export const supportedWallets = [
new PolkadotjsWallet(),
new SubWallet(),
new TalismanWallet(),
new WalletConnect(),
...(WC_PROJECT_ID ? [new WalletConnect()] : []),
web3AuthWalletInstance,
];

Expand Down
Loading