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/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; 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;