very good

This commit is contained in:
callebtc
2025-07-15 19:34:45 +02:00
parent 1d8eaa3926
commit 61b1c2c1e0
5 changed files with 24 additions and 11 deletions
@@ -132,7 +132,7 @@ fun CashuPaymentChip(
// Top row: Bitcoin icon and "bitcoin" text // Top row: Bitcoin icon and "bitcoin" text
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(3.dp) horizontalArrangement = Arrangement.spacedBy(4.dp)
) { ) {
// Orange Bitcoin circle with symbol inside // Orange Bitcoin circle with symbol inside
Box( Box(
@@ -204,6 +204,11 @@ class ChatViewModel(
// Check for commands // Check for commands
if (content.startsWith("/")) { if (content.startsWith("/")) {
var memo: String? = null
if (content.startsWith("/pay") && content.split(" ").size > 1) {
// command is /pay <amount> <memo can be multiple words>
memo = content.split(" ").drop(2).joinToString(" ")
}
commandProcessor.processCommand( commandProcessor.processCommand(
command = content, command = content,
meshService = meshService, meshService = meshService,
@@ -211,8 +216,8 @@ class ChatViewModel(
onSendMessage = { messageContent, mentions, channel -> onSendMessage = { messageContent, mentions, channel ->
meshService.sendMessage(messageContent, mentions, channel) meshService.sendMessage(messageContent, mentions, channel)
}, },
onPaymentRequest = { amount -> onPaymentRequest = { amount, memo ->
handlePaymentRequest(amount) handlePaymentRequest(amount, memo)
} }
) )
return return
@@ -289,8 +294,8 @@ class ChatViewModel(
/** /**
* Handle payment request from /pay command * Handle payment request from /pay command
*/ */
private fun handlePaymentRequest(amount: Long) { private fun handlePaymentRequest(amount: Long, memo: String? = null) {
paymentManager?.createPayment(amount) { token -> paymentManager?.createPayment(amount, memo) { token ->
// Send the created token to the current chat // Send the created token to the current chat
sendCashuTokenToChat(token) sendCashuTokenToChat(token)
} }
@@ -34,7 +34,7 @@ class CommandProcessor(
meshService: Any, meshService: Any,
myPeerID: String, myPeerID: String,
onSendMessage: (String, List<String>, String?) -> Unit, onSendMessage: (String, List<String>, String?) -> Unit,
onPaymentRequest: ((Long) -> Unit)? = null onPaymentRequest: ((Long, String?) -> Unit)? = null
): Boolean { ): Boolean {
if (!command.startsWith("/")) return false if (!command.startsWith("/")) return false
@@ -324,11 +324,11 @@ class CommandProcessor(
messageManager.addMessage(systemMessage) messageManager.addMessage(systemMessage)
} }
private fun handlePayCommand(parts: List<String>, onPaymentRequest: ((Long) -> Unit)?) { private fun handlePayCommand(parts: List<String>, onPaymentRequest: ((Long, String?) -> Unit)?) {
if (parts.size < 2) { if (parts.size < 2) {
val systemMessage = BitchatMessage( val systemMessage = BitchatMessage(
sender = "system", sender = "system",
content = "usage: /pay <amount> - send Cashu payment in sats", content = "usage: /pay <amount> <memo> - send Cashu payment in sats",
timestamp = Date(), timestamp = Date(),
isRelay = false isRelay = false
) )
@@ -338,6 +338,11 @@ class CommandProcessor(
val amountStr = parts[1] val amountStr = parts[1]
val amount = amountStr.toLongOrNull() val amount = amountStr.toLongOrNull()
var memo: String? = null;
if (parts.size > 2) {
memo = parts.drop(2).joinToString(" ")
}
if (amount == null || amount <= 0) { if (amount == null || amount <= 0) {
val systemMessage = BitchatMessage( val systemMessage = BitchatMessage(
@@ -362,7 +367,7 @@ class CommandProcessor(
} }
// Trigger payment creation // Trigger payment creation
onPaymentRequest?.invoke(amount) onPaymentRequest?.invoke(amount, memo)
} }
private fun handleUnknownCommand(cmd: String) { private fun handleUnknownCommand(cmd: String) {
@@ -37,6 +37,7 @@ class PaymentManager(
*/ */
fun createPayment( fun createPayment(
amount: Long, amount: Long,
memo: String? = null,
onTokenCreated: (String) -> Unit onTokenCreated: (String) -> Unit
) { ) {
Log.d(TAG, "Creating payment for $amount sats") Log.d(TAG, "Creating payment for $amount sats")
@@ -49,7 +50,7 @@ class PaymentManager(
// Use WalletViewModel's createCashuToken method // Use WalletViewModel's createCashuToken method
walletViewModel.createCashuTokenForPayment( walletViewModel.createCashuTokenForPayment(
amount = amount, amount = amount,
memo = "Payment via /pay command", memo = memo,
onSuccess = { token -> onSuccess = { token ->
Log.d(TAG, "Payment token created successfully: ${token.take(20)}...") Log.d(TAG, "Payment token created successfully: ${token.take(20)}...")
@@ -259,7 +259,9 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
onSuccess = { animationData -> onSuccess = { animationData ->
showSuccessAnimation(animationData) showSuccessAnimation(animationData)
viewModelScope.launch { viewModelScope.launch {
delay(500) // Delay navigation until partway through the success animation
// This allows the view transition to happen during the animation fade-out
delay(1200) // Animation is visible for 2000ms, start transition at 1200ms
hideReceiveDialog() hideReceiveDialog()
} }
}, },