tui: clean-look chrome redesign (one accent, honest tor phase, real frames) #120
1 changed files with 82 additions and 1 deletions
Merge branch 'main' into onionwire/t_bcf0ae45-onionwire-tui-clean-look-chrome-redesign
commit
8cbdcbbd94
83
src/node.rs
83
src/node.rs
|
|
@ -28,7 +28,7 @@ use crate::ratchet::{RatchetKeyPair, RatchetState};
|
|||
use crate::ratelimit::TokenBucket;
|
||||
use crate::sanitize;
|
||||
use crate::session::{self, Keys};
|
||||
use crate::store::{Friend, FriendProfile, Message, PaymentWrite, Store};
|
||||
use crate::store::{Friend, FriendProfile, Message, Payment, PaymentWrite, Store};
|
||||
use crate::wallet::{self, Readiness, Wallet, WalletConfig, WalletStatus};
|
||||
use crate::wallet_child::{ChildConfig, WalletChild, WalletChildState, WalletChildStatus};
|
||||
|
||||
|
|
@ -500,6 +500,23 @@ impl Node {
|
|||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// The signed `/pay` invoices and `/tip` receipts that came from one peer,
|
||||
/// oldest row first. A friend with no payment rows is an empty vector, not
|
||||
/// an error.
|
||||
///
|
||||
/// Read-only and fail-closed: it locks the store and nothing else — no Tor
|
||||
/// dial, no wallet RPC. `memo` is the text the peer signed, stored and
|
||||
/// returned as it arrived; a renderer sanitizes it with
|
||||
/// [`crate::sanitize::display_text`] at draw time, exactly as the chat
|
||||
/// bodies from [`Self::list_messages`] are.
|
||||
pub fn list_payments(&self, friend_pk: &[u8]) -> Result<Vec<Payment>, String> {
|
||||
self.store
|
||||
.lock()
|
||||
.map_err(|e| e.to_string())?
|
||||
.list_payments(friend_pk)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// The live wallet, cloned out of its lock. Every wallet call goes through
|
||||
/// this so a `std::sync::Mutex` guard never lives across an `.await`, and so
|
||||
/// the F7 screen can re-point the wallet mid-session.
|
||||
|
|
@ -2314,6 +2331,70 @@ mod tests {
|
|||
assert_eq!(rows[0].kind, "tip");
|
||||
}
|
||||
|
||||
/// The peer payment history the TUI needs: `Store::list_payments` existed but
|
||||
/// nothing on `Node` reached it, so the signed invoice/receipt frames a peer
|
||||
/// sent were invisible to the app. One row per stored frame, oldest first,
|
||||
/// and a friend with no rows is an empty vector, not an error.
|
||||
#[tokio::test]
|
||||
async fn list_payments_round_trips_a_peers_invoice_and_receipt() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let node = offline_node(&dir.path().join("bob"), Arc::new(NoDial));
|
||||
let peer = Keys::generate();
|
||||
let stranger = Keys::generate();
|
||||
let addr = xmr_addr();
|
||||
befriend(
|
||||
&node.store.lock().unwrap(),
|
||||
&peer.identity_pk,
|
||||
&peer.prekey_pk,
|
||||
"peer.onion",
|
||||
);
|
||||
{
|
||||
let store = node.store.lock().unwrap();
|
||||
store
|
||||
.insert_payment(
|
||||
&peer.identity_pk,
|
||||
PaymentWrite {
|
||||
dir: "in",
|
||||
kind: "invoice",
|
||||
amount_atomic: "500000000000",
|
||||
address: &addr,
|
||||
memo: "rent",
|
||||
txid: None,
|
||||
verified: false,
|
||||
},
|
||||
)
|
||||
.expect("store inbound invoice");
|
||||
store
|
||||
.insert_payment(
|
||||
&peer.identity_pk,
|
||||
PaymentWrite {
|
||||
dir: "in",
|
||||
kind: "receipt",
|
||||
amount_atomic: "250000000000",
|
||||
address: &addr,
|
||||
memo: "",
|
||||
txid: Some("deadbeef"),
|
||||
verified: false,
|
||||
},
|
||||
)
|
||||
.expect("store inbound receipt");
|
||||
}
|
||||
|
||||
let rows = node.list_payments(&peer.identity_pk).expect("payments");
|
||||
assert_eq!(rows.len(), 2, "one row per stored frame");
|
||||
assert_eq!(rows[0].kind, "invoice", "oldest row first");
|
||||
assert_eq!(rows[0].dir, "in");
|
||||
assert_eq!(rows[0].amount_atomic, "500000000000");
|
||||
assert_eq!(rows[0].memo, "rent");
|
||||
assert_eq!(rows[1].kind, "receipt");
|
||||
assert_eq!(rows[1].txid.as_deref(), Some("deadbeef"));
|
||||
|
||||
let none = node
|
||||
.list_payments(&stranger.identity_pk)
|
||||
.expect("a friend with no rows is an empty vector, not an error");
|
||||
assert!(none.is_empty());
|
||||
}
|
||||
|
||||
/// A stand-in for `monero-wallet-rpc`: it records its argv, then does what
|
||||
/// the test needs. The wallet child spawns a real process, so this is the
|
||||
/// only honest way to drive the start path offline.
|
||||
|
|
|
|||
Loading…
Reference in a new issue