mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-01-30 11:34:20 +01:00
add unlink functionality, "delete" only shows for default keys
This commit is contained in:
committed by
Tony Giorgio
parent
0e3f7d7458
commit
f307be7533
@@ -257,7 +257,6 @@ export async function setupMutinyWallet(
|
||||
|
||||
let nsec;
|
||||
// get nsec from secure storage
|
||||
// TODO: might have to check Capacitor.isNativePlatform but I think it's fine
|
||||
try {
|
||||
const value = await SecureStoragePlugin.get({ key: "nsec" });
|
||||
nsec = value.value;
|
||||
|
||||
@@ -42,11 +42,15 @@ export function Profile() {
|
||||
|
||||
const [copy, copied] = useCopy({ copiedTimeout: 1000 });
|
||||
|
||||
const profileDeleted = createMemo(() => {
|
||||
return profile().deleted === true || profile().deleted === "true";
|
||||
});
|
||||
|
||||
return (
|
||||
<MutinyWalletGuard>
|
||||
<DefaultMain>
|
||||
<BackLink />
|
||||
<Show when={profile() && !profile().deleted}>
|
||||
<Show when={profile() && !profileDeleted()}>
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<LabelCircle
|
||||
contact
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { A } from "@solidjs/router";
|
||||
import { SecureStoragePlugin } from "capacitor-secure-storage-plugin";
|
||||
import { Import, Trash } from "lucide-solid";
|
||||
import { createSignal, Match, Show, Switch } from "solid-js";
|
||||
import { Import, Trash, Unlink } from "lucide-solid";
|
||||
import { createResource, createSignal, Match, Show, Switch } from "solid-js";
|
||||
import { QRCodeSVG } from "solid-qr-code";
|
||||
|
||||
import {
|
||||
@@ -60,7 +60,52 @@ function DeleteAccount() {
|
||||
onConfirm={deleteNostrAccount}
|
||||
onCancel={() => setConfirmOpen(false)}
|
||||
>
|
||||
{i18n.t("settings.nostr_keys.delete_account_confirm")}
|
||||
<p>{i18n.t("settings.nostr_keys.delete_account_confirm")}</p>
|
||||
<p class="font-semibold">
|
||||
{i18n.t("settings.nostr_keys.delete_account_confirm_scary")}
|
||||
</p>
|
||||
</ConfirmDialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function UnlinkAccount() {
|
||||
const i18n = useI18n();
|
||||
|
||||
async function confirmUnlink() {
|
||||
setConfirmOpen(true);
|
||||
}
|
||||
|
||||
const [confirmOpen, setConfirmOpen] = createSignal(false);
|
||||
const [confirmLoading, setConfirmLoading] = createSignal(false);
|
||||
|
||||
async function unlinkNostrAccount() {
|
||||
setConfirmLoading(true);
|
||||
try {
|
||||
await SecureStoragePlugin.clear();
|
||||
window.location.href = "/";
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
setConfirmLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
class="flex w-full items-center justify-center gap-2 rounded-xl border border-white/10 bg-neutral-900 p-2 text-m-grey-350 no-underline active:-mb-[1px] active:mt-[1px] active:opacity-70"
|
||||
onClick={confirmUnlink}
|
||||
>
|
||||
<Unlink class="w-4" />
|
||||
{i18n.t("settings.nostr_keys.unlink_account")}
|
||||
</button>
|
||||
<ConfirmDialog
|
||||
loading={confirmLoading()}
|
||||
open={confirmOpen()}
|
||||
onConfirm={unlinkNostrAccount}
|
||||
onCancel={() => setConfirmOpen(false)}
|
||||
>
|
||||
{i18n.t("settings.nostr_keys.unlink_account_confirm")}
|
||||
</ConfirmDialog>
|
||||
</>
|
||||
);
|
||||
@@ -74,6 +119,19 @@ export function NostrKeys() {
|
||||
const nsec = () => state.mutiny_wallet?.export_nsec();
|
||||
const profile = () => state.mutiny_wallet?.get_nostr_profile();
|
||||
|
||||
// @ts-expect-error we're checking for an extension
|
||||
const windowHasNostr = window.nostr && window.nostr.getPublicKey;
|
||||
|
||||
const [nsecInSecureStorage] = createResource(async () => {
|
||||
try {
|
||||
const value = await SecureStoragePlugin.get({ key: "nsec" });
|
||||
if (value) return true;
|
||||
} catch (e) {
|
||||
console.log("No nsec stored");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<MutinyWalletGuard>
|
||||
<DefaultMain>
|
||||
@@ -111,19 +169,30 @@ export function NostrKeys() {
|
||||
</Show>
|
||||
</VStack>
|
||||
</FancyCard>
|
||||
<A
|
||||
href="/settings/importprofile"
|
||||
class="flex w-full items-center justify-center gap-2 rounded-xl border border-white/10 bg-neutral-900 p-2 text-m-grey-400 no-underline active:-mb-[1px] active:mt-[1px] active:opacity-70"
|
||||
>
|
||||
<Import class="w-4" />
|
||||
{i18n.t("settings.nostr_keys.import_profile")}
|
||||
</A>
|
||||
<DeleteAccount />
|
||||
<Show when={!windowHasNostr}>
|
||||
<A
|
||||
href="/settings/importprofile"
|
||||
class="flex w-full items-center justify-center gap-2 rounded-xl border border-white/10 bg-neutral-900 p-2 text-m-grey-350 no-underline active:-mb-[1px] active:mt-[1px] active:opacity-70"
|
||||
>
|
||||
<Import class="w-4" />
|
||||
{i18n.t("settings.nostr_keys.import_profile")}
|
||||
</A>
|
||||
</Show>
|
||||
<Switch>
|
||||
<Match when={nsecInSecureStorage()}>
|
||||
<UnlinkAccount />
|
||||
</Match>
|
||||
<Match
|
||||
when={!nsecInSecureStorage() && !windowHasNostr}
|
||||
>
|
||||
<DeleteAccount />
|
||||
</Match>
|
||||
</Switch>
|
||||
</Match>
|
||||
<Match when={profile() && profile().deleted}>
|
||||
<A
|
||||
href="/settings/importprofile"
|
||||
class="flex w-full items-center justify-center gap-2 rounded-xl border border-white/10 bg-neutral-900 p-2 text-m-grey-400 no-underline active:-mb-[1px] active:mt-[1px] active:opacity-70"
|
||||
class="flex w-full items-center justify-center gap-2 rounded-xl border border-white/10 bg-neutral-900 p-2 text-m-grey-350 no-underline active:-mb-[1px] active:mt-[1px] active:opacity-70"
|
||||
>
|
||||
<Import class="w-4" />
|
||||
{i18n.t("settings.nostr_keys.import_profile")}
|
||||
|
||||
Reference in New Issue
Block a user