Skip to content

Commit

Permalink
134 feat check react component wrapping (#135)
Browse files Browse the repository at this point in the history
* feat: wrap vechain dapp connect kit in react

* revert: create button with modal wrapped

* test: wrapped vechain dapp connect kit

---------

Co-authored-by: Darren Kelly <[email protected]>
  • Loading branch information
Valazan and darrenvechain authored Dec 5, 2023
1 parent 375c218 commit 0f8d406
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 6 deletions.
4 changes: 2 additions & 2 deletions apps/sample-react-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import reactLogo from './assets/react.svg';
import viteLogo from '/vite.svg';
import './App.css';
import { ConnectWalletButtonWithModal } from '@vechain/dapp-kit-react';
import { VechainDappConnectKit } from '@vechain/dapp-kit-react';

function App() {
return (
Expand All @@ -20,7 +20,7 @@ function App() {
</div>
<h1>Vite + React</h1>
<div className="card">
<ConnectWalletButtonWithModal />
<VechainDappConnectKit />
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import GlobalFonts from '../../../assets/fonts/fonts';
import { ThemeProvider } from '../../provider/ThemeProvider';
import { VechainDappConnectKitWithTheme } from './Wrapped/VechainDappConnectKitWrapped';

export const VechainDappConnectKit: React.FC = (): React.ReactElement => {
return (
<ThemeProvider>
<GlobalFonts />
<VechainDappConnectKitWithTheme />
</ThemeProvider>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { useMemo } from 'react';
import { createComponent } from '@lit/react';
import { VechainDappConnectKit as VechainDappConnectKitVanilla } from '@vechain/dapp-kit-ui';
import { useThemeSelector } from '../../../provider/ThemeProvider';

const VechainDappConnectKitWrapped = () =>
createComponent({
tagName: 'vwk-vechain-dapp-connect-kit',
elementClass: VechainDappConnectKitVanilla,
react: React,
});

export const VechainDappConnectKitWithTheme: React.FC = () => {
const { theme } = useThemeSelector();

const VechainDappConnectKit = useMemo(
() => VechainDappConnectKitWrapped(),
[],
);

return <VechainDappConnectKit mode={theme.mode} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './VechainDappConnectKit';
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,3 +1,4 @@
export * from './ConnectWalletButtonWithModal';
export * from './ConnectWalletModal';
export * from './SelectWalletModal';
export * from './VechainDappConnectKit';
4 changes: 3 additions & 1 deletion packages/dapp-kit-react/test/helpers/react-test-helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import {
ConnectWalletButtonWithModal,
ConnectWalletModal,
DAppKitProvider,
SelectWalletModal,
VechainDappConnectKit,
ConnectWalletButtonWithModal,
} from '../../src';
import { ThemeProvider } from '../../src/provider/ThemeProvider';

export const wrapper = ({ children }: { children?: React.ReactNode }) => (
<DAppKitProvider nodeUrl="https://testnet.vechain.org">
<ThemeProvider>
{children}
<VechainDappConnectKit />
<ConnectWalletButtonWithModal />
<SelectWalletModal isOpen={false} />
<ConnectWalletModal isOpen={false} />
Expand Down
9 changes: 6 additions & 3 deletions packages/dapp-kit-ui/src/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ export class DAppKitModal {
open(): void {
DAppKitLogger.debug('DAppKitModal', 'opening the modal');

const existingElement =
window.document.querySelector('vwk-connect-modal');
const existingElement = window.document.querySelector(
'vwk-vechain-dapp-connect-kit',
);

if (!existingElement) {
DAppKitLogger.debug(
Expand All @@ -95,7 +96,9 @@ export class DAppKitModal {
'creating a new element',
);

const element = window.document.createElement('vwk-connect-modal');
const element = window.document.createElement(
'vwk-vechain-dapp-connect-kit',
);

window.document.body.appendChild(element);
}
Expand Down

0 comments on commit 0f8d406

Please sign in to comment.