Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Fixed no chrysalis data to migrate #7565

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { api } from '@core/profile-manager'
import { updateProfile } from '@core/profile/stores'
import { getStorageDirectoryOfProfile } from '@core/profile/utils'

const ATTEMPT_MIGRATION_CHRYSALIS_TO_STARUDST_ERROR = 'migration failed no chrysalis data to migrate'

/**
* Updates the profile underlying DB from chrysalis model to stardust.
* @param profileId The profile that needs migration.
Expand All @@ -13,25 +15,39 @@ export async function migrateDbChrysalisToStardust(profileId: string, pinCode: s
const profileDirectory = await getStorageDirectoryOfProfile(profileId)
const response = await api.migrateDbChrysalisToStardust(profileDirectory, pinCode)

const _onSuccess = (): void => {
updateProfile(profileId, { needsChrysalisToStardustDbMigration: undefined })
}

if (response instanceof Error) {
updateProfile(profileId, { needsChrysalisToStardustDbMigration: true })
let reason = ''
let success = false

try {
reason = JSON.parse(response.message).payload?.error

// The 'no chrysalis data to migrate' error only happens when entering a Stardust profile
// that the wallet got migrated (hence the error) but the profile didn't, we can safely skip this error.
if (reason === ATTEMPT_MIGRATION_CHRYSALIS_TO_STARUDST_ERROR) {
success = true
}
} finally {
logAndNotifyError({
type: 'wallet',
message: `Chrysalis database migration failed: ${reason}`,
saveToErrorLog: true,
showNotification: true,
originalError: response,
})
if (success) {
_onSuccess()
} else {
logAndNotifyError({
type: 'wallet',
message: `Chrysalis database migration failed: ${reason}`,
saveToErrorLog: true,
showNotification: true,
originalError: response,
})
}
}

return false
return success
} else {
updateProfile(profileId, { needsChrysalisToStardustDbMigration: undefined })
_onSuccess()
return true
}
}