Fix missing mint param in exported backup in case db migration failed before

This commit is contained in:
minibits-cash
2024-10-12 23:08:21 +02:00
parent 7116d94a98
commit fcffbc21c4
4 changed files with 25 additions and 43 deletions
+1 -1
View File
@@ -96,7 +96,7 @@ android {
applicationId "com.minibits_wallet"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 58012
versionCode 58013
versionName "0.1.9"
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "minibits_wallet",
"version": "0.1.9-beta.18",
"version": "0.1.9-beta.19",
"private": true,
"scripts": {
"android:clean": "cd android && ./gradlew clean",
+13 -33
View File
@@ -32,7 +32,7 @@ import { ProofsStoreSnapshot } from '../models/ProofsStore'
import { getSnapshot } from 'mobx-state-tree'
import { ContactsStoreSnapshot } from '../models/ContactsStore'
import { MintsStoreSnapshot } from '../models/MintsStore'
import { TransactionsStoreSnapshot } from '../models/TransactionsStore'
import { Database } from '../services'
interface ExportBackupScreenProps extends SettingsStackScreenProps<'ExportBackup'> {}
@@ -44,7 +44,6 @@ export const ExportBackupScreen: FC<ExportBackupScreenProps> =
const {
mintsStore,
contactsStore,
transactionsStore,
proofsStore
} = useStores()
@@ -59,12 +58,21 @@ export const ExportBackupScreen: FC<ExportBackupScreenProps> =
const [isEcashInBackup, setIsEcashInBackup] = useState(true)
const [isMintsInBackup, setIsMintsInBackup] = useState(true)
const [isContactsInBackup, setIsContactsInBackup] = useState(true)
const [isTransactionsInBackup, setIsTransactionsInBackup] = useState(true)
useEffect(() => {
const loadProofs = async () => {
setIsLoading(true)
// log.trace('[loadProofs]', {proofs: proofsStore.proofs})
// fix if rootStore migration failed and some proofs are missing urls
if (proofsStore.allProofs.some(proof => proof.mintUrl.length === 0 )) {
for (const mint of mintsStore.allMints) {
for(const keysetId of mint.keysetIds) {
Database.updateProofsMintUrl(keysetId, mint.mintUrl)
}
}
}
// full refresh of proofs from DB in case the state is broken
await proofsStore.loadProofsFromDatabase()
@@ -88,10 +96,6 @@ export const ExportBackupScreen: FC<ExportBackupScreenProps> =
const toggleBackupContanctsSwitch = () =>
setIsContactsInBackup(previousState => !previousState)
const toggleBackupTransactionsSwitch = () =>
setIsTransactionsInBackup(previousState => !previousState)
const copyBackup = function () {
try {
@@ -115,10 +119,6 @@ export const ExportBackupScreen: FC<ExportBackupScreenProps> =
lastPendingReceivedCheck: undefined
}
let exportedTransactionsStore: TransactionsStoreSnapshot = {
transactions: []
}
if(isEcashInBackup) {
// This is emptied in snapshot postprocess!
exportedProofsStore = {
@@ -138,15 +138,10 @@ export const ExportBackupScreen: FC<ExportBackupScreenProps> =
exportedContactsStore = getSnapshot(contactsStore)
}
if(isTransactionsInBackup) {
exportedTransactionsStore = getSnapshot(transactionsStore)
}
const exportedSnapshot = {
proofsStore: exportedProofsStore,
mintsStore: exportedMintsStore,
contactsStore: exportedContactsStore,
transactionsStore: exportedTransactionsStore
contactsStore: exportedContactsStore,
}
log.trace({exportedSnapshot})
@@ -477,21 +472,6 @@ export const ExportBackupScreen: FC<ExportBackupScreenProps> =
topSeparator
/>
)}
{contactsStore.count > 0 && (
<ListItem
text="Recent transactions"
subText={`Number of transactions: ${transactionsStore.count}`}
RightComponent={
<View style={$rightContainer}>
<Switch
onValueChange={toggleBackupTransactionsSwitch}
value={isTransactionsInBackup}
/>
</View>
}
topSeparator
/>
)}
</>
}
style={[$card]}
+10 -8
View File
@@ -77,8 +77,7 @@ export const ImportBackupScreen: FC<AppStackScreenProps<'ImportBackup'>> = obser
const [walletSnapshot, setWalletSnapshot] = useState<{
proofsStore: ProofsStoreSnapshot,
mintsStore: MintsStoreSnapshot,
contactsStore: ContactsStoreSnapshot,
transactionsStore: TransactionsStoreSnapshot
contactsStore: ContactsStoreSnapshot,
} | undefined>(undefined) // type tbd
const [profileToRecover, setProfileToRecover] = useState<WalletProfileRecord | undefined>(undefined)
const [isLoading, setIsLoading] = useState(false)
@@ -140,6 +139,8 @@ export const ImportBackupScreen: FC<AppStackScreenProps<'ImportBackup'>> = obser
// Used by Import backup flow
const onPasteBackup = async function () {
try {
setStatusMessage('Inserting backup...')
setIsLoading(true)
const maybeBackup = await Clipboard.getString()
if(!maybeBackup) {
@@ -149,6 +150,8 @@ export const ImportBackupScreen: FC<AppStackScreenProps<'ImportBackup'>> = obser
const cleaned = maybeBackup.trim()
setBackup(cleaned)
setStatusMessage('')
setIsLoading(false)
} catch (e: any) {
handleError(e)
}
@@ -163,13 +166,12 @@ export const ImportBackupScreen: FC<AppStackScreenProps<'ImportBackup'>> = obser
const snapshot = JSON.parse(decoded) as {
proofsStore: ProofsStoreSnapshot,
mintsStore: MintsStoreSnapshot,
contactsStore: ContactsStoreSnapshot,
transactionsStore: TransactionsStoreSnapshot
contactsStore: ContactsStoreSnapshot,
}
// log.trace('[getWalletSnapshot]', {snapshot})
if(!snapshot.proofsStore || !snapshot.mintsStore || !snapshot.contactsStore || !snapshot.transactionsStore) {
if(!snapshot.proofsStore || !snapshot.mintsStore || !snapshot.contactsStore) {
throw new Error('Wrong backup format.')
}
@@ -259,8 +261,7 @@ export const ImportBackupScreen: FC<AppStackScreenProps<'ImportBackup'>> = obser
applySnapshot(proofsStore, walletSnapshot.proofsStore)
applySnapshot(mintsStore, walletSnapshot.mintsStore)
applySnapshot(contactsStore, walletSnapshot.contactsStore)
applySnapshot(transactionsStore, walletSnapshot.transactionsStore)
applySnapshot(contactsStore, walletSnapshot.contactsStore)
log.trace('After import', {rootStore})
@@ -341,6 +342,7 @@ export const ImportBackupScreen: FC<AppStackScreenProps<'ImportBackup'>> = obser
const numIconColor = useThemeColor('textDim')
const textHint = useThemeColor('textDim')
const inputBg = useThemeColor('background')
const loadingBg = useThemeColor('background')
const headerTitle = useThemeColor('headerTitle')
if(mnemonicExists && !isAddressOnlyRecovery) {
@@ -582,7 +584,7 @@ export const ImportBackupScreen: FC<AppStackScreenProps<'ImportBackup'>> = obser
/>
{error && <ErrorModal error={error} />}
{info && <InfoModal message={info} />}
{isLoading && <Loading statusMessage={statusMessage} textStyle={{color: 'white'}} style={{backgroundColor: headerBg, opacity: 1}}/>}
{isLoading && <Loading statusMessage={statusMessage} textStyle={{color: 'white'}} style={{backgroundColor: loadingBg, opacity: 1}}/>}
</Screen>
)
}