1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-28 05:12:18 +01:00
metamask-extension/ui/app/pages/first-time-flow/onboarding-initiator-util.js
Whymarrh Whitby 4357cda7b8
Fix no-shadow issues (#9246)
See [`no-shadow`](https://eslint.org/docs/rules/no-shadow) for more information.

This change enables `no-shadow` and fixes the issues raised by the rule.
2020-08-18 14:06:45 -02:30

51 lines
1.5 KiB
JavaScript

import extension from 'extensionizer'
import log from 'loglevel'
const returnToOnboardingInitiatorTab = async (onboardingInitiator) => {
const tab = await (new Promise((resolve) => {
// eslint-disable-next-line no-shadow
extension.tabs.update(onboardingInitiator.tabId, { active: true }, (tab) => {
if (tab) {
resolve(tab)
} else {
// silence console message about unchecked error
if (extension.runtime.lastError) {
log.debug(extension.runtime.lastError)
}
resolve()
}
})
}))
if (tab) {
window.close()
} else {
// this case can happen if the tab was closed since being checked with `extension.tabs.get`
log.warn(`Setting current tab to onboarding initiator has failed; falling back to redirect`)
window.location.assign(onboardingInitiator.location)
}
}
export const returnToOnboardingInitiator = async (onboardingInitiator) => {
const tab = await (new Promise((resolve) => {
// eslint-disable-next-line no-shadow
extension.tabs.get(onboardingInitiator.tabId, (tab) => {
if (tab) {
resolve(tab)
} else {
// silence console message about unchecked error
if (extension.runtime.lastError) {
log.debug(extension.runtime.lastError)
}
resolve()
}
})
}))
if (tab) {
await returnToOnboardingInitiatorTab(onboardingInitiator)
} else {
window.location.assign(onboardingInitiator.location)
}
}