Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 28 additions & 7 deletions liana-gui/src/app/state/receive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::{HashMap, HashSet};
use std::str::FromStr;
use std::sync::Arc;

use iced::{widget::qr_code, Subscription, Task};
Expand Down Expand Up @@ -286,9 +287,21 @@ impl State for ReceivePanel {
Task::none()
}
}
Message::View(view::Message::ShowQrCode(i)) => {
if let (Some(address), Some(index)) = (self.address(i), self.derivation_index(i)) {
if let Some(modal) = ShowQrCodeModal::new(address, *index) {
Message::View(view::Message::ShowQrCode(i, bip21)) => {
if let Some(address) = self.address(i) {
if bip21.is_some() {
if let Some(modal) =
ShowQrCodeModal::new(&bip21.clone().unwrap_or(address.to_string()))
{
self.modal = Modal::ShowQrCode(modal);
} else {
tracing::error!(
"Failed to create QR modal for BIP21 '{:?}' (address {})",
bip21,
address
);
}
} else if let Some(modal) = ShowQrCodeModal::new(&address.to_string()) {
self.modal = Modal::ShowQrCode(modal);
}
}
Expand Down Expand Up @@ -420,13 +433,21 @@ pub struct ShowQrCodeModal {
}

impl ShowQrCodeModal {
pub fn new(address: &Address, index: ChildNumber) -> Option<Self> {
qr_code::Data::new(format!("bitcoin:{}?index={}", address, index))
.ok()
.map(|qr_code| Self {
pub fn new(address: &str) -> Option<Self> {
if Address::from_str(address).is_ok() {
qr_code::Data::new(format!("bitcoin:{}", address))
.ok()
.map(|qr_code| Self {
qr_code,
address: address.to_string(),
})
} else {
// Already in bip21 format
qr_code::Data::new(address).ok().map(|qr_code| Self {
qr_code,
address: address.to_string(),
})
}
}

fn view(&self) -> Element<view::Message> {
Expand Down
2 changes: 1 addition & 1 deletion liana-gui/src/app/view/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum Message {
Previous,
SelectHardwareWallet(usize),
CreateRbf(CreateRbfMessage),
ShowQrCode(usize),
ShowQrCode(usize, Option<String>),
ImportExport(ImportExportMessage),
HideRescanWarning,
ExportPsbt,
Expand Down
6 changes: 4 additions & 2 deletions liana-gui/src/app/view/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use super::message::Message;
fn address_card<'a>(
row_index: usize,
address: &'a bitcoin::Address,
maybe_bip21: Option<String>,
labels: &'a HashMap<String, String>,
labels_editing: &'a HashMap<String, form::Value<String>>,
) -> Container<'a, Message> {
Expand Down Expand Up @@ -83,7 +84,7 @@ fn address_card<'a>(
.push(Space::with_width(Length::Fill))
.push(
button::secondary(None, "Show QR Code")
.on_press(Message::ShowQrCode(row_index)),
.on_press(Message::ShowQrCode(row_index, maybe_bip21)),
),
)
.spacing(10),
Expand Down Expand Up @@ -129,7 +130,7 @@ pub fn receive<'a>(
Column::new().spacing(10).width(Length::Fill),
|col, (i, address)| {
addresses_count += 1;
col.push(address_card(i, address, labels, labels_editing))
col.push(address_card(i, address, None, labels, labels_editing))
},
)),
)
Expand Down Expand Up @@ -229,6 +230,7 @@ pub fn receive<'a>(
Button::new(address_card(
addresses_count + i,
address,
None,
prev_labels,
labels_editing,
))
Expand Down
Loading