Skip to content

Commit d37ca7b

Browse files
committed
mmm, some improvements and fixes
1 parent 7e9b6ae commit d37ca7b

File tree

9 files changed

+60
-26
lines changed

9 files changed

+60
-26
lines changed

Diff for: packages/desktop/electron/preload.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ try {
109109
contextBridge.exposeInMainWorld('__WALLET__API__', {
110110
...methods,
111111
async createSecretManager(options) {
112-
const manager = new IotaSdk.SecretManager(options)
112+
const manager = await IotaSdk.SecretManager.create(options)
113113
bindMethodsAcrossContextBridge(IotaSdk.SecretManager.prototype, manager)
114114
return manager
115115
},
116116
// TODO(2.0): rename to createWallet
117117
async createWallet(id, options) {
118-
const wallet = new IotaSdk.Wallet(options)
118+
const wallet = await IotaSdk.Wallet.create(options)
119119
wallet.id = id
120120
wallets[id] = wallet
121121
bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, wallet)
@@ -133,7 +133,7 @@ try {
133133
async getWallet(id, walletOptions) {
134134
let wallet = wallets[id]
135135
if (!wallet) {
136-
wallet = new IotaSdk.Wallet(walletOptions)
136+
wallet = await IotaSdk.Wallet.create(walletOptions)
137137
wallets[id] = wallet
138138
bindMethodsAcrossContextBridge(IotaSdk.Account.prototype, wallet)
139139
}

Diff for: packages/desktop/views/onboarding/views/shared/EncryptMnemonicView.svelte

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { AnimationEnum } from '@auxiliary/animation'
33
import { showAppNotification } from '@auxiliary/notification'
44
import { OnboardingLayout } from '@components'
5-
import { updateOnboardingProfile, verifyAndStoreMnemonic } from '@contexts/onboarding'
5+
import { buildOnboardingSecretManager, updateOnboardingProfile, verifyAndStoreMnemonic } from '@contexts/onboarding'
66
import { localize } from '@core/i18n'
77
import { MAX_STRONGHOLD_PASSWORD_LENGTH } from '@core/profile'
88
import { Subrouter } from '@core/router'
@@ -45,8 +45,9 @@
4545
try {
4646
busy = true
4747
await setStrongholdPassword(strongholdPassword)
48-
await verifyAndStoreMnemonic()
4948
updateOnboardingProfile({ strongholdPassword, hasStoredMnemonic: true })
49+
await buildOnboardingSecretManager();
50+
await verifyAndStoreMnemonic()
5051
router.next()
5152
} catch (err) {
5253
console.error(err)

Diff for: packages/shared/lib/contexts/onboarding/actions/verifyAndStoreMnemonic.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { onboardingProfile } from '../stores'
66
* Verifies, stores, then clears the mnemonic used in the onboarding flow.
77
*/
88
export async function verifyAndStoreMnemonic(): Promise<void> {
9+
// TODO(2.0) This shouldn't use the onboarding profile always
910
const mnemonic = get(onboardingProfile)?.mnemonic?.join(' ') ?? ''
1011

1112
await verifyMnemonic(mnemonic)

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

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const onboardingProfileNetwork: Readable<IPersistedNetwork | undefined> =
1919

2020
export function updateOnboardingProfile(payload: Partial<IOnboardingProfile>): void {
2121
onboardingProfile.update((state) => ({ ...state, ...payload }))
22+
console.log("updated", get(onboardingProfile))
2223
}
2324

2425
export function updateShimmerClaimingAccount(shimmerClaimingAccount: IShimmerClaimingWallet): void {
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,52 @@
11
import { onboardingProfile } from '@contexts/onboarding/stores';
22
import { api } from '@core/api';
3-
import { SecretManager } from '@iota/sdk';
4-
import { Readable, derived, get } from 'svelte/store';
5-
6-
const onboardingProfileSecretManagerOptions = derived(onboardingProfile, ($onboardingProfile) => {
7-
return $onboardingProfile?.secretManagerOptions
8-
});
9-
10-
export const onboardingProfileSecretManager: Readable<SecretManager | null> = derived(onboardingProfileSecretManagerOptions, ($onboardingProfileSecretManagerOptions, set) => {
11-
if ($onboardingProfileSecretManagerOptions) {
12-
api.createSecretManager($onboardingProfileSecretManagerOptions)
13-
.then((secretManager) => {
14-
set(secretManager)
15-
})
3+
import { SecretManager, SecretManagerType } from '@iota/sdk';
4+
import { USE_LEDGER_SIMULATOR } from 'shared/lib/core/ledger';
5+
import { getStorageDirectoryOfProfile, ProfileType } from 'shared/lib/core/profile';
6+
import { get, writable, Writable } from 'svelte/store';
7+
8+
export const onboardingProfileSecretManager: Writable<SecretManager | null> = writable(null);
9+
10+
export async function buildOnboardingSecretManager(){
11+
const profile = get(onboardingProfile);
12+
if(profile){
13+
const { id, type, strongholdPassword } = profile;
14+
15+
const storagePath = await getStorageDirectoryOfProfile(id)
16+
const secretManagerOptions = getSecretManagerFromProfileType(type, {
17+
storagePath,
18+
strongholdPassword
19+
})
20+
21+
console.log("options", secretManagerOptions)
22+
23+
const secretManager = await api.createSecretManager(secretManagerOptions);
24+
25+
onboardingProfileSecretManager.set(secretManager)
1626
} else {
17-
set(null)
27+
onboardingProfileSecretManager.set(null)
1828
}
19-
})
29+
}
2030

2131
export function isOnboardingSecretManagerInitialized(): boolean {
2232
return !!get(onboardingProfileSecretManager)
2333
}
34+
35+
export function getSecretManagerFromProfileType(type?: ProfileType, { storagePath, strongholdPassword }: {
36+
storagePath?: string, strongholdPassword?: string
37+
} = {}): SecretManagerType {
38+
const strongholdSecretManager = {
39+
stronghold: { snapshotPath: `${storagePath}/wallet.stronghold`, password: strongholdPassword },
40+
}
41+
const ledgerSecretManager = {
42+
ledgerNano: USE_LEDGER_SIMULATOR,
43+
}
44+
45+
switch (type) {
46+
case ProfileType.Ledger:
47+
return ledgerSecretManager
48+
case ProfileType.Software:
49+
default:
50+
return strongholdSecretManager
51+
}
52+
}

Diff for: packages/shared/lib/core/profile/actions/active-profile/login.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
4848
// Step 1: create profile manager if its doesn't exist
4949
incrementLoginProgress()
5050
await waitForPreviousManagerToBeDestroyed()
51-
if (!isOnboardingSecretManagerInitialized()) {
52-
// TODO(2.0) Not sure about this
53-
await initialiseOnboardingProfileWithSecretManager(true)
54-
}
51+
// if (!isOnboardingSecretManagerInitialized()) {
52+
// // TODO(2.0) Not sure about this
53+
// await initialiseOnboardingProfileWithSecretManager(true)
54+
// }
5555

5656
// Step 3: load and build all the profile data
5757
incrementLoginProgress()

Diff for: packages/shared/lib/core/profile/actions/createWallet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { selectedWalletId } from '../../wallet'
1515
- __wallet2__/
1616
*/
1717
export async function createWallet(activeProfile = get(activeProfileStore)): Promise<IWallet> {
18-
const id = generateRandomId()
18+
const id = activeProfile.id;
1919
const storagePath = await getStorageDirectoryOfProfile(id)
2020
// const snapshotPath = ''
2121

Diff for: packages/shared/lib/core/profile/interfaces/persisted-profile.interface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface IPersistedProfile {
2020
hasVisitedDashboard?: boolean
2121
lastUsedWalletId?: string // Todo(2.0) Fix all usages of lastUsedAccountIndex
2222
clientOptions: ClientOptions
23-
secretManagerOptions: SecretManagerType,
23+
secretManagerOptions: SecretManagerType, // TODO(2.0) This sould be gone.
2424
forceAssetRefresh: boolean
2525
strongholdVersion?: StrongholdVersion
2626
needsChrysalisToStardustDbMigration?: boolean

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

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export async function storeMnemonic(mnemonic: string): Promise<void> {
66
// TODO(2.0) There are two secret managers, but we might only actually need one to store the mnemonic.
77
const secretManager = get(onboardingProfileSecretManager)
88

9+
console.log(secretManager)
10+
911
if (!secretManager) {
1012
return undefined
1113
}

0 commit comments

Comments
 (0)