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

fix: thordevkit imports #188

Merged
merged 15 commits into from
Feb 6, 2024
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
2 changes: 2 additions & 0 deletions packages/dapp-kit-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"watch": "tsup --watch"
},
"dependencies": {
"@vechain/connex": "2.1.0",
"@vechain/dapp-kit": "*",
"@vechain/picasso": "2.1.1",
"@wagmi/core": "^1.4.5",
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
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
4 changes: 2 additions & 2 deletions packages/dapp-kit/src/dapp-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
SimpleNet,
} from '@vechain/connex-driver/dist/index.js';
import { Framework } from '@vechain/connex-framework';
import { blake2b256 } from 'thor-devkit';
import * as ThorDevkit from 'thor-devkit';
import { WalletManager } from './classes';
import { DAppKitLogger, normalizeGenesisBlock } from './utils';
import type { DAppKitOptions } from './types';
Expand All @@ -14,7 +14,7 @@ const createThorDriver = (
node: string,
genesis: Connex.Thor.Block,
): DriverNoVendor => {
const key = blake2b256(
const key = ThorDevkit.blake2b256(
JSON.stringify({
node,
genesis,
Expand Down
6 changes: 3 additions & 3 deletions packages/dapp-kit/src/types/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Certificate } from 'thor-devkit';
import * as ThorDevkit from 'thor-devkit';
import type { WalletConnectOptions } from '@vechain/dapp-kit';
import type { LogLevel } from '../utils/logger';

Expand Down Expand Up @@ -53,14 +53,14 @@ type ConnexWallet = BaseWallet & {
interface ConnectResponse {
account: string;
verified: boolean;
connectionCertificate?: Certificate;
connectionCertificate?: ThorDevkit.Certificate;
}

interface WalletManagerState {
source: WalletSource | null;
address: string | null;
availableSources: WalletSource[];
connectionCertificate: Certificate | null;
connectionCertificate: ThorDevkit.Certificate | null;
}

export type {
Expand Down
6 changes: 3 additions & 3 deletions packages/dapp-kit/src/utils/create-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Connex } from '@vechain/connex';
import * as ConnexLib from '@vechain/connex';
import type {
ConnexWallet,
DAppKitOptions,
Expand Down Expand Up @@ -36,12 +36,12 @@ export const createWallet = ({
throw new Error('User is not in a Sync wallet');
}

const vendor = new Connex.Vendor(genesisId, 'sync');
const vendor = new ConnexLib.Connex.Vendor(genesisId, 'sync');

return new CertificateBasedWallet(convertVendorToSigner(vendor));
}
case 'sync2': {
const vendor = new Connex.Vendor(genesisId, 'sync2');
const vendor = new ConnexLib.Connex.Vendor(genesisId, 'sync2');

return new CertificateBasedWallet(convertVendorToSigner(vendor));
}
Expand Down
10 changes: 6 additions & 4 deletions packages/dapp-kit/src/utils/local-storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Certificate } from 'thor-devkit';
import * as ThorDevkit from 'thor-devkit';
import type { WalletSource } from '../types';
import { DAppKitLogger } from './logger';

Expand Down Expand Up @@ -26,7 +26,9 @@ const setAccount = (account: string | null): void => {
}
};

const setConnectionCertificate = (certificate: Certificate | null): void => {
const setConnectionCertificate = (
certificate: ThorDevkit.Certificate | null,
): void => {
DAppKitLogger.debug(
'LocalStorage',
'setConnectionCertificate',
Expand Down Expand Up @@ -59,14 +61,14 @@ const getAccount = (): string | null => {
return account;
};

const getConnectionCertificate = (): Certificate | null => {
const getConnectionCertificate = (): ThorDevkit.Certificate | null => {
const connectionCertificate = localStorage.getItem(CERTIFICATE_KEY);

if (!connectionCertificate) {
return null;
}

return JSON.parse(connectionCertificate) as Certificate;
return JSON.parse(connectionCertificate) as ThorDevkit.Certificate;
};

export const Storage = {
Expand Down
Loading