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 2 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,5 +1,6 @@
<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'
Expand All @@ -18,6 +19,23 @@
false
)
}

function onDeleteClick(): void {
openPopup(
{
id: PopupId.Confirmation,
props: {
variant: 'danger',
title: localize('popups.deleteProfile.title'),
MarkNerdi marked this conversation as resolved.
Show resolved Hide resolved
alert: { variant: 'warning', text: localize('popups.deleteProfile.confirmation') },
confirmText: localize('actions.delete'),
onConfirm: () => deleteProfile(profile.id),
MarkNerdi marked this conversation as resolved.
Show resolved Hide resolved
},
},
false,
false
)
}
</script>

<Menu
Expand All @@ -27,5 +45,11 @@
title: localize('popups.profileDiagnostics.title'),
onClick: onDiagnosticsClick,
},
{
variant: 'danger',
icon: IconName.Trash,
title: localize('popups.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,22 +1,18 @@
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'
import { closePopup } from '../../../../../../desktop/lib/auxiliary/popup'

/**
* It removes the active profile from the app's list of profiles, removes the profile's directory from
* 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,14 +23,15 @@ 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)

closePopup()
MarkNerdi marked this conversation as resolved.
Show resolved Hide resolved
/**
* NOTE: If there are no more profiles, then the user should be
* routed to the welcome screen.
Expand Down
Loading