Skip to content
Draft
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
23 changes: 13 additions & 10 deletions app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,10 @@ class AppViewModel @Inject constructor(
resetSendState()
resetQuickPay()

val input = result.removeLightningSchemes()

// TODO Workaround for https://github.com/synonymdev/bitkit-core/issues/63
if (Bip21Utils.isDuplicatedBip21(result)) {
if (Bip21Utils.isDuplicatedBip21(input)) {
toast(
type = Toast.ToastType.ERROR,
title = context.getString(R.string.other__scan_err_decoding),
Expand All @@ -1078,14 +1080,14 @@ class AppViewModel @Inject constructor(
return@withContext
}

val scan = runCatching { coreService.decode(result) }
.onFailure { Logger.error("Failed to decode scan data: '$result'", it, context = TAG) }
val scan = runCatching { coreService.decode(input) }
.onFailure { Logger.error("Failed to decode scan data: '$input'", it, context = TAG) }
.onSuccess { Logger.info("Handling decoded scan data: $it", context = TAG) }
.getOrNull()

when (scan) {
is Scanner.OnChain -> onScanOnchain(scan.invoice, result)
is Scanner.Lightning -> onScanLightning(scan.invoice, result)
is Scanner.OnChain -> onScanOnchain(scan.invoice, input)
is Scanner.Lightning -> onScanLightning(scan.invoice, input)
is Scanner.LnurlPay -> onScanLnurlPay(scan.data)
is Scanner.LnurlWithdraw -> onScanLnurlWithdraw(scan.data)
is Scanner.LnurlAuth -> onScanLnurlAuth(scan.data)
Expand Down Expand Up @@ -2221,17 +2223,18 @@ class AppViewModel @Inject constructor(

val data = uri.toString()
delay(SCREEN_TRANSITION_DELAY_MS)
handleScan(data.removeLightningSchemes())
handleScan(data)
}

// TODO Temporary fix while these schemes can't be decoded
@Suppress("SpellCheckingInspection")
private fun String.removeLightningSchemes(): String {
return this
.replace("lnurl:", "")
.replace("lnurlw:", "")
.replace("lnurlc:", "")
.replace("lnurlp:", "")
.replace(Regex("^lightning:", RegexOption.IGNORE_CASE), "")
.replace(Regex("^lnurl:", RegexOption.IGNORE_CASE), "")
.replace(Regex("^lnurlw:", RegexOption.IGNORE_CASE), "")
.replace(Regex("^lnurlc:", RegexOption.IGNORE_CASE), "")
.replace(Regex("^lnurlp:", RegexOption.IGNORE_CASE), "")
}

fun checkTimedSheets() = timedSheetManager.onHomeScreenEntered()
Expand Down
Loading