From 4ec10a7c679e4030189c7b587c43845c136b5724 Mon Sep 17 00:00:00 2001 From: Rui <102453770+ruixhuang@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:35:18 -0400 Subject: [PATCH] MOB-362: Some url links don't work with the deployment build (#31) * Test * Check for deeplink path during routing * Clean up * Clean up --- .../dydx/trading/core/DydxRouterImpl.kt | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/v4/core/src/main/java/exchange/dydx/trading/core/DydxRouterImpl.kt b/v4/core/src/main/java/exchange/dydx/trading/core/DydxRouterImpl.kt index ab3981e3..10e6094b 100644 --- a/v4/core/src/main/java/exchange/dydx/trading/core/DydxRouterImpl.kt +++ b/v4/core/src/main/java/exchange/dydx/trading/core/DydxRouterImpl.kt @@ -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 = 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) @@ -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 } }