mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-04-22 16:51:34 +00:00
New NDK instance for message input testing phase only
This commit is contained in:
parent
a26d9da76d
commit
2ad0574ccb
@ -4,25 +4,38 @@ import GenericButton from '@/components/buttons/GenericButton';
|
||||
import { Panel } from 'primereact/panel';
|
||||
import { useNDKContext } from "@/context/NDKContext";
|
||||
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||
import NDK, { NDKNip07Signer } from "@nostr-dev-kit/ndk";
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
|
||||
const MessageInput = ({ onMessageSent }) => {
|
||||
const [message, setMessage] = useState('');
|
||||
const [collapsed, setCollapsed] = useState(true);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const { ndk, addSigner } = useNDKContext();
|
||||
// todo: revert this after testing phase
|
||||
// const { ndk, addSigner } = useNDKContext();
|
||||
const ndk = new NDK({
|
||||
explicitRelayUrls: ["wss://nos.lol/",
|
||||
"wss://relay.damus.io/",
|
||||
"wss://relay.snort.social/",
|
||||
"wss://relay.nostr.band/",
|
||||
"wss://relay.mutinywallet.com/",
|
||||
"wss://relay.primal.net/",
|
||||
"wss://nostr21.com/",
|
||||
"wss://nostrue.com/",
|
||||
"wss://purplerelay.com/"]
|
||||
});
|
||||
const { showToast } = useToast();
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!message.trim() || !ndk || isSubmitting) return;
|
||||
|
||||
setIsSubmitting(true);
|
||||
if (!message.trim() || !ndk) return;
|
||||
|
||||
try {
|
||||
if (!ndk.signer) {
|
||||
await addSigner();
|
||||
}
|
||||
// if (!ndk.signer) {
|
||||
// await addSigner();
|
||||
// }
|
||||
|
||||
const nip07signer = new NDKNip07Signer();
|
||||
await ndk.signer?.user();
|
||||
ndk.signer = nip07signer;
|
||||
const event = new NDKEvent(ndk);
|
||||
event.kind = 1;
|
||||
event.content = message;
|
||||
@ -35,8 +48,6 @@ const MessageInput = ({ onMessageSent }) => {
|
||||
} catch (error) {
|
||||
console.error("Error publishing message:", error);
|
||||
showToast('error', 'Error', 'There was an error sending your message. Please try again.');
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
@ -75,11 +86,10 @@ const MessageInput = ({ onMessageSent }) => {
|
||||
outlined
|
||||
onClick={handleSubmit}
|
||||
className="w-fit py-2"
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
</div>
|
||||
</Panel>
|
||||
);
|
||||
};
|
||||
|
||||
export default MessageInput;
|
||||
export default MessageInput;
|
Loading…
x
Reference in New Issue
Block a user