Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOB-362: Some url links don't work with the deployment build #31

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading