Skip to content

Commit 147a2b5

Browse files
Refactor ClearData dialog text.
Signed-off-by: Dmitri Zagidulin <dzagidulin@gmail.com>
1 parent 559f342 commit 147a2b5

4 files changed

Lines changed: 56 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# @interop/was-react Changelog
22

3+
## 0.2.1 - TBD
4+
5+
### Changed
6+
7+
- `ClearDataDialog` warning text is now mode-aware: once connected, it explains
8+
that only the device copy is erased and the data already synced to the Web
9+
Space survives (reconnect to bring it back), instead of the local-only "cannot
10+
be recovered" warning, which was inaccurate in that state.
11+
- `clearLocalData` now also clears the persisted connected session (as `logout`
12+
already did), so clearing data while connected fully disconnects -- the next
13+
page load lands in `local` mode instead of silently reconnecting and syncing
14+
the cleared data back down.
15+
316
## 0.2.0 - 2026-07-20
417

518
### Changed

src/mui/ClearDataDialog.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
* Copyright (c) 2026 Interop Alliance. All rights reserved.
33
*/
44
/**
5-
* The clear-data confirmation dialog (local mode). A dumb presentational
6-
* component over the store's `clearLocalData` action: it confirms the
7-
* destructive reset -- deleting the local replica and minting a brand-new
8-
* anonymous identity -- and nudges the user to export their data first, since a
9-
* local-only, unsynced app has no server copy to recover from. Dismissing the
10-
* dialog (backdrop / escape / Cancel) leaves the data untouched.
5+
* The clear-data confirmation dialog. A dumb presentational component over the
6+
* store's `clearLocalData` action: it confirms the destructive reset --
7+
* deleting the local replica and minting a brand-new anonymous identity. The
8+
* warning text is mode-aware: in `local` mode the device copy is the ONLY copy,
9+
* so it nudges the user to export first; once connected, the copy already
10+
* synced to the Web Space survives the reset, so the text says so instead of
11+
* threatening total loss. Dismissing the dialog (backdrop / escape / Cancel)
12+
* leaves the data untouched.
1113
*/
1214
import {
1315
Button,
@@ -17,7 +19,7 @@ import {
1719
DialogContentText,
1820
DialogTitle
1921
} from '@mui/material'
20-
import { useClearData } from '../react/hooks.js'
22+
import { useClearData, useSession } from '../react/hooks.js'
2123

2224
/**
2325
* @param props {object}
@@ -34,6 +36,8 @@ export function ClearDataDialog({
3436
onClose: () => void
3537
}) {
3638
const clearData = useClearData()
39+
const { status } = useSession()
40+
const connected = status === 'connected' || status === 'reconnect'
3741

3842
async function handleClear(): Promise<void> {
3943
await clearData()
@@ -45,9 +49,15 @@ export function ClearDataDialog({
4549
<DialogTitle>Clear data</DialogTitle>
4650
<DialogContent>
4751
<DialogContentText>
48-
This permanently erases everything stored on this device and starts
49-
you over fresh. Your data lives only on this device, so once cleared
50-
it cannot be recovered -- export a copy first if you want to keep it.
52+
{connected
53+
? 'This erases the copy stored on this device and disconnects it ' +
54+
'from your Web Space. The data already saved to your Web Space ' +
55+
'stays there -- reconnect with your wallet to bring it back ' +
56+
'onto this device.'
57+
: 'This permanently erases everything stored on this device and ' +
58+
'starts you over fresh. Your data lives only on this device, ' +
59+
'so once cleared it cannot be recovered -- export a copy first ' +
60+
'if you want to keep it.'}
5161
</DialogContentText>
5262
</DialogContent>
5363
<DialogActions>

src/session/authStore.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
* anonymous seed + database are deleted once the activation lands. `adopt:
2525
* 'leave'` sets the anonymous replica aside untouched instead (it returns after
2626
* a logout). Logout returns to a fresh `local` (optionally wiping the connected
27-
* replica); `clearLocalData` mints a brand-new anonymous seed and replica.
27+
* replica); `clearLocalData` mints a brand-new anonymous seed and replica and
28+
* drops any persisted connected session.
2829
*
2930
* The library cannot bind a module-level store to app config, so this is a
3031
* FACTORY: {@link createAuthStore} captures the app's {@link WasAppConfig} and
@@ -206,8 +207,10 @@ export interface AuthState {
206207
logout: (options?: { wipe?: boolean }) => Promise<void>
207208
/**
208209
* Delete the local replica, discard the anonymous seed, and mint a fresh
209-
* anonymous seed/DID + replica. The shared reset primitive behind the
210-
* `local`-mode "Clear data" button.
210+
* anonymous seed/DID + replica. Also clears any persisted connected session,
211+
* so clearing while connected fully disconnects (a later boot lands `local`
212+
* instead of silently reconnecting and syncing the data back down). The
213+
* reset primitive behind the "Clear data" button.
211214
*/
212215
clearLocalData: () => Promise<void>
213216
/**
@@ -931,6 +934,7 @@ export function createAuthStore({
931934

932935
clearLocalData: async () => {
933936
await resetToFreshLocal({ deleteDb: true, discardAnonSeed: true })
937+
await clearAppSession({ store: sessionStore })
934938
set({ phase: null, reconnecting: false })
935939
},
936940

test/node/authStore.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* `local -> connected`, tearing down the anonymous replica but leaving its
1616
* seed intact; a cancelled `login()` leaves `local` intact;
1717
* - `logout({ wipe })` keeps vs deletes the connected replica, landing `local`;
18-
* - `clearLocalData()` mints a brand-new anonymous seed/DID and empties stores.
18+
* - `clearLocalData()` mints a brand-new anonymous seed/DID, empties stores,
19+
* and drops any persisted connected session.
1920
*
2021
* @vitest-environment node
2122
*/
@@ -625,4 +626,18 @@ describe('clearLocalData()', () => {
625626
expect(store.getState().controllerDid).toMatch(/^did:key:/)
626627
expect(await requireStore().listEntities('notes')).toHaveLength(0)
627628
})
629+
630+
it('clears the persisted session when run while connected', async () => {
631+
const seedStore = newSeedStore()
632+
await persistSession({ seedStore })
633+
const store = makeStore(baseConfig(), seedStore)
634+
await store.getState().boot()
635+
expect(store.getState().status).toBe('connected')
636+
637+
await store.getState().clearLocalData()
638+
639+
expect(store.getState().status).toBe('local')
640+
// The session record was cleared, so a later boot cannot reconnect.
641+
expect(await seedStore.loadSeed()).toBeNull()
642+
})
628643
})

0 commit comments

Comments
 (0)