fix js exception on undefined "id".

This commit is contained in:
fiatjaf 2022-03-09 10:20:11 -03:00
parent e17ec3d1f9
commit b135de6fc0

View File

@ -3,6 +3,7 @@ package app.handlers
import scala.annotation.{nowarn, tailrec} import scala.annotation.{nowarn, tailrec}
import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future import scala.concurrent.Future
import scala.util.{Failure, Success}
import scala.scalajs.js import scala.scalajs.js
import slinky.core.FunctionalComponent import slinky.core.FunctionalComponent
import slinky.web.html._ import slinky.web.html._
@ -127,10 +128,11 @@ object EventSignatures extends Handler {
) )
) )
Nostr val hash = Nostr.getEventHash(event)
.getEventHash(event) == (c.get[String]("id")).toOption.get match {
case true => Right(render(true)) c.get[String]("id") match {
case false => Left(render(false)) case Right(id) if id == hash => Right(render(true))
case _ => Left(render(false))
} }
} }
@ -148,13 +150,11 @@ object EventSignatures extends Handler {
) )
) )
Nostr.verifySignature(event).toFuture map { result => Nostr.verifySignature(event).toFuture map {
result match {
case true => Right(render(true)) case true => Right(render(true))
case false => Left(render(false)) case false => Left(render(false))
} }
} }
}
val protoElements = List[(String) => MaybeItem]( val protoElements = List[(String) => MaybeItem](
itemWrongProperties, itemWrongProperties,
@ -178,8 +178,8 @@ object EventSignatures extends Handler {
acc: List[slinky.core.TagMod[Nothing]] acc: List[slinky.core.TagMod[Nothing]]
): Future[List[slinky.core.TagMod[Nothing]]] = remaining match { ): Future[List[slinky.core.TagMod[Nothing]]] = remaining match {
case fn :: tail => { case fn :: tail => {
fn(props) flatMap { res => fn(props) flatMap {
res match { {
case Left(el) => runAndUnwrapUntilFirstLeft(Nil, el :: acc) case Left(el) => runAndUnwrapUntilFirstLeft(Nil, el :: acc)
case Right(el) => runAndUnwrapUntilFirstLeft(tail, el :: acc) case Right(el) => runAndUnwrapUntilFirstLeft(tail, el :: acc)
} }
@ -188,7 +188,11 @@ object EventSignatures extends Handler {
case Nil => Future { acc.reverse } case Nil => Future { acc.reverse }
} }
runAndUnwrapUntilFirstLeft(protoElements, List()) foreach setElements runAndUnwrapUntilFirstLeft(protoElements, List()) onComplete {
case Success(x) => setElements(x)
case Failure(err) =>
println(f"failed to run through elements: ${err}")
}
() => {} () => {}
}, },