mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 09:05:21 +00:00
very good
This commit is contained in:
@@ -132,7 +132,7 @@ fun CashuPaymentChip(
|
||||
// Top row: Bitcoin icon and "bitcoin" text
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(3.dp)
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
// Orange Bitcoin circle with symbol inside
|
||||
Box(
|
||||
|
||||
@@ -204,6 +204,11 @@ class ChatViewModel(
|
||||
|
||||
// Check for commands
|
||||
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(
|
||||
command = content,
|
||||
meshService = meshService,
|
||||
@@ -211,8 +216,8 @@ class ChatViewModel(
|
||||
onSendMessage = { messageContent, mentions, channel ->
|
||||
meshService.sendMessage(messageContent, mentions, channel)
|
||||
},
|
||||
onPaymentRequest = { amount ->
|
||||
handlePaymentRequest(amount)
|
||||
onPaymentRequest = { amount, memo ->
|
||||
handlePaymentRequest(amount, memo)
|
||||
}
|
||||
)
|
||||
return
|
||||
@@ -289,8 +294,8 @@ class ChatViewModel(
|
||||
/**
|
||||
* Handle payment request from /pay command
|
||||
*/
|
||||
private fun handlePaymentRequest(amount: Long) {
|
||||
paymentManager?.createPayment(amount) { token ->
|
||||
private fun handlePaymentRequest(amount: Long, memo: String? = null) {
|
||||
paymentManager?.createPayment(amount, memo) { token ->
|
||||
// Send the created token to the current chat
|
||||
sendCashuTokenToChat(token)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class CommandProcessor(
|
||||
meshService: Any,
|
||||
myPeerID: String,
|
||||
onSendMessage: (String, List<String>, String?) -> Unit,
|
||||
onPaymentRequest: ((Long) -> Unit)? = null
|
||||
onPaymentRequest: ((Long, String?) -> Unit)? = null
|
||||
): Boolean {
|
||||
if (!command.startsWith("/")) return false
|
||||
|
||||
@@ -324,11 +324,11 @@ class CommandProcessor(
|
||||
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) {
|
||||
val systemMessage = BitchatMessage(
|
||||
sender = "system",
|
||||
content = "usage: /pay <amount> - send Cashu payment in sats",
|
||||
content = "usage: /pay <amount> <memo> - send Cashu payment in sats",
|
||||
timestamp = Date(),
|
||||
isRelay = false
|
||||
)
|
||||
@@ -338,6 +338,11 @@ class CommandProcessor(
|
||||
|
||||
val amountStr = parts[1]
|
||||
val amount = amountStr.toLongOrNull()
|
||||
|
||||
var memo: String? = null;
|
||||
if (parts.size > 2) {
|
||||
memo = parts.drop(2).joinToString(" ")
|
||||
}
|
||||
|
||||
if (amount == null || amount <= 0) {
|
||||
val systemMessage = BitchatMessage(
|
||||
@@ -362,7 +367,7 @@ class CommandProcessor(
|
||||
}
|
||||
|
||||
// Trigger payment creation
|
||||
onPaymentRequest?.invoke(amount)
|
||||
onPaymentRequest?.invoke(amount, memo)
|
||||
}
|
||||
|
||||
private fun handleUnknownCommand(cmd: String) {
|
||||
|
||||
@@ -37,6 +37,7 @@ class PaymentManager(
|
||||
*/
|
||||
fun createPayment(
|
||||
amount: Long,
|
||||
memo: String? = null,
|
||||
onTokenCreated: (String) -> Unit
|
||||
) {
|
||||
Log.d(TAG, "Creating payment for $amount sats")
|
||||
@@ -49,7 +50,7 @@ class PaymentManager(
|
||||
// Use WalletViewModel's createCashuToken method
|
||||
walletViewModel.createCashuTokenForPayment(
|
||||
amount = amount,
|
||||
memo = "Payment via /pay command",
|
||||
memo = memo,
|
||||
onSuccess = { token ->
|
||||
Log.d(TAG, "Payment token created successfully: ${token.take(20)}...")
|
||||
|
||||
|
||||
@@ -259,7 +259,9 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
||||
onSuccess = { animationData ->
|
||||
showSuccessAnimation(animationData)
|
||||
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()
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user