Skip to content
Draft
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
11 changes: 10 additions & 1 deletion apps/mobile/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
import {
initializeDatabase,
getDatabase,
bootstrapCollections,
fromKeyValueStorage,
} from '@perawallet/wallet-core-database'
import { seedAlgoAsset } from '@perawallet/wallet-core-assets'
import { initializeSyncService } from '@perawallet/wallet-core-background'
Expand Down Expand Up @@ -98,7 +100,14 @@ const AppContent = () => {
provider.keyValueStorage.setItem(APP_INSTALLED_KEY, '1')

await initializeDatabase(provider.database)
await seedAlgoAsset(getDatabase())
bootstrapCollections({
mmkv: fromKeyValueStorage(provider.keyValueStorage),
})
// Keep a reference to the legacy SQLite handle alive so
// domains that have not yet migrated to the collections
// layer continue to function.
getDatabase()
await seedAlgoAsset()

initializeSyncService({ queryClient })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const mockRemoveItem = vi.fn()
const mockClearKeystore = vi.fn().mockResolvedValue(undefined)
const mockDeleteDatabase = vi.fn().mockResolvedValue(undefined)
const mockInitializeDatabase = vi.fn().mockResolvedValue(undefined)
const mockResetAllCollections = vi.fn()

vi.mock('@perawallet/wallet-extension-provider', () => ({
clearDataStores: vi.fn(),
Expand All @@ -44,6 +45,7 @@ vi.mock('@perawallet/wallet-extension-provider', () => ({
vi.mock('@perawallet/wallet-core-database', () => ({
deleteDatabase: (...args: unknown[]) => mockDeleteDatabase(...args),
initializeDatabase: (...args: unknown[]) => mockInitializeDatabase(...args),
resetAllCollections: () => mockResetAllCollections(),
}))

vi.mock('@perawallet/wallet-core-shared', () => ({
Expand Down
11 changes: 11 additions & 0 deletions apps/mobile/src/modules/settings/hooks/useDeleteAllData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useNetwork } from '@perawallet/wallet-core-blockchain'
import {
deleteDatabase,
initializeDatabase,
resetAllCollections,
} from '@perawallet/wallet-core-database'
import { useDeleteDeviceMutation } from '@perawallet/wallet-core-device'
import { useKMS } from '@perawallet/wallet-core-kms'
Expand Down Expand Up @@ -101,6 +102,16 @@ export const useDeleteAllData = (): UseDeleteAllDataResult => {
logger.error('Failed to delete database', { error: e })
}

// 8. Wipe every TanStack-DB-style collection backed by MMKV.
// Collections persist independently of the SQLite file, so
// `deleteDatabase` does not touch them — they need their own
// reset hook so the app boots into a fully empty state.
try {
resetAllCollections()
} catch (e) {
logger.error('Failed to reset collections', { error: e })
}

clearAllStores({ skip: [ACCOUNTS_STORE_NAME] })
}, [
queryClient,
Expand Down
Loading
Loading