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

Darren/implement new vechain sdk #310

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bd724b7
refactor: remove connex and init signer within dappkit
darrenvechain Nov 7, 2024
2087c9b
chore(deps): remove connex
darrenvechain Nov 7, 2024
ba41250
fix: gha syntax error
darrenvechain Nov 7, 2024
85908d9
chore(deps): remove connex
darrenvechain Nov 7, 2024
36c4603
fix: tests
darrenvechain Nov 7, 2024
4158910
fix: build errors
darrenvechain Nov 7, 2024
e2e91c5
revert: add sync2 back int
darrenvechain Nov 7, 2024
c2d4b78
fix: tests
darrenvechain Nov 7, 2024
e561e5e
refactor: yarn, e2e and eslint (#311)
darrenvechain Nov 13, 2024
1d5905c
fix: lint errors
darrenvechain Nov 13, 2024
b462b3c
fix: sync errors
darrenvechain Nov 13, 2024
bddbdb3
fix: sync2 not connecting
darrenvechain Nov 13, 2024
5bf713f
fix: sync2 txs broken
darrenvechain Nov 13, 2024
4777b4b
fix: tests
darrenvechain Nov 13, 2024
89f8a54
fix: tests
darrenvechain Nov 13, 2024
9ad6ea2
fix: yarn
darrenvechain Nov 14, 2024
f1df4a0
fix: yarn workspaces
darrenvechain Nov 14, 2024
d9a77e2
fix: missing declarations in test
darrenvechain Nov 14, 2024
ab6d545
fix: missing declarations in test
darrenvechain Nov 14, 2024
0510e74
fix: missing declarations in test
darrenvechain Nov 14, 2024
54d622e
fix: missing declarations in test
darrenvechain Nov 14, 2024
d57c6f3
fix: dapp-kit-react tsx
darrenvechain Nov 14, 2024
167d366
fix: add exports to package.json
darrenvechain Nov 14, 2024
b501724
fix: ignore cucumber in examples
darrenvechain Nov 14, 2024
a7d9332
fix: set type to module
darrenvechain Nov 14, 2024
6ee4296
fix: package.jsons
darrenvechain Nov 14, 2024
c53e9b2
fix: add type module
darrenvechain Nov 14, 2024
c6ff42e
fix: package.jsons
darrenvechain Nov 14, 2024
2affe45
fix: package.jsons
darrenvechain Nov 14, 2024
1ef08e0
fix: fix angular
darrenvechain Nov 14, 2024
d7e34c9
chore: documenation
darrenvechain Nov 14, 2024
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
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
Loading