-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: extension wasn't working unless running without ssr (#108)
* fix: extension wasn't working unless running without ssr * feat: add modal only component
- Loading branch information
1 parent
b8e0a6b
commit 6da3695
Showing
6 changed files
with
85 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
16 changes: 16 additions & 0 deletions
16
packages/dapp-kit-react/src/Components/ConnectWalletModal/ConnectWalletModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 />; | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/dapp-kit-react/src/Components/ConnectWalletModal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ConnectWalletModal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './ConnectWalletButtonWithModal'; | ||
export * from './ConnectWalletModal'; |