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

enhancement: delete profile while logged out #2464

Merged
merged 3 commits into from
May 10, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script lang="ts">
import { IconName, Menu } from '@bloomwalletio/ui'
import { deleteProfile } from '@contexts/settings/actions'
import { localize } from '@core/i18n'
import { IPersistedProfile } from '@core/profile'
import { PopupId, openPopup } from '@desktop/auxiliary/popup'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'

export let profile: IPersistedProfile

Expand All @@ -18,6 +19,26 @@
false
)
}

function onDeleteClick(): void {
openPopup(
{
id: PopupId.Confirmation,
props: {
variant: 'danger',
title: localize('popups.deleteProfile.title', { name: profile.name }),
alert: { variant: 'warning', text: localize('popups.deleteProfile.confirmation') },
confirmText: localize('actions.delete'),
onConfirm: () => {
deleteProfile(profile.id)
closePopup()
},
},
},
false,
false
)
}
</script>

<Menu
Expand All @@ -27,5 +48,11 @@
title: localize('popups.profileDiagnostics.title'),
onClick: onDiagnosticsClick,
},
{
variant: 'danger',
icon: IconName.Trash,
title: localize('views.settings.deleteProfile.title'),
onClick: onDeleteClick,
},
]}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { localize } from '@core/i18n'
import { PopupId, openPopup } from '@desktop/auxiliary/popup'
import SettingsSection from '../SettingsSection.svelte'
import { getActiveProfileId } from '@core/profile/stores'

function onDeleteClick(): void {
openPopup({
Expand All @@ -13,7 +14,7 @@
title: localize('popups.deleteProfile.title'),
alert: { variant: 'warning', text: localize('popups.deleteProfile.confirmation') },
confirmText: localize('actions.delete'),
onConfirm: deleteProfile,
onConfirm: () => deleteProfile(getActiveProfileId() as string),
},
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppContext } from '@core/app/enums'
import { removeProfileFolder } from '@core/profile'
import { logout, removeAllProfileData } from '@core/profile/actions'
import { activeProfileId, profiles } from '@core/profile/stores'
import { profiles } from '@core/profile/stores'
import { routerManager } from '@core/router/stores'
import { get } from 'svelte/store'

Expand All @@ -10,13 +10,8 @@ import { get } from 'svelte/store'
* the file system, and logs the user out
* @returns A Promise that resolves to void.
*/
export async function deleteProfile(): Promise<void> {
export async function deleteProfile(profileId: string): Promise<void> {
try {
const _activeProfileId = get(activeProfileId)
if (!_activeProfileId) {
return
}

/**
* CAUTION: Logout must occur before the profile is removed
* from the Svelte store list of profiles.
Expand All @@ -27,13 +22,13 @@ export async function deleteProfile(): Promise<void> {
* CAUTION: The profile and its data must be removed from the
* app's list of profiles that lives as a Svelte store.
*/
removeAllProfileData(_activeProfileId)
removeAllProfileData(profileId)

/**
* CAUTION: This removes the actual directory for the profile,
* so it should occur last.
*/
await removeProfileFolder(_activeProfileId)
await removeProfileFolder(profileId)

/**
* NOTE: If there are no more profiles, then the user should be
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@
"empty": "The error log is empty."
},
"deleteProfile": {
"title": "Delete profile",
"title": "Delete {name} profile",
"confirmation": "Are you sure you want to delete this profile? This operation cannot be undone.",
"typePassword": "Type your password to confirm."
},
Expand Down
Loading