Skip to content

Commit 3afc201

Browse files
authored
fix: reseting active profile and profile manager (#8689)
1 parent 7e72632 commit 3afc201

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

packages/desktop/views/login/views/EnterPinView.svelte

+12-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import { Icon, InitProfileActionsModal, MeatballMenuButton, Modal, PinInput, Profile, Text, TextHint } from '@ui'
1919
import { TextHintVariant } from 'shared/components/enums'
2020
import { onDestroy } from 'svelte'
21+
import { destroyProfileManager } from '@core/profile-manager/actions'
22+
import { isDestroyingManager } from '@core/profile/stores'
2123
2224
let attempts: number = 0
2325
let pinCode: string = ''
@@ -135,13 +137,22 @@
135137
}
136138
}
137139
138-
function onBackClick(): void {
140+
async function onBackClick(): Promise<void> {
139141
if (!hasReachedMaxAttempts) {
142+
await resetProfileManager()
143+
const { isStrongholdLocked } = $activeProfile
144+
isStrongholdLocked.set(true)
140145
resetActiveProfile()
141146
$loginRouter.previous()
142147
}
143148
}
144149
150+
async function resetProfileManager(): Promise<void> {
151+
isDestroyingManager.set(true)
152+
await destroyProfileManager()
153+
isDestroyingManager.set(false)
154+
}
155+
145156
onDestroy(() => {
146157
clearInterval(maxAttemptsTimer)
147158
clearTimeout(shakeTimeout)

packages/shared/components/modals/InitProfileActionsModal.svelte

+30-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
import { PopupId, openPopup } from '@auxiliary/popup'
1212
import { profileManager } from '@core/profile-manager/stores'
1313
import { isLatestStrongholdVersion } from '@core/app'
14+
import {
15+
CHECK_PREVIOUS_MANAGER_IS_DESTROYED_INTERVAL,
16+
CHECK_PREVIOUS_MANAGER_IS_DESTROYED_MAX_COUNT,
17+
} from '@core/profile/constants'
18+
import { get } from 'svelte/store'
19+
import { sleep } from '@core/utils/os'
20+
import { isDestroyingManager } from '@core/profile/stores'
1421
1522
export let modal: Modal | undefined
1623
@@ -49,7 +56,8 @@
4956
})
5057
return
5158
}
52-
if (!$profileManager) {
59+
await waitForPreviousManagerToBeDestroyed()
60+
if (!$profileManager || $profileManager?.id !== $activeProfile?.id) {
5361
const profileManagerOptions = await buildProfileManagerOptionsFromProfileData($activeProfile)
5462
const { storagePath, coinType, clientOptions, secretManager: secretManagerType } = profileManagerOptions
5563
const manager = await initialiseProfileManager(
@@ -61,7 +69,27 @@
6169
)
6270
profileManager.set(manager)
6371
}
64-
openUnlockStrongholdPopup()
72+
const { isStrongholdLocked } = $activeProfile
73+
if (!get(isStrongholdLocked)) {
74+
openPopup({
75+
id: PopupId.GetSeedPopup,
76+
props: {
77+
readFromFile: false,
78+
},
79+
})
80+
} else {
81+
openUnlockStrongholdPopup()
82+
}
83+
}
84+
85+
async function waitForPreviousManagerToBeDestroyed(): Promise<void> {
86+
for (let count = 0; count < CHECK_PREVIOUS_MANAGER_IS_DESTROYED_MAX_COUNT; count++) {
87+
if (!get(isDestroyingManager)) {
88+
return Promise.resolve()
89+
}
90+
await sleep(CHECK_PREVIOUS_MANAGER_IS_DESTROYED_INTERVAL)
91+
}
92+
return Promise.reject()
6593
}
6694
</script>
6795

0 commit comments

Comments
 (0)