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: requires chainId param on init #28

Merged
merged 2 commits into from
Apr 10, 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
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class SingleEthereum extends ISingleEthereum {
public events: ISingleEthereum["events"] = new EventEmitter();
public engine: ISingleEthereum["engine"];
public metadata: ISingleEthereum["metadata"];
public chainId: ISingleEthereum["chainId"];

static async init(opts: SingleEthereumTypes.Options) {
const client = new SingleEthereum(opts);
Expand All @@ -24,6 +25,7 @@ export class SingleEthereum extends ISingleEthereum {
this.name = opts.name || CLIENT_CONTEXT;
this.core = opts.core;
this.logger = this.core.logger;
this.chainId = opts.chainId;
this.engine = new Engine(this);
}

Expand Down
4 changes: 3 additions & 1 deletion src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {

export class Engine extends ISingleEthereumEngine {
public web3wallet: IWeb3Wallet;
public chainId?: number;
public chainId: number;
private pendingInternalRequests: {
id: number;
resolve: <T>(value?: T | PromiseLike<T>) => void;
Expand All @@ -30,11 +30,13 @@ export class Engine extends ISingleEthereumEngine {

constructor(client: ISingleEthereumEngine["client"]) {
super(client);
this.chainId = 1;
// initialized in init()
this.web3wallet = {} as IWeb3Wallet;
}

public init = async () => {
this.chainId = this.client.chainId;
this.web3wallet = await Web3Wallet.init({
core: this.client.core,
metadata: this.client.metadata,
Expand Down
2 changes: 2 additions & 0 deletions src/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export declare namespace SingleEthereumTypes {
core: ICore;
metadata: Metadata;
name?: string;
chainId: number;
}

type Metadata = CoreTypes.Metadata;
Expand Down Expand Up @@ -95,6 +96,7 @@ export abstract class ISingleEthereum {
public abstract logger: Logger;
public abstract core: ICore;
public abstract metadata: SingleEthereumTypes.Metadata;
public abstract chainId: number;

constructor(public opts: SingleEthereumTypes.Options) {}

Expand Down
2 changes: 1 addition & 1 deletion test/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("Auth Integration", () => {
metadata: {} as any,
name: "dapp",
});
wallet = await SingleEthereum.init({ core, name: "wallet", metadata: {} as any });
wallet = await SingleEthereum.init({ core, name: "wallet", metadata: {} as any, chainId: 1 });
expect(wallet).to.be.exist;
expect(dapp).to.be.exist;
expect(core).to.be.exist;
Expand Down
5 changes: 5 additions & 0 deletions test/sign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe("Sign Integration", () => {
core,
name: "wallet",
metadata: {} as any,
chainId: 1,
});
await new Promise((resolve) => setTimeout(resolve, 1000));
expect(wallet).to.be.exist;
Expand Down Expand Up @@ -284,6 +285,7 @@ describe("Sign Integration", () => {
core,
name: "wallet",
metadata: {} as any,
chainId: 1,
});

// first pair and approve session
Expand Down Expand Up @@ -670,6 +672,7 @@ describe("Sign Integration", () => {
core,
name: "wallet",
metadata: {} as any,
chainId: 1,
});
const expectedError = getSdkError("UNSUPPORTED_CHAINS");
await Promise.all([
Expand Down Expand Up @@ -707,6 +710,7 @@ describe("Sign Integration", () => {
core,
name: "wallet",
metadata: {} as any,
chainId: 1,
});
const expectedError = getSdkError("UNSUPPORTED_NAMESPACE_KEY");
await Promise.all([
Expand Down Expand Up @@ -744,6 +748,7 @@ describe("Sign Integration", () => {
core,
name: "wallet",
metadata: {} as any,
chainId: 1,
});
await Promise.all([
new Promise<void>((resolve) => {
Expand Down
Loading