Skip to content

Commit b33b08d

Browse files
committed
refactor: Onboarding WIP
1 parent e5f75c4 commit b33b08d

File tree

14 files changed

+72
-38
lines changed

14 files changed

+72
-38
lines changed

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

+1
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

+1
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

+5-4
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

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

+9
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ 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))
1415
if (!get(activeProfile)?.id) {
1516
createNewProfileFromOnboardingProfile()
1617
}
1718

19+
console.log(get(activeProfile))
20+
1821
const onboardingType = get(onboardingProfile)?.onboardingType
1922
const shouldRecoverAccounts = onboardingType === OnboardingType.Restore || onboardingType === OnboardingType.Claim
2023
showBalanceOverviewPopup.set(shouldRecoverAccounts)
@@ -31,16 +34,22 @@ export async function createOnboardingWallet(name?: string, color?: string): Pro
3134
// 1. Get the wallet name
3235
const walletName = name || `${localize('general.account')} ${(get(activeWallets)?.length ?? 0) + 1}`;
3336

37+
console.log("walletName", walletName)
38+
3439
// 2. Create the wallet instance
3540
const wallet = await createWallet()
3641

42+
console.log("wallet", wallet)
43+
3744
// 3. Sync the wallet with the Node
3845
// TODO(2.0): test & fix sync when we have iota2.0 nodes
3946
//await account.sync(DEFAULT_SYNC_OPTIONS)
4047

4148
// 4. Create a wrapper over the wallet instance and the persisted data
4249
const [walletState, accountPersistedData] = await buildWalletStateAndPersistedData(wallet, walletName, color)
4350

51+
console.log("walletState", walletState, accountPersistedData)
52+
4453
// TODO(2.0) Fix
4554
// addAccountToActiveAccounts(walletState)
4655
addWalletPersistedDataToOnboardingProfile(walletState.id, accountPersistedData)

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

+11-11
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

+2
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

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ import { IPersistedNetwork } from '@core/network'
88

99
export const onboardingProfile = writable<IOnboardingProfile | null>(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

+12-4
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

+2-2
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

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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'
77

88
// TODO(2.0): Fix and finish this method
99
/* - __storage__/
@@ -19,16 +19,20 @@ export async function createWallet(activeProfile = get(activeProfileStore)): Pro
1919

2020
const walletOptions = {
2121
clientOptions: activeProfile.clientOptions,
22-
secretManager: {
23-
stronghold: {
24-
snapshotPath,
25-
},
26-
},
22+
secretManager: getSecretManagerFromProfileType(activeProfile.type, storagePath),
23+
bipPath: {
24+
coinType: activeProfile.network.coinType
25+
}
2726
}
27+
console.log("walletOptions", walletOptions);
28+
2829
const wallet = await api.createWallet(id, {
2930
...walletOptions,
3031
storagePath,
3132
})
3233

34+
console.log("wallet", wallet);
35+
36+
3337
return wallet
3438
}

packages/shared/lib/core/profile/utils/getSecretManagerFromProfileType.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { USE_LEDGER_SIMULATOR } from '@core/ledger'
44
import { ProfileType } from '@core/profile'
55

66
// TODO(2.0) Fix all usages
7-
export function getSecretManagerFromProfileType(type: ProfileType, storagePath?: string): SecretManagerType {
7+
export function getSecretManagerFromProfileType(type?: ProfileType, storagePath?: string): SecretManagerType {
88
const strongholdSecretManager = {
99
stronghold: { snapshotPath: `${storagePath}/wallet.stronghold`, password: 'mellamobego' },
1010
}

packages/shared/lib/core/secret-manager/actions/storeMnemonic.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import { onboardingProfileSecretManager } from 'shared/lib/contexts/onboarding'
12
import { get } from 'svelte/store'
23
import { activeProfileSecretManager } from '../stores'
34

45
export async function storeMnemonic(mnemonic: string): Promise<void> {
5-
const secretManager = get(activeProfileSecretManager)
6+
// TODO(2.0) There are two secret managers, but we might only actually need one to store the mnemonic.
7+
const secretManager = get(onboardingProfileSecretManager)
8+
9+
console.log("storeMnemonic", mnemonic, "secretManager", secretManager);
10+
611

712
if (!secretManager) {
813
return undefined

packages/shared/lib/core/wallet/actions/setStrongholdPassword.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { get } from 'svelte/store'
22
import { selectedWallet } from '../stores/selected-wallet.store'
33

44
export async function setStrongholdPassword(password: string): Promise<void> {
5+
console.log(password)
56
const wallet = get(selectedWallet)
67
// Otherwise error is thrown, if password is still present in memory
78
await wallet?.clearStrongholdPassword()

packages/shared/lib/core/wallet/utils/transactions/getSenderAddressFromInputs.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { IWrappedOutput } from '@core/wallet/interfaces'
22
import { getBech32AddressFromAddressTypes } from '../getBech32AddressFromAddressTypes'
33
import {
44
AddressUnlockCondition,
5-
AliasAddress,
6-
AliasOutput,
5+
AccountOutput,
76
CommonOutput,
87
ExpirationUnlockCondition,
98
UnlockConditionType,
9+
AccountAddress,
1010
} from '@iota/sdk/out/types'
1111

1212
export function getSenderAddressFromInputs(inputs: IWrappedOutput[]): string | undefined {
@@ -38,10 +38,10 @@ export function getSenderAddressFromInputs(inputs: IWrappedOutput[]): string | u
3838
}
3939

4040
// TODO: if additional metadata is added to an aliasOutput, we could use it to determine the EVM Sender.
41-
const aliasId = (output as AliasOutput)?.aliasId
41+
const accountId = (output as AccountOutput)?.accountId
4242

43-
if (aliasId) {
44-
return getBech32AddressFromAddressTypes(new AliasAddress(aliasId))
43+
if (accountId) {
44+
return getBech32AddressFromAddressTypes(new AccountAddress(accountId))
4545
}
4646
}
4747

0 commit comments

Comments
 (0)