mirror of
https://github.com/lumehq/lume.git
synced 2025-03-26 17:51:51 +01:00
update useStronghold hook
This commit is contained in:
parent
5787eff7d5
commit
8d29e521cc
@ -11,6 +11,8 @@ import { ChatSidebar } from '@app/chat/components/sidebar';
|
||||
import { useNDK } from '@libs/ndk/provider';
|
||||
import { createChat, getChatMessages } from '@libs/storage';
|
||||
|
||||
import { useStronghold } from '@stores/stronghold';
|
||||
|
||||
import { useAccount } from '@utils/hooks/useAccount';
|
||||
|
||||
export function ChatScreen() {
|
||||
@ -30,13 +32,15 @@ export function ChatScreen() {
|
||||
}
|
||||
);
|
||||
|
||||
const userPrivkey = useStronghold((state) => state.privkey);
|
||||
|
||||
const itemContent: any = useCallback(
|
||||
(index: string | number) => {
|
||||
return (
|
||||
<ChatMessageItem
|
||||
data={data[index]}
|
||||
userPubkey={account.pubkey}
|
||||
userPrivkey={account.privkey}
|
||||
userPrivkey={userPrivkey}
|
||||
/>
|
||||
);
|
||||
},
|
||||
@ -131,7 +135,7 @@ export function ChatScreen() {
|
||||
<ChatMessageForm
|
||||
receiverPubkey={pubkey}
|
||||
userPubkey={account.pubkey}
|
||||
userPrivkey={account.privkey}
|
||||
userPrivkey={userPrivkey}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2,12 +2,16 @@ import { useState } from 'react';
|
||||
|
||||
import { EyeOffIcon, EyeOnIcon } from '@shared/icons';
|
||||
|
||||
import { useStronghold } from '@stores/stronghold';
|
||||
|
||||
import { useAccount } from '@utils/hooks/useAccount';
|
||||
|
||||
export function AccountSettingsScreen() {
|
||||
const { status, account } = useAccount();
|
||||
const [type, setType] = useState('password');
|
||||
|
||||
const privkey = useStronghold((state) => state.privkey);
|
||||
|
||||
const showPrivateKey = () => {
|
||||
if (type === 'password') {
|
||||
setType('text');
|
||||
@ -56,7 +60,7 @@ export function AccountSettingsScreen() {
|
||||
<input
|
||||
readOnly
|
||||
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"
|
||||
/>
|
||||
<button
|
||||
|
@ -19,9 +19,11 @@ import { ADD_IMAGEBLOCK_SHORTCUT } from '@stores/shortcuts';
|
||||
import { createBlobFromFile } from '@utils/createBlobFromFile';
|
||||
import { dateToUnix } from '@utils/date';
|
||||
import { useAccount } from '@utils/hooks/useAccount';
|
||||
import { usePublish } from '@utils/hooks/usePublish';
|
||||
|
||||
export function AddImageBlock() {
|
||||
const queryClient = useQueryClient();
|
||||
const publish = usePublish();
|
||||
|
||||
const [loading, setLoading] = 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);
|
||||
|
||||
const signer = new NDKPrivateKeySigner(account.privkey);
|
||||
ndk.signer = signer;
|
||||
|
||||
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();
|
||||
// publish file metedata
|
||||
await publish({ content: data.title, kind: 1063, tags: tags.current });
|
||||
|
||||
// mutate
|
||||
block.mutate({ kind: 0, title: data.title, content: data.content });
|
||||
|
@ -12,7 +12,7 @@ export function usePublish() {
|
||||
const { account } = useAccount();
|
||||
const { load } = useSecureStorage();
|
||||
|
||||
const privkey = useStronghold((state) => state.privkey);
|
||||
const cachePrivkey = useStronghold((state) => state.privkey);
|
||||
|
||||
const publish = async ({
|
||||
content,
|
||||
@ -20,13 +20,18 @@ export function usePublish() {
|
||||
tags,
|
||||
}: {
|
||||
content: string;
|
||||
kind: NDKKind;
|
||||
kind: NDKKind | number;
|
||||
tags: string[][];
|
||||
}): 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 signer = new NDKPrivateKeySigner(privkey ? privkey : securePrivkey);
|
||||
const signer = new NDKPrivateKeySigner(privkey);
|
||||
|
||||
event.content = content;
|
||||
event.kind = kind;
|
||||
|
Loading…
x
Reference in New Issue
Block a user