support nip05 addresses on advanced search.

This commit is contained in:
fiatjaf 2023-03-02 08:44:27 -03:00
parent a54a1cef8a
commit ad4be88d87
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 30 additions and 8 deletions

View File

@ -37,7 +37,7 @@
"husky": "^8.0.3",
"localforage": "^1.10.0",
"localforage-memoryStorageDriver": "^0.9.2",
"nostr-tools": "^1.4.1",
"nostr-tools": "^1.7.4",
"npm-run-all": "^4.1.5",
"qr-scanner": "^1.4.2",
"qrcode": "^1.5.1",

View File

@ -3,18 +3,40 @@
import {onDestroy} from 'svelte'
import {navigate} from 'svelte-routing'
import {waitFor} from 'hurdak/lib/hurdak'
import {any, flip, startsWith} from 'ramda'
import {nip05, nip19} from 'nostr-tools'
import Input from 'src/partials/Input.svelte'
import Anchor from 'src/partials/Anchor.svelte'
import Spinner from 'src/partials/Spinner.svelte'
import {toast} from "src/app/ui"
let mode = 'input', video, ready, value, scanner
const onDecode = result => {
goToEntity(result.data)
handleInput(result.data)
}
const goToEntity = entity => {
navigate("/" + entity.replace('nostr:', ''))
const handleInput = async input => {
input = input.replace('nostr:', '')
if (any(flip(startsWith)(input), ["note1", "npub1", "nevent1", "nprofile1"])) {
navigate("/" + input)
return
}
if (input.match(/^[a-f0-9]{64}$/)) {
navigate("/" + nip19.npubEncode(input))
return
}
let profile = await nip05.queryProfile(input)
if (profile) {
navigate("/" + nip19.nprofileEncode(profile))
return
}
toast.show("warning", "That isn't a valid nostr identifier")
return
}
const setMode = async newMode => {
@ -46,17 +68,17 @@
</script>
{#if mode === 'input'}
<div class="flex gap-2">
<form class="flex gap-2" on:submit|preventDefault={() => handleInput(value)}>
<Input placeholder="nprofile..." bind:value={value} wrapperClass="flex-grow" />
<Anchor type="button" on:click={() => goToEntity(value)}>
<Anchor type="button" on:click={() => handleInput(value)}>
<i class="fa fa-arrow-right" />
</Anchor>
<Anchor type="button" on:click={() => setMode('scan')}>
<i class="fa fa-qrcode" />
</Anchor>
</div>
</form>
<div class="text-center text-light">
Enter any nostr identifier (npub, nevent, nprofile or note), or click on the
Enter any nostr identifier (npub, nevent, nprofile, note or user@domain.tld), or click on the
camera icon to scan with your device's camera instead.
</div>
{:else}