|
11 | 11 | import { PopupId, openPopup } from '@auxiliary/popup'
|
12 | 12 | import { profileManager } from '@core/profile-manager/stores'
|
13 | 13 | 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' |
14 | 21 |
|
15 | 22 | export let modal: Modal | undefined
|
16 | 23 |
|
|
49 | 56 | })
|
50 | 57 | return
|
51 | 58 | }
|
52 |
| - if (!$profileManager) { |
| 59 | + await waitForPreviousManagerToBeDestroyed() |
| 60 | + if (!$profileManager || $profileManager?.id !== $activeProfile?.id) { |
53 | 61 | const profileManagerOptions = await buildProfileManagerOptionsFromProfileData($activeProfile)
|
54 | 62 | const { storagePath, coinType, clientOptions, secretManager: secretManagerType } = profileManagerOptions
|
55 | 63 | const manager = await initialiseProfileManager(
|
|
61 | 69 | )
|
62 | 70 | profileManager.set(manager)
|
63 | 71 | }
|
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() |
65 | 93 | }
|
66 | 94 | </script>
|
67 | 95 |
|
|
0 commit comments