diff --git a/examples/simple-dapp/index.html b/examples/simple-dapp/index.html index faa6ed96..a6c1f65a 100644 --- a/examples/simple-dapp/index.html +++ b/examples/simple-dapp/index.html @@ -3,6 +3,7 @@ + Simple dApp diff --git a/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/deep-link.module.ts b/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/deep-link.module.ts index 6fba667b..57729e22 100644 --- a/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/deep-link.module.ts +++ b/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/deep-link.module.ts @@ -3,6 +3,7 @@ import { errAsync, okAsync } from 'neverthrow' import { Logger, isMobile } from '../../../../helpers' import Bowser from 'bowser' import { SdkError } from '../../../../error' +import { isTMA } from './helpers' export type DeepLinkModule = ReturnType export const DeepLinkModule = (input: { @@ -13,6 +14,7 @@ export const DeepLinkModule = (input: { const userAgent = Bowser.parse(window.navigator.userAgent) const { platform } = userAgent const logger = input?.logger?.getSubLogger({ name: 'DeepLinkModule' }) + const isTelegramMiniApp = isTMA(globalThis) logger?.debug({ platform, @@ -34,8 +36,12 @@ export const DeepLinkModule = (input: { data: { ...values }, }) - if (isMobile() && globalThis.location?.href) { - globalThis.location.href = outboundUrl.toString() + if (isMobile()) { + const deepLink = outboundUrl.toString() + + // Telegram Mini App does not support deep linking by changing location.href value + if (isTelegramMiniApp) globalThis.open(deepLink, '_blank') + else if (globalThis.location?.href) globalThis.location.href = deepLink return okAsync(undefined) } diff --git a/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/helpers/index.ts b/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/helpers/index.ts new file mode 100644 index 00000000..502b20aa --- /dev/null +++ b/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/helpers/index.ts @@ -0,0 +1,2 @@ +export * from './base64url' +export * from './isTma' diff --git a/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/helpers/isTma.ts b/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/helpers/isTma.ts new file mode 100644 index 00000000..f2218c1e --- /dev/null +++ b/packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/helpers/isTma.ts @@ -0,0 +1,8 @@ +/** + * Checks if the provided object is a Telegram Mobile App (TMA) global object. + * + * @param maybeTgGlobalObject - The object to check. + * @returns `true` if the object has WebView initialization parameters, otherwise `false`. + */ +export const isTMA = (globalObject: any) => + Object.keys(globalObject?.Telegram?.WebView?.initParams || {}).length > 0