chore(git): merge branch 'staging' into 92-send-completion-dm
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 50s

This commit is contained in:
en 2025-03-06 16:07:02 +00:00
commit bb9febe25d
2 changed files with 66 additions and 56 deletions

View File

@ -112,6 +112,9 @@ export const DisplaySigit = ({
</> </>
)} )}
</div> </div>
{
// TODO: enable buttons once feature is ready
false && (
<div className={styles.itemActions}> <div className={styles.itemActions}>
<Tooltip title="Duplicate" arrow placement="top" disableInteractive> <Tooltip title="Duplicate" arrow placement="top" disableInteractive>
<Button <Button
@ -138,6 +141,8 @@ export const DisplaySigit = ({
</Button> </Button>
</Tooltip> </Tooltip>
</div> </div>
)
}
</div> </div>
) )
} }

View File

@ -46,7 +46,8 @@ import {
DEFAULT_TOOLBOX, DEFAULT_TOOLBOX,
settleAllFullfilfedPromises, settleAllFullfilfedPromises,
parseNostrEvent, parseNostrEvent,
uploadMetaToFileStorage uploadMetaToFileStorage,
timeout
} from '../../utils' } from '../../utils'
import { Container } from '../../components/Container' import { Container } from '../../components/Container'
import fileListStyles from '../../components/FileList/style.module.scss' import fileListStyles from '../../components/FileList/style.module.scss'
@ -81,6 +82,7 @@ import { useNDKContext } from '../../hooks/useNDKContext.ts'
import { useNDK } from '../../hooks/useNDK.ts' import { useNDK } from '../../hooks/useNDK.ts'
import { useImmer } from 'use-immer' import { useImmer } from 'use-immer'
import { ButtonUnderline } from '../../components/ButtonUnderline/index.tsx' import { ButtonUnderline } from '../../components/ButtonUnderline/index.tsx'
import { TimeoutError } from '../../types/errors/TimeoutError.ts'
type FoundUser = NostrEvent & { npub: string } type FoundUser = NostrEvent & { npub: string }
@ -165,8 +167,8 @@ export const CreatePage = () => {
return pubkey return pubkey
} }
const handleSearchUsers = async (searchValue?: string) => { const handleSearchUsers = async () => {
const searchString = searchValue || userSearchInput || undefined const searchString = userSearchInput || undefined
if (!searchString) return if (!searchString) return
@ -174,6 +176,7 @@ export const CreatePage = () => {
const searchTerm = searchString.trim() const searchTerm = searchString.trim()
Promise.race([
fetchEventsFromUserRelays( fetchEventsFromUserRelays(
{ {
kinds: [0], kinds: [0],
@ -181,7 +184,9 @@ export const CreatePage = () => {
}, },
usersPubkey, usersPubkey,
UserRelaysType.Write UserRelaysType.Write
) ),
timeout(30000)
])
.then((events) => { .then((events) => {
const nostrEvents = events.map((event) => event.rawEvent()) const nostrEvents = events.map((event) => event.rawEvent())
@ -219,6 +224,9 @@ export const CreatePage = () => {
toast.info('No user found with the provided search term') toast.info('No user found with the provided search term')
}) })
.catch((error) => { .catch((error) => {
if (error instanceof TimeoutError) {
toast.error('Search timed out. Please try again.')
}
console.error(error) console.error(error)
}) })
.finally(() => { .finally(() => {
@ -248,22 +256,23 @@ export const CreatePage = () => {
// If pasted user npub of nip05 is present, we just add the user to the counterparts list // If pasted user npub of nip05 is present, we just add the user to the counterparts list
if (pastedUserNpubOrNip05) { if (pastedUserNpubOrNip05) {
setUserInput(pastedUserNpubOrNip05) setUserInput(pastedUserNpubOrNip05.trim())
setPastedUserNpubOrNip05(undefined) setPastedUserNpubOrNip05(undefined)
} else { } else {
// Otherwize if search already provided some results, user must manually click the search button // Otherwise if search already provided some results, user must manually click the search button
if (!foundUsers.length) { if (!foundUsers.length) {
const searchTerm = userSearchInput.trim()
// If it's NIP05 (includes @ or is a valid domain) send request to .well-known // If it's NIP05 (includes @ or is a valid domain) send request to .well-known
const domainRegex = /^[a-zA-Z0-9@.-]+\.[a-zA-Z]{2,}$/ const domainRegex = /^[a-zA-Z0-9@.-]+\.[a-zA-Z]{2,}$/
if (domainRegex.test(userSearchInput)) { if (searchTerm.startsWith('_@') || domainRegex.test(searchTerm)) {
setSearchUsersLoading(true) setSearchUsersLoading(true)
const pubkey = await handleSearchUserNip05(userSearchInput) const pubkey = await handleSearchUserNip05(searchTerm)
setSearchUsersLoading(false) setSearchUsersLoading(false)
if (pubkey) { if (pubkey) {
setUserInput(userSearchInput) setUserInput(searchTerm)
} else { } else {
toast.error(`No user found with the NIP05: ${userSearchInput}`) toast.error(`No user found with the NIP05: ${userSearchInput}`)
} }
@ -414,7 +423,7 @@ export const CreatePage = () => {
setUserSearchInput('') setUserSearchInput('')
if (input.startsWith('npub')) { if (input.startsWith('npub1')) {
return handleAddNpubUser(input) return handleAddNpubUser(input)
} }
@ -1059,17 +1068,13 @@ export const CreatePage = () => {
} }
// Seems like it's npub format // Seems like it's npub format
if (value.startsWith('npub')) { if (value.trim().startsWith('npub1')) {
// We will try to convert npub to hex and if it's successfull that means setPastedUserNpubOrNip05(value.trim())
// npub is valid } else if (value.trim().startsWith('nsec1')) {
const validHexPubkey = npubToHex(value) toast.warn('Oops - never paste your nsec into a website! Key deleted.')
if (searchFieldRef.current) searchFieldRef.current.value = ''
if (validHexPubkey) { setUserSearchInput('')
// Arm the manual user npub add after enter is hit, we don't want to trigger search return
setPastedUserNpubOrNip05(value)
} else {
disarmAddOnEnter()
}
} else { } else {
// Disarm the add user on enter hit, and trigger search after 1 second // Disarm the add user on enter hit, and trigger search after 1 second
disarmAddOnEnter() disarmAddOnEnter()
@ -1229,7 +1234,7 @@ export const CreatePage = () => {
{!pastedUserNpubOrNip05 ? ( {!pastedUserNpubOrNip05 ? (
<Button <Button
disabled={!userSearchInput || searchUsersLoading} disabled={!userSearchInput || searchUsersLoading}
onClick={() => handleSearchUsers()} onClick={handleSearchUsers}
variant="contained" variant="contained"
aria-label="Add" aria-label="Add"
className={styles.counterpartToggleButton} className={styles.counterpartToggleButton}
@ -1243,7 +1248,7 @@ export const CreatePage = () => {
) : ( ) : (
<Button <Button
onClick={() => { onClick={() => {
setUserInput(userSearchInput) setUserInput(userSearchInput.trim())
}} }}
variant="contained" variant="contained"
aria-label="Add" aria-label="Add"