Skip to content

Commit

Permalink
fix: thordevkit imports (#188)
Browse files Browse the repository at this point in the history
* fix: thordevkit imports

* fix: fix connex

* fix: dapp-kit

* feat: react test

* fix: typescript configurations

* fix: vite

* fix: remove useless file

* fix: valtio version

* chore: add version

* chore: add version

* chore: fix version

* fix: layout

* fix: remove tsconfig and fix yarn lock

* fix: versions

* fix: linting problems
  • Loading branch information
davidecarpini authored Feb 6, 2024
1 parent b1e6e90 commit 0f9f3db
Show file tree
Hide file tree
Showing 27 changed files with 657 additions and 119 deletions.
1 change: 0 additions & 1 deletion examples/sample-next-app/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default function RootLayout({
genesis="test"
logLevel="DEBUG"
nodeUrl="https://testnet.vechain.org/"
themeMode="DARK"
usePersistence
walletConnectOptions={walletConnectOptions}
>
Expand Down
9 changes: 6 additions & 3 deletions examples/sample-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
"dev": "vite",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"purge": "yarn clean; rm -rf node_modules"
"purge": "yarn clean; rm -rf node_modules",
"test": "vitest"
},
"dependencies": {
"@vechain/dapp-kit": "*",
"@vechain/dapp-kit-react": "*",
"@vechain/dapp-kit-ui": "*",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vite-plugin-node-polyfills": "^0.17.0"
"vite": "^5.0.12"
},
"devDependencies": {
"@types/react": "^18.2.37",
Expand All @@ -28,7 +29,9 @@
"eslint": "^8.53.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"react-test-renderer": "^18.2.0",
"typescript": "^5.2.2",
"vite": "^4.5.2"
"vite-plugin-node-polyfills": "^0.17.0",
"vitest": "^1.2.2"
}
}
22 changes: 22 additions & 0 deletions examples/sample-react-app/test/setup/resizeObserverMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class ResizeObserverMock {
private readonly callback: ResizeObserverCallback;

constructor(callback: ResizeObserverCallback) {
this.callback = callback;
}

observe() {
// Mock observe method
}

unobserve() {
// Mock unobserve method
}

disconnect() {
// Mock disconnect method
}
}

// Make the mock globally available
global.ResizeObserver = ResizeObserverMock;
15 changes: 15 additions & 0 deletions examples/sample-react-app/test/setup/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { vi } from 'vitest';

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
33 changes: 33 additions & 0 deletions examples/sample-react-app/test/welcome.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import renderer from 'react-test-renderer';
import React from 'react';
import { test, expect } from 'vitest';
import App from '../src/App';
import { DAppKitProvider } from '@vechain/dapp-kit-react';
import { WalletConnectOptions } from '@vechain/dapp-kit';

test('Welcome', async () => {
const walletConnectOptions: WalletConnectOptions = {
projectId: 'a0b855ceaf109dbc8426479a4c3d38d8',
metadata: {
name: 'Sample VeChain dApp',
description: 'A sample VeChain dApp',
url: window.location.origin,
icons: [``],
},
};
const component = renderer.create(
<React.StrictMode>
<DAppKitProvider
nodeUrl={'https://testnet.vechain.org/'}
genesis={'test'}
usePersistence
walletConnectOptions={walletConnectOptions}
>
<App />
</DAppKitProvider>
</React.StrictMode>,
);

const tree = component.toJSON();
expect(tree).toBeDefined();
});
15 changes: 11 additions & 4 deletions examples/sample-react-app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { resolve } from 'path';

export default defineConfig({
plugins: [nodePolyfills(), react()],
build: {
commonjsOptions: {
transformMixedEsModules: true,
},
//vitest
test: {
globals: true,
environment: 'jsdom',
setupFiles: [
resolve(__dirname, 'test/setup/setup.ts'),
resolve(__dirname, 'test/setup/resizeObserverMock.ts'),
],
},
base:
process.env.NODE_ENV === 'production'
Expand Down
7 changes: 3 additions & 4 deletions packages/dapp-kit-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vechain/dapp-kit-react",
"version": "1.0.3",
"version": "1.0.4",
"private": false,
"homepage": "https://github.com/vechainfoundation/vechain-dapp-kit",
"repository": "github:vechain/vechain-dapp-kit",
Expand All @@ -16,9 +16,8 @@
"LICENSE"
],
"scripts": {
"build": "tsup src/index.ts --format esm --dts --external react",
"build": "tsup",
"clean": "rm -rf dist .turbo",
"dev": "tsup src/index.ts --format esm --watch --dts --external react",
"lint": "tsc --noEmit && eslint src --ext .js,.jsx,.ts,.tsx",
"purge": "yarn clean && rm -rf node_modules",
"test": "vitest run --coverage",
Expand All @@ -31,7 +30,7 @@
"@vechain/dapp-kit": "*",
"@vechain/dapp-kit-ui": "*",
"thor-devkit": "^2.0.9",
"valtio": "^1.12.1"
"valtio": "1.11.2"
},
"devDependencies": {
"@testing-library/react": "^14.1.2",
Expand Down
6 changes: 4 additions & 2 deletions packages/dapp-kit-react/src/DAppKitProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { WalletSource } from '@vechain/dapp-kit';
import { DAppKitUI } from '@vechain/dapp-kit-ui';
import { subscribeKey } from 'valtio/vanilla/utils';
import type { DAppKitProviderOptions, DAppKitContext } from './types';
import { Certificate } from 'thor-devkit';
import * as ThorDevkit from 'thor-devkit';

/**
* Context
Expand Down Expand Up @@ -71,7 +71,9 @@ export const DAppKitProvider: React.FC<DAppKitProviderOptions> = ({
connex.wallet.state.source,
);
const [connectionCertificate, setConnectionCertificate] =
useState<Certificate | null>(connex.wallet.state.connectionCertificate);
useState<ThorDevkit.Certificate | null>(
connex.wallet.state.connectionCertificate,
);

useEffect(() => {
const addressSub = subscribeKey(connex.wallet.state, 'address', (v) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/dapp-kit-react/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="@vechain/connex" />
import type React from 'react';
import type { Certificate } from 'thor-devkit';
import * as ThorDevkit from 'thor-devkit';
import type { ConnectResponse, WalletSource } from '@vechain/dapp-kit';
import { type DAppKitUIOptions } from '@vechain/dapp-kit-ui';

Expand Down Expand Up @@ -35,7 +35,7 @@ export interface DAppKitContext {
connect: () => Promise<ConnectResponse>;
account: string | null;
source: WalletSource | null;
connectionCertificate: Certificate | null;
connectionCertificate: ThorDevkit.Certificate | null;
};
modal: {
open: () => void;
Expand Down
24 changes: 21 additions & 3 deletions packages/dapp-kit-react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
{
"extends": "@vechain/repo-config/src/tsconfig/library.json",
"include": ["."],
"exclude": ["dist", "node_modules"]
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"target": "es2021",
"experimentalDecorators": true,
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"skipLibCheck": true,
"strict": true,
// React
"jsx": "react-jsx"
},
"include": ["src/**/*.ts", "test/**/*.test.ts"]
}
13 changes: 13 additions & 0 deletions packages/dapp-kit-react/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'tsup';

// eslint-disable-next-line import/no-default-export
export default defineConfig({
entry: ['src/index.ts'],
outDir: 'dist',
format: 'esm',
minify: true,
sourcemap: true,
dts: true,
clean: true,
external: ['react'],
});
8 changes: 5 additions & 3 deletions packages/dapp-kit-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vechain/dapp-kit-ui",
"version": "1.0.3",
"version": "1.0.4",
"private": false,
"description": "Vanilla JS DAppKit",
"keywords": [
Expand Down Expand Up @@ -31,17 +31,18 @@
"purge": "yarn clean && rm -rf node_modules",
"test": "vitest run --coverage",
"test:dev": "vitest run ",
"watch": "tsup --watch"
"watch": "yarn build --watch"
},
"dependencies": {
"@vechain/connex": "2.1.0",
"@vechain/dapp-kit": "*",
"@vechain/picasso": "2.1.1",
"@wagmi/core": "^1.4.5",
"@web3modal/ethereum": "^2.7.1",
"@web3modal/html": "^2.7.1",
"lit": "^3.0.0",
"qrcode": "1.5.3",
"valtio": "^1.12.1",
"valtio": "1.11.2",
"viem": "^1.18.4"
},
"devDependencies": {
Expand All @@ -53,6 +54,7 @@
"eslint": "^8.15.0",
"parcel": "^2.10.2",
"prettier": "^2.6.2",
"punycode": "^1.4.1",
"tsup": "^7.2.0",
"typechain": "^8.3.2",
"typescript": "~5.2.0",
Expand Down
24 changes: 16 additions & 8 deletions packages/dapp-kit-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
{
"extends": "@vechain/repo-config/src/tsconfig/base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"target": "es2021",
"experimentalDecorators": true
"experimentalDecorators": true,
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"skipLibCheck": true,
"strict": true
},
"include": [
"src/**/*.ts",
"test/utils/listeners.test.ts",
"test/utils/mobile.test.ts"
],
"exclude": []
"include": ["src/**/*.ts", "test/**/*.test.ts"]
}
26 changes: 0 additions & 26 deletions packages/dapp-kit-ui/web-dev-server.config.mjs

This file was deleted.

8 changes: 4 additions & 4 deletions packages/dapp-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vechain/dapp-kit",
"version": "1.0.3",
"version": "1.0.4",
"private": false,
"homepage": "https://github.com/vechainfoundation/vechain-dapp-kit",
"repository": "github:vechain/vechain-dapp-kit",
Expand All @@ -14,12 +14,12 @@
"LICENSE"
],
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts",
"build": "tsup",
"clean": "rm -rf dist .turbo",
"lint": "tsc --noEmit && eslint src --ext .js,.jsx,.ts,.tsx",
"purge": "yarn clean && rm -rf node_modules",
"test": "vitest run --coverage",
"watch": "tsup src/index.ts --format cjs,esm --watch --dts"
"watch": "yarn build --watch"
},
"dependencies": {
"@vechain/connex": "2.1.0",
Expand All @@ -31,7 +31,7 @@
"@walletconnect/utils": "2.10.2",
"events": "^3.3.0",
"thor-devkit": "^2.0.9",
"valtio": "^1.12.1"
"valtio": "1.11.2"
},
"devDependencies": {
"@types/react": "^18.2.28",
Expand Down
4 changes: 2 additions & 2 deletions packages/dapp-kit/src/classes/certificate-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Certificate } from 'thor-devkit';
import * as ThorDevkit from 'thor-devkit';
import type { BaseWallet, ConnectResponse, ConnexWallet } from '../types';
import { DEFAULT_CONNECT_CERT_MESSAGE } from '../constants';

Expand All @@ -24,7 +24,7 @@ class CertificateBasedWallet implements ConnexWallet {
};

try {
Certificate.verify(connectionCertificate);
ThorDevkit.Certificate.verify(connectionCertificate);

return {
account: signer,
Expand Down
4 changes: 2 additions & 2 deletions packages/dapp-kit/src/classes/wallet-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Certificate } from 'thor-devkit';
import * as ThorDevkit from 'thor-devkit';
import { proxy, subscribe } from 'valtio/vanilla';
import { subscribeKey } from 'valtio/vanilla/utils';
import type {
Expand Down Expand Up @@ -83,7 +83,7 @@ class WalletManager {
};

try {
Certificate.verify(connectionCertificate);
ThorDevkit.Certificate.verify(connectionCertificate);
this.state.address = signer;
this.state.connectionCertificate = connectionCertificate;
return {
Expand Down
Loading

0 comments on commit 0f9f3db

Please sign in to comment.