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

fix: extension wasn't working unless running without ssr #108

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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;