Skip to content

Commit

Permalink
fix: thordevkit imports
Browse files Browse the repository at this point in the history
  • Loading branch information
davidecarpini committed Feb 5, 2024
1 parent b1e6e90 commit 0bb3759
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
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
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
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

0 comments on commit 0bb3759

Please sign in to comment.