Files
minibits_wallet/src/models/RootStore.ts
T
minibits-cashandClaude Opus 4.8 3321096fe2 refactor(counters): remove counterBackups (SQLite retention supersedes it)
counterBackups preserved a removed mint's counters in MMKV for restore on
re-add. That's now redundant: mint_counters rows are never deleted on mint
removal and addMint restores via hydrateCountersFromDatabase. Keeping both
also caused a latent double-advance on re-add (updateMintCountersFromBackup
bumped SQLite on top of the retained row).

- MintsStore: remove counterBackups field, CounterBackupModel/CounterBackup
  type, addOrUpdateCounterBackup + updateMintCountersFromBackup, the call in
  removeMint/addMint, and the counterBackups loop in seedCountersToDatabase.
  removeMint now just detaches; addMint relies on hydrate.
- snapshot compat: MintsStore.preProcessSnapshot strips counterBackups from
  old snapshots so applySnapshot tolerates the removed field.
- backup export: drop the counterBackups field (old backups that contain it
  are stripped on import via the same preProcessSnapshot).
- one-time seed (rootStoreModelVersion 35->36): _runMigrations copies any
  removed-mint counters from the RAW pre-upgrade snapshot's counterBackups
  into SQLite, so a later re-add still restores them. Monotonic.

Full suite green (15 suites / 163 tests). counterBackups was the last
counter-adjacent field still in MMKV.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 10:02:04 +02:00

61 lines
2.5 KiB
TypeScript

import {Instance, SnapshotOut, types} from 'mobx-state-tree'
import {MintsStoreModel} from './MintsStore'
import {ContactsStoreModel} from './ContactsStore'
import {TransactionsStoreModel} from './TransactionsStore'
import {UserSettingsStoreModel} from './UserSettingsStore'
import {WalletProfileStoreModel} from './WalletProfileStore'
import {ProofsStoreModel} from './ProofsStore'
import {RelaysStoreModel} from './RelaysStore'
import {WalletStoreModel} from './WalletStore'
import {NwcStoreModel} from './NwcStore'
import {AuthStoreModel} from './AuthStore'
import { log } from '../services'
export const rootStoreModelVersion = 36 // Update this if model changes require migrations defined in setupRootStore.ts
/**
* A RootStore model.
*/
export const RootStoreModel = types
.model('RootStore')
.props({
mintsStore: types.optional(MintsStoreModel, {}),
contactsStore: types.optional(ContactsStoreModel, {}),
transactionsStore: types.optional(TransactionsStoreModel, {}),
userSettingsStore: types.optional(UserSettingsStoreModel, {}),
walletProfileStore: types.optional(WalletProfileStoreModel, {}),
proofsStore: types.optional(ProofsStoreModel, {}),
relaysStore: types.optional(RelaysStoreModel, {}),
walletStore: types.optional(WalletStoreModel, {}), // not persisted
nwcStore: types.optional(NwcStoreModel, {}),
authStore: types.optional(AuthStoreModel, {}), // not persisted
version: types.optional(types.number, rootStoreModelVersion),
})
.actions(self => ({
setVersion(version: number) {
self.version = version
},
reset() {
self.mintsStore = undefined as any
self.contactsStore = undefined as any
self.transactionsStore = undefined as any
self.userSettingsStore = undefined as any
self.walletProfileStore = undefined as any
self.proofsStore = undefined as any
self.relaysStore = undefined as any
self.walletStore = undefined as any
self.nwcStore = undefined as any
self.authStore = undefined as any
log.trace('[RootStore.reset]', 'RootStore reset, all stores cleared.')
}
}))
/**
* The RootStore instance.
*/
export interface RootStore extends Instance<typeof RootStoreModel> {}
/**
* The data of a RootStore.
*/
export interface RootStoreSnapshot extends SnapshotOut<typeof RootStoreModel> {}