Skip to content

Commit

Permalink
feat: adds update stronghold view (#6087)
Browse files Browse the repository at this point in the history
* feat: adds update stronghold router and route

* feat: adds update stronghold view

* enhancement: replace dummy prop

* fix: fix tests

* feat: adds update stronghold view

* fix: add login option to avoid next route call in login function

* fix: removes unused constant

---------

Co-authored-by: Mark Nardi <mark.nardi@iota.org>
  • Loading branch information
jeeanribeiro and MarkNerdi996 committed Mar 8, 2023
1 parent 8543221 commit 7db1923
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/desktop/views/login/LoginRouter.svelte
@@ -1,6 +1,6 @@
<script lang="ts">
import { Transition } from 'shared/components'
import { EnterPinView, SelectProfileView, LoadProfileView } from './views'
import { EnterPinView, SelectProfileView, LoadProfileView, UpdateStrongholdRouter } from './views'
import { loginRoute, LoginRoute } from '@core/router'
</script>

Expand All @@ -12,6 +12,10 @@
<Transition>
<EnterPinView />
</Transition>
{:else if $loginRoute === LoginRoute.UpdateStronghold}
<Transition>
<UpdateStrongholdRouter />
</Transition>
{:else if $loginRoute === LoginRoute.LoadProfile}
<Transition>
<LoadProfileView />
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/views/login/views/EnterPinView.svelte
Expand Up @@ -95,7 +95,7 @@
isBusy = true
const isVerified = await Platform.PincodeManager.verify($activeProfile?.id, pinCode)
if (isVerified) {
void login()
void login({ avoidNextRoute: updateRequired })
$loginRouter.next()
} else {
shake = true
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop/views/login/views/index.js
@@ -1,3 +1,5 @@
export * from './update-stronghold'

export { default as EnterPinView } from './EnterPinView.svelte'
export { default as LoadProfileView } from './LoadProfileView.svelte'
export { default as SelectProfileView } from './SelectProfileView.svelte'
@@ -0,0 +1,9 @@
<script lang="ts">
import { UpdateStrongholdView } from './views'
import { UpdateStrongholdRoute } from '@core/router/enums/login'
import { updateStrongholdRoute } from '@core/router/subrouters/login'
</script>

{#if $updateStrongholdRoute === UpdateStrongholdRoute.Update}
<UpdateStrongholdView />
{/if}
3 changes: 3 additions & 0 deletions packages/desktop/views/login/views/update-stronghold/index.js
@@ -0,0 +1,3 @@
export * from './views'

export { default as UpdateStrongholdRouter } from './UpdateStrongholdRouter'
@@ -0,0 +1,56 @@
<script lang="ts">
import { OnboardingLayout } from '@components'
import { Animation, Button, PasswordInput, Text } from '@ui'
import { HTMLButtonType, TextType } from '@ui/enums'
import { localize } from '@core/i18n'
import { unlockStronghold } from '@core/profile'
import { loginRouter, updateStrongholdRouter } from '@core/router'
let password: string = ''
let passwordError: string = ''
async function onSubmit(): Promise<void> {
try {
await unlockStronghold(password)
$updateStrongholdRouter.next()
} catch (err) {
passwordError = localize(err.message) ?? err.message
return
}
return
}
function onBackClick(): void {
$loginRouter.previous()
}
</script>

<OnboardingLayout {onBackClick}>
<div slot="title">
<Text type={TextType.h2}>
{localize('views.updateStronghold.update.title')}
</Text>
</div>
<div slot="leftpane__content">
<Text secondary classes="mb-12">
{localize('views.updateStronghold.update.body')}
</Text>
<form on:submit|preventDefault={onSubmit} id="update-stronghold-form">
<PasswordInput bind:value={password} bind:error={passwordError} autofocus showRevealToggle />
</form>
</div>
<div slot="leftpane__action">
<Button
type={HTMLButtonType.Submit}
form="update-stronghold-form"
classes="w-full"
disabled={!password || !!passwordError}
>
{localize('actions.continue')}
</Button>
</div>
<div slot="rightpane" class="w-full h-full flex justify-center bg-pastel-blue dark:bg-gray-900">
<Animation classes="setup-anim-aspect-ratio" animation="backup-recovery-phrase-desktop" />
</div>
</OnboardingLayout>
@@ -0,0 +1 @@
export { default as UpdateStrongholdView } from './UpdateStrongholdView.svelte'
Expand Up @@ -136,7 +136,9 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
lastActiveAt.set(new Date())
loggedIn.set(true)
setTimeout(() => {
loginRouter?.next()
if (!loginOptions?.avoidNextRoute) {
loginRouter?.next()
}
resetLoginProgress()
}, 500)

Expand Down
@@ -1,10 +1,10 @@
import { setStrongholdPassword } from '@core/profile-manager'
import { activeProfile } from '@core/profile'
import { activeProfile, IProfile } from '@core/profile'
import { get } from 'svelte/store'
import { setTimeStrongholdLastUnlocked } from '@core/profile/stores'

export async function unlockStronghold(password: string): Promise<void> {
const { isStrongholdLocked } = get(activeProfile)
export async function unlockStronghold(password: string, profile: IProfile = get(activeProfile)): Promise<void> {
const { isStrongholdLocked } = profile
if (get(isStrongholdLocked)) {
try {
await setStrongholdPassword(password)
Expand Down
Expand Up @@ -2,4 +2,5 @@ export interface ILoginOptions {
isFromOnboardingFlow?: boolean
shouldRecoverAccounts?: boolean
shouldCreateAccount?: boolean
avoidNextRoute?: boolean
}
6 changes: 6 additions & 0 deletions packages/shared/locales/en.json
Expand Up @@ -616,6 +616,12 @@
"fetching": "Fetching proposal data",
"hintVote": "You can not vote on a proposal that is in the announcement phase, voting will open in {time}."
}
},
"updateStronghold": {
"update": {
"title": "Update Stronghold",
"body": "Your Stronghold's version is out of date. Provide your password to update Stronghold."
}
}
},
"popups": {
Expand Down

0 comments on commit 7db1923

Please sign in to comment.