mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 12:25:20 +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,29 +272,33 @@ 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
|
||||||
|
if (_currentMintQuote.value?.id == quote.id) {
|
||||||
|
_currentMintQuote.value = updatedQuote
|
||||||
|
}
|
||||||
|
|
||||||
// Update currentMintQuote if it's the same quote
|
val transaction = WalletTransaction(
|
||||||
if (_currentMintQuote.value?.id == quote.id) {
|
id = UUID.randomUUID().toString(),
|
||||||
_currentMintQuote.value = updatedQuote
|
type = TransactionType.LIGHTNING_RECEIVE,
|
||||||
|
amount = quote.amount,
|
||||||
|
unit = quote.unit,
|
||||||
|
status = TransactionStatus.CONFIRMED,
|
||||||
|
timestamp = Date(),
|
||||||
|
description = "Lightning payment received",
|
||||||
|
quote = quote.id
|
||||||
|
)
|
||||||
|
repository.saveTransaction(transaction).onSuccess {
|
||||||
|
loadTransactions()
|
||||||
|
refreshBalance()
|
||||||
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
val transaction = WalletTransaction(
|
|
||||||
id = UUID.randomUUID().toString(),
|
|
||||||
type = TransactionType.LIGHTNING_RECEIVE,
|
|
||||||
amount = quote.amount,
|
|
||||||
unit = quote.unit,
|
|
||||||
status = TransactionStatus.CONFIRMED,
|
|
||||||
timestamp = Date(),
|
|
||||||
description = "Lightning payment received",
|
|
||||||
quote = quote.id
|
|
||||||
)
|
|
||||||
repository.saveTransaction(transaction)
|
|
||||||
|
|
||||||
loadTransactions()
|
|
||||||
refreshBalance()
|
|
||||||
|
|
||||||
Log.d(TAG, "Mint quote ${quote.id} was paid and minted")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,24 +559,30 @@ 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,
|
amount = quote.amount,
|
||||||
amount = quote.amount,
|
unit = quote.unit,
|
||||||
unit = quote.unit,
|
status = TransactionStatus.CONFIRMED,
|
||||||
status = TransactionStatus.CONFIRMED,
|
timestamp = Date(),
|
||||||
timestamp = Date(),
|
description = "Lightning payment sent",
|
||||||
description = "Lightning payment sent",
|
quote = quote.id,
|
||||||
quote = quote.id,
|
fee = quote.feeReserve
|
||||||
fee = quote.feeReserve
|
)
|
||||||
)
|
repository.saveTransaction(transaction).onSuccess {
|
||||||
repository.saveTransaction(transaction)
|
loadTransactions()
|
||||||
|
refreshBalance()
|
||||||
loadTransactions()
|
hideSendDialog()
|
||||||
refreshBalance()
|
}.onFailure { error ->
|
||||||
hideSendDialog()
|
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