Skip to content

Commit

Permalink
Merge pull request #2396 from zeitgeistpm/wc-fix
Browse files Browse the repository at this point in the history
Wallet Connect Fixes
  • Loading branch information
robhyrk authored Apr 23, 2024
2 parents 9c89e83 + 0377bfe commit 7ff35da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
25 changes: 15 additions & 10 deletions lib/state/wallet-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { WalletConnectSigner } from "lib/util/wallet-connect-signer";
import { ZTG_CHAIN_ID } from "lib/constants";

const WC_PROJECT_ID = process.env.NEXT_PUBLIC_WC_PROJECT_ID;
const WC_PROJECT_ID = process.env.NEXT_PUBLIC_WC_PROJECT_ID ?? "";
const DOMAIN_URL = "https://app.zeitgeist.pm/";

const walletConnectParams = {
Expand All @@ -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

0 comments on commit 7ff35da

Please sign in to comment.