-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81032f1
commit b6c85ee
Showing
10 changed files
with
178 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/dapp-kit-react/src/DAppKitProvider/hooks/useThor.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/dapp-kit-react/src/hooks/useVechainDomain/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters