Skip to content

Deep linking refactoring#1075

Merged
lmcmz merged 14 commits intodevelopfrom
wc-intermediary-window
May 26, 2025
Merged

Deep linking refactoring#1075
lmcmz merged 14 commits intodevelopfrom
wc-intermediary-window

Conversation

@lealobanov
Copy link
Copy Markdown
Contributor

@lealobanov lealobanov commented May 16, 2025

Related Issue

Summary of Changes

  • Refactor and consolidate deep linking logic into shared data structures and utility methods

Need Regression Testing

  • Yes
  • No

Risk Assessment

  • Low
  • Medium
  • High

Additional Notes

Screenshots (if applicable)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 16, 2025

PR Summary

Consolidated deep linking logic by introducing a centralized URI handling system. Added new data structures and utility methods to manage different types of deep links (WalletConnect, Telegram, universal links) more efficiently. Improved error handling and logging throughout the deep linking process.

Changes

File Summary
app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt Refactored URL handling in LilicoWebView to use the new UriHandler class, removing redundant code and improving handling of different URL schemes. Added better error handling and logging.
app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkType.kt Created new enums UniversalLinkHost and DeepLinkScheme to standardize handling of different deep link types and hosts. Added helper methods for scheme and host validation.
app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkingActivity.kt Modified DeepLinkingActivity to use the new UriHandler for processing URIs. Added specific handling for Telegram links and improved WalletConnect URI detection.
app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/PendingActionHelper.kt Added robust error handling and logging to PendingActionHelper. Improved SharedPreferences operations and URI parsing safety checks.
app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/UriHandler.kt Implemented new UriHandler class to centralize deep link processing logic. Added support for different URI types, WalletConnect extraction, and specialized handlers for Telegram and universal links.
app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/Utils.kt Deprecated old getWalletConnectUri in favor of UriHandler. Updated dispatch methods to use new URI handling system and improved error handling.

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.

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
Files Processed (6)
  • app/src/main/AndroidManifest.xml (1 hunk)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt (2 hunks)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkType.kt (1 hunk)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkingActivity.kt (3 hunks)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/UriHandler.kt (1 hunk)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/Utils.kt (4 hunks)
Actionable Comments (2)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/UriHandler.kt [61-64]

    security: "Potential security risk with Intent flags"

  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/UriHandler.kt [79-85]

    possible bug: "Potential race condition in WalletConnect initialization"

Skipped Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/UriHandler.kt [157-157]

    possible issue: "Missing return value documentation"

Comment on lines +61 to +64
try {
val intent = Intent(Intent.ACTION_VIEW, uri)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
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 alone for external activities can lead to task hijacking. Consider adding FLAG_ACTIVITY_CLEAR_TOP and validating the target package to ensure the intent only opens the official Telegram app.

Comment on lines +79 to +85
return try {
if (WalletConnect.isInitialized()) {
WalletConnect.get().pair(wcUri)
true
} else {
logd(TAG, "WalletConnect not initialized")
// Save for later processing or initialize
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 WalletConnect is initialized but doesn't handle the case where it becomes initialized right after the check. Consider using a synchronized block or implementing a proper initialization callback mechanism.

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)
Files Processed (0)
Actionable Comments (0)
Skipped Comments (0)

Base automatically changed from hot-fix-telegram-linking to develop May 16, 2025 09:50
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 (7)
  • 0a7a355: WC deep linking
  • a69552b: Hot fix - telegram deep linking
  • a29c063: Hot fix - telegram deep linking
  • 3a3501f: Hot fix - telegram deep linking
  • dbf897f: Hot fix - telegram deep linking
  • 7a2ab7e: Hot fix - telegram deep linking
  • aa21958: 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/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkingActivity.kt (3 hunks)
Actionable Comments (2)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [283-308]

    best practice: "Missing error handling for failed deep link actions"

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

    possible bug: "Potential null pointer dereference"

Skipped Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkingActivity.kt [36-41]

    maintainability: "Early return without proper cleanup"

Comment on lines +283 to +308
when (it.scheme) {
DeepLinkScheme.WC.scheme -> {
logd(TAG, "Handling WalletConnect URI")
WalletConnect.get().pair(it.toString())
return true
}
DeepLinkScheme.FRW.scheme, DeepLinkScheme.FCW.scheme -> {
if (it.path?.startsWith("/wc") == true) {
logd(TAG, "Handling ${it.scheme}://wc URI")
val uri = getWalletConnectUri(it)
uri?.let { wcUri ->
WalletConnect.get().pair(wcUri.toString())
}
return true
}
true
} catch (e: URISyntaxException) {
e.printStackTrace()
false
}
} else if (it.host == "link.lilico.app" || it.host == "frw-link.lilico.app" || it
.host == "fcw-link.lilico.app" || it.host == "link.wallet.flow.com") {
DeepLinkScheme.TG.scheme -> {
logd(TAG, "Handling Telegram URI")
UriHandler.processUri(context, it)

// Stop the WebView navigation to avoid looping
view?.stopLoading()
view?.clearHistory()
return true
}
"intent" -> {
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 deep link handling code should include error handling for cases where the actions fail. For example, when WalletConnect.pair() fails or when UriHandler.processUri() encounters an error. Consider wrapping these calls in try-catch blocks and showing appropriate error messages to users via Toast or other UI feedback mechanisms.

Comment on lines +292 to +296
val uri = getWalletConnectUri(it)
uri?.let { wcUri ->
WalletConnect.get().pair(wcUri.toString())
}
return true
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 doesn't handle the case where getWalletConnectUri(it) returns null. The current implementation might lead to a potential null pointer exception if the URI parsing fails. Consider adding an else branch to handle the null case and provide appropriate user feedback.

@lealobanov lealobanov changed the title WC intermediary window for FRW/FCW deep links Deep linking refactoring May 19, 2025
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 (3)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkType.kt (1 hunk)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/UriHandler.kt (1 hunk)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/Utils.kt (4 hunks)
Actionable Comments (2)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/UriHandler.kt [161-161]

    possible issue: "Missing error handling for pending action storage"

  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkType.kt [14-14]

    possible bug: "Case-sensitive host comparison may cause issues"

Skipped Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/UriHandler.kt [169-169]

    best practice: "Use more specific exception handling"

@lealobanov lealobanov self-assigned this May 19, 2025
@lealobanov lealobanov added this to the Release 2.8.6 milestone May 19, 2025
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 (2 hunks)
Actionable Comments (2)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt [279-279]

    possible bug: "Potential null pointer dereference in URL handling"

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

    possible issue: "Potential race condition in URL blocking check"

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

    possible bug: "Inconsistent WebView state management"

isLoading = true
request?.url?.let {
logd(TAG, "shouldOverrideUrlLoading URL: $it, scheme: ${it.scheme}")
request?.url?.let { 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 request?.url?.let block assumes the URL is non-null, but doesn't handle the case where request or url is null. Consider adding an else clause to handle null cases gracefully:

request?.url?.let { uri ->
    // existing code
} ?: run {
    return super.shouldOverrideUrlLoading(view, request)
}

Comment on lines 288 to 295
uiScope {
if (BlockManager.isBlocked(it.toString())) {
logd(TAG, "URL blocked: $url")
showBlockedViewLayout(it.toString())
if (BlockManager.isBlocked(uri.toString())) {
logd(TAG, "URL blocked: $uri")
showBlockedViewLayout(uri.toString())
loadUrl("about:blank#blocked")
isLoading = false
return@uiScope
}
}
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 URL blocking check is performed asynchronously in uiScope, but the method continues execution without waiting for the result. This could lead to a race condition where the URL starts loading before the blocking check completes. Consider restructuring the code to ensure the blocking check completes before proceeding with URL handling.

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/component/deeplinking/DeepLinkType.kt (1 hunk)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/PendingActionHelper.kt (1 hunk)
Actionable Comments (2)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkType.kt [14-16]

    possible bug: "Potential null pointer exception in host comparison"

  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/PendingActionHelper.kt [46-46]

    possible bug: "Potential URI parsing exception not handled"

Skipped Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/PendingActionHelper.kt [26-26]

    performance: "Consider using apply() instead of commit() for better performance"

Comment on lines +14 to +16
fun fromHost(host: String?): UniversalLinkHost? = values().firstOrNull {
it.host.equals(host, ignoreCase = true)
}
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 fromHost method compares a potentially null host parameter with it.host. While Kotlin's null safety would prevent a direct NPE, the current implementation might miss valid matches when host is null. Consider adding an early return for null host:

fun fromHost(host: String?): UniversalLinkHost? = 
    if (host == null) null 
    else values().firstOrNull { it.host.equals(host, ignoreCase = true) }

val deepLinkStr = getPrefs(context).getString(KEY_PENDING_DEEPLINK, null) ?: return null
return Uri.parse(deepLinkStr)
try {
val deepLinkStr = getPrefs(context).getString(KEY_PENDING_DEEPLINK, null) ?: return null
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 Uri.parse() call could throw an IllegalArgumentException if the stored URI string is malformed. Consider wrapping the parsing in a try-catch block to handle malformed URIs gracefully:

try {
    val deepLinkStr = getPrefs(context).getString(KEY_PENDING_DEEPLINK, null) ?: return null
    return Uri.parse(deepLinkStr)
} catch (e: IllegalArgumentException) {
    loge(TAG, "Invalid URI format: ${e.message}")
    return null
}

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)
Files Processed (1)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/PendingActionHelper.kt (1 hunk)
Actionable Comments (0)
Skipped Comments (3)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/PendingActionHelper.kt [26-26]

    performance: "Performance improvement for SharedPreferences write operations"

  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/PendingActionHelper.kt [65-65]

    performance: "Performance improvement for SharedPreferences write operations"

  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/PendingActionHelper.kt [29-31]

    best practice: "Consolidate error logging statements"

@lealobanov lealobanov marked this pull request as ready for review May 19, 2025 02:37
@lealobanov lealobanov requested a review from a team as a code owner May 19, 2025 02:38
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 (3)
  • app/src/main/java/com/flowfoundation/wallet/page/browser/widgets/LilicoWebView.kt (4 hunks)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkType.kt (1 hunk)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkingActivity.kt (3 hunks)
Actionable Comments (1)
  • app/src/main/java/com/flowfoundation/wallet/page/component/deeplinking/DeepLinkType.kt [14-16]

    possible bug: "Potential null pointer exception in host comparison"

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

    possible issue: "Potential race condition in WebView navigation handling"

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

    enhancement: "Early return optimization for null request handling"

Comment on lines +14 to +16
fun fromHost(host: String?): UniversalLinkHost? = entries.firstOrNull {
it.host.equals(host, ignoreCase = true)
}
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 fromHost() method accepts a nullable String parameter but doesn't handle the null case before using it in the equals() comparison. Consider adding a null check at the start of the method to avoid potential NPE:

fun fromHost(host: String?): UniversalLinkHost? = 
    if (host == null) null
    else entries.firstOrNull { it.host.equals(host, ignoreCase = true) }

@lealobanov lealobanov requested a review from jaymengxy May 19, 2025 02:51
@lealobanov lealobanov requested a review from lmcmz May 19, 2025 02:51
FRW("frw"),
FCW("fcw"),
LILICO("lilico"),
TG("tg"),
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 the tg, http, https are not required in here.

@lmcmz lmcmz merged commit edc27ee into develop May 26, 2025
4 checks passed
@lmcmz lmcmz deleted the wc-intermediary-window branch May 26, 2025 05:15
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