diff --git a/main/chains/index.js b/main/chains/index.js index 83b394a38..d352e71a9 100644 --- a/main/chains/index.js +++ b/main/chains/index.js @@ -1,6 +1,6 @@ // status = Network Mismatch, Not Connected, Connected, Standby, Syncing -const { powerMonitor } = require('electron') +const { app, powerMonitor } = require('electron') const EventEmitter = require('events') const { addHexPrefix } = require('@ethereumjs/util') const { Hardfork } = require('@ethereumjs/common') @@ -604,19 +604,21 @@ class Chains extends EventEmitter { }) } - powerMonitor.on('resume', () => { - const activeConnections = Object.keys(this.connections) - .map((type) => Object.keys(this.connections[type]).map((chainId) => `${type}:${chainId}`)) - .flat() + app.on('ready', () => { + powerMonitor.on('resume', () => { + const activeConnections = Object.keys(this.connections) + .map((type) => Object.keys(this.connections[type]).map((chainId) => `${type}:${chainId}`)) + .flat() - log.info('System resuming, resetting active connections', { chains: activeConnections }) + log.info('System resuming, resetting active connections', { chains: activeConnections }) - activeConnections.forEach((id) => { - const [type, chainId] = id.split(':') - removeConnection(chainId, type) - }) + activeConnections.forEach((id) => { + const [type, chainId] = id.split(':') + removeConnection(chainId, type) + }) - updateConnections() + updateConnections() + }) }) store.observer(updateConnections, 'chains:connections') diff --git a/test/__mocks__/electron.js b/test/__mocks__/electron.js index 0d4d2e76b..dd9f92118 100644 --- a/test/__mocks__/electron.js +++ b/test/__mocks__/electron.js @@ -4,14 +4,13 @@ const dataPaths = { userData: './test/.userData' } -const app = { - getVersion: () => '0.1', - getName: () => 'frame-test-app', - getPath: (key) => dataPaths[key] -} - -const setDataPath = (key, path) => (dataPaths[key] = path) +const app = new EventEmitter() +app.getVersion = () => '0.1' +app.getName = () => 'frame-test-app' +app.getPath = (key) => dataPaths[key] const powerMonitor = new EventEmitter() +const setDataPath = (key, path) => (dataPaths[key] = path) + export { app, setDataPath as _setDataPath, powerMonitor }