Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4290e2b
feat(dashpay)!: support shielded tips with dedicated wallet accounts
PastaPastaPasta Sep 7, 2026
4956dfa
fix(swift-example-app): expose shielded tip address storage
PastaPastaPasta Sep 7, 2026
75e1592
fix(platform-wallet): harden shielded tip recovery and mobile error h…
PastaPastaPasta Sep 8, 2026
b02eb22
fix(platform-wallet): address shielded tip review findings
PastaPastaPasta Sep 8, 2026
47e9e1b
Merge branch 'v4.2-dev' into feat/dashpay-shielded-tips
QuantumExplorer Sep 15, 2026
a637a0e
fix(platform-wallet): contain tip export panics and share the mobile …
QuantumExplorer Sep 15, 2026
8010d0c
Merge branch 'v5.1-dev' into feat/dashpay-shielded-tips
PastaPastaPasta Oct 5, 2026
4e070e9
fix(platform-wallet): address remaining shielded tip review threads
PastaPastaPasta Oct 5, 2026
0c61806
test(platform-wallet): set integer_range_clauses in the tip resolver …
PastaPastaPasta Oct 5, 2026
4e803f2
fix(wallet-storage): decode payment-only identity rewrites by their f…
PastaPastaPasta Oct 5, 2026
43b7eb7
fix(kotlin-example-app): make the shielded tip screens compile
PastaPastaPasta Oct 5, 2026
a69b2d0
fix(swift-example-app): rebind shielded with ordinary accounts only
PastaPastaPasta Oct 5, 2026
f4e9f07
test(platform-wallet-ffi): cover owned DashPay profile hydration thro…
PastaPastaPasta Oct 5, 2026
a1c33fa
fix(platform-wallet): verify the identity index before allocating a t…
PastaPastaPasta Oct 5, 2026
1e27b9f
fix(platform-wallet): refuse verified identity placement into an occu…
PastaPastaPasta Oct 5, 2026
86af2c2
fix(kotlin-example-app): rebind shielded after every successful disco…
PastaPastaPasta Oct 5, 2026
5b6e8d6
fix(platform-wallet): refuse adding an identity into an occupied slot
PastaPastaPasta Oct 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class AppContainer(private val context: Context) {

val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)

val shieldedTipSubmissions =
org.dashfoundation.example.ui.dashpay.ShieldedTipSubmissions(applicationScope)

val database: DashDatabase = DashDatabase.create(context)

val dataStore = context.preferencesStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ data class DashPayProfile(
val displayName: String?,
val publicMessage: String?,
val avatarUrl: String?,
val corePaymentAddress: String? = null,
val platformPaymentAddress: String? = null,
val shieldedAddress: String? = null,
)

/** Parse a `getProfile` / `getContactProfile` JSON object, or null. */
Expand All @@ -32,6 +35,9 @@ fun parseDashPayProfile(json: String?): DashPayProfile? {
displayName = obj.optStringOrNull("displayName"),
publicMessage = obj.optStringOrNull("publicMessage"),
avatarUrl = obj.optStringOrNull("avatarUrl"),
corePaymentAddress = obj.optStringOrNull("corePaymentAddress"),
platformPaymentAddress = obj.optStringOrNull("platformPaymentAddress"),
shieldedAddress = obj.optStringOrNull("shieldedAddress"),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -39,14 +40,20 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import java.math.BigDecimal
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.dashfoundation.dashsdk.tokens.PaymentAddressUpdate
import org.dashfoundation.example.di.LocalAppContainer
import org.dashfoundation.example.ui.components.FormSection
import org.dashfoundation.example.ui.components.LabeledContent
import org.dashfoundation.example.ui.components.SubmitButton
import org.dashfoundation.example.util.Base58
import org.dashfoundation.example.util.DashAddress
import org.dashfoundation.example.util.DashAddressType
import org.dashfoundation.example.util.generateQrBitmap
import org.dashfoundation.example.util.hexToBytes

Expand All @@ -72,7 +79,24 @@ fun DashPayProfileScreen(identityIdHex: String, navController: NavHostController
val walletId = identity?.walletId
val wallet = remember(manager, walletId) { walletId?.let { manager?.wallet(forWalletId = it) } }

// Derived from the live identity's index, not Room's placeholder 0 (see DashPayTabScreen).
val tipAccount by produceState<Int?>(initialValue = null, wallet, manager, identityIdHex) {
value = wallet?.let { w ->
runCatching { w.identityIndex(idBytes)?.let { index -> manager?.shieldedTipAccountIndex(index) } }
.getOrNull()
}
}
val tipBalance by remember(walletId, tipAccount) {
val account = tipAccount
if (walletId == null || account == null) flowOf(0L)
else container.database.shieldedDao().observeNotesByWalletAccount(walletId, account)
.map { notes -> notes.filter { !it.isSpent }.sumOf { it.value } }
}.collectAsStateWithLifecycle(initialValue = 0L)

var profile by remember { mutableStateOf<DashPayProfile?>(null) }
val publishedTipAddress = profile?.shieldedAddress?.let { raw ->
manager?.let { m -> runCatching { DashAddress.encodeOrchard(raw.hexToBytes(), m.network) }.getOrNull() }
}
var profileExists by remember { mutableStateOf(false) }
var qrUri by remember { mutableStateOf<String?>(null) }
var qrError by remember { mutableStateOf<String?>(null) }
Expand All @@ -87,6 +111,7 @@ fun DashPayProfileScreen(identityIdHex: String, navController: NavHostController
var displayNameField by remember { mutableStateOf("") }
var publicMessageField by remember { mutableStateOf("") }
var avatarUrlField by remember { mutableStateOf("") }
var shieldedAddressField by remember { mutableStateOf("") }
var isSaving by remember { mutableStateOf(false) }
var saveError by remember { mutableStateOf<String?>(null) }

Expand Down Expand Up @@ -132,6 +157,7 @@ fun DashPayProfileScreen(identityIdHex: String, navController: NavHostController
displayNameField = profile?.displayName.orEmpty()
publicMessageField = profile?.publicMessage.orEmpty()
avatarUrlField = profile?.avatarUrl.orEmpty()
shieldedAddressField = publishedTipAddress.orEmpty()
saveError = null
}
isEditing = !isEditing
Expand Down Expand Up @@ -172,6 +198,31 @@ fun DashPayProfileScreen(identityIdHex: String, navController: NavHostController
label = { Text("Avatar URL") },
singleLine = true,
)
TextButton(enabled = !isSaving && container.shieldedService.isAvailable, onClick = {
val m = manager ?: return@TextButton
val wid = walletId ?: return@TextButton
isSaving = true
saveError = null
scope.launch {
try {
shieldedAddressField = requireNotNull(DashAddress.encodeOrchard(m.prepareShieldedTipAddress(wid, idBytes), m.network))
} catch (e: Exception) {
saveError = e.message ?: "Could not prepare tip account"
} finally {
isSaving = false
}
}
}, modifier = Modifier.testTag("dashpay.profile.useTipAccount")) {
Text("Use this wallet’s dedicated tip account")
}
Text("The address is published only when you save.", style = MaterialTheme.typography.bodySmall)
OutlinedTextField(
value = shieldedAddressField,
onValueChange = { shieldedAddressField = it },
modifier = Modifier.fillMaxWidth().testTag("dashpay.profile.shieldedAddress"),
label = { Text("Shielded tip address") },
supportingText = { Text("Paste an external receiving address, or leave blank to disable tips. External funds are managed by the receiving wallet.") },
)
saveError?.let {
Text(it, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.error)
}
Expand All @@ -194,6 +245,15 @@ fun DashPayProfileScreen(identityIdHex: String, navController: NavHostController
avatarUrl = avatarUrlField.trim().ifEmpty { null },
doCreate = !profileExists,
signerHandle = m.signerHandle,
shieldedAddress = when (val address = shieldedAddressField.trim()) {
publishedTipAddress.orEmpty() -> PaymentAddressUpdate.Keep
"" -> PaymentAddressUpdate.Remove
else -> {
val parsed = DashAddress.parse(address, m.network) as? DashAddressType.Orchard
?: throw IllegalArgumentException("Enter a shielded address for this network")
PaymentAddressUpdate.Set(parsed.raw43)
}
},
)
loadProfile()
isEditing = false
Expand Down Expand Up @@ -224,6 +284,19 @@ fun DashPayProfileScreen(identityIdHex: String, navController: NavHostController
}
}

if (!isEditing) {
FormSection(title = "Shielded tips") {
Text("This wallet’s tip balance: ${BigDecimal.valueOf(tipBalance, 11).stripTrailingZeros().toPlainString()} DASH")
val address = publishedTipAddress
if (address == null) {
Text("Tips are not enabled.")
} else {
SelectionContainer { Text(address, style = MaterialTheme.typography.bodySmall) }
Text("This receiving address is public and associated with your username. Removing it does not revoke previously shared copies.", style = MaterialTheme.typography.bodySmall)
}
}
}

FormSection(title = "Identity") {
Text(
Base58.encode(idBytes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SheetValue
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
Expand All @@ -37,7 +39,9 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -159,6 +163,7 @@ fun DashPayTabScreen(navController: NavHostController) {
val appUiState = container.appUiState
var claimSheetUri by remember { mutableStateOf<String?>(null) }
var showClaimSheet by remember { mutableStateOf(false) }
var showTipSheet by remember { mutableStateOf(false) }
val pendingInvite by appUiState.pendingInviteUri.collectAsStateWithLifecycle()
val claimInFlight by appUiState.invitationClaimInFlight.collectAsStateWithLifecycle()
// The parked URI is NOT cleared at seeding: it stays in AppUiState (the
Expand Down Expand Up @@ -320,7 +325,61 @@ fun DashPayTabScreen(navController: NavHostController) {
onError = { unlockError = it },
)

val tipManager = manager
val tipWalletId = identity.walletId
// The tip account follows the live identity's derivation index, not
// Room's non-null `identityIndex`: its 0 is a placeholder for an identity
// with no recoverable index and would alias identity 0's tip pool.
// produceState keeps its last value when its keys change, so each result
// is tagged with the inputs it was resolved for and a result for another
// identity or wallet is never offered while the new lookup runs.
val tipAccountKey = listOf(managed, tipManager, identityHex)
val taggedTipAccount by produceState<Pair<List<Any?>, Result<Int>>?>(
initialValue = null, managed, tipManager, identityHex,
) {
Comment thread
PastaPastaPasta marked this conversation as resolved.
value = tipAccountKey to runCatching {
val index = requireNotNull(managed) { "Wallet is not loaded" }
.identityIndex(identity.identityId)
?: error("Tip account requires a recoverable identity index")
requireNotNull(tipManager).shieldedTipAccountIndex(index)
}
}
val tipAccountResult = taggedTipAccount
?.takeIf { (key, _) -> key == tipAccountKey }
?.second
val tipAccount = tipAccountResult?.getOrNull()
val tipSubmission = tipWalletId?.let {
container.shieldedTipSubmissions.forWallet(network.ffiValue, it.toHex())
}
val tipSending by rememberUpdatedState(tipSubmission?.busy == true)
val tipSheetState = rememberModalBottomSheetState(
confirmValueChange = { value -> value != SheetValue.Hidden || !tipSending },
)
if (showTipSheet && managed != null && tipManager != null && tipWalletId != null && tipAccount != null && tipSubmission != null) {
ModalBottomSheet(
sheetState = tipSheetState,
onDismissRequest = { if (!tipSubmission.busy) showTipSheet = false },
) {
ShieldedTipSheet(tipManager, managed, tipWalletId, tipAccount, tipSubmission)
}
}
FormSection(title = "DashPay") {
if (container.shieldedService.isAvailable) {
EntityRow(
icon = Icons.AutoMirrored.Filled.Send,
title = "Send shielded tip",
onClick = {
when (val result = tipAccountResult) {
null -> unlockError = "The tip account is still loading"
else -> result.fold(
onSuccess = { showTipSheet = true },
onFailure = { unlockError = it.message ?: "Could not open shielded tips" },
)
}
},
modifier = Modifier.testTag("dashpay.sendShieldedTip"),
)
}
EntityRow(
icon = Icons.Default.Group,
title = "Contacts",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.dashfoundation.example.ui.dashpay

import org.dashfoundation.dashsdk.errors.DashSdkError

/**
* Permit a fresh user review only for failures known not to have executed a tip.
* On the tip path, Rust maps selection/build/recipient-check failures to
* WalletOperation. Broadcast ambiguity maps to ShieldedSpendUnconfirmed, and
* successful post-broadcast bookkeeping is best-effort (never WalletOperation).
* Unknown exceptions, including JNI failures and cancellation, remain locked.
*/
internal fun canReviewShieldedTipAfterFailure(error: Exception): Boolean = when (error) {
is IllegalArgumentException,
is DashSdkError.InvalidParameter,
is DashSdkError.PlatformWallet.InvalidHandle,
is DashSdkError.PlatformWallet.NotFound,
is DashSdkError.PlatformWallet.SigningKeyUnavailable,
is DashSdkError.PlatformWallet.WalletOperation,
is DashSdkError.PlatformWallet.ShieldedNoRecordedAnchor,
is DashSdkError.PlatformWallet.ShieldedBroadcastFailed -> true
// ErrorInvalidParameter is a preflight-only FFI failure on this call path.
is DashSdkError.PlatformWallet.Generic -> error.nativeCode == 2
else -> false
}
Loading
Loading