Skip to content

Commit

Permalink
fix: extension wasn't working unless running without ssr (#108)
Browse files Browse the repository at this point in the history
* fix: extension wasn't working unless running without ssr

* feat: add modal only component
  • Loading branch information
darrenvechain authored Nov 28, 2023
1 parent b8e0a6b commit 6da3695
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 46 deletions.
33 changes: 1 addition & 32 deletions apps/sample-next-app/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@

import { Inter } from 'next/font/google';
import './globals.css';
import type { Options } from '@vechain/connex';
import { ConnexProvider } from '@vechainfoundation/dapp-kit-react';
import type { WalletConnectOptions } from '@vechainfoundation/dapp-kit';

const nodeOptions: Omit<Options, 'signer'> = {
node: 'https://testnet.vechain.org/',
network: 'test',
};

const walletConnectOptions: WalletConnectOptions = {
projectId: 'a0b855ceaf109dbc8426479a4c3d38d8',
metadata: {
name: 'Sample VeChain dApp',
description: 'A sample VeChain dApp',
url: typeof window !== 'undefined' ? window.location.origin : '',
icons: [
typeof window !== 'undefined'
? `${window.location.origin}/images/logo/my-dapp.png`
: '',
],
},
};

const inter = Inter({ subsets: ['latin'] });

Expand All @@ -36,16 +14,7 @@ export default function RootLayout({
}): React.ReactElement {
return (
<html lang="en">
<body className={inter.className}>
<ConnexProvider
key="connex"
nodeOptions={nodeOptions}
persistState
walletConnectOptions={walletConnectOptions}
>
{children}
</ConnexProvider>
</body>
<body className={inter.className}>{children}</body>
</html>
);
}
22 changes: 8 additions & 14 deletions apps/sample-next-app/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
'use client'; // This is a client component

import {
ConnectWalletButtonWithModal,
useWallet,
} from '@vechainfoundation/dapp-kit-react';
import React, { useEffect } from 'react';
import React from 'react';
import dynamic from 'next/dynamic';

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, import/no-default-export
export default function Home() {
const { account } = useWallet();

useEffect(() => {
// eslint-disable-next-line no-console
console.log('account', account);
}, [account]);
const ConnectWalletButton = dynamic(() => import('./pages/homepage'), {
ssr: false,
});

// eslint-disable-next-line import/no-default-export
export default function Page() {
return (
<main>
<ConnectWalletButtonWithModal />
<ConnectWalletButton />
</main>
);
}
58 changes: 58 additions & 0 deletions apps/sample-next-app/src/app/pages/homepage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
ConnectWalletButtonWithModal,
ConnexProvider,
useWallet,
} from '@vechainfoundation/dapp-kit-react';
import type { Options } from '@vechain/connex';
import type { WalletConnectOptions } from '@vechainfoundation/dapp-kit';
import { useEffect } from 'react';

const nodeOptions: Omit<Options, 'signer'> = {
node: 'https://testnet.vechain.org/',
network: 'test',
};

const walletConnectOptions: WalletConnectOptions = {
projectId: 'a0b855ceaf109dbc8426479a4c3d38d8',
metadata: {
name: 'Sample VeChain dApp',
description: 'A sample VeChain dApp',
url: typeof window !== 'undefined' ? window.location.origin : '',
icons: [
typeof window !== 'undefined'
? `${window.location.origin}/images/logo/my-dapp.png`
: '',
],
},
};

// eslint-disable-next-line func-style
function ConnectWallet() {
const { account } = useWallet();

useEffect(() => {
if (account) {
// eslint-disable-next-line no-console
console.log('account', account);
}
}, [account]);

return <ConnectWalletButtonWithModal />;
}

// eslint-disable-next-line func-style
function HomePage() {
return (
<ConnexProvider
key="connex"
nodeOptions={nodeOptions}
persistState
walletConnectOptions={walletConnectOptions}
>
<ConnectWallet />
</ConnexProvider>
);
}

// eslint-disable-next-line import/no-default-export
export default HomePage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { useMemo } from 'react';
import { createComponent } from '@lit/react';
import { ConnectModal } from '@vechainfoundation/dapp-kit-ui';

export const createButtonWithModal = () =>
createComponent({
tagName: 'vwk-connect-modal',
elementClass: ConnectModal,
react: React,
});

export const ConnectWalletModal: React.FC = () => {
const Modal = useMemo(() => createButtonWithModal(), []);

return <Modal />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ConnectWalletModal';
1 change: 1 addition & 0 deletions packages/dapp-kit-react/src/Components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './ConnectWalletButtonWithModal';
export * from './ConnectWalletModal';

0 comments on commit 6da3695

Please sign in to comment.