feat: add payment targets button to profile icon row
Shows a wallet icon button in the profile action row when a user has published payment targets (kind 10133). Tapping it opens a dropdown listing each target; selecting one opens the payto:// deep link. https://claude.ai/code/session_018G4g1cChqjeNEM5TztD3FE
This commit is contained in:
+110
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Vitor Pamplona
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.header
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.AccountBalanceWallet
|
||||||
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.FilledTonalButton
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalUriHandler
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.vitorpamplona.amethyst.R
|
||||||
|
import com.vitorpamplona.amethyst.model.User
|
||||||
|
import com.vitorpamplona.amethyst.ui.note.LoadAddressableNote
|
||||||
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import com.vitorpamplona.amethyst.ui.stringRes
|
||||||
|
import com.vitorpamplona.amethyst.ui.theme.ZeroPadding
|
||||||
|
import com.vitorpamplona.quartz.experimental.nipA3.PaymentTarget
|
||||||
|
import com.vitorpamplona.quartz.experimental.nipA3.PaymentTargetsEvent
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun PaymentButton(
|
||||||
|
user: User,
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
) {
|
||||||
|
val address =
|
||||||
|
remember(user.pubkeyHex) {
|
||||||
|
PaymentTargetsEvent.createAddress(user.pubkeyHex)
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadAddressableNote(address, accountViewModel) { note ->
|
||||||
|
val targets =
|
||||||
|
remember(note) {
|
||||||
|
(note?.event as? PaymentTargetsEvent)?.paymentTargets() ?: emptyList()
|
||||||
|
}
|
||||||
|
if (targets.isNotEmpty()) {
|
||||||
|
PaymentButtonWithTargets(targets)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun PaymentButtonWithTargets(targets: List<PaymentTarget>) {
|
||||||
|
val uri = LocalUriHandler.current
|
||||||
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
Box {
|
||||||
|
FilledTonalButton(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.padding(horizontal = 3.dp)
|
||||||
|
.width(50.dp),
|
||||||
|
onClick = { expanded = true },
|
||||||
|
contentPadding = ZeroPadding,
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.AccountBalanceWallet,
|
||||||
|
contentDescription = stringRes(R.string.payment_targets),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = expanded,
|
||||||
|
onDismissRequest = { expanded = false },
|
||||||
|
) {
|
||||||
|
targets.forEach { target ->
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = {
|
||||||
|
Text("${target.type.replaceFirstChar(Char::titlecase)}: ${target.authority}")
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
expanded = false
|
||||||
|
runCatching {
|
||||||
|
uri.openUri("payto://${target.type}/${target.authority}")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -40,6 +40,8 @@ fun ProfileActions(
|
|||||||
) {
|
) {
|
||||||
MessageButton(baseUser, accountViewModel, nav)
|
MessageButton(baseUser, accountViewModel, nav)
|
||||||
|
|
||||||
|
PaymentButton(baseUser, accountViewModel)
|
||||||
|
|
||||||
val isMe by
|
val isMe by
|
||||||
remember(accountViewModel) { derivedStateOf { accountViewModel.userProfile() == baseUser } }
|
remember(accountViewModel) { derivedStateOf { accountViewModel.userProfile() == baseUser } }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user