diff --git a/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts b/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts index 4c8792675ae..3bdfa5fac40 100644 --- a/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts +++ b/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts @@ -2,7 +2,6 @@ import { activeProfile, activeWallets, addWalletPersistedDataToActiveProfile, - addWalletToActiveWallets, createWallet, DirectoryManager, IPersistedProfile, @@ -11,12 +10,7 @@ import { import { get } from 'svelte/store' import { onboardingProfile } from '../stores' import { createNewProfileFromOnboardingProfile } from './createNewProfileFromOnboardingProfile' -import { - addEmptyWalletActivitiesToAllWalletActivities, - buildWalletStateAndPersistedData, - IWalletState, -} from '@core/wallet' -import { DEFAULT_SYNC_OPTIONS } from '@core/wallet/constants' +import { buildWalletPersistedData } from '@core/wallet' import { localize } from '@core/i18n' import { IOnboardingProfile } from '../interfaces' @@ -34,33 +28,30 @@ export async function completeOnboardingProcess(): Promise { } const { strongholdPassword } = profile - await initWallet(profile, strongholdPassword) + await initWalletAndPersistedData(profile, strongholdPassword) void login({ isFromOnboardingFlow: true }) onboardingProfile.set(undefined) } -export async function initWallet(profile: IOnboardingProfile, strongholdPassword?: string): Promise { +export async function initWalletAndPersistedData( + profile: IOnboardingProfile, + strongholdPassword?: string +): Promise { // 1. Get the wallet name const walletName = `${localize('general.wallet')} ${(get(activeWallets)?.length ?? 0) + 1}` // 2. Create the wallet instance const wallet = await createWallet(profile as IPersistedProfile, strongholdPassword) + // 3. Restore from stronghold if needed if (profile.importFilePath && strongholdPassword) { const strongholdBackupPath = await DirectoryManager.forStrongholdBackup(profile.id) await wallet.restoreFromStrongholdSnapshot(strongholdBackupPath, strongholdPassword, true) } - // 3. Sync the wallet with the Node - await wallet.sync(DEFAULT_SYNC_OPTIONS) - - // 4. Create a wrapper over the wallet instance and the persisted data - const [walletState, walletPersistedData] = await buildWalletStateAndPersistedData(profile.id, wallet, walletName) - - addWalletToActiveWallets(walletState) - addWalletPersistedDataToActiveProfile(walletState.id, walletPersistedData) - addEmptyWalletActivitiesToAllWalletActivities(walletState.id) + // 4. Create the persisted data + const walletPersistedData = await buildWalletPersistedData(profile.id, wallet, walletName) - return walletState + addWalletPersistedDataToActiveProfile(wallet.id, walletPersistedData) } diff --git a/packages/shared/lib/core/wallet/actions/buildWalletStateAndPersistedData.ts b/packages/shared/lib/core/wallet/actions/buildWalletStateAndPersistedData.ts index 5dd5af13a03..e234bfcc888 100644 --- a/packages/shared/lib/core/wallet/actions/buildWalletStateAndPersistedData.ts +++ b/packages/shared/lib/core/wallet/actions/buildWalletStateAndPersistedData.ts @@ -14,19 +14,28 @@ export async function buildWalletStateAndPersistedData( name?: string, color?: string ): Promise<[IWalletState, IPersistedWalletData]> { + const persistedWalletData = await buildWalletPersistedData(profileId, wallet, name, color) + const walletState = await buildWalletState(wallet, persistedWalletData) + walletState.balances = await getTotalWalletBalance(walletState, true) + return [walletState, persistedWalletData] +} + +export async function buildWalletPersistedData( + profileId: string, + wallet: IWallet, + name?: string, + color?: string +): Promise { const walletPath = await DirectoryManager.forWallet(profileId, wallet.id) const secretManagerPath = await DirectoryManager.forSecretManager(profileId) const walletOptions = getWalletOptions(get(activeProfile), walletPath, secretManagerPath) - const persistedWalletData: IPersistedWalletData = { + return { name: name || `${localize('general.wallet')}`, color: color || getRandomWalletColor(), hidden: false, shouldRevote: false, walletOptions, } - const walletState = await buildWalletState(wallet, persistedWalletData) - walletState.balances = await getTotalWalletBalance(walletState, true) - return [walletState, persistedWalletData] }