From fb098c726f0f504e58b71c7ce64e6182dc606051 Mon Sep 17 00:00:00 2001 From: yevhen1sec Date: Tue, 7 Jan 2025 01:22:03 +0100 Subject: [PATCH] Made parsing address from qr code more accurate --- .../vultisig/wallet/ui/screens/scan/ScanQrScreen.kt | 3 ++- .../main/java/com/vultisig/wallet/ui/utils/StringX.kt | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/vultisig/wallet/ui/screens/scan/ScanQrScreen.kt b/app/src/main/java/com/vultisig/wallet/ui/screens/scan/ScanQrScreen.kt index c979c1438..0447dde75 100644 --- a/app/src/main/java/com/vultisig/wallet/ui/screens/scan/ScanQrScreen.kt +++ b/app/src/main/java/com/vultisig/wallet/ui/screens/scan/ScanQrScreen.kt @@ -67,6 +67,7 @@ import com.vultisig.wallet.ui.components.UiSpacer import com.vultisig.wallet.ui.models.ScanQrViewModel import com.vultisig.wallet.ui.theme.Theme import com.vultisig.wallet.ui.utils.addWhiteBorder +import com.vultisig.wallet.ui.utils.getAddressFromQrCode import com.vultisig.wallet.ui.utils.uriToBitmap import kotlinx.coroutines.launch import timber.log.Timber @@ -97,7 +98,7 @@ internal fun ScanQrScreen( if (viewModel.getFlowType(qr) == JOIN_SEND_ON_ADDRESS_FLOW) { navController.previousBackStackEntry ?.savedStateHandle - ?.set(ARG_QR_CODE, qr) + ?.set(ARG_QR_CODE, qr.getAddressFromQrCode()) } navController.popBackStack() } diff --git a/app/src/main/java/com/vultisig/wallet/ui/utils/StringX.kt b/app/src/main/java/com/vultisig/wallet/ui/utils/StringX.kt index 147ca74ea..dbc25f1f3 100644 --- a/app/src/main/java/com/vultisig/wallet/ui/utils/StringX.kt +++ b/app/src/main/java/com/vultisig/wallet/ui/utils/StringX.kt @@ -1,12 +1,17 @@ package com.vultisig.wallet.ui.utils internal fun String.getAddressFromQrCode(): String { - val removedPrefix = if (contains(":")) { - substringAfter(":") + val removedSlashPrefix = if (contains("/")) { + substringAfterLast("/") } else { this } - val removedSuffix = if (contains("?")) { + val removedPrefix = if (removedSlashPrefix.contains(":")) { + removedSlashPrefix.substringAfter(":") + } else { + removedSlashPrefix + } + val removedSuffix = if (removedPrefix.contains("?")) { removedPrefix.substringBefore("?") } else { removedPrefix