diff --git a/app/scripts/controllers/app-state.js b/app/scripts/controllers/app-state.js index 0cf5fc24b..b63ff11ad 100644 --- a/app/scripts/controllers/app-state.js +++ b/app/scripts/controllers/app-state.js @@ -191,11 +191,9 @@ export default class AppStateController extends EventEmitter { const { timeoutMinutes } = this.store.getState(); if (this.timer) { - if (isManifestV3) { - chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM); - } else { - clearTimeout(this.timer); - } + clearTimeout(this.timer); + } else if (isManifestV3) { + chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM); } if (!timeoutMinutes) { @@ -207,16 +205,11 @@ export default class AppStateController extends EventEmitter { delayInMinutes: timeoutMinutes, periodInMinutes: timeoutMinutes, }); - chrome.alarms.onAlarm.addListener(() => { - chrome.alarms.getAll((alarms) => { - const hasAlarm = alarms.find( - (alarm) => alarm.name === AUTO_LOCK_TIMEOUT_ALARM, - ); - if (hasAlarm) { - this.onInactiveTimeout(); - chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM); - } - }); + chrome.alarms.onAlarm.addListener((alarmInfo) => { + if (alarmInfo.name === AUTO_LOCK_TIMEOUT_ALARM) { + this.onInactiveTimeout(); + chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM); + } }); } else { this.timer = setTimeout( diff --git a/app/scripts/controllers/metametrics.js b/app/scripts/controllers/metametrics.js index 212b9a908..14b49dd7d 100644 --- a/app/scripts/controllers/metametrics.js +++ b/app/scripts/controllers/metametrics.js @@ -162,17 +162,10 @@ export default class MetaMetricsController { }); } }); - chrome.alarms.onAlarm.addListener(() => { - chrome.alarms.getAll((alarms) => { - const hasAlarm = checkAlarmExists( - alarms, - METAMETRICS_FINALIZE_EVENT_FRAGMENT_ALARM, - ); - - if (hasAlarm) { - this.finalizeAbandonedFragments(); - } - }); + chrome.alarms.onAlarm.addListener((alarmInfo) => { + if (alarmInfo.name === METAMETRICS_FINALIZE_EVENT_FRAGMENT_ALARM) { + this.finalizeAbandonedFragments(); + } }); } else { setInterval(() => {