mirror of
https://github.com/lumehq/lume.git
synced 2025-09-20 05:32:35 +02:00
update useStronghold hook
This commit is contained in:
@@ -11,6 +11,8 @@ import { ChatSidebar } from '@app/chat/components/sidebar';
|
|||||||
import { useNDK } from '@libs/ndk/provider';
|
import { useNDK } from '@libs/ndk/provider';
|
||||||
import { createChat, getChatMessages } from '@libs/storage';
|
import { createChat, getChatMessages } from '@libs/storage';
|
||||||
|
|
||||||
|
import { useStronghold } from '@stores/stronghold';
|
||||||
|
|
||||||
import { useAccount } from '@utils/hooks/useAccount';
|
import { useAccount } from '@utils/hooks/useAccount';
|
||||||
|
|
||||||
export function ChatScreen() {
|
export function ChatScreen() {
|
||||||
@@ -30,13 +32,15 @@ export function ChatScreen() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const userPrivkey = useStronghold((state) => state.privkey);
|
||||||
|
|
||||||
const itemContent: any = useCallback(
|
const itemContent: any = useCallback(
|
||||||
(index: string | number) => {
|
(index: string | number) => {
|
||||||
return (
|
return (
|
||||||
<ChatMessageItem
|
<ChatMessageItem
|
||||||
data={data[index]}
|
data={data[index]}
|
||||||
userPubkey={account.pubkey}
|
userPubkey={account.pubkey}
|
||||||
userPrivkey={account.privkey}
|
userPrivkey={userPrivkey}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -131,7 +135,7 @@ export function ChatScreen() {
|
|||||||
<ChatMessageForm
|
<ChatMessageForm
|
||||||
receiverPubkey={pubkey}
|
receiverPubkey={pubkey}
|
||||||
userPubkey={account.pubkey}
|
userPubkey={account.pubkey}
|
||||||
userPrivkey={account.privkey}
|
userPrivkey={userPrivkey}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -2,12 +2,16 @@ import { useState } from 'react';
|
|||||||
|
|
||||||
import { EyeOffIcon, EyeOnIcon } from '@shared/icons';
|
import { EyeOffIcon, EyeOnIcon } from '@shared/icons';
|
||||||
|
|
||||||
|
import { useStronghold } from '@stores/stronghold';
|
||||||
|
|
||||||
import { useAccount } from '@utils/hooks/useAccount';
|
import { useAccount } from '@utils/hooks/useAccount';
|
||||||
|
|
||||||
export function AccountSettingsScreen() {
|
export function AccountSettingsScreen() {
|
||||||
const { status, account } = useAccount();
|
const { status, account } = useAccount();
|
||||||
const [type, setType] = useState('password');
|
const [type, setType] = useState('password');
|
||||||
|
|
||||||
|
const privkey = useStronghold((state) => state.privkey);
|
||||||
|
|
||||||
const showPrivateKey = () => {
|
const showPrivateKey = () => {
|
||||||
if (type === 'password') {
|
if (type === 'password') {
|
||||||
setType('text');
|
setType('text');
|
||||||
@@ -56,7 +60,7 @@ export function AccountSettingsScreen() {
|
|||||||
<input
|
<input
|
||||||
readOnly
|
readOnly
|
||||||
type={type}
|
type={type}
|
||||||
value={account.privkey}
|
value={privkey}
|
||||||
className="relative w-full rounded-lg bg-zinc-800 py-3 pl-3.5 pr-11 text-zinc-100 !outline-none placeholder:text-zinc-400"
|
className="relative w-full rounded-lg bg-zinc-800 py-3 pl-3.5 pr-11 text-zinc-100 !outline-none placeholder:text-zinc-400"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
|
@@ -19,9 +19,11 @@ import { ADD_IMAGEBLOCK_SHORTCUT } from '@stores/shortcuts';
|
|||||||
import { createBlobFromFile } from '@utils/createBlobFromFile';
|
import { createBlobFromFile } from '@utils/createBlobFromFile';
|
||||||
import { dateToUnix } from '@utils/date';
|
import { dateToUnix } from '@utils/date';
|
||||||
import { useAccount } from '@utils/hooks/useAccount';
|
import { useAccount } from '@utils/hooks/useAccount';
|
||||||
|
import { usePublish } from '@utils/hooks/usePublish';
|
||||||
|
|
||||||
export function AddImageBlock() {
|
export function AddImageBlock() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const publish = usePublish();
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
@@ -107,22 +109,11 @@ export function AddImageBlock() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = (data: any) => {
|
const onSubmit = async (data: any) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
const signer = new NDKPrivateKeySigner(account.privkey);
|
// publish file metedata
|
||||||
ndk.signer = signer;
|
await publish({ content: data.title, kind: 1063, tags: tags.current });
|
||||||
|
|
||||||
const event = new NDKEvent(ndk);
|
|
||||||
// build event
|
|
||||||
event.content = data.title;
|
|
||||||
event.kind = 1063;
|
|
||||||
event.created_at = dateToUnix();
|
|
||||||
event.pubkey = account.pubkey;
|
|
||||||
event.tags = tags.current;
|
|
||||||
|
|
||||||
// publish event
|
|
||||||
event.publish();
|
|
||||||
|
|
||||||
// mutate
|
// mutate
|
||||||
block.mutate({ kind: 0, title: data.title, content: data.content });
|
block.mutate({ kind: 0, title: data.title, content: data.content });
|
||||||
|
@@ -12,7 +12,7 @@ export function usePublish() {
|
|||||||
const { account } = useAccount();
|
const { account } = useAccount();
|
||||||
const { load } = useSecureStorage();
|
const { load } = useSecureStorage();
|
||||||
|
|
||||||
const privkey = useStronghold((state) => state.privkey);
|
const cachePrivkey = useStronghold((state) => state.privkey);
|
||||||
|
|
||||||
const publish = async ({
|
const publish = async ({
|
||||||
content,
|
content,
|
||||||
@@ -20,13 +20,18 @@ export function usePublish() {
|
|||||||
tags,
|
tags,
|
||||||
}: {
|
}: {
|
||||||
content: string;
|
content: string;
|
||||||
kind: NDKKind;
|
kind: NDKKind | number;
|
||||||
tags: string[][];
|
tags: string[][];
|
||||||
}): Promise<NDKEvent> => {
|
}): Promise<NDKEvent> => {
|
||||||
const securePrivkey = await load(account.pubkey);
|
let privkey: string;
|
||||||
|
if (cachePrivkey) {
|
||||||
|
privkey = cachePrivkey;
|
||||||
|
} else {
|
||||||
|
privkey = await load(account.pubkey);
|
||||||
|
}
|
||||||
|
|
||||||
const event = new NDKEvent(ndk);
|
const event = new NDKEvent(ndk);
|
||||||
const signer = new NDKPrivateKeySigner(privkey ? privkey : securePrivkey);
|
const signer = new NDKPrivateKeySigner(privkey);
|
||||||
|
|
||||||
event.content = content;
|
event.content = content;
|
||||||
event.kind = kind;
|
event.kind = kind;
|
||||||
|
Reference in New Issue
Block a user