Skip to content

Commit

Permalink
add unlink functionality, "delete" only shows for default keys
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul authored and TonyGiorgio committed Mar 29, 2024
1 parent 0e3f7d7 commit f307be7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 15 deletions.
5 changes: 4 additions & 1 deletion public/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,10 @@
"learn_more": "Learn more about nostr",
"import_profile": "Import a nostr profile",
"delete_account": "Delete account",
"delete_account_confirm": "Deleting your nostr profile cannot be undone and will disable some social features of the wallet."
"delete_account_confirm": "Deleting a nostr profile cannot be undone and will disable some social features of the wallet.",
"unlink_account": "Unlink nostr profile",
"unlink_account_confirm": "Unlinking your nostr profile will reset your wallet to its default nostr profile.",
"delete_account_confirm_scary": "THIS PROFILE WILL BE DELETED ACROSS ALL NOSTR APPS."
}
},
"swap": {
Expand Down
1 change: 0 additions & 1 deletion src/logic/mutinyWalletSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/routes/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
93 changes: 81 additions & 12 deletions src/routes/settings/NostrKeys.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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>
</>
);
Expand All @@ -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>
Expand Down Expand Up @@ -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")}
Expand Down

0 comments on commit f307be7

Please sign in to comment.