mirror of
https://github.com/coracle-social/coracle.git
synced 2024-10-06 11:43:30 +00:00
support nip05 addresses on advanced search.
This commit is contained in:
parent
a54a1cef8a
commit
ad4be88d87
@ -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",
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user