Merge branch 'main' into wt/app-icon-adaptive
This commit is contained in:
commit
6f69d629fb
22 changed files with 1474 additions and 174 deletions
|
|
@ -143,15 +143,13 @@ private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: Str
|
|||
val pk = entry.arguments?.getString("pk").orEmpty()
|
||||
val friend = friends.firstOrNull { it.pubkeyHex == pk }
|
||||
ChatScreen(
|
||||
vm = vm,
|
||||
peer = pk,
|
||||
title = friend?.petname?.takeIf { it.isNotBlank() }
|
||||
?: friend?.fingerprint
|
||||
?: pk.take(16),
|
||||
fingerprint = friend?.fingerprint ?: pk.take(16),
|
||||
onion = friend?.onion.orEmpty(),
|
||||
loadMessages = { vm.messages(pk) },
|
||||
loadOutbox = { vm.outbox(pk) },
|
||||
loadMaxAttempts = { vm.outboxMaxAttempts() },
|
||||
onSend = { body -> vm.send(pk, body) },
|
||||
onBack = { nav.popBackStack() },
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,14 @@ import com.siriusdevops.onionwire.keepalive.KeepAliveService
|
|||
import com.siriusdevops.onionwire.keepalive.KeepAliveStatus
|
||||
import com.siriusdevops.onionwire.keepalive.NodeHost
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import uniffi.onionwire_sdk.ChatMessage
|
||||
|
|
@ -61,6 +66,22 @@ sealed interface Unlock {
|
|||
data class OneTap(val backing: KeyBacking) : Unlock
|
||||
}
|
||||
|
||||
/**
|
||||
* Everything one open chat screen renders, refreshed on a single cadence.
|
||||
*
|
||||
* [messages] is null until the first read lands — the screen shows its spinner
|
||||
* on that, exactly as it did reading the SDK itself. [error] is the last load
|
||||
* failure and is sticky on purpose: it survives the ticks that succeed, so a
|
||||
* transient store error is still on screen after the next 2s tick rather than
|
||||
* blinking away. A send clears it (the user has acted on it).
|
||||
*/
|
||||
data class ChatState(
|
||||
val messages: List<ChatMessage>? = null,
|
||||
val outbox: List<OutboxRow> = emptyList(),
|
||||
val maxAttempts: UInt? = null,
|
||||
val error: String? = null,
|
||||
)
|
||||
|
||||
/**
|
||||
* Owns the UI side of the process's single node.
|
||||
*
|
||||
|
|
@ -101,6 +122,22 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
|||
private val _keepAliveNote = MutableStateFlow<String?>(null)
|
||||
val keepAliveNote: StateFlow<String?> = _keepAliveNote.asStateFlow()
|
||||
|
||||
/**
|
||||
* The currently open chat, or null when no chat screen is composed.
|
||||
*
|
||||
* There is exactly one node and one chat on screen at a time, so this is
|
||||
* one state object rather than a map keyed by peer: a second poller for a
|
||||
* second peer would double the SDK traffic for a screen nobody is looking
|
||||
* at, and the node's store reads are not free.
|
||||
*/
|
||||
private val _chat = MutableStateFlow<ChatState?>(null)
|
||||
val chat: StateFlow<ChatState?> = _chat.asStateFlow()
|
||||
|
||||
/** The peer [chat] belongs to; guards a stale tick from a previous peer. */
|
||||
private var chatPeer: String? = null
|
||||
|
||||
private var chatPoller: Job? = null
|
||||
|
||||
init {
|
||||
// A node the foreground service kept alive is still open. Adopt it and
|
||||
// go straight to the roster: showing an unlock screen for a store that
|
||||
|
|
@ -177,6 +214,10 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
|||
*/
|
||||
fun lock() {
|
||||
if (NodeHost.current() == null) return
|
||||
// Stop the chat tick before the node goes: the next read of a closed
|
||||
// store would surface as a chat load error on a screen the user has
|
||||
// already left, and every tick would keep re-reporting it.
|
||||
stopChatPoller()
|
||||
KeepAliveService.stop(getApplication())
|
||||
NodeHost.lock()
|
||||
_friends.value = emptyList()
|
||||
|
|
@ -381,6 +422,87 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
|||
*/
|
||||
suspend fun outboxMaxAttempts(): UInt = uniffi.onionwire_sdk.outboxMaxAttempts()
|
||||
|
||||
/**
|
||||
* Starts the one 2s refresh loop for [pubkeyHex] and resets the chat state.
|
||||
*
|
||||
* Called from the chat screen entering the composition. Re-entering the
|
||||
* same peer while its poller is alive is a no-op — navigating to the chat
|
||||
* and back must never stack a second loop on top of the first.
|
||||
*/
|
||||
fun openChat(pubkeyHex: String) {
|
||||
if (chatPeer == pubkeyHex && chatPoller?.isActive == true) return
|
||||
chatPoller?.cancel()
|
||||
chatPeer = pubkeyHex
|
||||
_chat.value = ChatState()
|
||||
chatPoller = viewModelScope.launch { pollChat(pubkeyHex) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the loop when the chat screen leaves. Ignored when another peer has
|
||||
* taken over in the meantime (navigating chat A → chat B disposes A after B
|
||||
* has already opened).
|
||||
*/
|
||||
fun closeChat(pubkeyHex: String) {
|
||||
if (chatPeer != pubkeyHex) return
|
||||
stopChatPoller()
|
||||
}
|
||||
|
||||
private fun stopChatPoller() {
|
||||
chatPoller?.cancel()
|
||||
chatPoller = null
|
||||
chatPeer = null
|
||||
_chat.value = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the last load error. The send path calls this: the user has acted,
|
||||
* so a stale "could not read" line must not sit under the composer while
|
||||
* the send is in flight.
|
||||
*/
|
||||
fun clearChatError() {
|
||||
_chat.update { it?.copy(error = null) }
|
||||
}
|
||||
|
||||
/**
|
||||
* The cadence, in the ViewModel: inbound messages are appended by the node
|
||||
* in the background and the retry worker moves queued rows along, and in v1
|
||||
* there is no push channel into the UI, so messages and outbox are read
|
||||
* together on one 2s tick. The outbox rows are read on that tick too —
|
||||
* their `next_attempt_at` is a fixed instant, so a row saying "retry 45s"
|
||||
* turns into "retry now" here without the store having to change.
|
||||
*
|
||||
* The retry budget is read once per open chat (it is a constant of the
|
||||
* outbox, not per-peer state); a failure leaves it null and the rows fall
|
||||
* back to the flat marker.
|
||||
*/
|
||||
private suspend fun pollChat(pk: String) {
|
||||
runCatching { outboxMaxAttempts() }.onSuccess { budget ->
|
||||
if (chatPeer == pk) _chat.update { it?.copy(maxAttempts = budget) }
|
||||
}
|
||||
while (currentCoroutineContext().isActive) {
|
||||
val loaded = runCatching { messages(pk) }
|
||||
val out = runCatching { outbox(pk) }
|
||||
// A cancelled loop can still be sitting in a completed SDK read:
|
||||
// writing that peer's rows into a state that now belongs to another
|
||||
// peer would show the wrong conversation.
|
||||
if (chatPeer != pk) return
|
||||
_chat.update { state ->
|
||||
val base = state ?: ChatState()
|
||||
base.copy(
|
||||
messages = loaded.getOrNull() ?: base.messages,
|
||||
outbox = out.getOrNull() ?: base.outbox,
|
||||
// Same order the screen's own loop reported them in, and
|
||||
// sticky on success — a new failure replaces the last one,
|
||||
// a successful tick does not clear the last one.
|
||||
error = out.exceptionOrNull()?.let { it.message ?: it.toString() }
|
||||
?: loaded.exceptionOrNull()?.let { it.message ?: it.toString() }
|
||||
?: base.error,
|
||||
)
|
||||
}
|
||||
delay(2_000)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends one chat message and reports what the core did with it.
|
||||
*
|
||||
|
|
@ -428,4 +550,16 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
|||
|
||||
suspend fun sendTip(pubkeyHex: String, amountXmr: String, memo: String = ""): Result<Unit> =
|
||||
runCatching { requireWire().sendTip(pubkeyHex, amountXmr, memo) }
|
||||
|
||||
suspend fun createWallet(password: String): Result<String> =
|
||||
runCatching { requireWire().createWallet(password) }
|
||||
|
||||
suspend fun importWallet(password: String, seed: String): Result<Unit> =
|
||||
runCatching { requireWire().importWallet(password, seed) }
|
||||
|
||||
fun spendAuthorityWarning(): String = runCatching {
|
||||
requireWire().spendAuthorityWarning()
|
||||
}.getOrElse {
|
||||
"this wallet file can spend. anyone with its passphrase or the RPC creds can move the balance. write down the seed."
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@ package com.siriusdevops.onionwire.ui
|
|||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
|
|
@ -15,11 +17,16 @@ import androidx.compose.foundation.layout.width
|
|||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
|
|
@ -27,6 +34,7 @@ import androidx.compose.material3.Text
|
|||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
|
|
@ -34,26 +42,28 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.delay
|
||||
import uniffi.onionwire_sdk.ChatMessage
|
||||
import uniffi.onionwire_sdk.OutboxRow
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.siriusdevops.onionwire.WireViewModel
|
||||
import uniffi.onionwire_sdk.SendState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ChatScreen(
|
||||
vm: WireViewModel,
|
||||
/** The peer's ed25519 pubkey hex — the key the open chat's poller runs for. */
|
||||
peer: String,
|
||||
title: String,
|
||||
fingerprint: String,
|
||||
onion: String,
|
||||
loadMessages: suspend () -> List<ChatMessage>,
|
||||
loadOutbox: suspend () -> List<OutboxRow>,
|
||||
loadMaxAttempts: suspend () -> UInt,
|
||||
onSend: suspend (String) -> SendState,
|
||||
onBack: () -> Unit,
|
||||
/**
|
||||
* Wall clock in unix seconds. `next_attempt_at` is absolute, so the
|
||||
|
|
@ -62,36 +72,55 @@ fun ChatScreen(
|
|||
*/
|
||||
nowSeconds: () -> Long = { System.currentTimeMillis() / 1_000L },
|
||||
) {
|
||||
var messages by remember { mutableStateOf<List<ChatMessage>?>(null) }
|
||||
var outbox by remember { mutableStateOf<List<OutboxRow>>(emptyList()) }
|
||||
// The core's retry budget, fetched once: `try 3/8` renders against this and
|
||||
// never against a constant in the app.
|
||||
var maxAttempts by remember { mutableStateOf<UInt?>(null) }
|
||||
// The refresh cadence lives in the ViewModel: one poller per open chat, not
|
||||
// one per composition. Collecting here means a re-composition (or a
|
||||
// configuration change) does not start a second loop against the SDK.
|
||||
val chat by vm.chat.collectAsStateWithLifecycle()
|
||||
val messages = chat?.messages
|
||||
val outbox = chat?.outbox.orEmpty()
|
||||
// The core's retry budget, fetched once per open chat: `try 3/8` renders
|
||||
// against this and never against a constant in the app.
|
||||
val maxAttempts = chat?.maxAttempts
|
||||
|
||||
var draft by remember { mutableStateOf("") }
|
||||
var pending by remember { mutableStateOf<String?>(null) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
// Send-path failures are the screen's own state; load failures come back on
|
||||
// [ChatState.error]. Both render in the same place under the list.
|
||||
var sendError by remember { mutableStateOf<String?>(null) }
|
||||
var notice by remember { mutableStateOf<String?>(null) }
|
||||
val error = sendError ?: chat?.error
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
// Poll: the node appends inbound messages in the background and the retry
|
||||
// worker moves queued rows along; there is no push channel into the UI in
|
||||
// v1, so the delivery markers refresh on the same cadence as the bodies.
|
||||
// The outbox rows are read on that cadence too — their `next_attempt_at` is
|
||||
// a fixed instant, so a row saying "retry 45s" turns into "retry now" here
|
||||
// without the store having to change.
|
||||
LaunchedEffect(Unit) {
|
||||
runCatching { loadMaxAttempts() }.onSuccess { maxAttempts = it }
|
||||
while (true) {
|
||||
runCatching { loadMessages() }
|
||||
.onSuccess { messages = it }
|
||||
.onFailure { error = it.message ?: it.toString() }
|
||||
runCatching { loadOutbox() }
|
||||
.onSuccess { outbox = it }
|
||||
.onFailure { error = it.message ?: it.toString() }
|
||||
delay(2_000)
|
||||
// Auto-scroll bookkeeping. `firstFillDone` keeps the one-jump-to-the-bottom
|
||||
// on the first load (and again after leaving and re-entering the chat);
|
||||
// `ownSendPending` is the user's own message asking for the list to follow
|
||||
// even though they may have scrolled up in history.
|
||||
var firstFillDone by remember { mutableStateOf(false) }
|
||||
var ownSendPending by remember { mutableStateOf(false) }
|
||||
|
||||
// The composer is the only place a message can be sent from, so after a
|
||||
// send the keyboard is left up and the caret goes back into the field —
|
||||
// the next message is one keystroke away instead of a re-tap.
|
||||
val inputFocus = remember { FocusRequester() }
|
||||
val send: () -> Unit = {
|
||||
if (draft.isNotBlank() && pending == null) {
|
||||
pending = draft
|
||||
draft = ""
|
||||
// The user's own message is the one case where the list is allowed
|
||||
// to move while they are scrolled up in history.
|
||||
ownSendPending = true
|
||||
inputFocus.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
// The poller's lifetime is the chat screen's: entering starts it, leaving
|
||||
// stops it, and re-entering the same peer is a no-op in the ViewModel, so
|
||||
// there is exactly one loop no matter how the nav stack is walked.
|
||||
DisposableEffect(peer) {
|
||||
vm.openChat(peer)
|
||||
onDispose { vm.closeChat(peer) }
|
||||
}
|
||||
|
||||
// Send. An unreachable peer's onion is not an error any more: the core
|
||||
// stores the message in its local outbox and the retry worker dials again
|
||||
// with backoff (30s doubling, capped at 30 min, 8 attempts, then terminal
|
||||
|
|
@ -99,22 +128,45 @@ fun ChatScreen(
|
|||
// queued for those.
|
||||
LaunchedEffect(pending) {
|
||||
val body = pending ?: return@LaunchedEffect
|
||||
error = null
|
||||
sendError = null
|
||||
notice = null
|
||||
runCatching { onSend(body) }
|
||||
// The user has acted on whatever the poller last reported.
|
||||
vm.clearChatError()
|
||||
runCatching { vm.send(peer, body) }
|
||||
.onSuccess {
|
||||
if (it == SendState.QUEUED) {
|
||||
notice = "Queued: their onion is unreachable. The message stays on " +
|
||||
"this device and is retried until it lands."
|
||||
}
|
||||
}
|
||||
.onFailure { error = it.message ?: it.toString() }
|
||||
.onFailure { sendError = it.message ?: it.toString() }
|
||||
pending = null
|
||||
}
|
||||
|
||||
// Known and accepted: this is keyed on the message count, so a delivery-only
|
||||
// change (a row flipping `queued` → `sent`, same size, different marker)
|
||||
// does not re-run it. That has always been the behaviour here and it is the
|
||||
// safe one — the list never moves for a marker.
|
||||
LaunchedEffect(messages?.size) {
|
||||
val n = messages?.size ?: 0
|
||||
if (n > 0) listState.animateScrollToItem(n - 1)
|
||||
if (n == 0) return@LaunchedEffect
|
||||
if (!firstFillDone) {
|
||||
// First load: one jump to the bottom so the newest message is the
|
||||
// one on screen, without an animation nobody asked for.
|
||||
listState.scrollToItem(n - 1)
|
||||
firstFillDone = true
|
||||
return@LaunchedEffect
|
||||
}
|
||||
// Follow the tail only when the reader is already there. `n - 2`
|
||||
// rather than `!canScrollForward`: the append has already made the list
|
||||
// scrollable by the time this runs, so "can I scroll further" is true
|
||||
// even for someone who was glued to the bottom a frame ago — and
|
||||
// `lastVisible >= n - 2` tolerates the last row being partly on screen.
|
||||
val lastVisible = listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: -1
|
||||
if (ownSendPending || lastVisible >= n - 2) {
|
||||
listState.animateScrollToItem(n - 1)
|
||||
}
|
||||
ownSendPending = false
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
|
|
@ -139,8 +191,17 @@ fun ChatScreen(
|
|||
),
|
||||
)
|
||||
},
|
||||
// The top bar carries its own status-bar inset; the content root applies
|
||||
// systemBars + IME once (see `screenContentInsets`) so the navigation
|
||||
// bar is not counted twice while the keyboard is up.
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||
) { pad ->
|
||||
Column(Modifier.padding(pad).fillMaxSize()) {
|
||||
Column(
|
||||
Modifier
|
||||
.padding(pad)
|
||||
.fillMaxSize()
|
||||
.screenContentInsets(),
|
||||
) {
|
||||
Text(
|
||||
"onion: $onion",
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
|
|
@ -152,14 +213,21 @@ fun ChatScreen(
|
|||
val list = messages
|
||||
when {
|
||||
list == null -> {
|
||||
Spacer(Modifier.height(16.dp))
|
||||
CircularProgressIndicator(Modifier.padding(16.dp))
|
||||
// The body region always claims the leftover height, so the
|
||||
// composer below it can never be pushed off the bottom —
|
||||
// least of all by the keyboard.
|
||||
Box(Modifier.weight(1f).fillMaxWidth(), contentAlignment = Alignment.Center) {
|
||||
CircularProgressIndicator(Modifier.padding(16.dp))
|
||||
}
|
||||
}
|
||||
|
||||
list.isEmpty() -> {
|
||||
Column(
|
||||
Modifier.fillMaxWidth().padding(24.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.fillMaxWidth()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(24.dp),
|
||||
) {
|
||||
Text("No messages", style = MaterialTheme.typography.titleSmall)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
|
|
@ -274,28 +342,60 @@ fun ChatScreen(
|
|||
)
|
||||
}
|
||||
|
||||
// The composer sticks to the bottom of the window: `screenContentInsets`
|
||||
// already lifted it above the keyboard, and its row is never allowed
|
||||
// to be squeezed out by the messages above it (they hold the weight).
|
||||
Row(
|
||||
Modifier.fillMaxWidth().padding(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(8.dp)
|
||||
.testTag("chat-composer"),
|
||||
verticalAlignment = Alignment.Bottom,
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = draft,
|
||||
onValueChange = { draft = it },
|
||||
modifier = Modifier.weight(1f),
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.focusRequester(inputFocus)
|
||||
.testTag("chat-input"),
|
||||
maxLines = 4,
|
||||
label = { Text("message") },
|
||||
// DECISION (item 3 of the follow-up card): the IME's action
|
||||
// key sends; the soft keyboard cannot insert a manual
|
||||
// newline. `ImeAction.Send` and `maxLines = 4` are not in
|
||||
// conflict — `maxLines` is a wrap limit (a long message
|
||||
// grows to four lines, then scrolls inside the field), not
|
||||
// a newline affordance. Chat convention wins: Enter-to-send
|
||||
// is what a messenger's users reach for, and the Send button
|
||||
// is on the same row. Nothing is unreachable either — a
|
||||
// hardware keyboard's Enter never goes through the IME
|
||||
// action, so Shift+Enter still inserts a real newline in
|
||||
// the field.
|
||||
keyboardOptions = KeyboardOptions(
|
||||
capitalization = KeyboardCapitalization.Sentences,
|
||||
imeAction = ImeAction.Send,
|
||||
),
|
||||
keyboardActions = KeyboardActions(onSend = { send() }),
|
||||
)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
if (pending != null) {
|
||||
CircularProgressIndicator()
|
||||
} else {
|
||||
Button(
|
||||
enabled = draft.isNotBlank(),
|
||||
onClick = {
|
||||
pending = draft
|
||||
draft = ""
|
||||
},
|
||||
) { Text("Send") }
|
||||
// Always drawn, never swapped out for a spinner: a button that
|
||||
// changes size under the thumb — or disappears — is how "I hit
|
||||
// send and nothing happened" gets reported.
|
||||
Button(
|
||||
enabled = draft.isNotBlank() && pending == null,
|
||||
onClick = send,
|
||||
modifier = Modifier.testTag("chat-send"),
|
||||
) {
|
||||
if (pending != null) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(14.dp),
|
||||
strokeWidth = 2.dp,
|
||||
color = LocalContentColor.current,
|
||||
)
|
||||
Spacer(Modifier.width(6.dp))
|
||||
}
|
||||
Text("Send")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
package com.siriusdevops.onionwire.ui
|
||||
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.WindowInsetsSides
|
||||
import androidx.compose.foundation.layout.ime
|
||||
import androidx.compose.foundation.layout.only
|
||||
import androidx.compose.foundation.layout.systemBars
|
||||
import androidx.compose.foundation.layout.union
|
||||
import androidx.compose.foundation.layout.windowInsetsPadding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
/**
|
||||
* The bottom + horizontal window insets one screen's content root must apply
|
||||
* itself.
|
||||
*
|
||||
* `MainActivity` calls `enableEdgeToEdge()`, which means
|
||||
* `setDecorFitsSystemWindows(window, false)`. On API 30+ that stops the
|
||||
* framework from resizing the window for the soft keyboard: the manifest's
|
||||
* `android:windowSoftInputMode="adjustResize"` has nothing left to resize, and
|
||||
* the IME arrives as a *window inset* instead. `Scaffold`'s
|
||||
* `contentWindowInsets` only covers `systemBars`, so anything anchored to the
|
||||
* bottom of the window — the chat composer, a submit button under a text field
|
||||
* — ends up drawn behind the keyboard, reachable only by dismissing it.
|
||||
*
|
||||
* The IME's bottom inset already covers the navigation bar, so the two are
|
||||
* unioned (per-side `max`), never summed: keyboard height while typing,
|
||||
* navigation-bar height otherwise, and no double padding in between.
|
||||
*
|
||||
* The `Top` side is deliberately excluded — a `Scaffold`'s `pad.top` is the app
|
||||
* bar's own measured height, and the app bar carries its own status-bar inset
|
||||
* (`TopAppBarDefaults.windowInsets`).
|
||||
*
|
||||
* Pair every use with `Scaffold(contentWindowInsets = WindowInsets(0, 0, 0, 0))`
|
||||
* so the same inset is not applied twice.
|
||||
*
|
||||
* `@Composable` because `WindowInsets.systemBars` / `WindowInsets.ime` are
|
||||
* composable reads — call it from a composable (every call site is one).
|
||||
*/
|
||||
@Composable
|
||||
fun Modifier.screenContentInsets(): Modifier =
|
||||
windowInsetsPadding(
|
||||
WindowInsets.systemBars.union(WindowInsets.ime)
|
||||
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom),
|
||||
)
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
package com.siriusdevops.onionwire.ui
|
||||
|
||||
import android.content.ClipData
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
|
|
@ -31,8 +33,8 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.platform.ClipEntry
|
||||
import androidx.compose.ui.platform.LocalClipboard
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.launch
|
||||
import uniffi.onionwire_sdk.FriendInfo
|
||||
|
|
@ -44,7 +46,8 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) {
|
|||
var invite by remember { mutableStateOf<String?>(null) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
var copied by remember { mutableStateOf(false) }
|
||||
val clip = LocalClipboardManager.current
|
||||
val clipboard = LocalClipboard.current
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
runCatching { ownerInvite() }
|
||||
|
|
@ -62,9 +65,17 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) {
|
|||
),
|
||||
)
|
||||
},
|
||||
// The root applies systemBars + IME itself (see `screenContentInsets`),
|
||||
// so Scaffold must not also pad for the navigation bar.
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||
) { pad ->
|
||||
Column(
|
||||
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
|
||||
Modifier
|
||||
.padding(pad)
|
||||
.fillMaxSize()
|
||||
.screenContentInsets()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(16.dp),
|
||||
) {
|
||||
Text(
|
||||
"Hand this to one person, over a channel you already trust. " +
|
||||
|
|
@ -98,8 +109,12 @@ fun ShareInviteScreen(ownerInvite: suspend () -> String, onBack: () -> Unit) {
|
|||
Spacer(Modifier.height(12.dp))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Button(onClick = {
|
||||
clip.setText(AnnotatedString(invite!!))
|
||||
copied = true
|
||||
scope.launch {
|
||||
clipboard.setClipEntry(
|
||||
ClipEntry(ClipData.newPlainText("onionwire invite", invite!!)),
|
||||
)
|
||||
copied = true
|
||||
}
|
||||
}) { Text(if (copied) "Copied" else "Copy") }
|
||||
}
|
||||
Spacer(Modifier.height(20.dp))
|
||||
|
|
@ -149,9 +164,18 @@ fun PasteInviteScreen(
|
|||
),
|
||||
)
|
||||
},
|
||||
// Same inset handoff as the chat composer: with the keyboard up, the
|
||||
// Verify / Approve buttons under the invite field must still be
|
||||
// reachable by scrolling, not by dismissing the keyboard.
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||
) { pad ->
|
||||
Column(
|
||||
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
|
||||
Modifier
|
||||
.padding(pad)
|
||||
.fillMaxSize()
|
||||
.screenContentInsets()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(16.dp),
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = raw,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Arrangement
|
|||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
|
|
@ -52,6 +53,11 @@ fun RosterScreen(
|
|||
var confirmWipe by remember { mutableStateOf(false) }
|
||||
|
||||
Scaffold(
|
||||
// The content root below consumes systemBars ∪ ime itself (see
|
||||
// `screenContentInsets`); zeroing the Scaffold's own insets keeps the
|
||||
// navigation bar from being applied twice and lets the wipe-confirm
|
||||
// strip sit above the keyboard instead of under it.
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text("OnionWire") },
|
||||
|
|
@ -64,7 +70,7 @@ fun RosterScreen(
|
|||
)
|
||||
},
|
||||
) { pad ->
|
||||
Column(Modifier.padding(pad).fillMaxSize()) {
|
||||
Column(Modifier.padding(pad).fillMaxSize().screenContentInsets()) {
|
||||
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
||||
|
|
@ -134,7 +140,11 @@ fun RosterScreen(
|
|||
)
|
||||
}
|
||||
} else {
|
||||
LazyColumn(Modifier.fillMaxSize()) {
|
||||
// weight(1f), not fillMaxSize(): the list must yield height to
|
||||
// its siblings (the action row and the wipe-confirm strip above
|
||||
// it) when the IME shrinks the window, instead of claiming all
|
||||
// of it and pushing them off the bottom.
|
||||
LazyColumn(Modifier.weight(1f).fillMaxWidth()) {
|
||||
items(friends, key = { it.pubkeyHex }) { f ->
|
||||
FriendRow(f) { onOpenChat(f) }
|
||||
HorizontalDivider()
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
|
|||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
|
|
@ -59,9 +60,17 @@ fun RotateScreen(
|
|||
),
|
||||
)
|
||||
},
|
||||
// Root owns systemBars + IME (see `screenContentInsets`) so the confirm
|
||||
// button under the passphrase field stays reachable with the keyboard up.
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||
) { pad ->
|
||||
Column(
|
||||
Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).padding(16.dp),
|
||||
Modifier
|
||||
.padding(pad)
|
||||
.fillMaxSize()
|
||||
.screenContentInsets()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(16.dp),
|
||||
) {
|
||||
Text("Rotate onion address?", style = MaterialTheme.typography.titleLarge)
|
||||
Spacer(Modifier.height(12.dp))
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ 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.layout.safeDrawingPadding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
|
|
@ -68,6 +69,10 @@ fun UnlockScreen(
|
|||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
// This screen has no Scaffold, so its root owns every window inset:
|
||||
// without this the keyboard covers the passphrase field's Open
|
||||
// button and the status bar overlaps the title.
|
||||
.safeDrawingPadding()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(24.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
|
|
|
|||
|
|
@ -9,14 +9,15 @@ 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.WindowInsets
|
||||
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.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
|
|
@ -47,11 +48,13 @@ import com.google.zxing.BarcodeFormat
|
|||
import com.google.zxing.EncodeHintType
|
||||
import com.google.zxing.qrcode.QRCodeWriter
|
||||
import com.siriusdevops.onionwire.WireViewModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import uniffi.onionwire_sdk.FriendInfo
|
||||
import uniffi.onionwire_sdk.TransferRow
|
||||
|
||||
private enum class PayKind { Invoice, Tip }
|
||||
private enum class SetupKind { Create, Import }
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
|
@ -67,6 +70,8 @@ fun WalletScreen(
|
|||
var transfers by remember { mutableStateOf<List<TransferRow>>(emptyList()) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
var composer by remember { mutableStateOf<PayKind?>(null) }
|
||||
var setup by remember { mutableStateOf<SetupKind?>(null) }
|
||||
var backupSeed by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
suspend fun reload() {
|
||||
runCatching { balance = vm.walletBalance() }
|
||||
|
|
@ -78,6 +83,11 @@ fun WalletScreen(
|
|||
LaunchedEffect(Unit) { reload() }
|
||||
|
||||
Scaffold(
|
||||
// The content root below consumes systemBars ∪ ime itself (see
|
||||
// `screenContentInsets`); zeroing the Scaffold's own insets keeps the
|
||||
// navigation bar from being applied twice, and keeps the IME inset out
|
||||
// of the Scaffold's inner padding.
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0),
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text("Wallet") },
|
||||
|
|
@ -91,7 +101,13 @@ fun WalletScreen(
|
|||
},
|
||||
) { pad ->
|
||||
Column(
|
||||
Modifier.padding(pad).fillMaxSize(),
|
||||
Modifier
|
||||
.padding(pad)
|
||||
.fillMaxSize()
|
||||
// systemBars ∪ ime, applied outside the scrolling viewport so
|
||||
// the inset does not scroll away with the content.
|
||||
.screenContentInsets()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
|
|
@ -167,22 +183,22 @@ fun WalletScreen(
|
|||
style = MaterialTheme.typography.titleSmall,
|
||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
|
||||
)
|
||||
LazyColumn(
|
||||
// Plain Column, not a LazyColumn: the root is a scrolling
|
||||
// container now, so a nested lazy list would either throw on the
|
||||
// unbounded height or need an arbitrary cap. `walletRecentTransfers`
|
||||
// is bounded (25 rows), and the page scrolls as one gesture.
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f, fill = false)
|
||||
.padding(horizontal = 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
items(transfers, key = { it.txid }) { t ->
|
||||
TransferCard(t)
|
||||
}
|
||||
transfers.forEach { t -> TransferCard(t) }
|
||||
}
|
||||
} else {
|
||||
Spacer(Modifier.weight(1f))
|
||||
}
|
||||
|
||||
val kind = composer
|
||||
val setupKind = setup
|
||||
if (kind != null) {
|
||||
PayComposer(
|
||||
kind = kind,
|
||||
|
|
@ -205,24 +221,72 @@ fun WalletScreen(
|
|||
}
|
||||
},
|
||||
)
|
||||
} else if (setupKind != null) {
|
||||
WalletSetupCard(
|
||||
kind = setupKind,
|
||||
warning = vm.spendAuthorityWarning(),
|
||||
onCancel = { setup = null },
|
||||
onCreated = { seed ->
|
||||
setup = null
|
||||
backupSeed = seed
|
||||
scope.launch { reload() }
|
||||
},
|
||||
onImported = {
|
||||
setup = null
|
||||
scope.launch { reload() }
|
||||
},
|
||||
onError = { error = it },
|
||||
create = { pw -> vm.createWallet(pw) },
|
||||
importWallet = { pw, seed -> vm.importWallet(pw, seed) },
|
||||
scope = scope,
|
||||
)
|
||||
} 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") }
|
||||
Column(Modifier.fillMaxWidth().padding(12.dp)) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
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") }
|
||||
}
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
OutlinedButton(
|
||||
onClick = { setup = SetupKind.Create },
|
||||
modifier = Modifier.weight(1f),
|
||||
) { Text("Create") }
|
||||
OutlinedButton(
|
||||
onClick = { setup = SetupKind.Import },
|
||||
modifier = Modifier.weight(1f),
|
||||
) { Text("Import") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
backupSeed?.let { seed ->
|
||||
Text(
|
||||
"write this seed down once. anyone with it can spend.",
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
)
|
||||
Text(
|
||||
seed,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
fontFamily = FontFamily.Monospace,
|
||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
|
||||
)
|
||||
TextButton(onClick = { backupSeed = null }) { Text("I wrote it down") }
|
||||
}
|
||||
|
||||
error?.let {
|
||||
Text(
|
||||
it,
|
||||
|
|
@ -347,6 +411,92 @@ private fun PayComposer(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WalletSetupCard(
|
||||
kind: SetupKind,
|
||||
warning: String,
|
||||
onCancel: () -> Unit,
|
||||
onCreated: (String) -> Unit,
|
||||
onImported: () -> Unit,
|
||||
onError: (String) -> Unit,
|
||||
create: suspend (String) -> Result<String>,
|
||||
importWallet: suspend (String, String) -> Result<Unit>,
|
||||
scope: CoroutineScope,
|
||||
) {
|
||||
var accepted by remember { mutableStateOf(kind != SetupKind.Create) }
|
||||
var password by remember { mutableStateOf("") }
|
||||
var seed by remember { mutableStateOf("") }
|
||||
val ready = password.isNotEmpty() && (kind == SetupKind.Create || seed.isNotBlank())
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(12.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceVariant,
|
||||
),
|
||||
) {
|
||||
Column(Modifier.padding(12.dp)) {
|
||||
Text(
|
||||
if (kind == SetupKind.Create) "Create wallet" else "Import wallet",
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
if (kind == SetupKind.Create && !accepted) {
|
||||
Text(warning, style = MaterialTheme.typography.bodySmall)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||
TextButton(onClick = onCancel) { Text("Cancel") }
|
||||
Button(onClick = { accepted = true }) { Text("I accept spend authority") }
|
||||
}
|
||||
return@Column
|
||||
}
|
||||
if (kind == SetupKind.Import) {
|
||||
Text(
|
||||
"Paste the 25-word seed. Create does not need a key.",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
OutlinedTextField(
|
||||
value = seed,
|
||||
onValueChange = { seed = it },
|
||||
label = { Text("seed") },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
}
|
||||
OutlinedTextField(
|
||||
value = password,
|
||||
onValueChange = { password = it },
|
||||
singleLine = true,
|
||||
label = { Text("wallet passphrase") },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||
TextButton(onClick = onCancel) { Text("Cancel") }
|
||||
Button(
|
||||
onClick = {
|
||||
scope.launch {
|
||||
when (kind) {
|
||||
SetupKind.Create -> create(password).fold(
|
||||
onSuccess = onCreated,
|
||||
onFailure = { onError(it.message ?: it.toString()) },
|
||||
)
|
||||
SetupKind.Import -> importWallet(password, seed.trim()).fold(
|
||||
onSuccess = { onImported() },
|
||||
onFailure = { onError(it.message ?: it.toString()) },
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
enabled = ready,
|
||||
) { Text(if (kind == SetupKind.Create) "Create" else "Import") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Generate a QR bitmap for the given URI string. Returns null on encode failure. */
|
||||
internal fun generateQrBitmap(uri: String): Bitmap? {
|
||||
return try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue