From a034fa18d7796c8643d7d44ea926cdd97888f385 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Dec 2024 10:40:09 +0600 Subject: [PATCH] fixes in status info --- .../jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt | 2 +- .../dev/inmo/tgbotapi/webapps/events/EventsList.json | 2 +- .../dev/inmo/tgbotapi/webapps/events/Extensions.kt | 4 ++-- .../inmo/tgbotapi/webapps/invoice/InvoiceClosedInfo.kt | 9 ++++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt index 06d59c3095..41eb003b75 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt @@ -218,7 +218,7 @@ external class WebApp { @JsName("onEvent") internal fun onContactRequested(type: String, callback: (dev.inmo.tgbotapi.webapps.args.ArgStatusObject) -> Unit) @JsName("onEvent") - internal fun onInvoiceClosed(type: String, callback: (String, dev.inmo.tgbotapi.webapps.invoice.InvoiceStatus) -> Unit) + internal fun onInvoiceClosed(type: String, callback: (String, String) -> Unit) @JsName("onEvent") internal fun onGyroscopeStarted(type: String, callback: () -> Unit) @JsName("onEvent") diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/EventsList.json b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/EventsList.json index e541936352..7c39c84f49 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/EventsList.json +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/EventsList.json @@ -41,7 +41,7 @@ }, { "event_name": "invoiceClosed", - "callback_args": "String, dev.inmo.tgbotapi.webapps.invoice.InvoiceStatus" + "callback_args": "String, String" }, { "event_name": "popupClosed", diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/Extensions.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/Extensions.kt index 529c5c1f68..5991b89931 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/Extensions.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/Extensions.kt @@ -885,14 +885,14 @@ fun WebApp.onEvent(type: EventType.ContactRequested, eventHandler: ContactReques fun WebApp.onContactRequested(eventHandler: ContactRequestedEventHandler) = onEvent(EventType.ContactRequested, eventHandler) // Part for callback typealias -typealias InvoiceClosedEventHandler = WebApp.(String, dev.inmo.tgbotapi.webapps.invoice.InvoiceStatus) -> Unit +typealias InvoiceClosedEventHandler = WebApp.(String, String) -> Unit // Part for outside of WebApp /** * @return The callback which should be used in case you want to turn off events handling */ -fun WebApp.onEvent(type: EventType.InvoiceClosed, eventHandler: InvoiceClosedEventHandler) = { p0: String, p1: dev.inmo.tgbotapi.webapps.invoice.InvoiceStatus -> +fun WebApp.onEvent(type: EventType.InvoiceClosed, eventHandler: InvoiceClosedEventHandler) = { p0: String, p1: String -> eventHandler(js("this").unsafeCast(), p0, p1) }.also { onInvoiceClosed( diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/invoice/InvoiceClosedInfo.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/invoice/InvoiceClosedInfo.kt index 39feb3087a..99605e1c8c 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/invoice/InvoiceClosedInfo.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/invoice/InvoiceClosedInfo.kt @@ -5,12 +5,15 @@ external interface InvoiceClosedInfo { val status: String } -val InvoiceClosedInfo.statusTyped - get() = when (status) { +val String.statusTyped + get() = when (this) { InvoiceStatus.Paid.name -> InvoiceStatus.Paid InvoiceStatus.Cancelled.name -> InvoiceStatus.Cancelled InvoiceStatus.Failed.name -> InvoiceStatus.Failed InvoiceStatus.Pending.name -> InvoiceStatus.Pending - else -> InvoiceStatus.Unknown(status) + else -> InvoiceStatus.Unknown(this) } +val InvoiceClosedInfo.statusTyped + get() = status.statusTyped +