Skip to content

Commit

Permalink
MOB-362: Some url links don't work with the deployment build (#31)
Browse files Browse the repository at this point in the history
* Test

* Check for deeplink path during routing

* Clean up

* Clean up
  • Loading branch information
ruixhuang authored Mar 15, 2024
1 parent 6465dc6 commit 4ec10a7
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions v4/core/src/main/java/exchange/dydx/trading/core/DydxRouterImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ class DydxRouterImpl(
"${appConfig.appScheme}://${appConfig.appSchemeHost}",
)

// All routes paths that are used for deeplinking
// This should match what's declared as intent-filters in the AndroidManifest
private val deeplinkRoutes: List<String> = listOf(
"markets",
"market",
"portfolio",
"settings",
"onboard",
"rewards",
"action",
"transfer",
)

private val destinationChangedListener: (controller: NavController, destination: NavDestination, arguments: Bundle?) -> Unit =
{ controller, destination, arguments ->
val dest = Destination(controller, destination, arguments)
Expand Down Expand Up @@ -193,15 +206,21 @@ class DydxRouterImpl(
}

private fun routePath(route: String): String {
var route = route
val route = trimUrlHead(route)
return if (route.startsWith("/")) route.substring(1) else route
}

private fun trimUrlHead(route: String): String {
// Remove the url head from the route if the route is a deeplink the app supports
// For example, if the route is "https://{app_web_host]/markets", return "/markets"
for (url in dydxUris) {
if (route.startsWith(url)) {
route = route.replace(url, "")
for (path in deeplinkRoutes) {
val urlPath = "$url/$path"
if (route.startsWith(urlPath)) {
return route.replace(url, "")
}
}
}
if (route.startsWith("/")) {
return route.substring(1)
}
return route
}
}

0 comments on commit 4ec10a7

Please sign in to comment.