Skip to content

Commit

Permalink
dapp push fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokin0andrey committed Dec 23, 2024
1 parent d58018c commit f1b1264
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,13 @@ class RootActivity: BaseWalletActivity() {
val dappDeepLink = extras?.getStringValue("dapp_deeplink")?.toUriOrNull()
if (dappDeepLink != null) {
viewModel.openDApp(dappDeepLink)
} else if (uri != null) {
return;
}
if (extras != null && !extras.isEmpty && viewModel.processIntentExtras(extras)) {
return;
}
if (uri != null) {
processDeepLink(DeepLink.fixBadUri(uri), false, intent.getStringExtra(Browser.EXTRA_APPLICATION_ID))
} else if (extras != null && !extras.isEmpty) {
viewModel.processIntentExtras(extras)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,38 +402,37 @@ class RootViewModel(
}
}

fun processIntentExtras(bundle: Bundle) {
val link = bundle.getString("link")
fun processIntentExtras(bundle: Bundle): Boolean {
val pushType = bundle.getString("type") ?: return false
val pushId = bundle.getStringValue("push_id", "utm_id", "utm_campaign")
hasWalletFlow.take(1).collectFlow {
if (link != null) {
if (pushType == "console_dapp_notification") {
processDAppPush(bundle)
} else {
val deeplink = bundle.getString("deeplink")?.toUriOrNull() ?: return@collectFlow
AnalyticsHelper.trackPushClick(
installId = installId,
pushId = pushId ?: "",
pushId = pushId ?: pushType,
payload = deeplink.toString(),
)
processDeepLinkPush(deeplink, bundle)
}
}

return true
}

private suspend fun processDAppPush(bundle: Bundle) {
val accountId = bundle.getString("account") ?: return
val dappUrl = bundle.getString("dapp_url")?.toUriOrNull() ?: return
val connections = tonConnectManager.accountConnectionsFlow(accountId).firstOrNull()?.filter { it.appUrl == dappUrl } ?: return
if (connections.isEmpty()) {
return
}
val wallet = accountRepository.getWalletByAccountId(accountId) ?: return
val openUrl = bundle.getString("link")?.toUriOrNull() ?: dappUrl
openScreen(DAppScreen.newInstance(
wallet = wallet,
url = openUrl,
source = "push"
))
val openUrl = bundle.getString("link")?.toUriOrNull() ?: bundle.getString("dapp_url")?.toUriOrNull()
if (openUrl != null) {
openScreen(DAppScreen.newInstance(
wallet = wallet,
url = openUrl,
source = "push"
))
}
}

private suspend fun processDeepLinkPush(uri: Uri, bundle: Bundle) {
Expand Down

0 comments on commit f1b1264

Please sign in to comment.