do not allow relay hints to be added on nsec screen.

This commit is contained in:
fiatjaf 2023-04-25 22:02:04 -03:00
parent d912a28987
commit ed16607a36
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -90,7 +90,11 @@ object Components {
sk.map { k => entry("private key (hex)", k.value.toHex) }, sk.map { k => entry("private key (hex)", k.value.toHex) },
sk.map { k => entry("nsec", NIP19.encode(k)) }, sk.map { k => entry("nsec", NIP19.encode(k)) },
entry("public key (hex)", pp.pubkey.value.toHex), entry("public key (hex)", pp.pubkey.value.toHex),
relayHints(store, pp.relays), relayHints(
store,
pp.relays,
dynamic = if sk.isDefined then false else true
),
entry("npub", NIP19.encode(pp.pubkey)), entry("npub", NIP19.encode(pp.pubkey)),
nip19_21("nprofile", NIP19.encode(pp)) nip19_21("nprofile", NIP19.encode(pp))
) )
@ -238,8 +242,11 @@ object Components {
private def relayHints( private def relayHints(
store: Store, store: Store,
relays: List[String] relays: List[String],
dynamic: Boolean = true
): Resource[IO, HtmlDivElement[IO]] = ): Resource[IO, HtmlDivElement[IO]] =
if !dynamic && relays.isEmpty then div("")
else
SignallingRef[IO].of(false).toResource.flatMap { active => SignallingRef[IO].of(false).toResource.flatMap { active =>
val value = val value =
if relays.size > 0 then relays.reduce((a, b) => s"$a, $b") else "" if relays.size > 0 then relays.reduce((a, b) => s"$a, $b") else ""
@ -257,7 +264,8 @@ object Components {
evt.key match { evt.key match {
case "Enter" => case "Enter" =>
self.value.get.flatMap(url => self.value.get.flatMap(url =>
if url.startsWith("wss://") || url.startsWith("ws://") if url.startsWith("wss://") || url
.startsWith("ws://")
then then
store.input.update( store.input.update(
_.trim() ++ " + " ++ url _.trim() ++ " + " ++ url
@ -270,12 +278,13 @@ object Components {
) )
} }
) )
case false => case false if dynamic =>
button( button(
Styles.buttonSmall, Styles.buttonSmall,
"add relay hint", "add relay hint",
onClick --> (_.foreach(_ => active.set(true))) onClick --> (_.foreach(_ => active.set(true)))
) )
case false => div("")
} }
) )
} }