Skip to content

Commit

Permalink
Fix missing WssException handling when scanning qr codes from profile
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarIlic committed Apr 8, 2024
1 parent bbebbe6 commit 598ea48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import kotlinx.coroutines.launch
import net.primal.android.core.compose.profile.model.asProfileDetailsUi
import net.primal.android.crypto.bech32ToHexOrThrow
import net.primal.android.navigation.profileId
import net.primal.android.networking.sockets.errors.WssException
import net.primal.android.nostr.ext.extractNoteId
import net.primal.android.nostr.ext.extractProfileId
import net.primal.android.profile.qr.ProfileQrCodeContract.SideEffect
Expand Down Expand Up @@ -95,11 +96,18 @@ class ProfileQrCodeViewModel @Inject constructor(
}

private suspend fun processWalletText(text: String) {
val draftTx = walletTextParser.parseText(userId = activeAccountStore.activeUserId(), text = text)
if (draftTx != null) {
setEffect(SideEffect.WalletTxDetected(draftTx = draftTx))
} else {
Timber.w("Unable to parse text. [text = $text]")
try {
val draftTx = walletTextParser.parseAndQueryText(
userId = activeAccountStore.activeUserId(),
text = text,
)
if (draftTx != null) {
setEffect(SideEffect.WalletTxDetected(draftTx = draftTx))
} else {
Timber.w("Unable to parse text. [text = $text]")
}
} catch (error: WssException) {
Timber.w(error)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class WalletTextParser @Inject constructor(
private val walletRepository: WalletRepository,
) {

suspend fun parseText(userId: String, text: String): DraftTx? {
suspend fun parseAndQueryText(userId: String, text: String): DraftTx? {
return when (text.parseRecipientType()) {
WalletRecipientType.LnInvoice -> handleLnInvoiceText(userId, text)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SendPaymentViewModel @Inject constructor(
setState { copy(parsing = true) }
val userId = activeAccountStore.activeUserId()
try {
val draftTx = walletTextParser.parseText(userId = userId, text = text)
val draftTx = walletTextParser.parseAndQueryText(userId = userId, text = text)
if (draftTx != null) {
setEffect(SideEffect.DraftTransactionReady(draft = draftTx))
} else {
Expand Down

0 comments on commit 598ea48

Please sign in to comment.