From b33b08d394f6a35225b62af8887c328ff32f65f8 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 5 Dec 2023 15:55:09 +0100 Subject: [PATCH 1/3] refactor: Onboarding WIP --- .../login/views/SelectProfileView.svelte | 1 + .../views/FinishOnboardingView.svelte | 1 + .../views/ChooseCreateProfileFlowView.svelte | 9 ++++---- .../actions/completeOnboardingProcess.ts | 9 ++++++++ .../actions/initialiseOnboardingProfile.ts | 22 +++++++++---------- ...liseProfileManagerFromOnboardingProfile.ts | 2 ++ .../stores/onboarding-profile.store.ts | 10 +++++---- .../stores/onboarding-secret-manager.store.ts | 16 ++++++++++---- .../actions/active-profile/loadWallets.ts | 4 ++-- .../lib/core/profile/actions/createWallet.ts | 16 +++++++++----- .../utils/getSecretManagerFromProfileType.ts | 2 +- .../secret-manager/actions/storeMnemonic.ts | 7 +++++- .../wallet/actions/setStrongholdPassword.ts | 1 + .../getSenderAddressFromInputs.ts | 10 ++++----- 14 files changed, 72 insertions(+), 38 deletions(-) diff --git a/packages/desktop/views/login/views/SelectProfileView.svelte b/packages/desktop/views/login/views/SelectProfileView.svelte index e37e90d2e12..2e6ab5daef4 100644 --- a/packages/desktop/views/login/views/SelectProfileView.svelte +++ b/packages/desktop/views/login/views/SelectProfileView.svelte @@ -31,6 +31,7 @@ async function onAddProfileClick(): Promise { onboardingRouter.set(new OnboardingRouter()) await initialiseOnboardingProfile(shouldBeDeveloperProfile()) + console.log("shuld be created") $routerManager.goToAppContext(AppContext.Onboarding) } diff --git a/packages/desktop/views/onboarding/views/complete-onboarding/views/FinishOnboardingView.svelte b/packages/desktop/views/onboarding/views/complete-onboarding/views/FinishOnboardingView.svelte index 4d1c983e7f3..308b1c81e93 100644 --- a/packages/desktop/views/onboarding/views/complete-onboarding/views/FinishOnboardingView.svelte +++ b/packages/desktop/views/onboarding/views/complete-onboarding/views/FinishOnboardingView.svelte @@ -28,6 +28,7 @@ } async function _continue(): Promise { + console.log($onboardingProfile) // Note: needed to cover the cases where the user has waited so long that the stronghold is locked if ($onboardingProfile?.restoreProfileType === RestoreProfileType.Stronghold) { await setStrongholdPassword($onboardingProfile.strongholdPassword) diff --git a/packages/desktop/views/onboarding/views/create-profile/views/ChooseCreateProfileFlowView.svelte b/packages/desktop/views/onboarding/views/create-profile/views/ChooseCreateProfileFlowView.svelte index 59964bd6fda..72f1360041c 100644 --- a/packages/desktop/views/onboarding/views/create-profile/views/ChooseCreateProfileFlowView.svelte +++ b/packages/desktop/views/onboarding/views/create-profile/views/ChooseCreateProfileFlowView.svelte @@ -2,12 +2,11 @@ import { OnboardingLayout } from '@components' import { CreateProfileType, - initialiseProfileManagerFromOnboardingProfile, onboardingProfile, updateOnboardingProfile, } from '@contexts/onboarding' import { localize } from '@core/i18n' - import { ProfileType, clearProfileFromMemory, removeProfileFolder } from '@core/profile' + import { ProfileType, clearProfileFromMemory, getSecretManagerFromProfileType, getStorageDirectoryOfProfile, removeProfileFolder } from '@core/profile' import features from '@features/features' import { Animation, OnboardingButton, Text } from '@ui' import { onMount } from 'svelte' @@ -27,8 +26,10 @@ async function onProfileTypeClick(createProfileType: CreateProfileType): Promise { isBusy = { ...isBusy, [createProfileType]: true } const type = createProfileType === CreateProfileType.Ledger ? ProfileType.Ledger : ProfileType.Software - updateOnboardingProfile({ createProfileType, type }) - await initialiseProfileManagerFromOnboardingProfile() + const storagePath = await getStorageDirectoryOfProfile($onboardingProfile.id) + const secretManagerOptions = getSecretManagerFromProfileType(type, storagePath) + console.log("secretManagerOptions", secretManagerOptions) + updateOnboardingProfile({ createProfileType, type, secretManagerOptions }) $createProfileRouter.next() } diff --git a/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts b/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts index d3a449a52ab..3848e30ea41 100644 --- a/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts +++ b/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts @@ -11,10 +11,13 @@ export async function completeOnboardingProcess(): Promise { // if we already have an active profile // it means we are trying to load again after an error // and we don't need to add it again + console.log(get(activeProfile), get(onboardingProfile)) if (!get(activeProfile)?.id) { createNewProfileFromOnboardingProfile() } + console.log(get(activeProfile)) + const onboardingType = get(onboardingProfile)?.onboardingType const shouldRecoverAccounts = onboardingType === OnboardingType.Restore || onboardingType === OnboardingType.Claim showBalanceOverviewPopup.set(shouldRecoverAccounts) @@ -31,9 +34,13 @@ export async function createOnboardingWallet(name?: string, color?: string): Pro // 1. Get the wallet name const walletName = name || `${localize('general.account')} ${(get(activeWallets)?.length ?? 0) + 1}`; + console.log("walletName", walletName) + // 2. Create the wallet instance const wallet = await createWallet() + console.log("wallet", wallet) + // 3. Sync the wallet with the Node // TODO(2.0): test & fix sync when we have iota2.0 nodes //await account.sync(DEFAULT_SYNC_OPTIONS) @@ -41,6 +48,8 @@ export async function createOnboardingWallet(name?: string, color?: string): Pro // 4. Create a wrapper over the wallet instance and the persisted data const [walletState, accountPersistedData] = await buildWalletStateAndPersistedData(wallet, walletName, color) + console.log("walletState", walletState, accountPersistedData) + // TODO(2.0) Fix // addAccountToActiveAccounts(walletState) addWalletPersistedDataToOnboardingProfile(walletState.id, accountPersistedData) diff --git a/packages/shared/lib/contexts/onboarding/actions/initialiseOnboardingProfile.ts b/packages/shared/lib/contexts/onboarding/actions/initialiseOnboardingProfile.ts index 786ca6b4557..cf88b1eb142 100644 --- a/packages/shared/lib/contexts/onboarding/actions/initialiseOnboardingProfile.ts +++ b/packages/shared/lib/contexts/onboarding/actions/initialiseOnboardingProfile.ts @@ -12,17 +12,17 @@ export async function initialiseOnboardingProfile( isDeveloperProfile: boolean, destroyPreviousManager = false ): Promise { - // TODO(2.0) Refactor this logic - if (get(profileManager)) { - if (destroyPreviousManager) { - if (get(isOnboardingLedgerProfile)) { - stopPollingLedgerNanoStatus() - } - await clearProfileFromMemory() - } else { - throw new OnboardingProfileManagerAlreadyInitializedError() - } - } + // TODO(2.0) Profile manager is gone, we should maybe check onboarding SecretManager insteadd + // if (get(profileManager)) { + // if (destroyPreviousManager) { + // if (get(isOnboardingLedgerProfile)) { + // stopPollingLedgerNanoStatus() + // } + // await clearProfileFromMemory() + // } else { + // throw new OnboardingProfileManagerAlreadyInitializedError() + // } + // } const _newProfile = buildInitialOnboardingProfile(isDeveloperProfile) onboardingProfile.set(_newProfile) diff --git a/packages/shared/lib/contexts/onboarding/actions/initialiseProfileManagerFromOnboardingProfile.ts b/packages/shared/lib/contexts/onboarding/actions/initialiseProfileManagerFromOnboardingProfile.ts index 351aaa8a4f5..8d515cb0f80 100644 --- a/packages/shared/lib/contexts/onboarding/actions/initialiseProfileManagerFromOnboardingProfile.ts +++ b/packages/shared/lib/contexts/onboarding/actions/initialiseProfileManagerFromOnboardingProfile.ts @@ -26,5 +26,7 @@ export async function initialiseOnboardingProfileWithSecretManager(checkForExist const secretManagerOptions = getSecretManagerFromProfileType(activeOnboardingProfile.type, storagePath) + console.log("secretManagerOptions", secretManagerOptions) + updateOnboardingProfile({ secretManagerOptions, hasInitialisedProfileManager: true }) } diff --git a/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts b/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts index 99401932818..1dacd04c4a6 100644 --- a/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts +++ b/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts @@ -8,9 +8,10 @@ import { IPersistedNetwork } from '@core/network' export const onboardingProfile = writable(null) -export const isOnboardingLedgerProfile: Readable = derived(onboardingProfile, ($onboardingProfile) => - isLedgerProfile($onboardingProfile?.type) -) +export const isOnboardingLedgerProfile: Readable = derived(onboardingProfile, ($onboardingProfile) =>{ + console.log("Changed?") + return isLedgerProfile($onboardingProfile?.type) +}) export const onboardingProfileNetwork: Readable = derived( onboardingProfile, @@ -18,7 +19,8 @@ export const onboardingProfileNetwork: Readable = ) export function updateOnboardingProfile(payload: Partial): void { - return onboardingProfile.update((state) => ({ ...state, ...payload })) + onboardingProfile.update((state) => ({ ...state, ...payload })) + console.log("UPDATED", get(onboardingProfile)) } export function updateShimmerClaimingAccount(shimmerClaimingAccount: IShimmerClaimingWallet): void { diff --git a/packages/shared/lib/contexts/onboarding/stores/onboarding-secret-manager.store.ts b/packages/shared/lib/contexts/onboarding/stores/onboarding-secret-manager.store.ts index 9c2e996543c..da32400043e 100644 --- a/packages/shared/lib/contexts/onboarding/stores/onboarding-secret-manager.store.ts +++ b/packages/shared/lib/contexts/onboarding/stores/onboarding-secret-manager.store.ts @@ -3,12 +3,20 @@ import { api } from '@core/api'; import { SecretManager } from '@iota/sdk'; import { Readable, derived, get } from 'svelte/store'; -const onboardingProfileSecretManagerOptions = derived(onboardingProfile, (onboardingProfile) => onboardingProfile?.secretManagerOptions); +onboardingProfile.subscribe(console.log) -export const onboardingProfileSecretManager: Readable = derived(onboardingProfileSecretManagerOptions, (onboardingProfileSecretManagerOptions, set) => { - if (onboardingProfileSecretManagerOptions) { - api.createSecretManager(onboardingProfileSecretManagerOptions) + +const onboardingProfileSecretManagerOptions = derived(onboardingProfile, ($onboardingProfile) => { + console.log("derived", $onboardingProfile?.secretManagerOptions) + return $onboardingProfile?.secretManagerOptions +}); + +export const onboardingProfileSecretManager: Readable = derived(onboardingProfileSecretManagerOptions, ($onboardingProfileSecretManagerOptions, set) => { + console.log("creating SC", $onboardingProfileSecretManagerOptions) + if ($onboardingProfileSecretManagerOptions) { + api.createSecretManager($onboardingProfileSecretManagerOptions) .then((secretManager) => { + console.log("secret manager created", secretManager) set(secretManager) }) } else { diff --git a/packages/shared/lib/core/profile/actions/active-profile/loadWallets.ts b/packages/shared/lib/core/profile/actions/active-profile/loadWallets.ts index cd7b7a0e1c2..d918fa165b7 100644 --- a/packages/shared/lib/core/profile/actions/active-profile/loadWallets.ts +++ b/packages/shared/lib/core/profile/actions/active-profile/loadWallets.ts @@ -1,6 +1,6 @@ import { loadWallet } from '@core/wallet' import { get } from 'svelte/store' -import { activeAccounts, activeProfile } from '../../stores' +import { activeWallets, activeProfile } from '../../stores' import { getWallets } from '../getWallets' export async function loadWallets(): Promise { @@ -14,7 +14,7 @@ export async function loadWallets(): Promise { const loadedWallets = await Promise.all( walletResponse?.map((accountResponse) => loadWallet(accountResponse)) ) - activeAccounts.set(loadedWallets) // TODO(2.0) We can't sort this like this: sort((a, b) => a.getMetadata().index - b.getMetadata().index) + activeWallets.set(loadedWallets) // TODO(2.0) We can't sort this like this: sort((a, b) => a.getMetadata().index - b.getMetadata().index) hasLoadedAccounts.set(true) } } diff --git a/packages/shared/lib/core/profile/actions/createWallet.ts b/packages/shared/lib/core/profile/actions/createWallet.ts index 62a906f21d0..077a6dff2da 100644 --- a/packages/shared/lib/core/profile/actions/createWallet.ts +++ b/packages/shared/lib/core/profile/actions/createWallet.ts @@ -3,7 +3,7 @@ import { generateRandomId } from '@core/utils' import { get } from 'svelte/store' import { IWallet } from '../interfaces' import { activeProfile as activeProfileStore } from '../stores' -import { getStorageDirectoryOfProfile } from '../utils' +import { getSecretManagerFromProfileType, getStorageDirectoryOfProfile } from '../utils' // TODO(2.0): Fix and finish this method /* - __storage__/ @@ -19,16 +19,20 @@ export async function createWallet(activeProfile = get(activeProfileStore)): Pro const walletOptions = { clientOptions: activeProfile.clientOptions, - secretManager: { - stronghold: { - snapshotPath, - }, - }, + secretManager: getSecretManagerFromProfileType(activeProfile.type, storagePath), + bipPath: { + coinType: activeProfile.network.coinType + } } + console.log("walletOptions", walletOptions); + const wallet = await api.createWallet(id, { ...walletOptions, storagePath, }) + console.log("wallet", wallet); + + return wallet } diff --git a/packages/shared/lib/core/profile/utils/getSecretManagerFromProfileType.ts b/packages/shared/lib/core/profile/utils/getSecretManagerFromProfileType.ts index 5afc870ebfd..3d8423ae974 100644 --- a/packages/shared/lib/core/profile/utils/getSecretManagerFromProfileType.ts +++ b/packages/shared/lib/core/profile/utils/getSecretManagerFromProfileType.ts @@ -4,7 +4,7 @@ import { USE_LEDGER_SIMULATOR } from '@core/ledger' import { ProfileType } from '@core/profile' // TODO(2.0) Fix all usages -export function getSecretManagerFromProfileType(type: ProfileType, storagePath?: string): SecretManagerType { +export function getSecretManagerFromProfileType(type?: ProfileType, storagePath?: string): SecretManagerType { const strongholdSecretManager = { stronghold: { snapshotPath: `${storagePath}/wallet.stronghold`, password: 'mellamobego' }, } diff --git a/packages/shared/lib/core/secret-manager/actions/storeMnemonic.ts b/packages/shared/lib/core/secret-manager/actions/storeMnemonic.ts index c9fe6006745..458c9457321 100644 --- a/packages/shared/lib/core/secret-manager/actions/storeMnemonic.ts +++ b/packages/shared/lib/core/secret-manager/actions/storeMnemonic.ts @@ -1,8 +1,13 @@ +import { onboardingProfileSecretManager } from 'shared/lib/contexts/onboarding' import { get } from 'svelte/store' import { activeProfileSecretManager } from '../stores' export async function storeMnemonic(mnemonic: string): Promise { - const secretManager = get(activeProfileSecretManager) + // TODO(2.0) There are two secret managers, but we might only actually need one to store the mnemonic. + const secretManager = get(onboardingProfileSecretManager) + + console.log("storeMnemonic", mnemonic, "secretManager", secretManager); + if (!secretManager) { return undefined diff --git a/packages/shared/lib/core/wallet/actions/setStrongholdPassword.ts b/packages/shared/lib/core/wallet/actions/setStrongholdPassword.ts index 97611fcec00..2422d731cbd 100644 --- a/packages/shared/lib/core/wallet/actions/setStrongholdPassword.ts +++ b/packages/shared/lib/core/wallet/actions/setStrongholdPassword.ts @@ -2,6 +2,7 @@ import { get } from 'svelte/store' import { selectedWallet } from '../stores/selected-wallet.store' export async function setStrongholdPassword(password: string): Promise { + console.log(password) const wallet = get(selectedWallet) // Otherwise error is thrown, if password is still present in memory await wallet?.clearStrongholdPassword() diff --git a/packages/shared/lib/core/wallet/utils/transactions/getSenderAddressFromInputs.ts b/packages/shared/lib/core/wallet/utils/transactions/getSenderAddressFromInputs.ts index 862081278b3..476dcb8028c 100644 --- a/packages/shared/lib/core/wallet/utils/transactions/getSenderAddressFromInputs.ts +++ b/packages/shared/lib/core/wallet/utils/transactions/getSenderAddressFromInputs.ts @@ -2,11 +2,11 @@ import { IWrappedOutput } from '@core/wallet/interfaces' import { getBech32AddressFromAddressTypes } from '../getBech32AddressFromAddressTypes' import { AddressUnlockCondition, - AliasAddress, - AliasOutput, + AccountOutput, CommonOutput, ExpirationUnlockCondition, UnlockConditionType, + AccountAddress, } from '@iota/sdk/out/types' export function getSenderAddressFromInputs(inputs: IWrappedOutput[]): string | undefined { @@ -38,10 +38,10 @@ export function getSenderAddressFromInputs(inputs: IWrappedOutput[]): string | u } // TODO: if additional metadata is added to an aliasOutput, we could use it to determine the EVM Sender. - const aliasId = (output as AliasOutput)?.aliasId + const accountId = (output as AccountOutput)?.accountId - if (aliasId) { - return getBech32AddressFromAddressTypes(new AliasAddress(aliasId)) + if (accountId) { + return getBech32AddressFromAddressTypes(new AccountAddress(accountId)) } } From 72362bdeda4f25f5e3cfe76b1c20a5d15dd3efa9 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Thu, 7 Dec 2023 12:55:32 +0100 Subject: [PATCH 2/3] fix: improve logs and try to sync balances for wallet WIP --- .../actions/completeOnboardingProcess.ts | 8 ++++++-- .../lib/core/profile/actions/createWallet.ts | 17 ++++++++--------- .../lib/core/wallet/actions/buildWalletState.ts | 3 +++ .../actions/buildWalletStateAndPersistedData.ts | 3 +++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts b/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts index 3848e30ea41..ec075fea83e 100644 --- a/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts +++ b/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts @@ -11,19 +11,23 @@ export async function completeOnboardingProcess(): Promise { // if we already have an active profile // it means we are trying to load again after an error // and we don't need to add it again - console.log(get(activeProfile), get(onboardingProfile)) + console.log("get(activeProfile), get(onboardingProfile)", get(activeProfile), get(onboardingProfile)) if (!get(activeProfile)?.id) { createNewProfileFromOnboardingProfile() } - console.log(get(activeProfile)) + console.log("post createNewProfileFromOnboardingProfile", get(activeProfile)) const onboardingType = get(onboardingProfile)?.onboardingType const shouldRecoverAccounts = onboardingType === OnboardingType.Restore || onboardingType === OnboardingType.Claim showBalanceOverviewPopup.set(shouldRecoverAccounts) + console.log("pre createOnboardingWallet -----") await createOnboardingWallet() + + console.log("post createOnboardingWallet and pre login"); + void login({ isFromOnboardingFlow: true, shouldRecoverAccounts }) diff --git a/packages/shared/lib/core/profile/actions/createWallet.ts b/packages/shared/lib/core/profile/actions/createWallet.ts index 077a6dff2da..e21659f9e97 100644 --- a/packages/shared/lib/core/profile/actions/createWallet.ts +++ b/packages/shared/lib/core/profile/actions/createWallet.ts @@ -4,6 +4,7 @@ import { get } from 'svelte/store' import { IWallet } from '../interfaces' import { activeProfile as activeProfileStore } from '../stores' import { getSecretManagerFromProfileType, getStorageDirectoryOfProfile } from '../utils' +import { WalletOptions } from '@iota/sdk' // TODO(2.0): Fix and finish this method /* - __storage__/ @@ -15,24 +16,22 @@ import { getSecretManagerFromProfileType, getStorageDirectoryOfProfile } from '. export async function createWallet(activeProfile = get(activeProfileStore)): Promise { const id = generateRandomId() const storagePath = await getStorageDirectoryOfProfile(id) - const snapshotPath = '' + // const snapshotPath = '' - const walletOptions = { + const walletOptions: WalletOptions = { clientOptions: activeProfile.clientOptions, secretManager: getSecretManagerFromProfileType(activeProfile.type, storagePath), bipPath: { - coinType: activeProfile.network.coinType - } + coinType: activeProfile.network.coinType, + account: 0, + addressIndex: 0 + }, + coinType: activeProfile.network.coinType } console.log("walletOptions", walletOptions); - const wallet = await api.createWallet(id, { ...walletOptions, storagePath, }) - - console.log("wallet", wallet); - - return wallet } diff --git a/packages/shared/lib/core/wallet/actions/buildWalletState.ts b/packages/shared/lib/core/wallet/actions/buildWalletState.ts index 3b921c2dd61..30368d005ed 100644 --- a/packages/shared/lib/core/wallet/actions/buildWalletState.ts +++ b/packages/shared/lib/core/wallet/actions/buildWalletState.ts @@ -21,17 +21,20 @@ export async function buildWalletState( basic: BigInt(0), foundry: BigInt(0), nft: BigInt(0), + delegation: BigInt(0) }, nativeTokens: [], nfts: [], foundries: [], potentiallyLockedOutputs: {}, accounts: [], + delegations: [] } let depositAddress = '' let votingPower = '' try { + await wallet.sync() balances = await wallet.getBalance() depositAddress = await getDepositAddress(wallet) votingPower = balances.baseCoin.votingPower diff --git a/packages/shared/lib/core/wallet/actions/buildWalletStateAndPersistedData.ts b/packages/shared/lib/core/wallet/actions/buildWalletStateAndPersistedData.ts index 83167659ea4..f787ef46f21 100644 --- a/packages/shared/lib/core/wallet/actions/buildWalletStateAndPersistedData.ts +++ b/packages/shared/lib/core/wallet/actions/buildWalletStateAndPersistedData.ts @@ -18,6 +18,9 @@ export async function buildWalletStateAndPersistedData( shouldRevote: false, walletOptions: {} } + console.log("persistedWalletData", persistedWalletData); + const accountState = await buildWalletState(wallet, persistedWalletData) + console.log("accountState", accountState); return [accountState, persistedWalletData] } From f9c5cb078a970fa2db656a83452f6d6ca4c3bacd Mon Sep 17 00:00:00 2001 From: cpl121 Date: Tue, 12 Dec 2023 12:14:12 +0100 Subject: [PATCH 3/3] refactor: complete onboarding --- .../actions/completeOnboardingProcess.ts | 27 +++++-------------- .../stores/onboarding-profile.store.ts | 2 +- .../core/wallet/actions/buildWalletState.ts | 1 - .../wallet/actions/getAddressesWithOutputs.ts | 4 +-- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts b/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts index ec075fea83e..4a4dcf979a2 100644 --- a/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts +++ b/packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts @@ -1,4 +1,4 @@ -import { activeProfile, activeWallets, addWalletPersistedDataToActiveProfile, createWallet, login } from '@core/profile' +import { IWallet, activeProfile, activeWallets, addWalletPersistedDataToActiveProfile, createWallet, login } from '@core/profile' import { get } from 'svelte/store' import { OnboardingType } from '../enums' import { addWalletPersistedDataToOnboardingProfile, onboardingProfile } from '../stores' @@ -16,50 +16,35 @@ export async function completeOnboardingProcess(): Promise { createNewProfileFromOnboardingProfile() } - console.log("post createNewProfileFromOnboardingProfile", get(activeProfile)) - const onboardingType = get(onboardingProfile)?.onboardingType const shouldRecoverAccounts = onboardingType === OnboardingType.Restore || onboardingType === OnboardingType.Claim showBalanceOverviewPopup.set(shouldRecoverAccounts) - console.log("pre createOnboardingWallet -----") - await createOnboardingWallet() - - console.log("post createOnboardingWallet and pre login"); - - void login({ isFromOnboardingFlow: true, shouldRecoverAccounts }) onboardingProfile.set(undefined) } -export async function createOnboardingWallet(name?: string, color?: string): Promise { +export async function createOnboardingWallet(name?: string, color?: string): Promise { // 1. Get the wallet name const walletName = name || `${localize('general.account')} ${(get(activeWallets)?.length ?? 0) + 1}`; - console.log("walletName", walletName) - // 2. Create the wallet instance const wallet = await createWallet() - console.log("wallet", wallet) - // 3. Sync the wallet with the Node // TODO(2.0): test & fix sync when we have iota2.0 nodes - //await account.sync(DEFAULT_SYNC_OPTIONS) - + //await wallet.sync(DEFAULT_SYNC_OPTIONS) // 4. Create a wrapper over the wallet instance and the persisted data - const [walletState, accountPersistedData] = await buildWalletStateAndPersistedData(wallet, walletName, color) - - console.log("walletState", walletState, accountPersistedData) + // const [walletState, accountPersistedData] = await buildWalletStateAndPersistedData(wallet, walletName, color) // TODO(2.0) Fix // addAccountToActiveAccounts(walletState) - addWalletPersistedDataToOnboardingProfile(walletState.id, accountPersistedData) + // addWalletPersistedDataToOnboardingProfile(walletState.id, accountPersistedData) // TODO(2.0) Fix // addEmptyAccountActivitiesToAllAccountActivities(walletState.id) - return walletState + return wallet } diff --git a/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts b/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts index 1dacd04c4a6..7c04d09bcfc 100644 --- a/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts +++ b/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts @@ -6,7 +6,7 @@ import { IOnboardingProfile, IShimmerClaimingWallet } from '../interfaces' import { IBaseToken, IPersistedWalletData } from '@core/wallet/interfaces' import { IPersistedNetwork } from '@core/network' -export const onboardingProfile = writable(null) +export const onboardingProfile = writable(null) export const isOnboardingLedgerProfile: Readable = derived(onboardingProfile, ($onboardingProfile) =>{ console.log("Changed?") diff --git a/packages/shared/lib/core/wallet/actions/buildWalletState.ts b/packages/shared/lib/core/wallet/actions/buildWalletState.ts index 30368d005ed..65afd00967e 100644 --- a/packages/shared/lib/core/wallet/actions/buildWalletState.ts +++ b/packages/shared/lib/core/wallet/actions/buildWalletState.ts @@ -34,7 +34,6 @@ export async function buildWalletState( let depositAddress = '' let votingPower = '' try { - await wallet.sync() balances = await wallet.getBalance() depositAddress = await getDepositAddress(wallet) votingPower = balances.baseCoin.votingPower diff --git a/packages/shared/lib/core/wallet/actions/getAddressesWithOutputs.ts b/packages/shared/lib/core/wallet/actions/getAddressesWithOutputs.ts index 731ea9cb7ff..dc96e69a2da 100644 --- a/packages/shared/lib/core/wallet/actions/getAddressesWithOutputs.ts +++ b/packages/shared/lib/core/wallet/actions/getAddressesWithOutputs.ts @@ -3,10 +3,10 @@ import { IWallet } from '@core/profile/interfaces' import { Address } from '@iota/sdk/out/types' // TODO(2.0) Fix all usages -export async function getAddressesWithOutputs(account: IWallet | IWalletState): Promise { +export async function getAddressesWithOutputs(wallet: IWallet | IWalletState): Promise { let addressesWithOutputs: AddressWithOutputs[] = [] const addresses: Address[] = [] // await account.accounts - const outputs = await account.outputs() + const outputs = await wallet.outputs() const outputMapped: AddressWithOutputs[] = outputs.reduce((acc: AddressWithOutputs[], output) => { const address = getBech32AddressFromAddressTypes(output.address)