@@ -2,13 +2,24 @@ package com.getcode.util
22
33import android.content.Intent
44import android.net.Uri
5+ import androidx.core.net.toUri
56import cafe.adriel.voyager.core.screen.Screen
7+ import com.getcode.models.DeepLinkRequest
8+ import com.getcode.models.PlatformKeys
9+ import com.getcode.models.encode
610import com.getcode.navigation.screens.HomeScreen
711import com.getcode.navigation.screens.LoginScreen
12+ import com.getcode.network.repository.encodeBase64
813import com.getcode.network.repository.urlDecode
914import com.getcode.utils.TraceType
15+ import com.getcode.utils.base64EncodedData
1016import com.getcode.utils.trace
17+ import com.getcode.vendor.Base58
1118import kotlinx.coroutines.flow.MutableStateFlow
19+ import kotlinx.serialization.ExperimentalSerializationApi
20+ import kotlinx.serialization.encodeToString
21+ import kotlinx.serialization.json.buildJsonObject
22+ import kotlinx.serialization.json.put
1223import timber.log.Timber
1324import javax.inject.Inject
1425import javax.inject.Singleton
@@ -42,7 +53,17 @@ class DeeplinkHandler @Inject constructor() {
4253 val intent = MutableStateFlow (debounceIntent)
4354
4455 fun handle (intent : Intent ? = debounceIntent): DeeplinkResult ? {
45- val uri = intent?.data ? : return null
56+ val uri = when {
57+ intent?.data != null -> intent.data
58+ intent?.getStringExtra(Intent .EXTRA_TEXT ) != null -> {
59+ val sharedLink = intent.getStringExtra(Intent .EXTRA_TEXT )?.toUri() ? : return null
60+ sharedLink.resolveSharedEntity
61+ }
62+
63+ else -> null
64+ } ? : return null
65+
66+ println (" resolved uri=$uri " )
4667 return when (val type = uri.deeplinkType) {
4768 is Type .Login -> {
4869 DeeplinkResult (
@@ -71,6 +92,35 @@ class DeeplinkHandler @Inject constructor() {
7192 }
7293 }
7394
95+ /* *
96+ * Handles converting inbound shared content with possible deeplinks
97+ * e.g sharing a tweet to trigger a tipcard flow
98+ */
99+ private val Uri .resolveSharedEntity: Uri
100+ get() {
101+ // https://x.com/<username>/status/<tweetId>
102+ when (this .host) {
103+ " x.com" ,
104+ " twitter.com" -> {
105+ // convert shared tweets to owner's tip card
106+ val username = pathSegments.firstOrNull() ? : return this
107+ val payload = buildJsonObject {
108+ put(" mode" , " tip" )
109+ put(
110+ " platform" ,
111+ buildJsonObject {
112+ put(" name" , " Twitter" )
113+ put(" username" , username)
114+ }
115+ )
116+ }
117+ val encodedPayload = encode(payload).toByteArray().encodeBase64()
118+ return " codewallet://sdk.getcode.com/v1/elements/tip-request-page-mobile/#/p=$encodedPayload " .toUri()
119+ }
120+ else -> return this
121+ }
122+ }
123+
74124 private val Uri .deeplinkType: Type
75125 get() = when (val segment = lastPathSegment) {
76126 " login" -> {
0 commit comments