Skip to content

Commit f7cfffb

Browse files
marc2332cpl121
andauthored
refactor: Onboarding (#7763)
* refactor: Onboarding WIP * fix: improve logs and try to sync balances for wallet WIP * refactor: complete onboarding --------- Co-authored-by: cpl121 <[email protected]>
1 parent fea68d6 commit f7cfffb

File tree

17 files changed

+79
-52
lines changed

17 files changed

+79
-52
lines changed

packages/desktop/views/login/views/SelectProfileView.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
async function onAddProfileClick(): Promise<void> {
3232
onboardingRouter.set(new OnboardingRouter())
3333
await initialiseOnboardingProfile(shouldBeDeveloperProfile())
34+
console.log("shuld be created")
3435
$routerManager.goToAppContext(AppContext.Onboarding)
3536
}
3637

packages/desktop/views/onboarding/views/complete-onboarding/views/FinishOnboardingView.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
}
2929
3030
async function _continue(): Promise<void> {
31+
console.log($onboardingProfile)
3132
// Note: needed to cover the cases where the user has waited so long that the stronghold is locked
3233
if ($onboardingProfile?.restoreProfileType === RestoreProfileType.Stronghold) {
3334
await setStrongholdPassword($onboardingProfile.strongholdPassword)

packages/desktop/views/onboarding/views/create-profile/views/ChooseCreateProfileFlowView.svelte

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
import { OnboardingLayout } from '@components'
33
import {
44
CreateProfileType,
5-
initialiseProfileManagerFromOnboardingProfile,
65
onboardingProfile,
76
updateOnboardingProfile,
87
} from '@contexts/onboarding'
98
import { localize } from '@core/i18n'
10-
import { ProfileType, clearProfileFromMemory, removeProfileFolder } from '@core/profile'
9+
import { ProfileType, clearProfileFromMemory, getSecretManagerFromProfileType, getStorageDirectoryOfProfile, removeProfileFolder } from '@core/profile'
1110
import features from '@features/features'
1211
import { Animation, OnboardingButton, Text } from '@ui'
1312
import { onMount } from 'svelte'
@@ -27,8 +26,10 @@
2726
async function onProfileTypeClick(createProfileType: CreateProfileType): Promise<void> {
2827
isBusy = { ...isBusy, [createProfileType]: true }
2928
const type = createProfileType === CreateProfileType.Ledger ? ProfileType.Ledger : ProfileType.Software
30-
updateOnboardingProfile({ createProfileType, type })
31-
await initialiseProfileManagerFromOnboardingProfile()
29+
const storagePath = await getStorageDirectoryOfProfile($onboardingProfile.id)
30+
const secretManagerOptions = getSecretManagerFromProfileType(type, storagePath)
31+
console.log("secretManagerOptions", secretManagerOptions)
32+
updateOnboardingProfile({ createProfileType, type, secretManagerOptions })
3233
$createProfileRouter.next()
3334
}
3435
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { activeProfile, activeWallets, addWalletPersistedDataToActiveProfile, createWallet, login } from '@core/profile'
1+
import { IWallet, activeProfile, activeWallets, addWalletPersistedDataToActiveProfile, createWallet, login } from '@core/profile'
22
import { get } from 'svelte/store'
33
import { OnboardingType } from '../enums'
44
import { addWalletPersistedDataToOnboardingProfile, onboardingProfile } from '../stores'
@@ -11,6 +11,7 @@ export async function completeOnboardingProcess(): Promise<void> {
1111
// if we already have an active profile
1212
// it means we are trying to load again after an error
1313
// and we don't need to add it again
14+
console.log("get(activeProfile), get(onboardingProfile)", get(activeProfile), get(onboardingProfile))
1415
if (!get(activeProfile)?.id) {
1516
createNewProfileFromOnboardingProfile()
1617
}
@@ -19,15 +20,13 @@ export async function completeOnboardingProcess(): Promise<void> {
1920
const shouldRecoverAccounts = onboardingType === OnboardingType.Restore || onboardingType === OnboardingType.Claim
2021
showBalanceOverviewPopup.set(shouldRecoverAccounts)
2122

22-
2323
await createOnboardingWallet()
24-
2524
void login({ isFromOnboardingFlow: true, shouldRecoverAccounts })
2625

2726
onboardingProfile.set(undefined)
2827
}
2928

30-
export async function createOnboardingWallet(name?: string, color?: string): Promise<IWalletState> {
29+
export async function createOnboardingWallet(name?: string, color?: string): Promise<IWallet> {
3130
// 1. Get the wallet name
3231
const walletName = name || `${localize('general.account')} ${(get(activeWallets)?.length ?? 0) + 1}`;
3332

@@ -36,17 +35,16 @@ export async function createOnboardingWallet(name?: string, color?: string): Pro
3635

3736
// 3. Sync the wallet with the Node
3837
// TODO(2.0): test & fix sync when we have iota2.0 nodes
39-
//await account.sync(DEFAULT_SYNC_OPTIONS)
40-
38+
//await wallet.sync(DEFAULT_SYNC_OPTIONS)
4139
// 4. Create a wrapper over the wallet instance and the persisted data
42-
const [walletState, accountPersistedData] = await buildWalletStateAndPersistedData(wallet, walletName, color)
40+
// const [walletState, accountPersistedData] = await buildWalletStateAndPersistedData(wallet, walletName, color)
4341

4442
// TODO(2.0) Fix
4543
// addAccountToActiveAccounts(walletState)
46-
addWalletPersistedDataToOnboardingProfile(walletState.id, accountPersistedData)
44+
// addWalletPersistedDataToOnboardingProfile(walletState.id, accountPersistedData)
4745
// TODO(2.0) Fix
4846
// addEmptyAccountActivitiesToAllAccountActivities(walletState.id)
4947

5048

51-
return walletState
49+
return wallet
5250
}

packages/shared/lib/contexts/onboarding/actions/initialiseOnboardingProfile.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ export async function initialiseOnboardingProfile(
1212
isDeveloperProfile: boolean,
1313
destroyPreviousManager = false
1414
): Promise<void> {
15-
// TODO(2.0) Refactor this logic
16-
if (get(profileManager)) {
17-
if (destroyPreviousManager) {
18-
if (get(isOnboardingLedgerProfile)) {
19-
stopPollingLedgerNanoStatus()
20-
}
21-
await clearProfileFromMemory()
22-
} else {
23-
throw new OnboardingProfileManagerAlreadyInitializedError()
24-
}
25-
}
15+
// TODO(2.0) Profile manager is gone, we should maybe check onboarding SecretManager insteadd
16+
// if (get(profileManager)) {
17+
// if (destroyPreviousManager) {
18+
// if (get(isOnboardingLedgerProfile)) {
19+
// stopPollingLedgerNanoStatus()
20+
// }
21+
// await clearProfileFromMemory()
22+
// } else {
23+
// throw new OnboardingProfileManagerAlreadyInitializedError()
24+
// }
25+
// }
2626

2727
const _newProfile = buildInitialOnboardingProfile(isDeveloperProfile)
2828
onboardingProfile.set(_newProfile)

packages/shared/lib/contexts/onboarding/actions/initialiseProfileManagerFromOnboardingProfile.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ export async function initialiseOnboardingProfileWithSecretManager(checkForExist
2626

2727
const secretManagerOptions = getSecretManagerFromProfileType(activeOnboardingProfile.type, storagePath)
2828

29+
console.log("secretManagerOptions", secretManagerOptions)
30+
2931
updateOnboardingProfile({ secretManagerOptions, hasInitialisedProfileManager: true })
3032
}

packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ import { IOnboardingProfile, IShimmerClaimingWallet } from '../interfaces'
66
import { IBaseToken, IPersistedWalletData } from '@core/wallet/interfaces'
77
import { IPersistedNetwork } from '@core/network'
88

9-
export const onboardingProfile = writable<IOnboardingProfile | null>(null)
9+
export const onboardingProfile = writable<IOnboardingProfile | null | undefined>(null)
1010

11-
export const isOnboardingLedgerProfile: Readable<boolean> = derived(onboardingProfile, ($onboardingProfile) =>
12-
isLedgerProfile($onboardingProfile?.type)
13-
)
11+
export const isOnboardingLedgerProfile: Readable<boolean> = derived(onboardingProfile, ($onboardingProfile) =>{
12+
console.log("Changed?")
13+
return isLedgerProfile($onboardingProfile?.type)
14+
})
1415

1516
export const onboardingProfileNetwork: Readable<IPersistedNetwork | undefined> = derived(
1617
onboardingProfile,
1718
($onboardingProfile) => $onboardingProfile?.network
1819
)
1920

2021
export function updateOnboardingProfile(payload: Partial<IOnboardingProfile>): void {
21-
return onboardingProfile.update((state) => ({ ...state, ...payload }))
22+
onboardingProfile.update((state) => ({ ...state, ...payload }))
23+
console.log("UPDATED", get(onboardingProfile))
2224
}
2325

2426
export function updateShimmerClaimingAccount(shimmerClaimingAccount: IShimmerClaimingWallet): void {

packages/shared/lib/contexts/onboarding/stores/onboarding-secret-manager.store.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@ import { api } from '@core/api';
33
import { SecretManager } from '@iota/sdk';
44
import { Readable, derived, get } from 'svelte/store';
55

6-
const onboardingProfileSecretManagerOptions = derived(onboardingProfile, (onboardingProfile) => onboardingProfile?.secretManagerOptions);
6+
onboardingProfile.subscribe(console.log)
77

8-
export const onboardingProfileSecretManager: Readable<SecretManager | null> = derived(onboardingProfileSecretManagerOptions, (onboardingProfileSecretManagerOptions, set) => {
9-
if (onboardingProfileSecretManagerOptions) {
10-
api.createSecretManager(onboardingProfileSecretManagerOptions)
8+
9+
const onboardingProfileSecretManagerOptions = derived(onboardingProfile, ($onboardingProfile) => {
10+
console.log("derived", $onboardingProfile?.secretManagerOptions)
11+
return $onboardingProfile?.secretManagerOptions
12+
});
13+
14+
export const onboardingProfileSecretManager: Readable<SecretManager | null> = derived(onboardingProfileSecretManagerOptions, ($onboardingProfileSecretManagerOptions, set) => {
15+
console.log("creating SC", $onboardingProfileSecretManagerOptions)
16+
if ($onboardingProfileSecretManagerOptions) {
17+
api.createSecretManager($onboardingProfileSecretManagerOptions)
1118
.then((secretManager) => {
19+
console.log("secret manager created", secretManager)
1220
set(secretManager)
1321
})
1422
} else {

packages/shared/lib/core/profile/actions/active-profile/loadWallets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { loadWallet } from '@core/wallet'
22
import { get } from 'svelte/store'
3-
import { activeAccounts, activeProfile } from '../../stores'
3+
import { activeWallets, activeProfile } from '../../stores'
44
import { getWallets } from '../getWallets'
55

66
export async function loadWallets(): Promise<void> {
@@ -14,7 +14,7 @@ export async function loadWallets(): Promise<void> {
1414
const loadedWallets = await Promise.all(
1515
walletResponse?.map((accountResponse) => loadWallet(accountResponse))
1616
)
17-
activeAccounts.set(loadedWallets) // TODO(2.0) We can't sort this like this: sort((a, b) => a.getMetadata().index - b.getMetadata().index)
17+
activeWallets.set(loadedWallets) // TODO(2.0) We can't sort this like this: sort((a, b) => a.getMetadata().index - b.getMetadata().index)
1818
hasLoadedAccounts.set(true)
1919
}
2020
}

packages/shared/lib/core/profile/actions/createWallet.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { generateRandomId } from '@core/utils'
33
import { get } from 'svelte/store'
44
import { IWallet } from '../interfaces'
55
import { activeProfile as activeProfileStore } from '../stores'
6-
import { getStorageDirectoryOfProfile } from '../utils'
6+
import { getSecretManagerFromProfileType, getStorageDirectoryOfProfile } from '../utils'
7+
import { WalletOptions } from '@iota/sdk'
78

89
// TODO(2.0): Fix and finish this method
910
/* - __storage__/
@@ -15,20 +16,22 @@ import { getStorageDirectoryOfProfile } from '../utils'
1516
export async function createWallet(activeProfile = get(activeProfileStore)): Promise<IWallet> {
1617
const id = generateRandomId()
1718
const storagePath = await getStorageDirectoryOfProfile(id)
18-
const snapshotPath = ''
19+
// const snapshotPath = ''
1920

20-
const walletOptions = {
21+
const walletOptions: WalletOptions = {
2122
clientOptions: activeProfile.clientOptions,
22-
secretManager: {
23-
stronghold: {
24-
snapshotPath,
25-
},
23+
secretManager: getSecretManagerFromProfileType(activeProfile.type, storagePath),
24+
bipPath: {
25+
coinType: activeProfile.network.coinType,
26+
account: 0,
27+
addressIndex: 0
2628
},
29+
coinType: activeProfile.network.coinType
2730
}
31+
console.log("walletOptions", walletOptions);
2832
const wallet = await api.createWallet(id, {
2933
...walletOptions,
3034
storagePath,
3135
})
32-
3336
return wallet
3437
}

0 commit comments

Comments
 (0)