flotilla/src/routes/settings/profile/+page.svelte

191 lines
6.7 KiB
Svelte
Raw Normal View History

2024-10-02 23:36:08 +00:00
<script lang="ts">
2025-04-09 22:32:18 +00:00
import * as nip19 from "nostr-tools/nip19"
import {Client} from "@pomade/core"
2025-06-06 23:38:11 +00:00
import {hexToBytes} from "@welshman/lib"
2024-11-15 22:25:18 +00:00
import {displayPubkey, displayProfile} from "@welshman/util"
import {pubkey, session, SessionMethod, displayNip05, deriveProfile} from "@welshman/app"
import {slideAndFade} from "@lib/transition"
2025-09-10 22:26:39 +00:00
import PenNewSquare from "@assets/icons/pen-new-square.svg?dataurl"
import UserRounded from "@assets/icons/user-rounded.svg?dataurl"
import Key from "@assets/icons/key-minimalistic.svg?dataurl"
import Letter from "@assets/icons/letter.svg?dataurl"
2025-09-10 22:26:39 +00:00
import LinkRound from "@assets/icons/link-round.svg?dataurl"
import Copy from "@assets/icons/copy.svg?dataurl"
2025-10-28 23:46:49 +00:00
import Settings from "@assets/icons/settings.svg?dataurl"
2025-09-10 22:26:39 +00:00
import AltArrowDown from "@assets/icons/alt-arrow-down.svg?dataurl"
import AltArrowUp from "@assets/icons/alt-arrow-up.svg?dataurl"
import TrashBin2 from "@assets/icons/trash-bin-2.svg?dataurl"
2024-10-02 23:36:08 +00:00
import Icon from "@lib/components/Icon.svelte"
import FieldInline from "@lib/components/FieldInline.svelte"
2024-10-02 23:36:08 +00:00
import Button from "@lib/components/Button.svelte"
import Spinner from "@lib/components/Spinner.svelte"
import ProfileCircle from "@app/components/ProfileCircle.svelte"
2025-10-06 18:23:19 +00:00
import ContentMinimal from "@app/components/ContentMinimal.svelte"
2024-11-15 22:25:18 +00:00
import ProfileEdit from "@app/components/ProfileEdit.svelte"
2025-02-14 23:59:20 +00:00
import ProfileDelete from "@app/components/ProfileDelete.svelte"
import SignerStatus from "@app/components/SignerStatus.svelte"
import PasswordReset from "@app/components/PasswordReset.svelte"
2024-11-27 00:39:49 +00:00
import InfoKeys from "@app/components/InfoKeys.svelte"
import {pushModal} from "@app/util/modal"
import {clip, pushToast} from "@app/util/toast"
2024-10-02 23:36:08 +00:00
2025-07-02 23:48:44 +00:00
const npub = nip19.npubEncode($pubkey!)
2025-04-15 22:45:48 +00:00
const profile = deriveProfile($pubkey!)
2024-10-02 23:36:08 +00:00
const pubkeyDisplay = displayPubkey($pubkey!)
2025-07-02 23:48:44 +00:00
const copyNpub = () => clip(npub)
const copyNsec = () => clip(nip19.nsecEncode(hexToBytes($session!.secret!)))
2024-11-15 22:25:18 +00:00
const startEdit = () => pushModal(ProfileEdit)
2024-11-27 00:39:49 +00:00
2025-02-14 23:59:20 +00:00
const startDelete = () => pushModal(ProfileDelete)
const startPasswordReset = async () => {
loading = true
try {
const {ok, peersByPrefix} = await Client.requestChallenge($session!.email)
if (!ok) {
pushToast({
theme: "error",
message: "Failed to initiate password reset!",
})
}
pushModal(PasswordReset, {peersByPrefix})
} finally {
loading = false
}
}
2026-01-16 18:06:25 +00:00
const startRecovery = () => pushModal(InfoKeys)
2026-01-12 23:21:58 +00:00
let loading = $state(false)
let showAdvanced = $state(false)
2024-10-02 23:36:08 +00:00
</script>
<div class="content column gap-4">
2025-11-05 23:32:55 +00:00
<div class="card2 bg-alt shadow-md">
2024-10-08 18:39:16 +00:00
<div class="flex justify-between gap-2">
<div class="flex max-w-full gap-3">
2024-10-03 21:32:55 +00:00
<div class="py-1">
<ProfileCircle pubkey={$pubkey!} size={10} />
2024-10-03 21:32:55 +00:00
</div>
2024-10-08 18:39:16 +00:00
<div class="flex min-w-0 flex-col">
<div class="flex items-center gap-2">
<div class="text-bold overflow-hidden text-ellipsis">
2025-04-15 22:45:48 +00:00
{displayProfile($profile, pubkeyDisplay)}
2024-10-02 23:36:08 +00:00
</div>
</div>
2024-10-08 18:39:16 +00:00
<div class="overflow-hidden text-ellipsis text-sm opacity-75">
2025-04-15 22:45:48 +00:00
{$profile?.nip05 ? displayNip05($profile.nip05) : pubkeyDisplay}
2024-10-03 21:32:55 +00:00
</div>
2024-10-02 23:36:08 +00:00
</div>
</div>
2026-04-04 16:46:08 +00:00
<Button class="center btn btn-circle btn-neutral -mr-2 -mt-2 h-12 w-12" onclick={startEdit}>
2025-09-10 22:26:39 +00:00
<Icon icon={PenNewSquare} />
2024-10-03 21:32:55 +00:00
</Button>
2024-10-02 23:36:08 +00:00
</div>
2025-04-15 22:45:48 +00:00
{#key $profile?.about}
2025-10-06 18:23:19 +00:00
<ContentMinimal event={{content: $profile?.about || "", tags: []}} />
2024-10-03 21:32:55 +00:00
{/key}
2024-10-02 23:36:08 +00:00
</div>
<div class="card2 bg-alt col-4 shadow-md">
{#if $session?.method === SessionMethod.Pomade}
2024-11-27 00:39:49 +00:00
<FieldInline>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<Icon icon={Letter} />
2025-02-04 00:37:14 +00:00
<p>Email Address</p>
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center gap-2">
2025-09-10 22:26:39 +00:00
<Icon icon={UserRounded} />
2025-02-04 00:37:14 +00:00
<input readonly value={$session.email} class="grow" />
</label>
{/snippet}
2024-11-27 00:39:49 +00:00
</FieldInline>
{/if}
2024-11-15 22:25:18 +00:00
<FieldInline>
2025-02-04 00:37:14 +00:00
{#snippet label()}
2025-03-04 18:58:14 +00:00
<p class="flex items-center gap-3">
2025-09-10 22:26:39 +00:00
<Icon icon={Key} />
2025-03-04 18:58:14 +00:00
Public Key
</p>
2025-02-04 00:37:14 +00:00
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center justify-between gap-2">
<div class="row-2 flex-grow items-center">
2025-09-10 22:26:39 +00:00
<Icon icon={LinkRound} />
2025-07-02 23:48:44 +00:00
<input readonly class="ellipsize flex-grow" value={npub} />
2025-02-04 00:37:14 +00:00
</div>
<Button class="flex items-center" onclick={copyNpub}>
2025-09-10 22:26:39 +00:00
<Icon icon={Copy} />
</Button>
</label>
2025-02-04 00:37:14 +00:00
{/snippet}
{#snippet info()}
<p>
Your public key is your nostr user identifier. It also allows other people to authenticate
your messages.
</p>
{/snippet}
</FieldInline>
{#if $session?.method === "nip01"}
<FieldInline>
{#snippet label()}
2025-03-04 18:58:14 +00:00
<p class="flex items-center gap-3">
2025-09-10 22:26:39 +00:00
<Icon icon={Key} />
2025-03-04 18:58:14 +00:00
Private Key
</p>
2025-02-04 00:37:14 +00:00
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center gap-2">
2025-09-10 22:26:39 +00:00
<Icon icon={LinkRound} />
2025-02-04 00:37:14 +00:00
<input readonly value={$session.secret} class="grow" type="password" />
<Button class="flex items-center" onclick={copyNsec}>
2025-09-10 22:26:39 +00:00
<Icon icon={Copy} />
2025-02-04 00:37:14 +00:00
</Button>
</label>
{/snippet}
{#snippet info()}
<p>Your private key is your nostr password. Keep this somewhere safe!</p>
{/snippet}
2024-11-15 22:25:18 +00:00
</FieldInline>
{/if}
<SignerStatus />
{#if $session?.method === SessionMethod.Pomade}
2026-03-10 22:13:33 +00:00
<div class="flex flex-col lg:flex-row gap-4 lg:gap-2 justify-end">
<Button class="btn" onclick={startPasswordReset}>
<Spinner {loading}>Update your password</Spinner>
</Button>
<Button class="btn btn-primary" onclick={startRecovery}>Start holding your own keys</Button>
</div>
{/if}
2024-11-15 22:25:18 +00:00
</div>
2025-11-05 23:32:55 +00:00
<div class="card2 bg-alt shadow-md">
<div class="flex items-center justify-between">
2025-03-04 18:58:14 +00:00
<strong class="flex items-center gap-3">
2025-09-10 22:26:39 +00:00
<Icon icon={Settings} />
2025-03-04 18:58:14 +00:00
Advanced
</strong>
<Button onclick={() => (showAdvanced = !showAdvanced)}>
{#if showAdvanced}
2025-09-10 22:26:39 +00:00
<Icon icon={AltArrowDown} />
{:else}
2025-09-10 22:26:39 +00:00
<Icon icon={AltArrowUp} />
{/if}
</Button>
</div>
{#if showAdvanced}
2025-03-04 18:58:14 +00:00
<div transition:slideAndFade class="flex flex-col gap-2 pt-4">
2026-01-12 23:21:58 +00:00
<Button class="btn btn-error" onclick={startDelete}>
2025-09-10 22:26:39 +00:00
<Icon icon={TrashBin2} />
Delete your profile
</Button>
</div>
{/if}
2025-02-14 23:59:20 +00:00
</div>
2024-10-02 23:36:08 +00:00
</div>