Skip to content

Commit

Permalink
refactor: complete onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
cpl121 committed Dec 12, 2023
1 parent 72362bd commit f9c5cb0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { activeProfile, activeWallets, addWalletPersistedDataToActiveProfile, createWallet, login } from '@core/profile'
import { IWallet, activeProfile, activeWallets, addWalletPersistedDataToActiveProfile, createWallet, login } from '@core/profile'

Check failure on line 1 in packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts

View workflow job for this annotation

GitHub Actions / lint

'addWalletPersistedDataToActiveProfile' is defined but never used
import { get } from 'svelte/store'
import { OnboardingType } from '../enums'
import { addWalletPersistedDataToOnboardingProfile, onboardingProfile } from '../stores'

Check failure on line 4 in packages/shared/lib/contexts/onboarding/actions/completeOnboardingProcess.ts

View workflow job for this annotation

GitHub Actions / lint

'addWalletPersistedDataToOnboardingProfile' is defined but never used
Expand All @@ -16,50 +16,35 @@ export async function completeOnboardingProcess(): Promise<void> {
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<IWalletState> {
export async function createOnboardingWallet(name?: string, color?: string): Promise<IWallet> {
// 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<IOnboardingProfile | null>(null)
export const onboardingProfile = writable<IOnboardingProfile | null | undefined>(null)

export const isOnboardingLedgerProfile: Readable<boolean> = derived(onboardingProfile, ($onboardingProfile) =>{
console.log("Changed?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AddressWithOutputs[]> {
export async function getAddressesWithOutputs(wallet: IWallet | IWalletState): Promise<AddressWithOutputs[]> {
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)
Expand Down

0 comments on commit f9c5cb0

Please sign in to comment.