Skip to content

Commit

Permalink
fix(ui): correct data retrieval in tma
Browse files Browse the repository at this point in the history
  • Loading branch information
thekiba committed Dec 15, 2023
1 parent 6dc42bf commit d462342
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/ui/src/app/utils/tma-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ declare global {

interface Window {
TelegramWebviewProxy?: TelegramWebviewProxy;
Telegram?: {
WebApp?: {
platform?: TmaPlatform;
version?: string;
};
};
}
}

Expand All @@ -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.
Expand Down

0 comments on commit d462342

Please sign in to comment.