mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-26 00:05:22 +00:00
a bit better
This commit is contained in:
@@ -376,6 +376,10 @@ class CashuService {
|
|||||||
Log.w(TAG, "Failed to mint for paid quote: ${e.message}")
|
Log.w(TAG, "Failed to mint for paid quote: ${e.message}")
|
||||||
Result.success(false)
|
Result.success(false)
|
||||||
}
|
}
|
||||||
|
} else if (quoteResponse.state == FfiMintQuoteState.ISSUED) {
|
||||||
|
// Quote is issued
|
||||||
|
Log.d(TAG, "Quote $quoteId is issued")
|
||||||
|
Result.success(true)
|
||||||
} else {
|
} else {
|
||||||
// Quote not paid yet
|
// Quote not paid yet
|
||||||
Result.success(false)
|
Result.success(false)
|
||||||
|
|||||||
@@ -272,8 +272,7 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
if (success) {
|
if (success) {
|
||||||
// Update quote status and add transaction
|
// Update quote status and add transaction
|
||||||
val updatedQuote = quote.copy(paid = true, state = MintQuoteState.PAID)
|
val updatedQuote = quote.copy(paid = true, state = MintQuoteState.PAID)
|
||||||
repository.saveMintQuote(updatedQuote)
|
repository.saveMintQuote(updatedQuote).onSuccess {
|
||||||
|
|
||||||
// Update currentMintQuote if it's the same quote
|
// Update currentMintQuote if it's the same quote
|
||||||
if (_currentMintQuote.value?.id == quote.id) {
|
if (_currentMintQuote.value?.id == quote.id) {
|
||||||
_currentMintQuote.value = updatedQuote
|
_currentMintQuote.value = updatedQuote
|
||||||
@@ -289,12 +288,17 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
description = "Lightning payment received",
|
description = "Lightning payment received",
|
||||||
quote = quote.id
|
quote = quote.id
|
||||||
)
|
)
|
||||||
repository.saveTransaction(transaction)
|
repository.saveTransaction(transaction).onSuccess {
|
||||||
|
|
||||||
loadTransactions()
|
loadTransactions()
|
||||||
refreshBalance()
|
refreshBalance()
|
||||||
|
|
||||||
Log.d(TAG, "Mint quote ${quote.id} was paid and minted")
|
Log.d(TAG, "Mint quote ${quote.id} was paid and minted")
|
||||||
|
}.onFailure { error ->
|
||||||
|
Log.e(TAG, "Failed to save transaction for mint quote ${quote.id}", error)
|
||||||
|
}
|
||||||
|
}.onFailure { error ->
|
||||||
|
Log.e(TAG, "Failed to save updated mint quote ${quote.id}", error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,10 +420,13 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
description = memo ?: "Cashu token sent",
|
description = memo ?: "Cashu token sent",
|
||||||
token = token
|
token = token
|
||||||
)
|
)
|
||||||
repository.saveTransaction(transaction)
|
repository.saveTransaction(transaction).onSuccess {
|
||||||
|
|
||||||
loadTransactions()
|
loadTransactions()
|
||||||
refreshBalance()
|
refreshBalance()
|
||||||
|
}.onFailure { error ->
|
||||||
|
Log.e(TAG, "Failed to save transaction", error)
|
||||||
|
_errorMessage.value = "Failed to save transaction: ${error.message}"
|
||||||
|
}
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
_errorMessage.value = "Failed to create token: ${error.message}"
|
_errorMessage.value = "Failed to create token: ${error.message}"
|
||||||
}
|
}
|
||||||
@@ -467,11 +474,14 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
description = "Cashu token received",
|
description = "Cashu token received",
|
||||||
token = token
|
token = token
|
||||||
)
|
)
|
||||||
repository.saveTransaction(transaction)
|
repository.saveTransaction(transaction).onSuccess {
|
||||||
|
|
||||||
loadTransactions()
|
loadTransactions()
|
||||||
refreshBalance()
|
refreshBalance()
|
||||||
hideReceiveDialog()
|
hideReceiveDialog()
|
||||||
|
}.onFailure { error ->
|
||||||
|
Log.e(TAG, "Failed to save transaction", error)
|
||||||
|
_errorMessage.value = "Failed to save transaction: ${error.message}"
|
||||||
|
}
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
_errorMessage.value = "Failed to receive token: ${error.message}"
|
_errorMessage.value = "Failed to receive token: ${error.message}"
|
||||||
}
|
}
|
||||||
@@ -492,8 +502,12 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
_currentMintQuote.value = quote
|
_currentMintQuote.value = quote
|
||||||
|
|
||||||
// Save quote for tracking
|
// Save quote for tracking
|
||||||
repository.saveMintQuote(quote)
|
repository.saveMintQuote(quote).onSuccess {
|
||||||
loadPendingQuotes()
|
loadPendingQuotes()
|
||||||
|
}.onFailure { error ->
|
||||||
|
Log.e(TAG, "Failed to save mint quote", error)
|
||||||
|
_errorMessage.value = "Failed to save invoice: ${error.message}"
|
||||||
|
}
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
_errorMessage.value = "Failed to create invoice: ${error.message}"
|
_errorMessage.value = "Failed to create invoice: ${error.message}"
|
||||||
}
|
}
|
||||||
@@ -514,11 +528,15 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
_currentMeltQuote.value = quote
|
_currentMeltQuote.value = quote
|
||||||
|
|
||||||
// Save quote for tracking
|
// Save quote for tracking
|
||||||
repository.saveMeltQuote(quote)
|
repository.saveMeltQuote(quote).onSuccess {
|
||||||
loadPendingQuotes()
|
loadPendingQuotes()
|
||||||
|
|
||||||
// kick off the polling
|
// kick off the polling
|
||||||
startPolling()
|
startPolling()
|
||||||
|
}.onFailure { error ->
|
||||||
|
Log.e(TAG, "Failed to save melt quote", error)
|
||||||
|
_errorMessage.value = "Failed to save quote: ${error.message}"
|
||||||
|
}
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
_errorMessage.value = "Failed to process invoice: ${error.message}"
|
_errorMessage.value = "Failed to process invoice: ${error.message}"
|
||||||
}
|
}
|
||||||
@@ -541,8 +559,7 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
val quote = _currentMeltQuote.value
|
val quote = _currentMeltQuote.value
|
||||||
if (quote != null) {
|
if (quote != null) {
|
||||||
val updatedQuote = quote.copy(paid = true, state = MeltQuoteState.PAID)
|
val updatedQuote = quote.copy(paid = true, state = MeltQuoteState.PAID)
|
||||||
repository.saveMeltQuote(updatedQuote)
|
repository.saveMeltQuote(updatedQuote).onSuccess {
|
||||||
|
|
||||||
val transaction = WalletTransaction(
|
val transaction = WalletTransaction(
|
||||||
id = UUID.randomUUID().toString(),
|
id = UUID.randomUUID().toString(),
|
||||||
type = TransactionType.LIGHTNING_SEND,
|
type = TransactionType.LIGHTNING_SEND,
|
||||||
@@ -554,11 +571,18 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
quote = quote.id,
|
quote = quote.id,
|
||||||
fee = quote.feeReserve
|
fee = quote.feeReserve
|
||||||
)
|
)
|
||||||
repository.saveTransaction(transaction)
|
repository.saveTransaction(transaction).onSuccess {
|
||||||
|
|
||||||
loadTransactions()
|
loadTransactions()
|
||||||
refreshBalance()
|
refreshBalance()
|
||||||
hideSendDialog()
|
hideSendDialog()
|
||||||
|
}.onFailure { error ->
|
||||||
|
Log.e(TAG, "Failed to save transaction", error)
|
||||||
|
_errorMessage.value = "Failed to save transaction: ${error.message}"
|
||||||
|
}
|
||||||
|
}.onFailure { error ->
|
||||||
|
Log.e(TAG, "Failed to save melt quote", error)
|
||||||
|
_errorMessage.value = "Failed to save quote: ${error.message}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_errorMessage.value = "Payment failed"
|
_errorMessage.value = "Payment failed"
|
||||||
@@ -671,7 +695,11 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
info = mintInfo,
|
info = mintInfo,
|
||||||
lastSync = Date()
|
lastSync = Date()
|
||||||
)
|
)
|
||||||
repository.saveMint(updatedMint)
|
repository.saveMint(updatedMint).onSuccess {
|
||||||
|
// Mint updated successfully
|
||||||
|
}.onFailure { error ->
|
||||||
|
Log.e(TAG, "Failed to save updated mint ${mint.url}", error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error syncing mint ${mint.url}", e)
|
Log.e(TAG, "Error syncing mint ${mint.url}", e)
|
||||||
|
|||||||
Reference in New Issue
Block a user