Skip to content

Commit

Permalink
Darren/implement new vechain sdk (#310)
Browse files Browse the repository at this point in the history
* refactor: remove connex and init signer within dappkit

* chore(deps): remove connex

* fix: gha syntax error

* chore(deps): remove connex

* fix: tests

* fix: build errors

* revert: add sync2 back int

* fix: tests

* refactor: yarn, e2e and eslint (#311)

* refactor: yarn, e2e and eslint

* fix(GHA): install before install:all

* fix(GHA): install before install:all

* fix(extension): bug in extension

* fix(extension): bug in extension

* fix: update cucumber

* fix: run stop preview after e2e

* fix: lint errors

* fix: sync errors

* fix: sync2 not connecting

* fix: sync2 txs broken

* fix: tests

* fix: tests

* fix: yarn

* fix: yarn workspaces

* fix: missing declarations in test

* fix: missing declarations in test

* fix: missing declarations in test

* fix: missing declarations in test

* fix: dapp-kit-react tsx

* fix: add exports to package.json

* fix: ignore cucumber in examples

* fix: set type to module

* fix: package.jsons

* fix: add type module

* fix: package.jsons

* fix: package.jsons

* fix: fix angular

* chore: documenation
  • Loading branch information
darrenvechain authored Nov 19, 2024
1 parent 16bbb20 commit 5eb9131
Show file tree
Hide file tree
Showing 107 changed files with 29,457 additions and 20,666 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
const Config = require('@vechain/repo-config');

module.exports = Config.EslintLibrary;
module.exports = {
...Config.EslintLibrary,
rules: {
...Config.EslintLibrary.rules,
'import/no-extraneous-dependencies': 'error',
},
};
51 changes: 26 additions & 25 deletions .github/workflows/lint-build-test.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
name: Lint, Build & Test

on:
push:
branches: [ main-v2 ]
pull_request:
branches: [ main-v2 ]
push:
branches: [ main-v2 ]
pull_request:

concurrency:
group: ${{ github.head_ref || github.ref_name }}-build-test-scan
cancel-in-progress: true
group: ${{ github.head_ref || github.ref_name }}-build-test-scan
cancel-in-progress: true

jobs:
build-and-test:
runs-on: ubuntu-latest
name: Lint, Build & Test
build-and-test:
runs-on: ubuntu-latest
name: Lint, Build & Test

steps:
- name: Checkout
uses: actions/checkout@v3
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: 'yarn'
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'yarn'

- name: Install
run: yarn install:all
- name: Install
run: |
yarn
yarn install:all
- name: Lint
run: yarn run lint
- name: Lint
run: yarn run lint

- name: Test
run: yarn run test
- name: Test
run: yarn run test

- name: Build
run: yarn run build
- name: Build
run: yarn run build
71 changes: 36 additions & 35 deletions .github/workflows/test-e2e.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
name: E2E Tests

on:
push:
branches: [ main-v2 ]
pull_request:
branches: [ main-v2 ]
push:
branches: [ main-v2 ]
pull_request:

concurrency:
group: ${{ github.head_ref || github.ref_name }}-e2e-test
cancel-in-progress: true
group: ${{ github.head_ref || github.ref_name }}-e2e-test
cancel-in-progress: true

jobs:
e2e-tests:
runs-on: ubuntu-latest
name: E2E Tests

steps:
- name: Install Stable Chrome
run: |
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get install google-chrome-stable
- name: Install Stable chromedriver
uses: nanasess/setup-chromedriver@v2

- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: 'yarn'

- name: Install
run: yarn install:all

- name: Run E2E Tests
run: yarn test:e2e:ci
e2e-tests:
runs-on: ubuntu-latest
name: E2E Tests

steps:
- name: Install Stable Chrome
run: |
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get install google-chrome-stable
- name: Install Stable chromedriver
uses: nanasess/setup-chromedriver@v2

- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'yarn'

- name: Install
run: |
yarn
yarn install:all
- name: Run E2E Tests
run: yarn test:e2e:ci
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

Binary file added .yarn/install-state.gz
Binary file not shown.
934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.5.1.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.5.1.cjs
6 changes: 3 additions & 3 deletions examples/sample-angular-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"@ngx-translate/core": "^15.0.0",
"@ngx-translate/http-loader": "^8.0.0",
"@popperjs/core": "^2.11.8",
"@vechain/dapp-kit": "*",
"@vechain/dapp-kit-ui": "*",
"@vechain/dapp-kit": "workspace:^",
"@vechain/dapp-kit-ui": "workspace:^",
"angular-svg-icon": "^16.0.0",
"assert": "2.1.0",
"axios": "^1.4.0",
Expand All @@ -50,7 +50,7 @@
"@angular/cli": "^18.2.2",
"@angular/compiler-cli": "^18.2.2",
"@types/jasmine": "~3.10.0",
"@types/node": "^12.11.1",
"@types/node": "^22.9.0",
"@vechain/repo-config": "https://github.com/vechain/repo-config#v0.0.1",
"jasmine-core": "~4.0.0",
"karma": "~6.3.0",
Expand Down
8 changes: 3 additions & 5 deletions examples/sample-angular-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Angular modules
import { CUSTOM_ELEMENTS_SCHEMA, Component, type OnInit } from '@angular/core';
import { Component, CUSTOM_ELEMENTS_SCHEMA, type OnInit } from '@angular/core';
import { DAppKitUI } from '@vechain/dapp-kit-ui';

@Component({
Expand All @@ -24,13 +24,11 @@ export class AppComponent implements OnInit {
},
};

const vechainDAppKitOptions = {
DAppKitUI.configure({
nodeUrl: 'https://testnet.vechain.org/',
genesis: 'test',
walletConnectOptions,
usePersistence: true,
};
DAppKitUI.configure(vechainDAppKitOptions);
});

// custom button configuration
const customButton = document.getElementById('custom-button');
Expand Down
1 change: 1 addition & 0 deletions examples/sample-angular-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"target": "ES2022",
"module": "es2020",
"lib": ["es2020", "dom", "ES2021.String"],
"typeRoots": ["node_modules/@types", "../../node_modules/@types"],
"paths": {
"crypto": ["../../node_modules/crypto-browserify"],
"buffer": ["../../node_modules/buffer"],
Expand Down
8 changes: 4 additions & 4 deletions examples/sample-next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"purge": "yarn clean; rm -rf node_modules"
},
"dependencies": {
"@vechain/dapp-kit": "*",
"@vechain/dapp-kit-react": "*",
"@vechain/dapp-kit-ui": "*",
"next": "14.1.4",
"@vechain/dapp-kit": "workspace:^",
"@vechain/dapp-kit-react": "workspace:^",
"@vechain/dapp-kit-ui": "workspace:^",
"next": "15.0.3",
"react": "^18",
"react-dom": "^18"
},
Expand Down
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 @@ -46,7 +46,6 @@ export default function RootLayout({
</head>
<body className={inter.className}>
<DAppKitProvider
genesis="test"
logLevel="DEBUG"
nodeUrl="https://testnet.vechain.org/"
usePersistence
Expand Down
3 changes: 2 additions & 1 deletion examples/sample-next-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
],
"paths": {
"@/*": ["./src/*"]
}
},
"typeRoots": ["node_modules/@types"]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
Expand Down
10 changes: 5 additions & 5 deletions examples/sample-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
},
"dependencies": {
"@originjs/vite-plugin-commonjs": "^1.0.3",
"@vechain/dapp-kit": "*",
"@vechain/dapp-kit-react": "*",
"@vechain/dapp-kit-ui": "*",
"@vechain/sdk-core": "1.0.0-beta.30",
"@vechain/sdk-network": "1.0.0-beta.30",
"@vechain/dapp-kit": "workspace:^",
"@vechain/dapp-kit-react": "workspace:^",
"@vechain/dapp-kit-ui": "workspace:^",
"@vechain/sdk-core": "1.0.0-rc.1",
"@vechain/sdk-network": "1.0.0-rc.1",
"ethers": "6.13.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
66 changes: 50 additions & 16 deletions examples/sample-react-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import {
WalletButton,
useSDK,
useThor,
useWallet,
useWalletModal,
WalletButton,
} from '@vechain/dapp-kit-react';
import { ERC20_ABI, VTHO_ADDRESS } from '@vechain/sdk-core';
import { useEffect, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { Counter } from './counter.ts';

function App() {
const { account, signer } = useWallet();

const thor = useSDK().thor;
const thor = useThor();
const [count, setCount] = useState(BigInt(0));
const [error, setError] = useState<Error>();
const [txId, setTxId] = useState('');
const [loading, setLoading] = useState(false);
const { open, onConnectionStatusChange } = useWalletModal();
const [buttonText, setButtonText] = useState('Connect Custom Button');

const counterContract = useMemo(() => {
return Counter.load(thor, signer);
}, [thor, signer]);

useEffect(() => {
const loadCounter = async () => {
const counter = await counterContract.read.counter({
revision: {},
});
setCount(counter[0]);
};

loadCounter();
}, [counterContract, loading, error, txId]);

useEffect(() => {
const handleConnected = (address: string | null) => {
if (address) {
Expand All @@ -37,16 +55,26 @@ function App() {
}, [signer]);

const testTx = async () => {
const vthoContract = thor.contracts.load(
VTHO_ADDRESS,
ERC20_ABI,
signer,
);
setTxId('');
setError(undefined);
try {
setLoading(true);

// TODO: Set the delegation URL so that transactions are free
const tx = await counterContract.transact.increment();

const receipt = await tx.wait();
if (receipt == null || receipt.reverted) {
setError(new Error('Transaction failed'));
return;
}

vthoContract.transact.transfer(
'0x0000000000000000000000000000000000000000',
1000000000000000000n,
);
setTxId(receipt.meta.txID!);
} catch (e) {
setError(e as Error);
} finally {
setLoading(false);
}
};

return (
Expand All @@ -56,7 +84,13 @@ function App() {
<WalletButton />
<div className="label">custom button:</div>
<button onClick={open}>{buttonText}</button>
<button onClick={testTx}>Test TX</button>
<br></br>
<div className="label">Counter</div>
{account && !loading && <button onClick={testTx}>Increment</button>}
{loading && <div>Loading...</div>}
{error && <div>Error: {error.message}</div>}
{account && txId && <div>Transaction ID: {txId}</div>}
<div>Counter: {count.toString()}</div>
</div>
);
}
Expand Down
36 changes: 36 additions & 0 deletions examples/sample-react-app/src/counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ThorClient } from '@vechain/sdk-network';
import { VeChainSignerDAppKit } from '@vechain/dapp-kit';

export const Counter = {
abi: {
counter: {
inputs: [],
name: 'counter',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
increment: {
inputs: [],
name: 'increment',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
},
address: '0x8384738c995d49c5b692560ae688fc8b51af1059',
delegateURL: 'https://sponsor-testnet.vechain.energy/by/90',
load: (thor: ThorClient, signer?: VeChainSignerDAppKit) => {
return thor.contracts.load(
Counter.address,
[Counter.abi.counter, Counter.abi.increment] as const,
signer,
);
},
} as const;
Loading

0 comments on commit 5eb9131

Please sign in to comment.