From fd0c25a725fca7830900e9e805dfa2cbf690c5b7 Mon Sep 17 00:00:00 2001 From: Luphia Chang Date: Wed, 26 Jul 2023 12:09:08 +0800 Subject: [PATCH 1/2] get chainId from ethereum provider --- src/connectors/connector.ts | 12 +++++++++++- src/connectors/metamask.ts | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/connectors/connector.ts b/src/connectors/connector.ts index e76536a..eff83fc 100644 --- a/src/connectors/connector.ts +++ b/src/connectors/connector.ts @@ -4,6 +4,15 @@ import IAsset from "../interfaces/iasset"; import IBlockchain from "../interfaces/iblockchain"; import { EventEmitter } from 'events'; +const g: any = typeof globalThis === "object" + ? globalThis + : typeof window === "object" + ? window + : typeof global === "object" + ? global + : null; // Causes an error on the next line +const { ethereum } = g; + class Connector { _isConnected: boolean = false; _address: string = '0x'; @@ -41,7 +50,8 @@ class Connector { return this._type; } get chainId() { - return this._blockchain.chainId; + const chainId = ethereum?.chainId || this._blockchain.chainId; + return chainId; } get emitter() { return this._emitter; diff --git a/src/connectors/metamask.ts b/src/connectors/metamask.ts index 773abc8..021a9c1 100644 --- a/src/connectors/metamask.ts +++ b/src/connectors/metamask.ts @@ -78,7 +78,9 @@ class Metamask extends Connector { async signTypedData(data: IEIP712Data): Promise { const typedData: IEIP712Data = data; - typedData.domain.chainId = this.chainId; + typedData.domain.chainId = typedData.domain.chainId ? + typedData.domain.chainId : + this.chainId; typedData.message.from = this.address; const from = this.address; From e70d51064b0deb743daaeb2f291ca2d93318edcf Mon Sep 17 00:00:00 2001 From: Luphia Chang Date: Wed, 26 Jul 2023 12:10:31 +0800 Subject: [PATCH 2/2] update version number --- package.json | 2 +- src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1961be0..104f81e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cafeca/lunar", - "version": "0.5.9", + "version": "0.5.10", "description": "Blockchain Connect Module", "main": "dist/index.js", "files": [ diff --git a/src/index.ts b/src/index.ts index 47b535d..e60fe4f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,7 +21,7 @@ declare global { export class Lunar { private static instance: Lunar; - public static version = `v0.5.9`; + public static version = `v0.5.10`; public static Blockchains = Blockchains; public static Wallets = Wallets; public static keccak256 = keccak256;