Skip to content

Commit

Permalink
revert: add sync2 back int
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Nov 7, 2024
1 parent 4158910 commit e2e91c5
Show file tree
Hide file tree
Showing 28 changed files with 265 additions and 144 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint-build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:

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

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'yarn'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- 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 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
Expand All @@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'yarn'
Expand Down
1 change: 0 additions & 1 deletion examples/sample-angular-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class AppComponent implements OnInit {

DAppKitUI.configure({
nodeUrl: 'https://testnet.vechain.org/',
genesis: 'test',
walletConnectOptions,
usePersistence: true,
});
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
1 change: 0 additions & 1 deletion examples/sample-react-app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
nodeUrl={'https://testnet.vechain.org/'}
usePersistence
walletConnectOptions={walletConnectOptions}
genesis={'test'}
>
<App />
</DAppKitProvider>
Expand Down
3 changes: 1 addition & 2 deletions examples/sample-react-app/test/welcome.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import renderer from 'react-test-renderer';
import React from 'react';
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';
import App from '../src/App';
import { DAppKitProvider } from '@vechain/dapp-kit-react';
import { WalletConnectOptions } from '@vechain/dapp-kit';
Expand All @@ -19,7 +19,6 @@ test('Welcome', async () => {
<React.StrictMode>
<DAppKitProvider
nodeUrl={'https://testnet.vechain.org/'}
genesis={'test'}
usePersistence
walletConnectOptions={walletConnectOptions}
>
Expand Down
5 changes: 2 additions & 3 deletions examples/sample-remix-app/app/.client/app.client.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
DAppKitProvider,
WalletButton,
WalletConnectOptions,
useWallet,
useWalletModal,
WalletButton,
WalletConnectOptions,
} from '@vechain/dapp-kit-react';
import { useEffect, useState } from 'react';

Expand Down Expand Up @@ -58,7 +58,6 @@ const walletConnectOptions: WalletConnectOptions = {
export const App = () => {
return (
<DAppKitProvider
genesis="test"
logLevel="DEBUG"
nodeUrl="https://testnet.vechain.org/"
usePersistence
Expand Down
1 change: 0 additions & 1 deletion examples/sample-svelte-app/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const walletConnectOptions = {

DAppKitUI.configure({
nodeUrl: 'https://testnet.vechain.org/',
genesis: 'test',
walletConnectOptions,
usePersistence: true,
});
Expand Down
1 change: 0 additions & 1 deletion examples/sample-vanilla-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const walletConnectOptions = {

DAppKitUI.configure({
nodeUrl: 'https://testnet.vechain.org/',
genesis: 'test',
walletConnectOptions,
usePersistence: true,
});
Expand Down
5 changes: 3 additions & 2 deletions examples/sample-vue-app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { DAppKitUI } from '@vechain/dapp-kit-ui';
import { Genesis } from '@vechain/dapp-kit';
const walletConnectOptions = {
projectId: 'a0b855ceaf109dbc8426479a4c3d38d8',
Expand All @@ -27,7 +26,6 @@ const walletConnectOptions = {
const vechainDAppKitOptions = {
nodeUrl: 'https://testnet.vechain.org/',
genesis: 'test' as Genesis,
walletConnectOptions,
usePersistence: true,
};
Expand Down Expand Up @@ -78,9 +76,11 @@ body {
align-items: center;
justify-content: center;
}
h2 {
margin: 0;
}
.container {
display: flex;
flex-direction: column;
Expand All @@ -90,6 +90,7 @@ h2 {
border-radius: 20px;
padding: 20px;
}
.label {
margin-top: 20px;
margin-bottom: 10px;
Expand Down
7 changes: 4 additions & 3 deletions packages/dapp-kit-react/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# `@vechain/dapp-kit-react`

The Vechain DApp Kit serves as a sophisticated layer built upon @vechain/connex, providing a simplified and efficient avenue for engaging with a multitude of Vechain wallets. This innovative toolkit enhances the ease of interaction, offering developers a seamless bridge to connect with diverse Vechain wallet functionalities. For more information, please refer to the official [Vechain Docs](https://docs.vechain.org/developer-resources/sdks-and-providers/dapp-kit)
The Vechain DApp Kit serves as a sophisticated layer built upon @vechain/connex, providing a simplified and efficient
avenue for engaging with a multitude of Vechain wallets. This innovative toolkit enhances the ease of interaction,
offering developers a seamless bridge to connect with diverse Vechain wallet functionalities. For more information,
please refer to the official [Vechain Docs](https://docs.vechain.org/developer-resources/sdks-and-providers/dapp-kit)

## Installation

Expand Down Expand Up @@ -37,8 +40,6 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
<DAppKitProvider
// REQUIRED: The URL of the node you want to connect to
nodeUrl={'https://testnet.vechain.org/'}
// OPTIONAL: Required if you're not connecting to the main net
genesis={'test'}
// OPTIONAL: Whether or not to persist state in local storage (account, wallet source)
usePersistence={true}
// OPTIONAL: Options to enable wallet connect
Expand Down
3 changes: 0 additions & 3 deletions packages/dapp-kit-react/src/DAppKitProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const Context = createContext<DAppKitContext | undefined>(undefined);
export const DAppKitProvider: React.FC<DAppKitProviderOptions> = ({
children,
nodeUrl,
genesis,
walletConnectOptions,
usePersistence = false,
logLevel,
Expand All @@ -37,7 +36,6 @@ export const DAppKitProvider: React.FC<DAppKitProviderOptions> = ({
() =>
DAppKitUI.configure({
nodeUrl,
genesis,
walletConnectOptions,
usePersistence,
logLevel,
Expand All @@ -52,7 +50,6 @@ export const DAppKitProvider: React.FC<DAppKitProviderOptions> = ({
}),
[
nodeUrl,
genesis,
walletConnectOptions,
usePersistence,
logLevel,
Expand Down
6 changes: 4 additions & 2 deletions packages/dapp-kit-ui/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# `@vechain/dapp-kit-ui`

The Vechain DApp Kit serves as a sophisticated layer built upon @vechain/connex, providing a simplified and efficient avenue for engaging with a multitude of Vechain wallets. This innovative toolkit enhances the ease of interaction, offering developers a seamless bridge to connect with diverse Vechain wallet functionalities. For more information, please refer to the official [Vechain Docs](https://docs.vechain.org/developer-resources/sdks-and-providers/dapp-kit)
The Vechain DApp Kit serves as a sophisticated layer built upon @vechain/connex, providing a simplified and efficient
avenue for engaging with a multitude of Vechain wallets. This innovative toolkit enhances the ease of interaction,
offering developers a seamless bridge to connect with diverse Vechain wallet functionalities. For more information,
please refer to the official [Vechain Docs](https://docs.vechain.org/developer-resources/sdks-and-providers/dapp-kit)

## Usage

Expand All @@ -26,7 +29,6 @@ const walletConnectOptions: WalletConnectOptions = {

const options: DAppKitOptions = {
nodeUrl: 'https://testnet.vechain.org/',
genesis: 'test',
walletConnectOptions,
usePersistence: true,
};
Expand Down
12 changes: 11 additions & 1 deletion packages/dapp-kit-ui/src/constants/sources.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { WalletSource } from '@vechain/dapp-kit';
import { VeWorldLogo, WalletConnectLogo } from '../assets/images';
import { SyncLogo, VeWorldLogo, WalletConnectLogo } from '../assets/images';

export interface SourceInfo {
id: WalletSource;
Expand All @@ -18,4 +18,14 @@ export const WalletSources: Record<WalletSource, SourceInfo> = {
name: 'VeWorld',
logo: VeWorldLogo,
},
sync: {
id: 'sync',
name: 'Sync',
logo: SyncLogo,
},
sync2: {
id: 'sync2',
name: 'Sync2',
logo: SyncLogo,
},
};
13 changes: 8 additions & 5 deletions packages/dapp-kit/src/classes/certificate-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Certificate } from '@vechain/sdk-core';
import type { BaseWallet, ConnectResponse, VechainWallet } from '../types';
import type { ConnectResponse, VechainWallet } from '../types';
import { DEFAULT_CONNECT_CERT_MESSAGE } from '../constants';
import type {
CertificateMessage,
Expand All @@ -9,13 +9,14 @@ import type {
TransactionOptions,
TransactionResponse,
} from '../types/requests';
import type { WalletSigner } from '../types/types';

/**
* A `VechainWallet` for wallet's that use a certificate connection
*/
class CertificateBasedWallet implements VechainWallet {
constructor(
private readonly wallet: BaseWallet,
private readonly wallet: Promise<WalletSigner>,
private readonly connectionCertificateData?: {
message?: CertificateMessage;
options?: CertificateOptions;
Expand Down Expand Up @@ -60,14 +61,16 @@ class CertificateBasedWallet implements VechainWallet {
signCert = (
msg: CertificateMessage,
options: CertificateOptions,
): Promise<CertificateResponse> => this.wallet.signCert(msg, options);
): Promise<CertificateResponse> =>
this.wallet.then((w) => w.signCert(msg, options));

signTx = (
msg: TransactionMessage[],
options: TransactionOptions,
): Promise<TransactionResponse> => this.wallet.signTx(msg, options);
): Promise<TransactionResponse> =>
this.wallet.then((w) => w.signTx(msg, options));

disconnect = async (): Promise<void> => this.wallet.disconnect?.();
disconnect = () => Promise.resolve();

Check warning on line 73 in packages/dapp-kit/src/classes/certificate-wallet.ts

View workflow job for this annotation

GitHub Actions / Lint, Build & Test

Missing return type on function
}

export { CertificateBasedWallet };
1 change: 0 additions & 1 deletion packages/dapp-kit/src/classes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './wallet-manager';
export * from './certificate-wallet';
export * from './wc-wallet';
export * from './vechain-signer';
20 changes: 14 additions & 6 deletions packages/dapp-kit/src/classes/wallet-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { proxy, subscribe } from 'valtio/vanilla';
import { subscribeKey } from 'valtio/vanilla/utils';
import { Certificate } from '@vechain/sdk-core';
import type { ThorClient } from '@vechain/sdk-network';
import type {
ConnectResponse,
DAppKitOptions,
Expand All @@ -23,7 +24,10 @@ class WalletManager {
public readonly state: WalletManagerState;
private wallets: Record<string, VechainWallet | undefined> = {};

constructor(private readonly options: DAppKitOptions) {
constructor(
private readonly options: DAppKitOptions,
private readonly thor: ThorClient,
) {
this.state = this.initState(options.usePersistence ?? false);
this.initPersistence(options.usePersistence ?? false);
DAppKitLogger.debug('WalletManager', 'constructor', this.state);
Expand All @@ -36,7 +40,7 @@ class WalletManager {
}

private get wallet(): VechainWallet {
let source = this.state.source;
const source = this.state.source;

DAppKitLogger.debug(
'WalletManager',
Expand All @@ -46,10 +50,7 @@ class WalletManager {
);

if (!source) {
if (this.state.availableSources.length > 1) {
throw new Error('No wallet selected');
}
source = this.state.availableSources[0];
throw new Error('No wallet selected');
}

let wallet = this.wallets[source];
Expand All @@ -70,6 +71,7 @@ class WalletManager {
...this.options,
source,
onDisconnected: () => this.disconnect(true),
thor: this.thor,
};
wallet = createWallet(opts);

Expand Down Expand Up @@ -288,6 +290,12 @@ class WalletManager {
wallets.push('wallet-connect');
}

wallets.push('sync2');

if (window.connex) {
wallets.push('sync');
}

return wallets;
};

Expand Down
36 changes: 0 additions & 36 deletions packages/dapp-kit/src/classes/wc-wallet.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/dapp-kit/src/constants/wallet-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const WalletMapping: Record<WalletSource, WalletConfig> = {
requiresCertificate: false,
},
veworld: DEFAULT_CONFIG,
sync2: DEFAULT_CONFIG,
sync: DEFAULT_CONFIG,
};

const WalletSources = Object.keys(WalletMapping) as WalletSource[];
Expand Down
5 changes: 2 additions & 3 deletions packages/dapp-kit/src/dapp-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ class DAppKit {
}

const { nodeUrl } = options;
const walletManager = new WalletManager(options);

this.thor = ThorClient.fromUrl(nodeUrl);
this.wallet = walletManager;
this.wallet = new WalletManager(options, this.thor);
this.signer = new VeChainSignerDAppKit(
walletManager,
this.wallet,
new VeChainProvider(this.thor),
);
}
Expand Down
Loading

0 comments on commit e2e91c5

Please sign in to comment.