From 7fa4d391694db42dfc9ebf449b5cd6a0b1fcae26 Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Wed, 10 Apr 2024 12:37:38 +0300 Subject: [PATCH] fix: requires `chainId` param on init --- src/client.ts | 2 ++ src/controllers/engine.ts | 4 +++- src/types/client.ts | 2 ++ test/sign.spec.ts | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 98cebd0..e04925c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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: number; static async init(opts: SingleEthereumTypes.Options) { const client = new SingleEthereum(opts); @@ -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); } diff --git a/src/controllers/engine.ts b/src/controllers/engine.ts index 032e50f..df07722 100644 --- a/src/controllers/engine.ts +++ b/src/controllers/engine.ts @@ -19,7 +19,7 @@ import { export class Engine extends ISingleEthereumEngine { public web3wallet: IWeb3Wallet; - public chainId?: number; + public chainId: number; private pendingInternalRequests: { id: number; resolve: (value?: T | PromiseLike) => void; @@ -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, diff --git a/src/types/client.ts b/src/types/client.ts index c8adf0b..2abd709 100644 --- a/src/types/client.ts +++ b/src/types/client.ts @@ -52,6 +52,7 @@ export declare namespace SingleEthereumTypes { core: ICore; metadata: Metadata; name?: string; + chainId: number; } type Metadata = CoreTypes.Metadata; @@ -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) {} diff --git a/test/sign.spec.ts b/test/sign.spec.ts index 048f080..894ae8f 100644 --- a/test/sign.spec.ts +++ b/test/sign.spec.ts @@ -284,6 +284,7 @@ describe("Sign Integration", () => { core, name: "wallet", metadata: {} as any, + chainId: 1, }); // first pair and approve session