Skip to content

Commit

Permalink
fix: merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiorigam committed Dec 16, 2024
1 parent 81032f1 commit b6c85ee
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/dapp-kit-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@vechain/dapp-kit-react",
"version": "1.1.1",
"private": false,
"homepage": "https://github.com/vechain/vechain-dapp-kit",
"repository": "github:vechain/vechain-dapp-kit",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export const DAppKitProviderData = ({
const closeModal = useCallback(() => {
DAppKitUI.modal.close();
}, []);

const onModalConnected = useCallback(
(callback: (address: string | null) => void) =>
DAppKitUI.modal.onConnectionStatusChange(callback),
Expand Down Expand Up @@ -181,4 +180,4 @@ export const DAppKitProvider = ({
return (
<DAppKitProviderData dAppKit={dAppKit}>{children}</DAppKitProviderData>
);
};
};
21 changes: 21 additions & 0 deletions packages/dapp-kit-react/src/DAppKitProvider/hooks/useThor.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, it, expect } from 'vitest';
import { renderHook } from '@testing-library/react';
import { useThor } from '../..';
import { wrapper } from '../../../test';

describe('useConnex', () => {
it('connex should get initialised', () => {
const { result } = renderHook(() => useThor(), { wrapper });

expect(result.current).toBeDefined();
expect(result.current.thor.genesis.id).toBe(
'0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a',
);
});

it('should throw an error when used outside of DAppKitProvider', () => {
expect(() => renderHook(() => useThor())).toThrow(
'"useConnex" must be used within a ConnexProvider',
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* The VNS resolver addresses
*/
export const VNS_RESOLVER = {
main: '0xA11413086e163e41901bb81fdc5617c975Fa5a1A',
test: '0xc403b8EA53F707d7d4de095f0A20bC491Cf2bc94',
};
39 changes: 39 additions & 0 deletions packages/dapp-kit/src/classes/wc-wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ethers } from 'ethers';
import type { ConnectResponse, ConnexWallet, WCSigner } from '../types';
import { SignTypedDataOptions } from '../types/types';

class WCWallet implements ConnexWallet {
constructor(private readonly signer: WCSigner) {}

connect = async (): Promise<ConnectResponse> => {
const account = await this.signer.connect();

return {
account,
verified: false,
};
};

signCert = (
msg: Connex.Vendor.CertMessage,
options: Connex.Signer.CertOptions,
): Promise<Connex.Vendor.CertResponse> =>
this.signer.signCert(msg, options);

signTx = (
msg: Connex.Vendor.TxMessage,
options: Connex.Signer.TxOptions,
): Promise<Connex.Vendor.TxResponse> => this.signer.signTx(msg, options);

signTypedData = async (
_domain: ethers.TypedDataDomain,
_types: Record<string, ethers.TypedDataField[]>,
_value: Record<string, unknown>,
_options?: SignTypedDataOptions,
): Promise<string> =>
this.signer.signTypedData(_domain, _types, _value, _options);

disconnect = (): Promise<void> => this.signer.disconnect();
}

export { WCWallet };
76 changes: 76 additions & 0 deletions packages/dapp-kit/src/utils/convert-vendor-to-signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { ExpandedConnexSigner } from '../types/types';
import { DAppKitLogger } from './logger';

export const convertVendorToSigner = (
vendor: Connex.Vendor,
): ExpandedConnexSigner => {
return {
signTx: (msg, options): Promise<Connex.Vendor.TxResponse> => {
const service = vendor.sign('tx', msg);

if (options.gas) {
service.gas(options.gas);
}

if (options.signer) {
service.signer(options.signer);
}

if (options.dependsOn) {
service.dependsOn(options.dependsOn);
}

if (options.link) {
service.link(options.link);
}

if (options.comment) {
service.comment(options.comment);
}

if (options.delegator) {
service.delegate(
options.delegator.url,
options.delegator.signer,
);
}

if (options.onAccepted) {
service.accepted(options.onAccepted);
}

DAppKitLogger.debug('vendor', 'signTx', {
messages: msg.length,
options,
});

return service.request();
},

signCert: (msg, options): Promise<Connex.Vendor.CertResponse> => {
const service = vendor.sign('cert', msg);

if (options.signer) {
service.signer(options.signer);
}

if (options.link) {
service.link(options.link);
}

if (options.onAccepted) {
service.accepted(options.onAccepted);
}

DAppKitLogger.debug('vendor', 'signCert', {
message: msg,
options,
});

return service.request();
},
signTypedData(_domain, _types, _value, _options) {
throw new Error('Sign typed data it is not available with sync2');
},
};
};
5 changes: 4 additions & 1 deletion packages/dapp-kit/src/utils/create-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ export const createWallet = ({
throw e;
});

return new CertificateBasedWallet(signer, connectionCertificate);
return new CertificateBasedWallet(
signer as BaseWallet,
connectionCertificate,
);
}
case 'wallet-connect': {
if (!walletConnectOptions) {
Expand Down
13 changes: 13 additions & 0 deletions packages/dapp-kit/test/utils/signer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { WCModal, WCSigner } from '../../src';
import { createWcClient, createWcSigner } from '../../src';
import { mockedSignClient } from '../helpers/mocked-sign-client';
import { address } from '../helpers/mocked-signer';
import { typedData } from '../fixture';

vi.spyOn(SignClient, 'init').mockResolvedValue(mockedSignClient);

Expand Down Expand Up @@ -68,6 +69,18 @@ describe('createWcSigner', () => {
expect(certRes).toBeDefined();
});

it('can sign typed data', async () => {
const signer = createNewSignClient();

const signedData = await signer.signTypedData(
typedData.domain,
typedData.types,
typedData.value,
);

expect(signedData).toBeDefined();
});

it('can disconnect', async () => {
const signer = createNewSignClient();

Expand Down
14 changes: 14 additions & 0 deletions packages/dapp-kit/test/wallet-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ describe('WalletManager', () => {
});
});

describe('signTypedData', () => {
it('should sign the typedData', async () => {
const walletManager = newWalletManager();
walletManager.setSource('veworld');
const res = await walletManager.signTypedData(
typedData.domain,
typedData.types,
typedData.value,
);

expect(res).toBeDefined();
});
});

describe('disconnect', () => {
it('is not connected', async () => {
const walletManager = newWalletManager();
Expand Down
4 changes: 2 additions & 2 deletions scripts/prepare-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const preparePackages = async () => {
console.log(' - ✅ Removed!');

console.log(' Build:');
console.log(' - 📦 Building packages...');
await exec('yarn install && yarn install:all');
console.log(' - 📦 Install dependencies and build packages...');
await exec('yarn install:all');
console.log(' - ✅ Built!');

console.log(' Test:');
Expand Down

0 comments on commit b6c85ee

Please sign in to comment.