Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a delay before user can finish V0 migration to encourage reading #1943

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/1943.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a delay before user can finish V0 migration to encourage reading
4 changes: 2 additions & 2 deletions playwright/tests/migrating-v0-ext-persisted-state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test('Migrate from V0 extension persisted state to valid RootState', async ({
),
).toBeVisible()
await page.getByText('I’ve safely stored my mnemonic').check()
await page.getByRole('button', { name: /Next/ }).click()
await page.getByRole('button', { name: /Next/ }).click({ timeout: 8000 })

// await expect(page).toHaveScreenshot({ fullPage: true })
await page.getByRole('button', { name: /Tap to show/ }).click()
Expand All @@ -49,7 +49,7 @@ test('Migrate from V0 extension persisted state to valid RootState', async ({
),
).toBeVisible()
await page.getByText('I’ve safely stored my private keys').check()
await page.getByRole('button', { name: /Open the new version of the wallet/ }).click()
await page.getByRole('button', { name: /Open the new version of the wallet/ }).click({ timeout: 8000 })
})

await test.step('should result in valid RootState', async () => {
Expand Down
32 changes: 32 additions & 0 deletions src/app/components/CountdownButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Button, ButtonExtendedProps } from 'grommet/es6/components/Button'
import { useEffect, useState } from 'react'

export const CountdownButton = (props: Omit<ButtonExtendedProps, 'disabled'>) => {
const [countdown, setCountdown] = useState(5)
const isDisabled = countdown > 0

useEffect(() => {
const timerId = setInterval(() => {
setCountdown(prevCountdown => {
const newCount = prevCountdown - 1
if (newCount <= 0) clearInterval(timerId)
return newCount
})
}, 1000)

return () => clearInterval(timerId)
}, [])

return (
<Button
{...props}
primary
disabled={isDisabled}
label={
<span>
{props.label} {isDisabled && <span>({countdown})</span>}
</span>
}
/>
)
}
7 changes: 4 additions & 3 deletions src/app/components/Persist/MigrateV0StateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { themeActions } from '../../../styles/theme/slice'
import { RevealOverlayButton } from '../RevealOverlayButton'
import { PrivateKeyFormatter } from '../PrivateKeyFormatter'
import { PasswordWrongError } from '../../../types/errors'
import { CountdownButton } from '../CountdownButton'

export function MigrateV0StateForm() {
const { t, i18n } = useTranslation()
Expand Down Expand Up @@ -155,14 +156,14 @@ export function MigrateV0StateForm() {
/>
</FormField>
{migratingV0State.invalidPrivateKeys.length > 0 ? (
<Button
<CountdownButton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have multiple submit buttons to handle different labels?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah - ideally these would trigger different handlers too, but we are using a single Form onSubmit. And could be styled differently, but invalid keys are should be so rare that it doesn't matter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so they are incidentally only different in labels

type="submit"
label={t('migrateV0Extension.nextStep', 'Next')}
fill="horizontal"
primary
/>
) : (
<Button
<CountdownButton
type="submit"
label={t('migrateV0Extension.finishMigration', 'Open the new version of the wallet')}
fill="horizontal"
Expand Down Expand Up @@ -224,7 +225,7 @@ export function MigrateV0StateForm() {
)}
/>
</FormField>
<Button
<CountdownButton
type="submit"
label={t('migrateV0Extension.finishMigration', 'Open the new version of the wallet')}
fill="horizontal"
Expand Down
Loading