Skip to content

Commit

Permalink
Merge pull request #1943 from oasisprotocol/lw/countdown-btn
Browse files Browse the repository at this point in the history
Add a delay before user can finish V0 migration to encourage reading
  • Loading branch information
lukaw3d authored May 21, 2024
2 parents c9dc34f + dfbcf0c commit 67dcf59
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
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
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

0 comments on commit 67dcf59

Please sign in to comment.