diff --git a/app/src/main/java/com/alphawallet/app/service/DeepLinkService.java b/app/src/main/java/com/alphawallet/app/service/DeepLinkService.java index 694a0558ba..4d7f61f684 100644 --- a/app/src/main/java/com/alphawallet/app/service/DeepLinkService.java +++ b/app/src/main/java/com/alphawallet/app/service/DeepLinkService.java @@ -1,13 +1,10 @@ package com.alphawallet.app.service; -import static com.alphawallet.app.entity.WalletPage.DAPP_BROWSER; -import static com.alphawallet.app.entity.WalletPage.WALLET; import static com.alphawallet.app.ui.HomeActivity.AW_MAGICLINK_DIRECT; import android.content.Intent; import android.text.TextUtils; -import com.alphawallet.app.analytics.Analytics; import com.alphawallet.app.api.v1.entity.request.ApiV1Request; import com.alphawallet.app.entity.CryptoFunctions; import com.alphawallet.app.entity.DeepLinkRequest; @@ -16,8 +13,6 @@ import com.alphawallet.app.entity.QRResult; import com.alphawallet.app.entity.attestation.ImportAttestation; import com.alphawallet.app.repository.EthereumNetworkRepository; -import com.alphawallet.app.router.ImportTokenRouter; -import com.alphawallet.app.ui.DappBrowserFragment; import com.alphawallet.app.util.Utils; import com.alphawallet.token.entity.SalesOrderMalformed; import com.alphawallet.token.tools.ParseMagicLink; @@ -26,14 +21,30 @@ public class DeepLinkService { public static final String AW_APP = "https://aw.app/"; public static final String WC_PREFIX = "wc?uri="; + public static final String WC_COMMAND = "wc:"; public static final String AW_PREFIX = "awallet://"; + public static final String OPEN_URL_PREFIX = "openURL?q="; + public static DeepLinkRequest parseIntent(String importData, Intent startIntent) { + boolean isOpenURL = false; + if (TextUtils.isEmpty(importData)) { return checkIntents(startIntent); } + if (importData.startsWith(AW_PREFIX)) //strip AW_PREFIX + { + importData = importData.substring(AW_PREFIX.length()); + } + + if (importData.startsWith(OPEN_URL_PREFIX)) + { + isOpenURL = true; + importData = importData.substring(OPEN_URL_PREFIX.length()); + } + importData = Utils.universalURLDecode(importData); if (checkSmartPass(importData)) @@ -41,12 +52,17 @@ public static DeepLinkRequest parseIntent(String importData, Intent startIntent) return new DeepLinkRequest(DeepLinkType.SMARTPASS, importData); } - if (importData.startsWith(AW_APP + WC_PREFIX) || importData.startsWith(AW_PREFIX + WC_PREFIX)) + if (importData.startsWith(AW_APP + WC_PREFIX) || importData.startsWith(WC_PREFIX)) { int prefixIndex = importData.indexOf(WC_PREFIX) + WC_PREFIX.length(); return new DeepLinkRequest(DeepLinkType.WALLETCONNECT, importData.substring(prefixIndex)); } + if (importData.startsWith(WC_COMMAND)) + { + return new DeepLinkRequest(DeepLinkType.WALLETCONNECT, importData); + } + if (importData.startsWith(NotificationService.AWSTARTUP)) { return new DeepLinkRequest(DeepLinkType.TOKEN_NOTIFICATION, importData.substring(NotificationService.AWSTARTUP.length())); @@ -84,6 +100,11 @@ public static DeepLinkRequest parseIntent(String importData, Intent startIntent) return new DeepLinkRequest(DeepLinkType.IMPORT_SCRIPT, null); } + //finally check if it's a plain openURL + if (isOpenURL && Utils.isValidUrl(importData)) + { + return new DeepLinkRequest(DeepLinkType.URL_REDIRECT, importData); + } // finally see if there was a url in the intent (with non empty importData) or bail with invalid link return checkIntents(startIntent); @@ -124,13 +145,20 @@ private static boolean isLegacyMagiclink(String importData) private static boolean checkSmartPass(String importData) { QRResult result = null; - if (importData != null && importData.startsWith(ImportAttestation.SMART_PASS_URL)) + if (importData != null) { - importData = importData.substring(ImportAttestation.SMART_PASS_URL.length()); //chop off leading URL - result = new QRResult(importData); - result.type = EIP681Type.EAS_ATTESTATION; + if (importData.startsWith(ImportAttestation.SMART_PASS_URL)) + { + importData = importData.substring(ImportAttestation.SMART_PASS_URL.length()); //chop off leading URL + } + String taglessAttestation = Utils.parseEASAttestation(importData); - result.functionDetail = Utils.toAttestationJson(taglessAttestation); + if (taglessAttestation != null && taglessAttestation.length() > 0) + { + result = new QRResult(importData); + result.type = EIP681Type.EAS_ATTESTATION; + result.functionDetail = Utils.toAttestationJson(taglessAttestation); + } } return result != null && !TextUtils.isEmpty(result.functionDetail); diff --git a/app/src/test/java/com/alphawallet/app/IntentTest.java b/app/src/test/java/com/alphawallet/app/IntentTest.java index 9961b51a2e..e4e6ae0275 100644 --- a/app/src/test/java/com/alphawallet/app/IntentTest.java +++ b/app/src/test/java/com/alphawallet/app/IntentTest.java @@ -32,6 +32,9 @@ public void intentsAreParsedCorrectly() String walletconnectTest2 = "wc:d3995aaf65b26f95e6047aa93dec800255b6d763823472238b8137dc3ff519c3%402%3Frelay-protocol%3Dirn%26symKey" + "%3D6ce01accc21d0b59752107d3d43c303ee7ccbdb5f418923c9b12742630f4c792"; String walletconnectTest3 = "awallet://wc?uri=wc%3A5f577f99-2f54-40f7-9463-7ff640772090%401%3Fbridge%3Dhttps%253A%252F%252Fwalletconnect.depay.com%26key%3D1938aa2c9d4104c91cbc60e94631cf769c96ebad1ea2fc30e18ba09e39bc3c0b"; + String walletconnectTest4 = "awallet://openURL?q=wc%3A115a1223589295f91056be883897ce4edef1525f0becdec54b24cb6e296e9a40%402%3Frelay-protocol%3Dirn%26symKey%3Dbf97933cebac73de3106e3deff551ec09b0d2a13ac1ed40d7dc8e33de1a4f86b"; + + String attestationIntent = "awallet://openURL?q=https%3A%2F%2Fsmart-layer.vercel.app%2Fpass%3Ftype%3Deas%26ticket%3DeNrFU0luHDEM_EufBwF3kUfbnflE4INEUQ8wEiDPj3q-0IBDQSvIIotQ_TrgB9nxQETVvTwO-PtB1mK9n9ymCrt_lAQ_8XxvygQnsRU6ah2Xs3uGjl41uyKEFEwlsNZUbdbYAdqXUFApoZl001YRAdJWkvcXiFaKTmQ2XrUWEU0jqjArg2jWcq3pmcyLNRC4iXBijbWSMfF4ULtwRGxzALd402l6PpsN15-Up4_xPOcbZbeS-UraFsGqBmni1Xs4sQzHYbkZiDj3SITu6sGbkE-IXZxXDhrpaC8QuGkXyO6-BYopIz3g9fD760_dh_ebxeVddvgfoy_ryjIFlVQk9x6i-3N-n3Umjj0aM8M-8zW_L70gCMzF3TJ4BcAW8EKmwt5tzcCapbgV5ZoOcnXGcEHAjLA09vTLHWUMjzFCbF9qRZ8JW60T5qQuTZKbKzYzLNn6m2trZkukQzDelQd8_gOdBAEY%26secret%3D0x1a89af8bed1c8ce25e2737a7e3990a7f302f29094380234d6adf9ec62b7b3636%26id%3Dweihong0427%2540163.com"; DeepLinkRequest request = DeepLinkService.parseIntent(walletconnectTest1, null); assertTrue(request.type == DeepLinkType.WALLETCONNECT); @@ -45,11 +48,18 @@ public void intentsAreParsedCorrectly() assertTrue(request.type == DeepLinkType.WALLETCONNECT); assertTrue(request.data.startsWith("wc:")); + request = DeepLinkService.parseIntent(walletconnectTest4, null); + assertTrue(request.type == DeepLinkType.WALLETCONNECT); + assertTrue(request.data.startsWith("wc:")); + //SmartPass import String sp = "https://aw.app/openurl?url=?ticket=eNrFk02OGzAIRu-SdVRhwGCWk0lziaoLfswBqlbq8evMHCFSB3ll2e8DpPfjAt9QLtdxvcDft4GgD7rdHJG_Y1pSyn36Q-gOO8Zc-L7n0svzMUw37_JKnRLFsIoz02JVZEiotsQ07gnskZDmgo4521iaPiE4ta2bo7HHajVi0zW82MeeOVDVypDZdeXQYVukIcyB8nTjlyvqkyPy9hCFh1YrNQK8s9_mJCDoc3bfWM-H-0eoB5UtVeWyzr0nKW7J6p60BKmrNp8QJF4CprVIxqId1Fkw4nP8F-sJOWsX4xODYFf4uPj9689-Hb9ebC7hS2u8TFBRMWUhaTHZ_38Cwq9cIA9gdJvCDSURR7AC34Kr0Plo2tKqySE8yUj3YDuqEeBYIsXmy2H1dgB7Cl6hCMJ0xCvEozYuDa3hMjVzxBrlVDNjL8IRfhzHV_WAn_8AxSYC3Q==&secret=0x2eb74750df993a163a95db3031359f0bfca6eb56e597f6ede056bd69d1803196&id=geman%40gemanji.com"; request = DeepLinkService.parseIntent(sp, null); assertTrue(request.type == DeepLinkType.SMARTPASS); + request = DeepLinkService.parseIntent(attestationIntent, null); + assertTrue(request.type == DeepLinkType.SMARTPASS); + String sp2 = "https://aw.app/openurl?url=ticket=eNrFk02OGzAIRu-SdVRhwGCWk0lziaoLfswBqlbq8evMHCFSB3ll2e8DpPfjAt9QLtdxvcDft4GgD7rdHJG_Y1pSyn36Q-gOO8Zc-L7n0svzMUw37_JKnRLFsIoz02JVZEiotsQ07gnskZDmgo4521iaPiE4ta2bo7HHajVi0zW82MeeOVDVypDZdeXQYVukIcyB8nTjlyvqkyPy9hCFh1YrNQK8s9_mJCDoc3bfWM-H-0eoB5UtVeWyzr0nKW7J6p60BKmrNp8QJF4CprVIxqId1Fkw4nP8F-sJOWsX4xODYFf4uPj9689-Hb9ebC7hS2u8TFBRMWUhaTHZ_38Cwq9cIA9gdJvCDSURR7AC34Kr0Plo2tKqySE8yUj3YDuqEeBYIsXmy2H1dgB7Cl6hCMJ0xCvEozYuDa3hMjVzxBrlVDNjL8IRfhzHV_WAn_8AxSYC3Q==&secret=0x2eb74750df993a163a95db3031359f0bfca6eb56e597f6ede056bd69d1803196&id=geman%40gemanji.com"; request = DeepLinkService.parseIntent(sp2, null); assertTrue(request.type == DeepLinkType.SMARTPASS); @@ -60,6 +70,12 @@ public void intentsAreParsedCorrectly() assertTrue(request.type == DeepLinkType.URL_REDIRECT); assertTrue(request.data.equals("https://ratyeeting.com?ratlaunch=5000")); + //test awallet style link + url = "awallet://openURL?q=https://ratyeeting.com?ratlaunch=5000"; + request = DeepLinkService.parseIntent(url, null); + assertTrue(request.type == DeepLinkType.URL_REDIRECT); + assertTrue(request.data.equals("https://ratyeeting.com?ratlaunch=5000")); + url = "https://aw.app/openurl"; Intent startIntent = new Intent(); startIntent.putExtra("url", "https://wombatcave.com.au");