Skip to content

Hot fix - telegram deep linking#1074

Merged
lealobanov merged 8 commits intodevelopfrom
hot-fix-telegram-linking
May 16, 2025
Merged

Hot fix - telegram deep linking#1074
lealobanov merged 8 commits intodevelopfrom
hot-fix-telegram-linking

Conversation

@lealobanov
Copy link
Copy Markdown
Contributor

@lealobanov lealobanov commented May 16, 2025

Related Issue

Screenshot 2025-05-16 at 3 57 33 PM

Summary of Changes

Support deep links with "tg" scheme.

Need Regression Testing

  • Yes
  • No

Risk Assessment

  • Low
  • Medium
  • High

Additional Notes

Screenshots (if applicable)

@lealobanov lealobanov requested a review from a team as a code owner May 16, 2025 06:55
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 16, 2025

PR Summary

Enhanced deep linking capabilities by adding support for Telegram deep links with "tg" scheme and improved WalletConnect URI handling. Added window color customization through JavaScript interface and included error handling for Telegram app availability.

Changes

File Summary
app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt Added support for tg scheme URLs, improved WalletConnect URI handling, and added error handling for Telegram app availability. Added getCallback() method and enhanced URL scheme processing for frw and fcw paths.
app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/Utils.kt Enhanced getWalletConnectUri function to handle Telegram URIs and direct WalletConnect links from Lilico domains. Added specific handling for /wc paths and URL decoding.
app/src/main/java/com/flowfoundation/wallet/widgets/webview/JsInterface.kt Implemented new windowColor JavaScript interface method to allow dynamic window color changes through the WebView callback system.
app/src/main/res/values/strings.xml Added new string resource telegram_not_installed for displaying error message when Telegram app is not available on device.

autogenerated by presubmit.ai

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
  • aa21958: Hot fix - telegram deep linking
Files Processed (2)
  • app/src/main/AndroidManifest.xml (1 hunk)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt (1 hunk)
Actionable Comments (0)
Skipped Comments (2)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [274-281]

    best practice: "Exception handling could be more specific"

  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [279-279]

    best practice: "Consider logging error details"

@lealobanov lealobanov changed the base branch from master to develop May 16, 2025 07:06
@lealobanov
Copy link
Copy Markdown
Contributor Author

Case 1: User click Crypto Kitties button, Telegram is not installed on the phone -> redirect to Play Store

Screen.Recording.2025-05-16.at.4.35.14.PM.mov

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
  • 7a2ab7e: Hot fix - telegram deep linking
Files Processed (3)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt (10 hunks)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/Utils.kt (1 hunk)
  • app/src/main/java/com/flowfoundation/wallet/widgets/webview/JsInterface.kt (1 hunk)
Actionable Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [278-281]

    security: "Potential security issue with package validation"

Skipped Comments (2)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [332-341]

    possible issue: "Missing error handling for web intent"

  • app/src/main/java/com/flowfoundation/wallet/widgets/webview/JsInterface.kt [54-56]

    possible bug: "Input validation missing for color parsing"

Comment on lines +278 to +281
val pkg = ri.activityInfo.packageName
if (pkg != "android" && pkg != context.packageName) {
return true // found a 3rd-party app that can open tg:
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current package validation for Telegram deep linking is insufficient. A malicious app could register the tg: scheme and intercept these links. Consider explicitly checking for the official Telegram package name (org.telegram.messenger) instead of accepting any non-system package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

org.telegram.messenger didn't seem to open the app when it is installed from Telegram website (https://telegram.org/android) instead of PlayStore, so I removed this check

@lealobanov
Copy link
Copy Markdown
Contributor Author

Screen.Recording.2025-05-16.at.4.50.16.PM.mov

Case 2: Telegram is installed

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
  • dbf897f: Hot fix - telegram deep linking
Files Processed (2)
  • app/src/main/AndroidManifest.xml (2 hunks)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt (10 hunks)
Actionable Comments (2)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [299-319]

    possible bug: "Potential crash when handling Telegram deep links"

  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [295-295]

    security: "Potential security risk with deep link handling"

Skipped Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [321-324]

    possible issue: "Potential state inconsistency in WebView"

e.printStackTrace()
false
}
} else if (it.scheme == "tg") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code accepts any URI with the 'tg' scheme without validating the host or path. This could potentially be exploited if a malicious site provides a crafted 'tg://' URL. Consider adding validation for expected Telegram deep link formats before processing them.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
  • 3a3501f: Hot fix - telegram deep linking
Files Processed (2)
  • app/src/main/AndroidManifest.xml (1 hunk)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt (10 hunks)
Actionable Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [296-297]

    security: "Potential security risk with FLAG_ACTIVITY_NEW_TASK"

Skipped Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [299-319]

    best practice: "Missing error logging for Telegram app launch failure"

Comment on lines +296 to +297
val openTg = Intent(Intent.ACTION_VIEW, it)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using FLAG_ACTIVITY_NEW_TASK with an Intent that handles external data (deep links) could potentially lead to task hijacking. Consider using FLAG_ACTIVITY_RESET_TASK_IF_NEEDED in combination or evaluating if the flag is truly necessary for your use case.

@lealobanov lealobanov requested review from jaymengxy and lmcmz May 16, 2025 08:02
}
}

@JavascriptInterface
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unrelated issue that was being thrown to the console from internal web browser, so I added handling for it

Comment thread app/src/main/AndroidManifest.xml Outdated
request?.url?.let {
logd(TAG, "shouldOverrideUrlLoading URL: $it, scheme: ${it.scheme}")

if (it.scheme == "wc") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should handle frw://, fcw:// and all universal link in here. and check if it's wc connection url

Copy link
Copy Markdown
Contributor Author

@lealobanov lealobanov May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we currently have one check for wc URLs above the tg check. I realize we are missing the frw and fcw cases here, will add this in a separate PR to address the middle window appearing during the wallet session auth.

context.startActivity(openTg)
} catch (e: Exception) {
// Nothing handled it → send user to Play Store (or web fallback)
val pkgName = "org.telegram.messenger"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wired, if we can't open just show a toast. No need go to play store.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen.Recording.2025-05-16.at.5.17.30.PM.mov

Updated:

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
  • a29c063: Hot fix - telegram deep linking
Files Processed (2)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt (11 hunks)
  • app/src/main/res/values/strings.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (2)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [302-304]

    best practice: "Generic exception handling could mask specific errors"

  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [306-308]

    enhancement: "WebView history manipulation could affect user experience"

@lealobanov lealobanov requested a review from lmcmz May 16, 2025 08:23
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
  • a69552b: Hot fix - telegram deep linking
Files Processed (0)
Actionable Comments (0)
Skipped Comments (0)

view?.stopLoading()
view?.clearHistory()
return true
} else if (it.host == "link.lilico.app" || it.host == "frw-link.lilico.app" || it
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's register all universal link as a enum class, then check the host in the list of enum.

enum UniversaLinks: String {
case frw = ""
case fcw = ""
case wallet = ""
}

enum Deeplinks: {
case frw
case fcw
}

UniversaLinks.values.contains(host)
Deeplinks.values.contains(scheme)

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
Files Processed (2)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt (11 hunks)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/Utils.kt (1 hunk)
Actionable Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/Utils.kt [188-194]

    possible bug: "Potential null pointer exception in URL processing"

Skipped Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [304-312]

    best practice: "Missing error handling specificity in Telegram deep linking"

Comment on lines +188 to +194
if (uri.host?.contains("lilico.app") == true && uri.path == "/wc") {
logd(TAG, "Processing WalletConnect link URL: $uri")
val wcUriParam = uri.getQueryParameter("uri")
if (wcUriParam != null) {
return@runCatching URLDecoder.decode(wcUriParam, StandardCharsets.UTF_8.name())
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code checks if the host contains 'lilico.app' but doesn't verify that the host itself isn't null before the contains check. While the null check is there with the safe call operator, restructuring the condition to uri.host?.contains("lilico.app") == true && uri.path == "/wc" would be more robust and prevent potential NPEs.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
Files Processed (1)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt (11 hunks)
Actionable Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [322-326]

    possible issue: "Potential null pointer dereference in wallet link handling"

Skipped Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [307-311]

    best practice: "Improve error handling for Telegram deep links"

Comment on lines +322 to +326
val wcUri = getWalletConnectUri(it)
wcUri?.let { uri ->
logd(TAG, "Wallet Connect URI: $uri")
WalletConnect.get().pair(uri)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code calls toString() on the result of getWalletConnectUri() without null checking in the existing code, but now properly handles the null case. However, if wcUri is null, the code silently fails without any error handling or user feedback. Consider adding appropriate error handling:

val wcUri = getWalletConnectUri(it)
if (wcUri != null) {
    logd(TAG, "Wallet Connect URI: $wcUri")
    WalletConnect.get().pair(wcUri)
} else {
    logd(TAG, "Failed to parse Wallet Connect URI")
    // Show appropriate error to user
}

@lealobanov lealobanov merged commit 972c7b9 into develop May 16, 2025
3 checks passed
@lealobanov lealobanov deleted the hot-fix-telegram-linking branch May 16, 2025 09:50
lealobanov added a commit that referenced this pull request May 16, 2025
* Hot fix - telegram deep linking
lealobanov added a commit that referenced this pull request May 16, 2025
* Hot fix - telegram deep linking (#1074)

* Hot fix - telegram deep linking

* Hot fix - telegram deep linking

* Hot fix - telegram deep linking

* Hot fix - telegram deep linking

* Hot fix - telegram deep linking

* Hot fix - telegram deep linking

* WC deep linking

* WC deep linking

* fix: update the version code

---------

Co-authored-by: Lea Lobanov <44328396+lealobanov@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants