mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-18 11:13:30 +00:00
update import key flow
This commit is contained in:
parent
8e513404c3
commit
8f8617d8f9
@ -1,3 +1,6 @@
|
|||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { WorldIcon } from '@shared/icons';
|
||||||
import { Image } from '@shared/image';
|
import { Image } from '@shared/image';
|
||||||
|
|
||||||
import { useProfile } from '@utils/hooks/useProfile';
|
import { useProfile } from '@utils/hooks/useProfile';
|
||||||
@ -8,7 +11,7 @@ export function User({ pubkey, fallback }: { pubkey: string; fallback?: string }
|
|||||||
if (status === 'loading') {
|
if (status === 'loading') {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<div className="relative h-10 w-10 shrink-0 animate-pulse rounded-md bg-white/10 backdrop-blur-xl" />
|
<div className="relative h-11 w-11 shrink-0 animate-pulse rounded-md bg-white/10 backdrop-blur-xl" />
|
||||||
<div className="flex w-full flex-1 flex-col items-start gap-1 text-start">
|
<div className="flex w-full flex-1 flex-col items-start gap-1 text-start">
|
||||||
<span className="h-4 w-1/2 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
<span className="h-4 w-1/2 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
||||||
<span className="h-3 w-1/3 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
<span className="h-3 w-1/3 animate-pulse rounded bg-white/10 backdrop-blur-xl" />
|
||||||
@ -24,10 +27,21 @@ export function User({ pubkey, fallback }: { pubkey: string; fallback?: string }
|
|||||||
alt={pubkey}
|
alt={pubkey}
|
||||||
className="h-11 w-11 shrink-0 rounded-lg object-cover"
|
className="h-11 w-11 shrink-0 rounded-lg object-cover"
|
||||||
/>
|
/>
|
||||||
<div className="flex w-full flex-1 flex-col items-start text-start">
|
<div className="flex w-full flex-col items-start gap-1 text-start">
|
||||||
<p className="max-w-[15rem] truncate font-semibold text-white">
|
<div className="inline-flex items-center gap-2">
|
||||||
{user?.name || user?.display_name}
|
<p className="max-w-[15rem] truncate font-semibold leading-none text-white">
|
||||||
</p>
|
{user?.name || user?.display_name}
|
||||||
|
</p>
|
||||||
|
{user?.website ? (
|
||||||
|
<Link
|
||||||
|
to={user.website}
|
||||||
|
target="_blank"
|
||||||
|
className="border-l border-white/10 pl-2"
|
||||||
|
>
|
||||||
|
<WorldIcon className="h-4 w-4 text-white/70 hover:text-white" />{' '}
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
<div className="line-clamp-4 break-all text-sm text-white/70">
|
<div className="line-clamp-4 break-all text-sm text-white/70">
|
||||||
{user?.about || user?.bio || 'No bio'}
|
{user?.about || user?.bio || 'No bio'}
|
||||||
</div>
|
</div>
|
||||||
|
38
src/app/auth/components/userImport.tsx
Normal file
38
src/app/auth/components/userImport.tsx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { Image } from '@shared/image';
|
||||||
|
|
||||||
|
import { useProfile } from '@utils/hooks/useProfile';
|
||||||
|
import { displayNpub } from '@utils/shortenKey';
|
||||||
|
|
||||||
|
export function UserImport({ pubkey }: { pubkey: string }) {
|
||||||
|
const { status, user } = useProfile(pubkey);
|
||||||
|
|
||||||
|
if (status === 'loading') {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2.5">
|
||||||
|
<div className="12 12 relative shrink-0 animate-pulse rounded-lg bg-white/10 backdrop-blur-xl" />
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<span className="h-5 w-1/2 animate-pulse rounded bg-white/10" />
|
||||||
|
<span className="h-4 w-1/3 animate-pulse rounded bg-white/10" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2.5">
|
||||||
|
<Image
|
||||||
|
src={user?.picture || user?.image}
|
||||||
|
alt={pubkey}
|
||||||
|
className="h-12 w-12 shrink-0 rounded-lg object-cover"
|
||||||
|
/>
|
||||||
|
<div className="flex w-full flex-col gap-1">
|
||||||
|
<h3 className="max-w-[15rem] truncate text-lg font-semibold leading-none text-white">
|
||||||
|
{user?.name || user?.display_name}
|
||||||
|
</h3>
|
||||||
|
<p className="leading-none text-white/70">
|
||||||
|
{user?.nip05 || user?.username || displayNpub(pubkey, 16)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@ -66,10 +66,11 @@ export function ImportStep1Screen() {
|
|||||||
// add account to local database
|
// add account to local database
|
||||||
db.createAccount(npub, pubkey);
|
db.createAccount(npub, pubkey);
|
||||||
|
|
||||||
// redirect to step 2
|
// redirect to step 2 with delay 1.2s
|
||||||
navigate('/auth/import/step-2', { replace: true });
|
setTimeout(() => navigate('/auth/import/step-2', { replace: true }), 1200);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
setLoading(false);
|
||||||
setError('privkey', {
|
setError('privkey', {
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
message: 'Private key is invalid, please check again',
|
message: 'Private key is invalid, please check again',
|
||||||
@ -84,20 +85,24 @@ export function ImportStep1Screen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-8 text-center">
|
<div className="mb-4 pb-4">
|
||||||
<h1 className="text-xl font-semibold text-white">Import your key</h1>
|
<h1 className="text-center text-2xl font-semibold text-white">
|
||||||
|
Import your Nostr key
|
||||||
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="mb-0 flex flex-col gap-3">
|
<form onSubmit={handleSubmit(onSubmit)} className="mb-0 flex flex-col gap-3">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<span className="text-base font-semibold text-white/50">Private key</span>
|
<label htmlFor="privkey" className="font-medium text-white">
|
||||||
|
Insert your nostr private key, in nsec or hex format
|
||||||
|
</label>
|
||||||
<input
|
<input
|
||||||
{...register('privkey', { required: true, minLength: 32 })}
|
{...register('privkey', { required: true, minLength: 32 })}
|
||||||
type={'password'}
|
type={'password'}
|
||||||
placeholder="nsec or hexstring"
|
placeholder="nsec1..."
|
||||||
className="relative h-11 w-full rounded-lg bg-white/10 px-3 py-1 text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
className="relative h-12 w-full rounded-lg border-t border-white/10 bg-white/20 px-3 py-1 text-white backdrop-blur-xl placeholder:text-white/70 focus:outline-none"
|
||||||
/>
|
/>
|
||||||
<span className="text-sm text-red-400">
|
<span className="text-sm text-red-500">
|
||||||
{errors.privkey && <p>{errors.privkey.message}</p>}
|
{errors.privkey && <p>{errors.privkey.message}</p>}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@ -105,12 +110,12 @@ export function ImportStep1Screen() {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={!isDirty || !isValid}
|
disabled={!isDirty || !isValid}
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<>
|
<>
|
||||||
<span className="w-5" />
|
<span className="w-5" />
|
||||||
<span>Creating...</span>
|
<span>Importing...</span>
|
||||||
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
@ -86,10 +86,16 @@ export function ImportStep2Screen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-8 text-center">
|
<div className="mb-4 border-b border-white/10 pb-4">
|
||||||
<h1 className="text-xl font-semibold text-white">
|
<h1 className="mb-2 text-center text-2xl font-semibold text-white">
|
||||||
Set password to secure your key
|
Set password to secure your key
|
||||||
</h1>
|
</h1>
|
||||||
|
<p className="text-white/70">
|
||||||
|
Password is not related to your Nostr account. It is only used to secure your
|
||||||
|
keys stored on your local machine and to unlock the app (like unlocking your
|
||||||
|
phone with a passcode). When you move to other Nostr clients, you just need to
|
||||||
|
copy your private key.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-3">
|
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-3">
|
||||||
@ -98,12 +104,12 @@ export function ImportStep2Screen() {
|
|||||||
<input
|
<input
|
||||||
{...register('password', { required: true })}
|
{...register('password', { required: true })}
|
||||||
type={passwordInput}
|
type={passwordInput}
|
||||||
className="relative h-11 w-full rounded-lg bg-white/10 px-3.5 py-1 text-center text-white !outline-none backdrop-blur-xl placeholder:text-white/50"
|
className="relative h-12 w-full rounded-lg border-t border-white/10 bg-white/20 px-3.5 py-1 text-center tracking-widest text-white !outline-none backdrop-blur-xl placeholder:text-white/70"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => showPassword()}
|
onClick={() => showPassword()}
|
||||||
className="group absolute right-2 top-1/2 -translate-y-1/2 transform rounded p-1 backdrop-blur-xl hover:bg-white/10"
|
className="group absolute right-2 top-1/2 -translate-y-1/2 transform rounded p-1 backdrop-blur-xl hover:bg-white/20"
|
||||||
>
|
>
|
||||||
{passwordInput === 'password' ? (
|
{passwordInput === 'password' ? (
|
||||||
<EyeOffIcon className="h-4 w-4 text-white/50 group-hover:text-white" />
|
<EyeOffIcon className="h-4 w-4 text-white/50 group-hover:text-white" />
|
||||||
@ -112,11 +118,6 @@ export function ImportStep2Screen() {
|
|||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm text-white/50">
|
|
||||||
Password is use to unlock app and secure your key store in local machine.
|
|
||||||
When you move to other clients, you just need to copy your private key as
|
|
||||||
nsec or hexstring
|
|
||||||
</p>
|
|
||||||
<span className="text-sm text-red-400">
|
<span className="text-sm text-red-400">
|
||||||
{errors.password && <p>{errors.password.message}</p>}
|
{errors.password && <p>{errors.password.message}</p>}
|
||||||
</span>
|
</span>
|
||||||
@ -125,12 +126,12 @@ export function ImportStep2Screen() {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={!isDirty || !isValid}
|
disabled={!isDirty || !isValid}
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg border-t border-white/10 bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<>
|
<>
|
||||||
<span className="w-5" />
|
<span className="w-5" />
|
||||||
<span>Creating...</span>
|
<span>Securing your account...</span>
|
||||||
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
<LoaderIcon className="h-5 w-5 animate-spin text-white" />
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { User } from '@app/auth/components/user';
|
import { UserImport } from '@app/auth/components/userImport';
|
||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
@ -15,11 +15,11 @@ export function ImportStep3Screen() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const setStep = useOnboarding((state) => state.setStep);
|
const setStep = useOnboarding((state) => state.setStep);
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
|
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
const { fetchUserData, prefetchEvents } = useNostr();
|
const { fetchUserData, prefetchEvents } = useNostr();
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
try {
|
try {
|
||||||
// show loading indicator
|
// show loading indicator
|
||||||
@ -49,17 +49,19 @@ export function ImportStep3Screen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto w-full max-w-md">
|
<div className="mx-auto w-full max-w-md">
|
||||||
<div className="mb-8 text-center">
|
<div className="mb-4 pb-4">
|
||||||
<h1 className="text-xl font-semibold">
|
<h1 className="text-center text-2xl font-semibold text-white">
|
||||||
{loading ? 'Prefetching data...' : 'Continue with'}
|
{loading ? 'Prefetching data...' : 'Your Nostr profile'}
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full rounded-xl bg-white/10 p-4 backdrop-blur-xl">
|
<div className="flex flex-col gap-3">
|
||||||
<div className="flex flex-col gap-3">
|
<div className="rounded-lg border-t border-white/10 bg-white/20 px-3 py-3">
|
||||||
<User pubkey={db.account.pubkey} />
|
<UserImport pubkey={db.account.pubkey} />
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="inline-flex h-11 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
className="inline-flex h-12 w-full items-center justify-between gap-2 rounded-lg bg-fuchsia-500 px-6 font-medium leading-none text-white hover:bg-fuchsia-600 focus:outline-none"
|
||||||
onClick={() => submit()}
|
onClick={() => submit()}
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
@ -76,6 +78,10 @@ export function ImportStep3Screen() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
|
<span className="text-center text-sm text-white/50">
|
||||||
|
By clicking 'Continue', Lume will download your relay list and all
|
||||||
|
events from the last 24 hours. It may take a bit
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user