Skip to content

Commit 169324a

Browse files
committed
fixes and clean up
1 parent ce4b1e1 commit 169324a

File tree

15 files changed

+32
-47
lines changed

15 files changed

+32
-47
lines changed

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

+19-14
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ try {
109109
contextBridge.exposeInMainWorld('__WALLET__API__', {
110110
...methods,
111111
async createSecretManager(options) {
112-
const manager = await IotaSdk.SecretManager.create(options)
112+
const manager = IotaSdk.SecretManager.create(options)
113113
bindMethodsAcrossContextBridge(IotaSdk.SecretManager.prototype, manager)
114114
return manager
115115
},
@@ -122,19 +122,23 @@ try {
122122
bindMethodsAcrossContextBridge(IotaSdk.Client.prototype, client)
123123
return client
124124
},
125-
// TODO(2.0): rename to createWallet
126-
async createWallet(id, options) {
127-
const wallet = await IotaSdk.Wallet.create(options)
128-
wallet.id = id
129-
wallets[id] = wallet
130-
bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, wallet)
125+
// TODO(2.0): Is there a difference between this and getWallet? They both really make the same thing
126+
async createWallet(id, walletOptions) {
127+
let wallet = wallets[id]
128+
if (!wallet) {
129+
wallet = await IotaSdk.Wallet.create(walletOptions)
130+
wallet.id = id
131+
wallets[id] = wallet
132+
bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, wallet)
133+
}
131134
return wallet
132135
},
133136
// TODO(2.0): also remove from file system? Does it make sense? file system != memoery
134-
deleteWallet(id) {
137+
async deleteWallet(id) {
135138
if (id && id in wallets) {
136139
const wallet = wallets[id]
137-
wallet.destroy()
140+
await wallet.stopBackgroundSync()
141+
await wallet.destroy()
138142
delete wallets[id]
139143
}
140144
},
@@ -143,6 +147,7 @@ try {
143147
let wallet = wallets[id]
144148
if (!wallet) {
145149
wallet = await IotaSdk.Wallet.create(walletOptions)
150+
wallet.id = id
146151
wallets[id] = wallet
147152
bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, wallet)
148153
}
@@ -155,12 +160,12 @@ try {
155160
accounts.forEach((account) => bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, account))
156161
return accounts
157162
},
158-
clearWalletsFromMemory() {
159-
Object.keys(wallets).forEach((id) => {
160-
const wallet = wallets[id]
161-
wallet.destroy()
163+
async clearWalletsFromMemory() {
164+
for(const [id, wallet] of Object.entries(wallets)){
165+
await wallet.stopBackgroundSync()
166+
await wallet.destroy()
162167
delete wallets[id]
163-
})
168+
}
164169
},
165170
async migrateStrongholdSnapshotV2ToV3(currentPath, newPath, currentPassword, newPassword) {
166171
const snapshotSaltV2 = 'wallet.rs'

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function createOnboardingWallet(name?: string, color?: string): Pro
3434

3535
// 3. Sync the wallet with the Node
3636
// TODO(2.0): test & fix sync when we have iota2.0 nodes
37-
//await wallet.sync(DEFAULT_SYNC_OPTIONS)
37+
await wallet.sync(DEFAULT_SYNC_OPTIONS)
3838
// 4. Create a wrapper over the wallet instance and the persisted data
3939
const [walletState, walletPersistedData] = await buildWalletStateAndPersistedData(wallet, walletName, color)
4040

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

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ 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))
2322
}
2423

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

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ export async function buildOnboardingSecretManager(){
1717
storagePath,
1818
strongholdPassword
1919
})
20-
21-
console.log("options", secretManagerOptions)
22-
20+
2321
const secretManager = await api.createSecretManager(secretManagerOptions);
2422

2523
onboardingProfileSecretManager.set(secretManager)

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

+1-10
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
4747
if (id) {
4848
// Step 1: create profile manager if its doesn't exist
4949
incrementLoginProgress()
50-
console.log(1)
5150
await waitForPreviousManagerToBeDestroyed()
5251
// if (!isOnboardingSecretManagerInitialized()) {
5352
// // TODO(2.0) Not sure about this
@@ -72,7 +71,6 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
7271
} else {
7372
wallets = await getWallets()
7473
}
75-
console.log(2, wallets)
7674
/**
7775
* NOTE: In the case no wallets with funds were recovered, we must
7876
* create one for the new profile.
@@ -88,7 +86,6 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
8886
checkActiveProfileAuth(onSuccess, config, onCancel)
8987
})
9088
const success = await onUnlocked
91-
console.log("success", success)
9289
if (success) {
9390
await createNewWallet()
9491
} else {
@@ -97,14 +94,10 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
9794
}
9895
}
9996

100-
console.log(3)
101-
10297
// Step 4: load wallets
10398
incrementLoginProgress()
10499
await loadWallets()
105100

106-
console.log(4)
107-
108101
let initialSelectedWalletId = get(activeWallets)?.[0]?.id
109102

110103
// TODO(2.0): is needed lastUsedWalletId?
@@ -122,9 +115,7 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
122115
incrementLoginProgress()
123116
await checkAndUpdateActiveProfileNetwork()
124117
void pollNetworkStatus()
125-
126-
console.log(5)
127-
118+
128119
// Step 5: load assets
129120
incrementLoginProgress()
130121
await refreshWalletAssetsForActiveProfile(
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { api } from '@core/api'
2+
import { selectedWalletId } from '@core/wallet'
3+
import { activeWallets } from '../stores'
24

35
export async function clearProfileFromMemory(): Promise<void> {
6+
selectedWalletId.set(null)
7+
activeWallets.set([])
48
await api.clearWalletsFromMemory()
59
}

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

-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export function getWalletOptions(profile: IProfile, storagePath:string): WalletO
1919
},
2020
}
2121

22-
console.log("aaa", walletOptions)
23-
2422
return walletOptions
2523
}
2624

@@ -36,7 +34,6 @@ export async function createWallet(activeProfile = get(activeProfileStore)): Pro
3634
const storagePath = await getStorageDirectoryOfProfile(id)
3735

3836
const walletOptions = getWalletOptions(activeProfile, storagePath);
39-
console.log("walletOptions", walletOptions);
4037

4138
const wallet = await api.createWallet(id, {
4239
...walletOptions,
@@ -45,6 +42,5 @@ export async function createWallet(activeProfile = get(activeProfileStore)): Pro
4542

4643
// TODO(2.0): Fix
4744
selectedWalletId.set(id)
48-
console.log("wallet in createWallet", wallet);
4945
return wallet
5046
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { IWallet } from '../interfaces/wallet.interface'
88
export async function getWallets(): Promise<IWallet[]> {
99
const profile = get(activeProfile)
1010
let wallets: IWallet[] = []
11-
console.log(profile)
1211
if (profile.walletPersistedData) {
1312
wallets = await Promise.all(Object.entries(profile.walletPersistedData)
1413
.map(([id, data]) => api.getWallet(id, data.walletOptions)))

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

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ 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-
119
if (!secretManager) {
1210
return undefined
1311
}

Diff for: packages/shared/lib/core/wallet/actions/buildWalletStateAndPersistedData.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function buildWalletStateAndPersistedData(
1414
): Promise<[IWalletState, IPersistedWalletData]> {
1515
const storagePath = await getStorageDirectoryOfProfile(wallet.id)
1616
const walletOptions = getWalletOptions(get(activeProfile), storagePath)
17-
console.log("walletOptions", walletOptions)
17+
1818
const persistedWalletData: IPersistedWalletData = {
1919
name: name || `${localize('general.wallet')}`,
2020
color: color || getRandomWalletColor(),

Diff for: packages/shared/lib/core/wallet/actions/createNewWallet.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { localize } from '@core/i18n'
22
import { activeWallets, addWalletPersistedDataToActiveProfile, addWalletToActiveWallets, createWallet } from '@core/profile'
33
import { get } from 'svelte/store'
44

5-
import { DEFAULT_SYNC_OPTIONS } from '../../wallet/constants'
6-
import { IWalletState } from '../../wallet/interfaces'
5+
import { DEFAULT_SYNC_OPTIONS } from '@core/wallet/constants'
6+
import { IWalletState } from '@core/wallet/interfaces'
77

88
import { buildWalletStateAndPersistedData } from './buildWalletStateAndPersistedData'
99
import { addEmptyWalletActivitiesToAllWalletActivities } from '../stores'
@@ -17,7 +17,7 @@ export async function createNewWallet(name?: string, color?: string): Promise<IW
1717

1818
// 3. Sync the wallet with the Node
1919
// TODO(2.0): test & fix sync when we have iota2.0 nodes
20-
// await wallet.sync(DEFAULT_SYNC_OPTIONS)
20+
await wallet.sync(DEFAULT_SYNC_OPTIONS)
2121

2222
// 4. Create a wrapper over the wallet instance and the persisted data
2323
const [walletState, walletPersistedData] = await buildWalletStateAndPersistedData(wallet, walletName, color)

Diff for: packages/shared/lib/core/wallet/actions/getClient.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { get } from 'svelte/store';
55

66
export function getClient(): Promise<Client> {
77
const selectedWallet = get(selectedWalletId);
8-
console.log("wallet in getClient", selectedWallet);
98

109
return api.getClientFromWallet(selectedWallet)
1110
}

Diff for: packages/shared/lib/core/wallet/actions/getNodeInfo.ts

-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import { getClient } from './getClient'
44

55
export async function getNodeInfo(url?: string, auth?: IAuth): Promise<INodeInfoResponse> {
66
const client = await getClient();
7-
console.log("client --------------", client);
87

98
const nodeUrl = url ?? (await client.getNode()).url
10-
console.log("nodeUrl --------------", nodeUrl);
119

1210
const nodeInfo = await client.getNodeInfo(nodeUrl, auth)
13-
console.log("nodeInfo --------------", nodeInfo);
1411

1512
return {
1613
url: nodeUrl,

Diff for: packages/shared/lib/core/wallet/actions/loadWallet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export async function loadWallet(wallet: IWallet): Promise<IWalletState> {
99
// Temporary sync on load until we enable background sync and event listeners
1010
const walletId = wallet.id
1111
// TODO(2.0): test & fix sync when we have iota2.0 nodes
12-
// await wallet.sync({ ...DEFAULT_SYNC_OPTIONS })
12+
await wallet.sync({ ...DEFAULT_SYNC_OPTIONS })
1313
const walletPersistedData = getActiveProfilePersistedWalletData(walletId)
14-
console.log("walletPersistedData", walletPersistedData, walletId, wallet)
14+
1515
let accountState: IWalletState
1616
if (walletPersistedData) {
1717
accountState = await buildWalletState(wallet, walletPersistedData)

Diff for: packages/shared/lib/core/wallet/actions/setClientOptions.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { getSelectedWallet } from '../stores'
33

44
export async function setClientOptions(clientOptions: Partial<ClientOptions>): Promise<void> {
55
const wallet = getSelectedWallet();
6-
console.log("wallet in setClientOptions", wallet);
76

87
await wallet.setClientOptions(clientOptions)
98
}

0 commit comments

Comments
 (0)