diff --git a/.forgejo/workflows/android-release.yml b/.forgejo/workflows/android-release.yml index fac345a..8b93cd0 100644 --- a/.forgejo/workflows/android-release.yml +++ b/.forgejo/workflows/android-release.yml @@ -124,7 +124,7 @@ jobs: join=0 if [ -n "${FORGEJO_TOKEN:-}" ]; then http=$(curl -sS --http1.1 -o /tmp/latest-rel.json -w '%{http_code}' \ - -u "sirius:${FORGEJO_TOKEN}" \ + -H "Authorization: Bearer $FORGEJO_TOKEN" \ "$REPO_API/releases/tags/$latest" || true) if [ "$http" != "200" ]; then join=1 @@ -427,7 +427,7 @@ jobs: i=0 while [ "$i" -lt 6 ]; do code=$(curl -sS --http1.1 -o /tmp/tag.json -w '%{http_code}' \ - -u "sirius:${FORGEJO_TOKEN}" \ + -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ "$REPO_API/tags/$TAG" || true) if [ "$code" = "200" ]; then tag_exists=1 diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml index ac5e6ef..c4b13d0 100644 --- a/.forgejo/workflows/release.yml +++ b/.forgejo/workflows/release.yml @@ -86,7 +86,7 @@ jobs: api_curl() { curl -sS --http1.1 --retry 5 --retry-all-errors --retry-delay 3 \ --connect-timeout 20 --max-time 60 \ - -u "sirius:${FORGEJO_TOKEN}" "$@" | sed 's/\r$//' + -H "Authorization: Bearer $FORGEJO_TOKEN" "$@" } input_tag="${INPUT_TAG:-}" @@ -430,19 +430,19 @@ jobs: FORGEJO_TOKEN=$(printf '%s' "$FORGEJO_TOKEN" | tr -d '\r\n') echo "fail-closed: removing tag $TAG created by this run" code=$(curl -sS --http1.1 -o /tmp/rel.json -w '%{http_code}' \ - -u "sirius:${FORGEJO_TOKEN}" \ + -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ "$REPO_API/releases/tags/$TAG") if [ "$code" = "200" ]; then rid=$(python3 -c "import json; print(json.load(open('/tmp/rel.json'))['id'])") echo "deleting incomplete release id $rid" curl -sS --http1.1 -X DELETE \ - -u "sirius:${FORGEJO_TOKEN}" \ + -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ "$REPO_API/releases/$rid" -o /dev/null -w "DELETE release HTTP %{http_code}\n" else echo "no release for $TAG (HTTP $code)" fi del=$(curl -sS --http1.1 -o /tmp/tag-del.json -w '%{http_code}' -X DELETE \ - -u "sirius:${FORGEJO_TOKEN}" \ + -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ "$REPO_API/tags/$TAG") echo "DELETE tag HTTP $del" if [ "$del" != "204" ] && [ "$del" != "404" ]; then diff --git a/.gitignore b/.gitignore index dca8ac8..44746d1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ # whatever the developer has installed — never commit them. /.android-env.sh android/local.properties -android/.cargo/ # Gradle / Android build output android/.gradle/ diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index f72f3ac..f1238bb 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -136,7 +136,4 @@ dependencies { androidTestImplementation(libs.junit) androidTestImplementation(libs.androidx.test.ext.junit) androidTestImplementation(libs.androidx.test.runner) - - // QR code rendering for the wallet receive-address screen. - implementation(libs.zxing) } diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt b/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt index 6038c5c..45872b3 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt @@ -29,7 +29,6 @@ import com.siriusdevops.onionwire.ui.RosterScreen import com.siriusdevops.onionwire.ui.RotateScreen import com.siriusdevops.onionwire.ui.ShareInviteScreen import com.siriusdevops.onionwire.ui.UnlockScreen -import com.siriusdevops.onionwire.ui.WalletScreen import com.siriusdevops.onionwire.ui.OnionWireTheme import kotlinx.coroutines.launch @@ -105,7 +104,6 @@ private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: Str onRotate = { nav.navigate("rotate") }, onWipe = { scope.launch { vm.wipeMessages() } }, onLock = vm::lock, - onOpenWallet = { nav.navigate("wallet") }, ) } @@ -132,10 +130,6 @@ private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: Str ) } - composable("wallet") { - WalletScreen(vm = vm, onBack = { nav.popBackStack() }) - } - composable( route = "chat/{pk}", arguments = listOf(navArgument("pk") { type = NavType.StringType }), diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt b/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt index b25a0c0..dd49f75 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt @@ -23,7 +23,6 @@ import uniffi.onionwire_sdk.InviteInfo import uniffi.onionwire_sdk.OutboxRow import uniffi.onionwire_sdk.RotateOutcome import uniffi.onionwire_sdk.SendState -import uniffi.onionwire_sdk.TransferRow import uniffi.onionwire_sdk.Wire import uniffi.onionwire_sdk.decodeInvite import java.io.File @@ -406,26 +405,4 @@ class WireViewModel(app: Application) : AndroidViewModel(app) { } suspend fun decode(invite: String): InviteInfo = decodeInvite(invite) - - // --- Wallet & payments ------------------------------------------------- - // These mirror the SDK surface added for the wallet screen. Payment sends - // are one-shot: if the peer's onion is unreachable, `send_*` fails now. - // They are NOT queued through the outbox like chat messages — that is a - // deliberate choice in the core, not a bug. - - suspend fun walletBalance(): String = requireWire().walletBalance() - - suspend fun walletReceiveAddress(): String? = runCatching { - requireWire().walletReceiveAddress() - }.getOrElse { null } - - suspend fun walletRecentTransfers(cap: Int = 25): List = runCatching { - requireWire().walletRecentTransfers(cap.toUInt()) - }.getOrElse { emptyList() } - - suspend fun sendInvoice(pubkeyHex: String, amountXmr: String, memo: String = ""): Result = - runCatching { requireWire().sendInvoice(pubkeyHex, amountXmr, memo) } - - suspend fun sendTip(pubkeyHex: String, amountXmr: String, memo: String = ""): Result = - runCatching { requireWire().sendTip(pubkeyHex, amountXmr, memo) } } diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt index 18b8750..c4fbe42 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/RosterScreen.kt @@ -47,7 +47,6 @@ fun RosterScreen( onRotate: () -> Unit, onWipe: () -> Unit, onLock: () -> Unit, - onOpenWallet: () -> Unit, ) { var confirmWipe by remember { mutableStateOf(false) } @@ -97,13 +96,12 @@ fun RosterScreen( Spacer(Modifier.height(8.dp)) Row( - modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp), + Modifier.fillMaxWidth().padding(horizontal = 8.dp), horizontalArrangement = Arrangement.SpaceEvenly, ) { TextButton(onClick = onShare) { Text("Invite") } TextButton(onClick = onPaste) { Text("Add") } TextButton(onClick = onRotate) { Text("Rotate") } - TextButton(onClick = onOpenWallet) { Text("Wallet") } TextButton(onClick = { confirmWipe = true }) { Text("Wipe chat") } } diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt deleted file mode 100644 index a4d3776..0000000 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt +++ /dev/null @@ -1,366 +0,0 @@ -package com.siriusdevops.onionwire.ui - -import android.graphics.Bitmap -import android.graphics.Color -import androidx.compose.foundation.Image -import androidx.compose.foundation.border -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.aspectRatio -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Button -import androidx.compose.material3.Card -import androidx.compose.material3.CardDefaults -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.OutlinedButton -import androidx.compose.material3.OutlinedTextField -import androidx.compose.material3.Scaffold -import androidx.compose.material3.Text -import androidx.compose.material3.TextButton -import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.asImageBitmap -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.text.font.FontFamily -import androidx.compose.ui.unit.dp -import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.google.zxing.BarcodeFormat -import com.google.zxing.EncodeHintType -import com.google.zxing.qrcode.QRCodeWriter -import com.siriusdevops.onionwire.WireViewModel -import kotlinx.coroutines.launch -import uniffi.onionwire_sdk.FriendInfo -import uniffi.onionwire_sdk.TransferRow - -private enum class PayKind { Invoice, Tip } - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun WalletScreen( - vm: WireViewModel, - onBack: () -> Unit, -) { - val friends by vm.friends.collectAsStateWithLifecycle() - val scope = rememberCoroutineScope() - var showQr by remember { mutableStateOf(false) } - var balance by remember { mutableStateOf(null) } - var address by remember { mutableStateOf(null) } - var transfers by remember { mutableStateOf>(emptyList()) } - var error by remember { mutableStateOf(null) } - var composer by remember { mutableStateOf(null) } - - suspend fun reload() { - runCatching { balance = vm.walletBalance() } - .onFailure { error = it.message ?: it.toString() } - runCatching { address = vm.walletReceiveAddress() } - runCatching { transfers = vm.walletRecentTransfers(25) } - } - - LaunchedEffect(Unit) { reload() } - - Scaffold( - topBar = { - TopAppBar( - title = { Text("Wallet") }, - navigationIcon = { - TextButton(onClick = onBack) { Text("Back") } - }, - colors = TopAppBarDefaults.topAppBarColors( - containerColor = MaterialTheme.colorScheme.background, - ), - ) - }, - ) { pad -> - Column( - Modifier.padding(pad).fillMaxSize(), - ) { - Card( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 12.dp, vertical = 8.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), - ) { - Column( - Modifier.padding(16.dp), - horizontalAlignment = Alignment.CenterHorizontally, - ) { - Text( - when (balance) { - null -> "loading…" - "off" -> "wallet off" - "err" -> "balance —" - else -> balance ?: "" - }, - style = MaterialTheme.typography.headlineSmall, - fontFamily = FontFamily.Monospace, - ) - val addr = address - if (addr != null) { - Spacer(Modifier.height(8.dp)) - Text( - "receive address", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - Spacer(Modifier.height(4.dp)) - Text( - addr, - style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, - modifier = Modifier.fillMaxWidth(), - ) - TextButton(onClick = { showQr = !showQr }) { - Text(if (showQr) "Hide QR" else "Show QR") - } - if (showQr) { - val qr = remember(addr) { generateQrBitmap(addr) } - qr?.let { bm -> - Box( - modifier = Modifier - .fillMaxWidth() - .aspectRatio(1f) - .border( - 1.dp, - MaterialTheme.colorScheme.outline, - RoundedCornerShape(8.dp), - ) - .padding(8.dp), - contentAlignment = Alignment.Center, - ) { - Image( - bitmap = bm.asImageBitmap(), - contentDescription = "QR code for receive address", - modifier = Modifier.fillMaxSize(), - contentScale = ContentScale.Fit, - ) - } - } - } - } - } - } - - if (transfers.isNotEmpty()) { - Text( - "recent transfers", - style = MaterialTheme.typography.titleSmall, - modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp), - ) - LazyColumn( - modifier = Modifier - .fillMaxWidth() - .weight(1f, fill = false) - .padding(horizontal = 12.dp), - verticalArrangement = Arrangement.spacedBy(4.dp), - ) { - items(transfers, key = { it.txid }) { t -> - TransferCard(t) - } - } - } else { - Spacer(Modifier.weight(1f)) - } - - val kind = composer - if (kind != null) { - PayComposer( - kind = kind, - friends = friends, - onCancel = { composer = null }, - onSend = { pk, amount, memo -> - scope.launch { - error = null - val result = when (kind) { - PayKind.Invoice -> vm.sendInvoice(pk, amount, memo) - PayKind.Tip -> vm.sendTip(pk, amount, memo) - } - result.fold( - onSuccess = { - composer = null - reload() - }, - onFailure = { error = it.message ?: it.toString() }, - ) - } - }, - ) - } else { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(12.dp), - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - OutlinedButton( - onClick = { composer = PayKind.Invoice }, - modifier = Modifier.weight(1f), - ) { Text("Invoice") } - OutlinedButton( - onClick = { composer = PayKind.Tip }, - modifier = Modifier.weight(1f), - ) { Text("Tip") } - } - } - - error?.let { - Text( - it, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error, - modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp), - ) - } - } - } -} - -@Composable -private fun TransferCard(t: TransferRow) { - Card( - modifier = Modifier.fillMaxWidth(), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), - ) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(12.dp), - horizontalArrangement = Arrangement.SpaceBetween, - ) { - Column(modifier = Modifier.weight(1f)) { - Text( - t.txid.take(16) + "…", - style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, - ) - Text( - t.address, - style = MaterialTheme.typography.labelSmall, - fontFamily = FontFamily.Monospace, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } - Text( - t.amount, - style = MaterialTheme.typography.bodyMedium, - fontFamily = FontFamily.Monospace, - ) - } - } -} - -@Composable -private fun PayComposer( - kind: PayKind, - friends: List, - onCancel: () -> Unit, - onSend: (pubkeyHex: String, amount: String, memo: String) -> Unit, -) { - var selected by remember { - mutableStateOf(friends.singleOrNull()?.pubkeyHex) - } - var amount by remember { mutableStateOf("") } - var memo by remember { mutableStateOf("") } - val ready = selected != null && amount.trim().isNotEmpty() - - Card( - modifier = Modifier - .fillMaxWidth() - .padding(12.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), - ) { - Column(Modifier.padding(12.dp)) { - Text( - if (kind == PayKind.Invoice) "Send invoice" else "Send tip", - style = MaterialTheme.typography.titleSmall, - ) - Spacer(Modifier.height(8.dp)) - if (friends.isEmpty()) { - Text( - "Add a friend first. Invoice and tip are one-shot to a peer onion.", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } else { - Text("to", style = MaterialTheme.typography.labelSmall) - friends.forEach { f -> - val label = f.petname?.takeIf { it.isNotBlank() } ?: f.fingerprint - TextButton(onClick = { selected = f.pubkeyHex }) { - Text(if (selected == f.pubkeyHex) "• $label" else label) - } - } - } - OutlinedTextField( - value = amount, - onValueChange = { amount = it }, - singleLine = true, - label = { Text("amount XMR") }, - modifier = Modifier.fillMaxWidth(), - ) - Spacer(Modifier.height(8.dp)) - OutlinedTextField( - value = memo, - onValueChange = { memo = it }, - singleLine = true, - label = { Text("memo (optional)") }, - modifier = Modifier.fillMaxWidth(), - ) - Spacer(Modifier.height(8.dp)) - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.End, - ) { - TextButton(onClick = onCancel) { Text("Cancel") } - Button( - onClick = { - val pk = selected ?: return@Button - onSend(pk, amount.trim(), memo.trim()) - }, - enabled = ready, - ) { Text("Send") } - } - } - } -} - -/** Generate a QR bitmap for the given URI string. Returns null on encode failure. */ -internal fun generateQrBitmap(uri: String): Bitmap? { - return try { - val hints = mapOf(EncodeHintType.MARGIN to 1) - val writer = QRCodeWriter() - val matrix = writer.encode(uri, BarcodeFormat.QR_CODE, 512, 512, hints) - val buf = Bitmap.createBitmap(matrix.width, matrix.height, Bitmap.Config.ARGB_8888) - for (y in 0 until matrix.height) { - for (x in 0 until matrix.width) { - buf.setPixel(x, y, if (matrix.get(x, y)) Color.BLACK else Color.WHITE) - } - } - buf - } catch (_: Exception) { - null - } -} diff --git a/android/app/src/main/res/drawable/ic_launcher_background.xml b/android/app/src/main/res/drawable/ic_launcher_background.xml index 625fd6f..8824ee3 100644 --- a/android/app/src/main/res/drawable/ic_launcher_background.xml +++ b/android/app/src/main/res/drawable/ic_launcher_background.xml @@ -1,6 +1,4 @@ - - - - diff --git a/android/app/src/main/res/drawable/ic_launcher_foreground.xml b/android/app/src/main/res/drawable/ic_launcher_foreground.xml index 4643d05..3eb66a7 100644 --- a/android/app/src/main/res/drawable/ic_launcher_foreground.xml +++ b/android/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -1,138 +1,41 @@ - + - + + android:fillColor="#7C4DFF" + android:pathData="M54,28 C72,28 82,46 82,62 C82,78 69,88 54,88 C39,88 26,78 26,62 C26,46 36,28 54,28 Z" /> - - - - - - - - - + - + android:pathData="M54,28 L54,18" /> - + + android:pathData="M38,40 C33,54 35,74 48,84" /> - - - - + android:pathData="M70,40 C75,54 73,74 60,84" /> - - - - - - - - - - - - - - - - - + android:pathData="M54,32 L54,86" /> diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml index 6d44ff6..1ef47c0 100644 --- a/android/gradle/libs.versions.toml +++ b/android/gradle/libs.versions.toml @@ -11,7 +11,6 @@ coroutines = "1.11.0" junit = "4.13.2" androidxTestJunit = "1.3.0" androidxTestRunner = "1.7.0" -zxing = "3.5.3" [libraries] androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" } @@ -31,7 +30,6 @@ compose-ui-graphics = { module = "androidx.compose.ui:ui-graphics" } compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" } compose-material3 = { module = "androidx.compose.material3:material3" } -zxing = { module = "com.google.zxing:core", version.ref = "zxing" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } diff --git a/crates/onionwire-sdk/Cargo.lock b/crates/onionwire-sdk/Cargo.lock index 266dfa7..62079af 100644 --- a/crates/onionwire-sdk/Cargo.lock +++ b/crates/onionwire-sdk/Cargo.lock @@ -2769,7 +2769,6 @@ dependencies = [ "ed25519-dalek", "futures", "md-5", - "qrcode", "rand 0.8.8", "ratatui", "rpassword", @@ -3223,12 +3222,6 @@ dependencies = [ "thiserror 2.0.20", ] -[[package]] -name = "qrcode" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec" - [[package]] name = "quote" version = "1.0.47" diff --git a/crates/onionwire-sdk/Cargo.toml b/crates/onionwire-sdk/Cargo.toml index 7415714..e3847bd 100644 --- a/crates/onionwire-sdk/Cargo.toml +++ b/crates/onionwire-sdk/Cargo.toml @@ -8,13 +8,13 @@ license = "MIT" publish = false # Standalone workspace on purpose. +# # Arti's TLS backends (`native-tls` vs `rustls`) are non-additive: exactly one # may be enabled per feature resolution. The Linux TUI crate keeps native-tls, # Android has no OpenSSL in the NDK and needs rustls. Two separate workspaces # keep the two resolutions from colliding — this crate path-depends on the # root package without joining its feature graph. [workspace] -resolver = "2" [lib] name = "onionwire_sdk" diff --git a/crates/onionwire-sdk/src/lib.rs b/crates/onionwire-sdk/src/lib.rs index df25c28..86aa369 100644 --- a/crates/onionwire-sdk/src/lib.rs +++ b/crates/onionwire-sdk/src/lib.rs @@ -32,12 +32,12 @@ use onionwire::Message; use onionwire::hs::TorState as CoreTorState; use onionwire::node::{FlushOutcome as CoreFlushOutcome, Node}; use onionwire::outbox::{DEFAULT_MAX_ATTEMPTS, OutboxEntry, OutboxStatus}; -use onionwire::pay; use onionwire::qr; uniffi::setup_scaffolding!(); /// Install rustls's process-level default `CryptoProvider`, exactly once. +/// /// Belt and braces. `Cargo.toml` pins `rustls` with the `ring` feature, which /// is what actually fixes the missing-provider failure: with it, rustls /// resolves a provider from crate features on its own. This function exists @@ -484,97 +484,6 @@ impl Wire { pub async fn version(&self) -> String { env!("CARGO_PKG_VERSION").to_string() } - - // ---- Wallet / payment surface (v1 Monero features) ---- - - /// Current wallet balance as a display string, or `"off"` / `"err"`. - /// - /// Returns `"off"` when the wallet is not configured (no `ONIONWIRE_WALLET_RPC`), - /// `"err"` when the wallet RPC call failed, and `"balance X.X XMR"` on success. - /// A stopped node (shut-down handle) returns `"off"` — the wallet is not - /// accessible without a live node, and the UI treats "off" as "wallet not - /// available" rather than an error state. - pub async fn wallet_balance(&self) -> String { - match self.node() { - Ok(node) => node.wallet_balance().await, - Err(_) => "off".to_string(), - } - } - - /// Receive address for the wallet screen: a freshly created subaddress when - /// the wallet is configured, else the profile `xmr_addr` fallback. - /// - /// Returns the raw address (not a `monero:` URI) so the QR render path can - /// decide how to wrap it. Returns `WireError.Stopped` on a shut-down handle, - /// `WireError.Failed` on RPC/profile errors. - pub async fn wallet_receive_address(&self) -> WResult { - let node = self.node()?; - node.wallet_receive_address().await.map_err(WireError::new) - } - - /// Recent in/out transfers for the wallet screen, newest first, capped to `cap`. - /// - /// Returns an empty list when the wallet is not configured (no transfers to show). - /// `amount` is formatted XMR, not raw piconero. - pub async fn wallet_recent_transfers(&self, cap: u32) -> WResult> { - let node = self.node()?; - let rows = node - .wallet_recent_transfers(cap as usize) - .await - .map_err(WireError::new)?; - Ok(rows - .into_iter() - .map(|r| TransferRow { - txid: r.txid, - amount: pay::atomic_to_xmr_str(&r.amount), - address: r.address, - }) - .collect()) - } - - /// Send an invoice to a friend: sign an invoice for my receive address and send - /// the frame one-shot. Peer onion down → this fails; invoices are not queued. - /// - /// `amount_xmr` is a user-facing XMR amount (e.g. `"0.5"`) — validated and - /// converted to piconero internally. `memo` may be empty. The invoice uses the - /// wallet subaddress if available, else the profile `xmr_addr` fallback. - pub async fn send_invoice( - &self, - pubkey_hex: String, - amount_xmr: String, - memo: String, - ) -> WResult<()> { - let pk = unhex(&pubkey_hex)?; - let atomic = pay::xmr_to_atomic(&amount_xmr).map_err(WireError::new)?; - self.node()? - .pay_invoice(&pk, &atomic, &memo) - .await - .map_err(WireError::new) - } - - /// Send a tip to a friend: transfer XMR from my wallet, then send a signed - /// receipt and tip frame, both one-shot. Peer onion down → this fails after - /// the chain transfer; tips are not queued. - /// - /// `amount_xmr` is a user-facing XMR amount. `memo` may be empty. The - /// recipient's Monero address is read from their profile. - /// - /// Requires the wallet to be configured (`ONIONWIRE_WALLET_RPC`). Fails when - /// the wallet is not connected, the friend has no Monero address, or the - /// amount is invalid. - pub async fn send_tip( - &self, - pubkey_hex: String, - amount_xmr: String, - memo: String, - ) -> WResult<()> { - let pk = unhex(&pubkey_hex)?; - let atomic = pay::xmr_to_atomic(&amount_xmr).map_err(WireError::new)?; - self.node()? - .tip(&pk, &atomic, &memo) - .await - .map_err(WireError::new) - } } fn from_core_flush(o: CoreFlushOutcome) -> FlushOutcome { @@ -656,45 +565,6 @@ fn outbox_row(entry: &OutboxEntry) -> OutboxRow { } } -/// A Monero transfer row for the wallet screen. -/// -/// `amount` is formatted XMR (not raw piconero) — the SDK formats it from the -/// core's piconero string so the UI never parses atomic units. -#[derive(Debug, Clone, uniffi::Record)] -pub struct TransferRow { - pub txid: String, - pub amount: String, - pub address: String, -} - -/// Convert a user-facing XMR amount string to a piconero string. -/// -/// Accepts `"0.5"`, `"1"`, `"0.001"` etc. Returns the piconero string on -/// success so the caller can pass it to the payment send methods. Fails on -/// empty, non-numeric, zero, or out-of-range input. -#[uniffi::export] -pub fn xmr_to_atomic(amount_xmr: String) -> WResult { - pay::xmr_to_atomic(&amount_xmr).map_err(WireError::new) -} - -/// Format a piconero string as a human-readable XMR string. -/// -/// The core stores amounts as piconero strings; this is what the wallet screen -/// renders. `"0"` → `"0"`, `"1000000000000"` → `"1"`, `"150000000000"` → `"0.15"`. -#[uniffi::export] -pub fn atomic_to_xmr_str(amount_atomic: String) -> String { - pay::atomic_to_xmr_str(&amount_atomic) -} - -/// Check whether a string is a valid Monero address. -/// -/// Validates checksum and prefix byte. Used by the UI to reject typos before -/// sending a payment. Both standard and integrated addresses are accepted. -#[uniffi::export] -pub fn check_address(address: String) -> WResult<()> { - pay::check_address(&address).map_err(WireError::new) -} - #[cfg(test)] mod tests { //! No Tor here on purpose: these exercise the *lifecycle* contract of the @@ -798,11 +668,7 @@ mod tests { Some("sending") ); assert_eq!( - delivery_of( - "out", - Some(OutboxStatus::Failed("no route".into())) - ) - .as_deref(), + delivery_of("out", Some(OutboxStatus::Failed("no route".into()))).as_deref(), Some("failed: no route") ); } @@ -936,61 +802,4 @@ mod tests { std::fs::remove_dir_all(&home).ok(); } - - #[test] - fn wallet_balance_on_stopped_handle_returns_off() { - // A stopped/shut-down handle has no node, so the wallet is inaccessible. - // The UI treats "off" as "wallet not available" — same as "not configured". - assert_eq!(block_on(stopped_wire().wallet_balance()), "off"); - } - - #[test] - fn wallet_receive_address_on_stopped_handle_is_stopped_error() { - let err = block_on(stopped_wire().wallet_receive_address()).expect_err("must fail"); - assert!(matches!(err, WireError::Stopped { .. }), "got {err:?}"); - } - - #[test] - fn wallet_recent_transfers_on_stopped_handle_is_stopped_error() { - let err = - block_on(stopped_wire().wallet_recent_transfers(8)).expect_err("must fail"); - assert!(matches!(err, WireError::Stopped { .. }), "got {err:?}"); - } - - #[test] - fn xmr_to_atomic_rejects_zero() { - assert!(xmr_to_atomic("0".to_string()).is_err()); - } - - #[test] - fn xmr_to_atomic_accepts_one_xmr() { - assert_eq!(xmr_to_atomic("1".to_string()).unwrap(), "1000000000000"); - } - - #[test] - fn xmr_to_atomic_accepts_fractional_xmr() { - assert_eq!(xmr_to_atomic("0.5".to_string()).unwrap(), "500000000000"); - } - - #[test] - fn atomic_to_xmr_str_formats_correctly() { - assert_eq!(atomic_to_xmr_str("1000000000000".to_string()), "1"); - assert_eq!(atomic_to_xmr_str("500000000000".to_string()), "0.5"); - assert_eq!(atomic_to_xmr_str("0".to_string()), "0"); - } - - #[test] - fn check_address_accepts_valid_address() { - // Standard mainnet address from tests/pay.rs (same spend/view keys). - assert!(check_address( - "4AdUndXHHZ6cfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYTRj5UzqtReoS44qo9mtmXCqY45DJ852K5Jv2684Rge" - .to_string() - ) - .is_ok()); - } - - #[test] - fn check_address_rejects_invalid_address() { - assert!(check_address("not-an-address".to_string()).is_err()); - } } diff --git a/scripts/publish-release.sh b/scripts/publish-release.sh index 164a612..ae0e784 100755 --- a/scripts/publish-release.sh +++ b/scripts/publish-release.sh @@ -21,7 +21,7 @@ api_curl() { } auth_json() { - api_curl -u "sirius:${FORGEJO_TOKEN}" -H "Content-Type: application/json" "$@" + api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" -H "Content-Type: application/json" "$@" } tag="${1:?usage: publish-release.sh ...}" @@ -109,7 +109,7 @@ for f in "$@"; do fi asset=$(basename "$f") echo "publish: asset $asset is $bytes bytes on disk" - api_curl -u "sirius:${FORGEJO_TOKEN}" "$api/releases/$rid/assets" \ + api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" "$api/releases/$rid/assets" \ | python3 -c " import json,sys for a in json.load(sys.stdin): @@ -118,7 +118,7 @@ for a in json.load(sys.stdin): if [ "$aname" = "$asset" ]; then echo "publish: deleting stale asset $aname ($aid)" del=$(api_curl -o /tmp/release-adel.json -w '%{http_code}' \ - -X DELETE -u "sirius:${FORGEJO_TOKEN}" \ + -X DELETE -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ "$api/releases/$rid/assets/$aid") if [ "$del" != "204" ] && [ "$del" != "404" ]; then die_http "DELETE asset $aid" "$del" /tmp/release-adel.json @@ -127,7 +127,7 @@ for a in json.load(sys.stdin): done up=$(api_curl -o /tmp/release-asset.json -w '%{http_code}' \ -X POST "$api/releases/$rid/assets?name=$asset" \ - -u "sirius:${FORGEJO_TOKEN}" \ + -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ -F "attachment=@$f") if [ "$up" != "201" ]; then die_http "upload $asset" "$up" /tmp/release-asset.json @@ -142,7 +142,7 @@ if not size: " done -api_curl -u "sirius:${FORGEJO_TOKEN}" "$api/releases/$rid/assets" \ +api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" "$api/releases/$rid/assets" \ | python3 -c " import json,sys for a in json.load(sys.stdin): diff --git a/src/tui.rs b/src/tui.rs index e149d9a..2e36530 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -1600,9 +1600,15 @@ impl App { } fn open_wallet(&mut self) -> Result<(), String> { - let addr = self.rt.block_on(self.node.wallet_receive_address())?; + let addr = match self.rt.block_on(self.node.wallet_receive_address()) { + Ok(a) => a, + Err(e) => return Err(e), + }; let balance = self.rt.block_on(self.node.wallet_balance()); - let transfers = self.rt.block_on(self.node.wallet_recent_transfers(8)).unwrap_or_default(); + let transfers = match self.rt.block_on(self.node.wallet_recent_transfers(8)) { + Ok(t) => t, + Err(_) => Vec::new(), + }; self.screen = Screen::Wallet { receive_addr: addr, balance,