Skip to content

Commit a758ef1

Browse files
cpl121marc2332
andauthored
refactor: Fix Login and onboarding improvements (#7779)
* refactor: login WIP * fix: selected wallet id * mmm, some improvements and fixes * fixes and improvements * fixes and clean up --------- Co-authored-by: marc2332 <[email protected]>
1 parent f7cfffb commit a758ef1

File tree

88 files changed

+417
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+417
-362
lines changed

packages/desktop/components/AccountSummary.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import { TextType } from '@ui/enums'
55
66
import { localize } from '@core/i18n'
7-
import { nodeInfo } from '@core/network'
7+
import { nodeInfoNetworkName } from '@core/network'
88
import { selectedWalletAssets } from '@core/wallet'
99
import { activeProfile } from '@core/profile'
1010
11-
$: fomattedNetworkName = $nodeInfo?.protocol.networkName
11+
$: fomattedNetworkName = $nodeInfoNetworkName
1212
.split(' ')
1313
.map((word) => word[0].toUpperCase() + word.substring(1))
1414
.join(' ')

packages/desktop/components/AccountSwitcher.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { AccountLabel, Icon, Modal } from '@ui'
2+
import { WalletLabel, Icon, Modal } from '@ui'
33
import { WalletSwitcherModal } from '@components'
44
import { selectedWallet } from '@core/wallet/stores'
55
import { Icon as IconEnum } from '@auxiliary/icon'
@@ -19,7 +19,7 @@
1919
<svelte:window on:click={onOutsideClick} />
2020
<account-switcher>
2121
<button type="button" on:click={onButtonClick} class="flex flex-row justify-center items-center space-x-2">
22-
<AccountLabel account={$selectedWallet} />
22+
<WalletLabel wallet={$selectedWallet} />
2323
<icon-container class:rotate={isModalOpened}>
2424
<Icon height="18" width="18" icon={IconEnum.ChevronDown} classes="text-gray-800 dark:text-white" />
2525
</icon-container>

packages/desktop/components/modals/WalletActionsMenu.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// $selectedWallet?.id === $activeWallets?.length - 1 && $visibleActiveWallets?.length > 1
2121
2222
function onCustomiseAccountClick(): void {
23-
openPopup({ id: PopupId.ManageAccount })
23+
openPopup({ id: PopupId.ManageWallet })
2424
modal?.close()
2525
}
2626

packages/desktop/components/popups/AddNodePopup.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { showAppNotification } from '@auxiliary/notification'
66
import { closePopup } from '@auxiliary/popup'
77
import { Platform } from '@core/app'
8-
import { activeAccounts, activeProfile } from '@core/profile'
8+
import { activeWallets, activeProfile } from '@core/profile'
99
import { registerProposalsForAccounts } from '@contexts/governance'
1010
1111
export let node: INode = structuredClone(EMPTY_NODE)
@@ -33,7 +33,7 @@
3333
}
3434
3535
if (Platform.isFeatureFlagEnabled('governance')) {
36-
await registerProposalsForAccounts({ node }, $activeAccounts)
36+
await registerProposalsForAccounts({ node }, $activeWallets)
3737
}
3838
3939
onSuccess()

packages/desktop/components/popups/AddProposalPopup.svelte

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script lang="ts">
22
import { showAppNotification } from '@auxiliary/notification/actions'
33
import { closePopup, openPopup, PopupId } from '@auxiliary/popup'
4-
import { registerProposalsForAccounts, registeredProposalsForSelectedWallet } from '@contexts/governance'
4+
import { registerProposalsForWallets, registeredProposalsForSelectedWallet } from '@contexts/governance'
55
import { selectedWallet } from '@core/wallet'
66
import { handleError } from '@core/error/handlers/handleError'
77
import { localize } from '@core/i18n'
8-
import { activeAccounts, updateActiveAccountPersistedData } from '@core/profile'
8+
import { activeWallets, updateActiveWalletPersistedData } from '@core/profile'
99
import { truncateString } from '@core/utils/string'
1010
import type { Auth } from '@iota/sdk/out/types'
1111
import { Button, Checkbox, NodeInput, Text, TextInput, TextType } from 'shared/components'
@@ -21,7 +21,7 @@
2121
let nodeInputError: string
2222
let isBusy = false
2323
let isRegisteringAllProposals = false
24-
let isAddingForAllAccounts = false
24+
let isAddingForAllWallets = false
2525
2626
$: isEditMode = !!initialEventId && !!initialNodeUrl
2727
$: disabled = isBusy || !nodeUrl || (!isRegisteringAllProposals && !eventId)
@@ -35,11 +35,11 @@
3535
try {
3636
isBusy = true
3737
await Promise.all([
38-
!isRegisteringAllProposals && validateEventId(!isAddingForAllAccounts && !isEditMode),
38+
!isRegisteringAllProposals && validateEventId(!isAddingForAllWallets && !isEditMode),
3939
nodeInput?.validate(),
4040
])
4141
await registerParticipationWrapper()
42-
updateActiveAccountPersistedData($selectedWallet.id, {
42+
updateActiveWalletPersistedData($selectedWallet.id, {
4343
removedProposalIds: $selectedWallet.removedProposalIds?.filter((id) => id !== inputtedEventId),
4444
})
4545
isBusy = false
@@ -82,8 +82,8 @@
8282
node: { url: nodeUrl, auth },
8383
eventsToRegister: isRegisteringAllProposals ? [] : [eventId],
8484
}
85-
const accounts = isAddingForAllAccounts ? $activeAccounts : [$selectedWallet]
86-
await registerProposalsForAccounts(options, accounts)
85+
const wallets = isAddingForAllWallets ? $activeWallets : [$selectedWallet]
86+
await registerProposalsForWallets(options, wallets)
8787
showAppNotification({
8888
type: 'success',
8989
message: generateSuccessMessage(),
@@ -96,7 +96,7 @@
9696
if (isEditMode) {
9797
return localize('views.governance.proposals.successEdit')
9898
} else {
99-
return localize(`views.governance.proposals.${isAddingForAllAccounts ? 'successAddAll' : 'successAdd'}`, {
99+
return localize(`views.governance.proposals.${isAddingForAllWallets ? 'successAddAll' : 'successAdd'}`, {
100100
values: { numberOfProposals: isRegisteringAllProposals ? 'other' : 'one' },
101101
})
102102
}
@@ -139,7 +139,7 @@
139139
label={localize('views.governance.details.proposalInformation.eventId')}
140140
/>
141141
{#if !isEditMode}
142-
<Checkbox label={localize('popups.addProposal.addToAllAccounts')} bind:checked={isAddingForAllAccounts} />
142+
<Checkbox label={localize('popups.addProposal.addToAllAccounts')} bind:checked={isAddingForAllWallets} />
143143
{/if}
144144
</div>
145145
<div class="flex w-full space-x-4 mt-6">

packages/desktop/components/popups/CreateWalletPopup.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<Input
7474
{error}
7575
bind:value={accountAlias}
76-
placeholder={localize('general.accountName')}
76+
placeholder={localize('general.walletName')}
7777
autofocus
7878
submitHandler={onCreateClick}
7979
disabled={isBusy}

packages/desktop/components/popups/ManageAccountPopup.svelte renamed to packages/desktop/components/popups/ManageWalletPopup.svelte

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
<script lang="ts">
22
import { closePopup } from '@auxiliary/popup'
33
import { localize } from '@core/i18n'
4-
import { updateActiveAccountPersistedData } from '@core/profile/actions'
4+
import { updateActiveWalletPersistedData } from '@core/profile/actions'
55
import { getTrimmedLength } from '@core/utils'
66
import { selectedWallet, validateWalletName } from '@core/wallet'
77
import { Button, ColorPicker, Input, Text, TextType } from '@ui'
88
99
export let error = ''
1010
1111
let isBusy = false
12-
let accountAlias = $selectedWallet.name
12+
let walletAlias = $selectedWallet.name
1313
let color = $selectedWallet.color
1414
15-
$: accountAlias, (error = '')
16-
$: trimmedAccountAlias = accountAlias.trim()
17-
$: invalidAliasUpdate = !getTrimmedLength(accountAlias) || isBusy || accountAlias === $selectedWallet.name
15+
$: walletAlias, (error = '')
16+
$: trimmedWalletAlias = walletAlias.trim()
17+
$: invalidAliasUpdate = !getTrimmedLength(walletAlias) || isBusy || walletAlias === $selectedWallet.name
1818
$: hasColorChanged = $selectedWallet.color !== color
1919
2020
async function onSaveClick(): Promise<void> {
21-
if (trimmedAccountAlias) {
21+
if (trimmedWalletAlias) {
2222
error = ''
2323
try {
24-
await validateWalletName(trimmedAccountAlias, true, trimmedAccountAlias !== $selectedWallet.name)
24+
await validateWalletName(trimmedWalletAlias, true, trimmedWalletAlias !== $selectedWallet.name)
2525
} catch ({ message }) {
2626
error = message
2727
return
2828
}
2929
3030
isBusy = true
31-
saveAccountPersistedData()
31+
saveWalletPersistedData()
3232
}
3333
}
3434
3535
function onCancelClick(): void {
3636
closePopup()
3737
}
3838
39-
function saveAccountPersistedData(): void {
39+
function saveWalletPersistedData(): void {
4040
try {
41-
if (trimmedAccountAlias || color) {
42-
updateActiveAccountPersistedData($selectedWallet?.id, { name: trimmedAccountAlias, color })
41+
if (trimmedWalletAlias || color) {
42+
updateActiveWalletPersistedData($selectedWallet?.id, { name: trimmedWalletAlias, color })
4343
closePopup()
4444
}
4545
} finally {
@@ -51,13 +51,13 @@
5151
<manage-account-popup class="flex flex-col h-full justify-between space-y-4">
5252
<div>
5353
<title-container class="flex flex-row mb-6">
54-
<Text type={TextType.h5}>{localize('general.manageAccount')}</Text>
54+
<Text type={TextType.h5}>{localize('general.manageWallet')}</Text>
5555
</title-container>
5656
<manage-account-popup-inputs class="w-full flex flex-col justify-between space-y-4">
5757
<Input
5858
{error}
59-
bind:value={accountAlias}
60-
placeholder={localize('general.accountName')}
59+
bind:value={walletAlias}
60+
placeholder={localize('general.walletName')}
6161
autofocus
6262
submitHandler={onSaveClick}
6363
disabled={isBusy}

packages/desktop/components/popups/Popup.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import LedgerAppGuidePopup from './LedgerAppGuidePopup.svelte'
3131
import LedgerConnectionGuidePopup from './LedgerConnectionGuidePopup.svelte'
3232
import LegalUpdatePopup from './LegalUpdatePopup.svelte'
33-
import ManageAccountPopup from './ManageAccountPopup.svelte'
33+
import ManageWalletPopup from './ManageWalletPopup.svelte'
3434
import ManageVotingPowerPopup from './ManageVotingPowerPopup.svelte'
3535
import MintNativeTokenConfirmationPopup from './MintNativeTokenConfirmationPopup.svelte'
3636
import MintNativeTokenFormPopup from './MintNativeTokenFormPopup.svelte'
@@ -79,7 +79,7 @@
7979
$: switch (id) {
8080
case PopupId.ConnectLedger:
8181
case PopupId.createWallet:
82-
case PopupId.ManageAccount:
82+
case PopupId.ManageWallet:
8383
size = PopupSize.Small
8484
break
8585
case PopupId.LedgerAppGuide:
@@ -116,7 +116,7 @@
116116
[PopupId.LedgerAppGuide]: LedgerAppGuidePopup,
117117
[PopupId.LedgerConnection]: LedgerConnectionGuidePopup,
118118
[PopupId.LegalUpdate]: LegalUpdatePopup,
119-
[PopupId.ManageAccount]: ManageAccountPopup,
119+
[PopupId.ManageWallet]: ManageWalletPopup,
120120
[PopupId.ManageVotingPower]: ManageVotingPowerPopup,
121121
[PopupId.MetricSystemInfo]: MetricSystemInfoPopup,
122122
[PopupId.MintNativeTokenConfirmation]: MintNativeTokenConfirmationPopup,

packages/desktop/components/popups/RemoveProposalPopup.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import { selectedWallet } from '@core/wallet/stores'
1212
import { handleError } from '@core/error/handlers'
1313
import { localize } from '@core/i18n'
14-
import { updateActiveAccountPersistedData } from '@core/profile/actions'
14+
import { updateActiveWalletPersistedData } from '@core/profile/actions'
1515
import { governanceRouter } from '@core/router'
1616
import { Button, Text, TextHint, TextType } from 'shared/components'
1717
import { ButtonVariant, TextHintVariant } from 'shared/components/enums'
@@ -23,7 +23,7 @@
2323
async function onConfirmClick(): Promise<void> {
2424
try {
2525
await $selectedWallet.deregisterParticipationEvent($selectedProposalId)
26-
updateActiveAccountPersistedData($selectedWallet.id, {
26+
updateActiveWalletPersistedData($selectedWallet.id, {
2727
removedProposalIds: [...($selectedWallet.removedProposalIds ?? []), $selectedProposalId],
2828
})
2929
$governanceRouter.previous()

packages/desktop/electron/preload.js

+32-18
Original file line numberDiff line numberDiff line change
@@ -109,49 +109,63 @@ try {
109109
contextBridge.exposeInMainWorld('__WALLET__API__', {
110110
...methods,
111111
async createSecretManager(options) {
112-
const manager = new IotaSdk.SecretManager(options)
112+
const manager = IotaSdk.SecretManager.create(options)
113113
bindMethodsAcrossContextBridge(IotaSdk.SecretManager.prototype, manager)
114114
return manager
115115
},
116-
// TODO(2.0): rename to createWallet
117-
async createWallet(id, options) {
118-
const wallet = new IotaSdk.Wallet(options)
119-
wallet.id = id
120-
wallets[id] = wallet
121-
bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, wallet)
116+
async getClientFromWallet(id){
117+
const wallet = wallets[id];
118+
// Why is this here?:
119+
// We cannot create classes from exposed functions
120+
// https://www.electronjs.org/docs/latest/api/context-bridge
121+
const client = await wallet.getClient();
122+
bindMethodsAcrossContextBridge(IotaSdk.Client.prototype, client)
123+
return client
124+
},
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+
}
122134
return wallet
123135
},
124-
// TODO(2.0): also remove from file system
125-
deleteWallet(id) {
136+
// TODO(2.0): also remove from file system? Does it make sense? file system != memoery
137+
async deleteWallet(id) {
126138
if (id && id in wallets) {
127139
const wallet = wallets[id]
128-
wallet.destroy()
140+
await wallet.stopBackgroundSync()
141+
await wallet.destroy()
129142
delete wallets[id]
130143
}
131144
},
132145
// TODO(2.0): Rename this to getWallet and fix all usages
133146
async getWallet(id, walletOptions) {
134147
let wallet = wallets[id]
135148
if (!wallet) {
136-
wallet = new IotaSdk.Wallet(walletOptions)
149+
wallet = await IotaSdk.Wallet.create(walletOptions)
150+
wallet.id = id
137151
wallets[id] = wallet
138-
bindMethodsAcrossContextBridge(IotaSdk.Account.prototype, wallet)
152+
bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, wallet)
139153
}
140154
return wallet
141155
},
142156
// TODO(2.0): remove this method from here and move to new profile
143157
async recoverAccounts(managerId, payload) {
144158
const manager = wallets[managerId]
145159
const accounts = await manager.recoverAccounts(...Object.values(payload))
146-
accounts.forEach((account) => bindMethodsAcrossContextBridge(IotaSdk.Account.prototype, account))
160+
accounts.forEach((account) => bindMethodsAcrossContextBridge(IotaSdk.Wallet.prototype, account))
147161
return accounts
148162
},
149-
clearWalletsFromMemory() {
150-
Object.keys(wallets).forEach((id) => {
151-
const wallet = wallets[id]
152-
wallet.destroy()
163+
async clearWalletsFromMemory() {
164+
for(const [id, wallet] of Object.entries(wallets)){
165+
await wallet.stopBackgroundSync()
166+
await wallet.destroy()
153167
delete wallets[id]
154-
})
168+
}
155169
},
156170
async migrateStrongholdSnapshotV2ToV3(currentPath, newPath, currentPassword, newPassword) {
157171
const snapshotSaltV2 = 'wallet.rs'

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

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
async function onAddProfileClick(): Promise<void> {
3232
onboardingRouter.set(new OnboardingRouter())
3333
await initialiseOnboardingProfile(shouldBeDeveloperProfile())
34-
console.log("shuld be created")
3534
$routerManager.goToAppContext(AppContext.Onboarding)
3635
}
3736

packages/desktop/views/onboarding/views/complete-onboarding/views/FinishOnboardingView.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
}
2929
3030
async function _continue(): Promise<void> {
31-
console.log($onboardingProfile)
3231
// Note: needed to cover the cases where the user has waited so long that the stronghold is locked
3332
if ($onboardingProfile?.restoreProfileType === RestoreProfileType.Stronghold) {
3433
await setStrongholdPassword($onboardingProfile.strongholdPassword)

packages/desktop/views/onboarding/views/create-profile/views/ChooseCreateProfileFlowView.svelte

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
const type = createProfileType === CreateProfileType.Ledger ? ProfileType.Ledger : ProfileType.Software
2929
const storagePath = await getStorageDirectoryOfProfile($onboardingProfile.id)
3030
const secretManagerOptions = getSecretManagerFromProfileType(type, storagePath)
31-
console.log("secretManagerOptions", secretManagerOptions)
3231
updateOnboardingProfile({ createProfileType, type, secretManagerOptions })
3332
$createProfileRouter.next()
3433
}

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)

0 commit comments

Comments
 (0)