Skip to content

Commit 3116ae5

Browse files
committed
refactor(migration): use global 48h checkpoint expiration
1 parent 6679b92 commit 3116ae5

2 files changed

Lines changed: 5 additions & 27 deletions

File tree

__tests__/screens/account-migration/hooks/use-migration-checkpoint.spec.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe("useMigrationCheckpoint", () => {
106106
})
107107

108108
it("ignores expired checkpoint and removes from storage", async () => {
109-
const expiredTimestamp = Date.now() - 25 * 60 * 60 * 1000 // 25 hours ago
109+
const expiredTimestamp = Date.now() - 49 * 60 * 60 * 1000
110110
mockLoadJson.mockResolvedValue({
111111
step: MigrationCheckpoint.BackupAlerts,
112112
savedAt: expiredTimestamp,
@@ -120,23 +120,8 @@ describe("useMigrationCheckpoint", () => {
120120
expect(mockRemove).toHaveBeenCalledWith("migrationCheckpoint")
121121
})
122122

123-
it("ignores expired backup method checkpoint after 1 hour", async () => {
124-
const expiredTimestamp = Date.now() - 2 * 60 * 60 * 1000 // 2 hours ago
125-
mockLoadJson.mockResolvedValue({
126-
step: MigrationCheckpoint.BackupMethod,
127-
savedAt: expiredTimestamp,
128-
})
129-
130-
const { result } = renderHook(() => useMigrationCheckpoint())
131-
132-
await act(async () => {})
133-
134-
expect(result.current.checkpoint).toBeNull()
135-
expect(mockRemove).toHaveBeenCalledWith("migrationCheckpoint")
136-
})
137-
138-
it("keeps valid backup method checkpoint within 1 hour", async () => {
139-
const recentTimestamp = Date.now() - 30 * 60 * 1000 // 30 minutes ago
123+
it("keeps valid checkpoint within 48 hours", async () => {
124+
const recentTimestamp = Date.now() - 47 * 60 * 60 * 1000
140125
mockLoadJson.mockResolvedValue({
141126
step: MigrationCheckpoint.BackupMethod,
142127
savedAt: recentTimestamp,

app/screens/account-migration/hooks/use-migration-checkpoint.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { useCallback, useEffect, useState } from "react"
33
import { loadJson, remove, saveJson } from "@app/utils/storage"
44

55
const STORAGE_KEY = "migrationCheckpoint"
6-
const SHORT_EXPIRATION_MS = 60 * 60 * 1000 // 1 hour
7-
const DEFAULT_EXPIRATION_MS = 24 * SHORT_EXPIRATION_MS // 24 hours
6+
const EXPIRATION_MS = 48 * 60 * 60 * 1000
87

98
export const MigrationCheckpoint = {
109
BackupMethod: "backupMethod",
@@ -15,12 +14,6 @@ export const MigrationCheckpoint = {
1514
export type MigrationCheckpointType =
1615
(typeof MigrationCheckpoint)[keyof typeof MigrationCheckpoint]
1716

18-
const checkpointExpirationMap: Record<MigrationCheckpointType, number> = {
19-
[MigrationCheckpoint.BackupMethod]: SHORT_EXPIRATION_MS,
20-
[MigrationCheckpoint.CloudBackup]: DEFAULT_EXPIRATION_MS,
21-
[MigrationCheckpoint.BackupAlerts]: DEFAULT_EXPIRATION_MS,
22-
}
23-
2417
const checkpointRouteMap = {
2518
[MigrationCheckpoint.BackupMethod]: "sparkBackupMethodScreen",
2619
[MigrationCheckpoint.CloudBackup]: "sparkCloudBackupScreen",
@@ -50,7 +43,7 @@ export const useMigrationCheckpoint = () => {
5043
}
5144

5245
const typedStep = step as MigrationCheckpointType
53-
if (Date.now() - savedAt > checkpointExpirationMap[typedStep]) {
46+
if (Date.now() - savedAt > EXPIRATION_MS) {
5447
remove(STORAGE_KEY)
5548
setLoading(false)
5649
return

0 commit comments

Comments
 (0)