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

feat: allow custom net injection #257

Merged
merged 8 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/dapp-kit/src/dapp-kit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Net } from '@vechain/connex-driver';
import {
DriverNoVendor,
SimpleNet,
Expand All @@ -19,10 +20,12 @@ const cache: Record<string, DriverNoVendor | undefined> = {};
*
* @param node - The node URL
* @param genesis - The genesis block
* @param net - The network
*/
const createThorDriver = (
node: string,
genesis: Connex.Thor.Block,
net: Net,
): DriverNoVendor => {
// Stringify the certificate to hash
const certificateToHash = JSON.stringify({
Expand All @@ -40,7 +43,7 @@ const createThorDriver = (

let driver = cache[key];
if (!driver) {
driver = new DriverNoVendor(new SimpleNet(node), genesis);
driver = new DriverNoVendor(net, genesis);
cache[key] = driver;
}
return driver;
Expand All @@ -61,7 +64,8 @@ class DAppKit {

const genesisBlock = normalizeGenesisBlock(genesis);

const driver = createThorDriver(nodeUrl, genesisBlock);
const net = options.customNet || new SimpleNet(nodeUrl);
const driver = createThorDriver(nodeUrl, genesisBlock, net);

const walletManager = new WalletManager(options, driver);

Expand Down
1 change: 1 addition & 0 deletions packages/dapp-kit/src/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface DAppKitOptions {
message?: Connex.Vendor.CertMessage;
options?: Connex.Signer.CertOptions;
};
customNet?: Net;
}

type BaseWallet = ExpandedConnexSigner & {
Expand Down
Loading