From d4623427cb5119979a766e6ed0cdbf576c993ff5 Mon Sep 17 00:00:00 2001
From: thekiba
Date: Sat, 16 Dec 2023 00:05:10 +0400
Subject: [PATCH] fix(ui): correct data retrieval in tma
---
packages/ui/src/app/utils/tma-api.ts | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/packages/ui/src/app/utils/tma-api.ts b/packages/ui/src/app/utils/tma-api.ts
index bf73a528..bccbc1ed 100644
--- a/packages/ui/src/app/utils/tma-api.ts
+++ b/packages/ui/src/app/utils/tma-api.ts
@@ -15,6 +15,12 @@ declare global {
interface Window {
TelegramWebviewProxy?: TelegramWebviewProxy;
+ Telegram?: {
+ WebApp?: {
+ platform?: TmaPlatform;
+ version?: string;
+ };
+ };
}
}
@@ -25,14 +31,20 @@ try {
} catch (e) {}
let tmaPlatform: TmaPlatform = 'unknown';
-if (initParams.tgWebAppPlatform) {
- tmaPlatform = initParams.tgWebAppPlatform as TmaPlatform;
+if (initParams?.tgWebAppPlatform) {
+ tmaPlatform = (initParams.tgWebAppPlatform as TmaPlatform) ?? 'unknown';
+}
+if (tmaPlatform === 'unknown') {
+ tmaPlatform = window?.Telegram?.WebApp?.platform ?? 'unknown';
}
let webAppVersion = '6.0';
-if (initParams.tgWebAppVersion) {
+if (initParams?.tgWebAppVersion) {
webAppVersion = initParams.tgWebAppVersion;
}
+if (!webAppVersion) {
+ webAppVersion = window?.Telegram?.WebApp?.version ?? '6.0';
+}
/**
* Returns true if the app is running in TMA on the specified platform.