Skip to content

Commit 27bfbe5

Browse files
cpl121marc2332evavirsedabegonaalvarezd
authored
feat: hook implicit account logic step3 (#7906)
* refactor(2.0): Dynamic password * refactor(2.0): Remove Profile Manager (wip) * clean up and fix * clean up * clean up more code * feat: add account to routes * feat: add to analytics featureflag * feat: add account view and multistep * style: refinements * feat: rename files and add locale * feat: prepare UI step 1 * feat: add locales * fix: update naming * feat: update naming and improve code * fix: move comment * fix import * feat: hook logic * clean up * adapt and remove for profile-manager related code * clean up more code * fmt * fix: remove accountImplicit route and add to wallet tab * fix: improve naming * Update packages/desktop/views/dashboard/wallet/Wallet.svelte * Update packages/desktop/views/dashboard/wallet/Wallet.svelte * more cleanup * fix: add router * minor fixes * more cleanup * ix: add missing dots * fix: colors * fix: remove unnecessary function * fix: rename files * fix: move if/else and key block * fix: reset after finish * small tweaks * fix: undo changes * feat: use implicitAccountCreationAddress * fix: rename and remove onmount * more cleanup * format * update * clean up * feat: hook logic, first steps * fix: add todo * https://api.testnet.shimmer.network * revert Wallet.svelte * clean up * feat: hook logic in implicit account creation step 3 * clean up * clean up * feat: update logic to go next route * fix: update logic * feat: remove getNftByIdFromAllAccountNfts debris * feat: hook implicit account logic step3 done * fix: problem with the merge * fix: avoid reactive error * fix: remove logic duplicated --------- Co-authored-by: marc2332 <[email protected]> Co-authored-by: evavirseda <[email protected]> Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
1 parent 2c44c89 commit 27bfbe5

File tree

5 files changed

+47
-32
lines changed

5 files changed

+47
-32
lines changed

packages/desktop/views/dashboard/wallet/Wallet.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { selectedWallet } from '@core/wallet'
33
import { ImplicitAccountCreationView, WalletView } from './views'
44
5-
$: hasAccount = $selectedWallet.accountOutputs.length !== 0
5+
$: hasAccount = $selectedWallet?.accountOutputs?.length !== 0
66
</script>
77

88
{#if $selectedWallet}
Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
<script lang="ts">
22
import { Button, FontWeight, PasswordInput, Text, TextType } from 'shared/components'
33
import { localize } from '@core/i18n'
4-
import { showAppNotification } from '@auxiliary/notification'
4+
import { selectedWallet } from '@core/wallet'
5+
import { activeProfile, unlockStronghold } from '@core/profile'
6+
import { get } from 'svelte/store'
57
68
let error = ''
9+
let isBusy = false
710
let strongholdPassword = ''
8-
$: strongholdPassword, (error = '')
911
10-
function unlockWalletAndCreateAccount(): void {
11-
// TODO: add logic to active account
12-
showAppNotification({
13-
type: 'error',
14-
alert: true,
15-
message: localize('error.global.generic'),
16-
})
12+
async function unlockWalletAndCreateAccount(): Promise<void> {
13+
isBusy = true
14+
error = ''
15+
try {
16+
if (!strongholdPassword || $selectedWallet?.implicitAccountOutputs.length === 0) return
17+
// TODO(2.0): patch because it comes unlocked by default
18+
const { isStrongholdLocked } = get(activeProfile)
19+
isStrongholdLocked.set(true)
20+
21+
await unlockStronghold(strongholdPassword)
22+
const outputId = $selectedWallet?.implicitAccountOutputs[0].outputId
23+
await $selectedWallet?.implicitAccountTransition(outputId)
24+
} catch (err) {
25+
console.error('err', err)
26+
error = localize(err?.message ?? err)
27+
isBusy = false
28+
}
1729
}
1830
</script>
1931

@@ -29,14 +41,16 @@
2941
>{localize('views.implicit-account-creation.steps.step3.view.title')}</Text
3042
>
3143
<PasswordInput
32-
{error}
44+
bind:error
3345
bind:value={strongholdPassword}
3446
autofocus
3547
submitHandler={unlockWalletAndCreateAccount}
3648
placeholder={localize('views.implicit-account-creation.steps.step3.view.placeholder')}
3749
/>
3850
</div>
39-
<Button onClick={unlockWalletAndCreateAccount}
40-
>{localize('views.implicit-account-creation.steps.step2.view.action')}</Button
51+
<Button
52+
onClick={unlockWalletAndCreateAccount}
53+
disabled={!strongholdPassword || strongholdPassword.length === 0 || isBusy}
54+
{isBusy}>{localize('views.implicit-account-creation.steps.step2.view.action')}</Button
4155
>
4256
</step-content>

packages/shared/lib/core/secret-manager/stores/secret-manager.store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { api } from '@core/api'
2-
import { activeProfile } from '@core/profile/stores/active-profile.store'
2+
import { activeProfile } from '@core/profile/stores'
33
import { SecretManager, SecretManagerType } from '@iota/sdk'
44
import { writable } from 'svelte/store'
55

packages/shared/lib/core/wallet/actions/events-handlers/handleNewOutputEvent.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
addPersistedAsset,
1717
generateActivities,
1818
getOrRequestAssetFromPersistedAssets,
19-
allWalletActivities,
2019
syncBalance,
2120
validateWalletApiEvent,
2221
getBech32AddressFromAddressTypes,
@@ -63,15 +62,23 @@ export async function handleNewOutputEventInternal(walletId: string, payload: Ne
6362
return
6463
}
6564

65+
const isAccountOutput = output.type === OutputType.Account
66+
67+
if (isAccountOutput) {
68+
const accounts = await wallet.accounts()
69+
const depositAddress = await getDepositAddress(wallet)
70+
updateSelectedWallet({
71+
accountOutputs: accounts,
72+
depositAddress,
73+
})
74+
return
75+
}
76+
6677
const address = getBech32AddressFromAddressTypes(outputData.address)
67-
const isNewAliasOutput =
68-
output.type === OutputType.Account &&
69-
!get(allWalletActivities)[walletId].find((_activity) => _activity.id === outputData.outputId)
70-
const isNftOutput = output.type === OutputType.Nft
7178

72-
const isAccountOutput = output.type === OutputType.Account
79+
const isNftOutput = output.type === OutputType.Nft
7380

74-
if ((wallet?.depositAddress === address && !outputData?.remainder) || isNewAliasOutput) {
81+
if (wallet?.depositAddress === address && !outputData?.remainder) {
7582
await syncBalance(wallet.id)
7683
const walletOutputs = await wallet.outputs()
7784
updateActiveWallet(wallet.id, { walletOutputs })
@@ -98,13 +105,4 @@ export async function handleNewOutputEventInternal(walletId: string, payload: Ne
98105

99106
checkAndRemoveProfilePicture()
100107
}
101-
102-
if (isAccountOutput) {
103-
const accounts = await wallet.accounts()
104-
const depositAddress = await getDepositAddress(wallet)
105-
updateSelectedWallet({
106-
accountOutputs: accounts,
107-
depositAddress,
108-
})
109-
}
110108
}

packages/shared/lib/core/wallet/utils/getDepositAddress.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { AccountOutput } from '@iota/sdk'
1+
import { AccountAddress, AccountOutput } from '@iota/sdk/out/types'
22
import { IWallet } from '../../profile/interfaces'
3+
import { getBech32AddressFromAddressTypes } from './getBech32AddressFromAddressTypes'
34

45
// TODO(2.0): Update the implementation to handle multiple accounts and use the selected account's address.
56
export async function getDepositAddress(wallet: IWallet): Promise<string> {
67
const accounts = await wallet?.accounts()
78
if (accounts?.length) {
8-
return (accounts[0]?.output as AccountOutput).accountId ?? ''
9+
const accountId = (accounts[0]?.output as AccountOutput).accountId
10+
const accountAddress = getBech32AddressFromAddressTypes(new AccountAddress(accountId))
11+
return accountAddress ?? ''
912
} else {
1013
return ''
1114
}

0 commit comments

Comments
 (0)