Fix nprofile scan when there are no relays

This commit is contained in:
Jonathan Staab 2023-03-02 16:33:02 -06:00
parent 2781434b86
commit 17afc35d1c
2 changed files with 13 additions and 6 deletions

View File

@ -2,10 +2,11 @@
import {objOf} from 'ramda'
import {onMount} from 'svelte'
import {nip19} from 'nostr-tools'
import {warn} from 'src/util/logger'
import Content from 'src/partials/Content.svelte'
import NoteDetail from 'src/views/notes/NoteDetail.svelte'
import Person from 'src/views/person/PersonDetail.svelte'
import {getUserReadRelays} from 'src/agent/relays'
import {sampleRelays} from 'src/agent/relays'
export let entity
@ -14,9 +15,9 @@
onMount(() => {
try {
({type, data} = nip19.decode(entity) as {type: string, data: any})
relays = (data.relays || []).map(objOf('url')).concat(getUserReadRelays())
relays = sampleRelays((data.relays || []).map(objOf('url')))
} catch (e) {
// pass
warn(e)
}
})
</script>

View File

@ -1,13 +1,15 @@
<script lang="ts">
import type {ProfilePointer} from 'nostr-tools/nip19'
import QrScanner from 'qr-scanner'
import {onDestroy} from 'svelte'
import {navigate} from 'svelte-routing'
import {waitFor} from 'hurdak/lib/hurdak'
import {any, flip, startsWith} from 'ramda'
import {pluck, find} 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 {getUserReadRelays} from 'src/agent/relays'
import {toast} from "src/app/ui"
let mode = 'input', video, ready, value, scanner
@ -19,7 +21,7 @@
const handleInput = async input => {
input = input.replace('nostr:', '')
if (any(flip(startsWith)(input), ["note1", "npub1", "nevent1", "nprofile1"])) {
if (find(s => input.startsWith(s), ["note1", "npub1", "nevent1", "nprofile1"])) {
navigate("/" + input)
return
}
@ -29,8 +31,12 @@
return
}
let profile = await nip05.queryProfile(input)
let profile = await nip05.queryProfile(input) as ProfilePointer
if (profile) {
if (profile.relays.length === 0) {
profile.relays = pluck('url', getUserReadRelays())
}
navigate("/" + nip19.nprofileEncode(profile))
return
}