Skip to content

Commit

Permalink
feat: show ln-invoice as qr-code
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Apr 3, 2024
1 parent c261ae0 commit 33b226e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions moksha-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ url = "2.4.1"
anyhow = { version = "1.0.75", features = ["backtrace"] }
dialoguer = "0.11.0"
num-format = "0.4.4"
qrcode = "0.14.0"
28 changes: 22 additions & 6 deletions moksha-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use moksha_wallet::http::CrossPlatformHttpClient;
use moksha_wallet::localstore::sqlite::SqliteLocalStore;
use moksha_wallet::wallet::Wallet;
use num_format::{Locale, ToFormattedString};
use qrcode::render::unicode;
use qrcode::QrCode;
use std::io::Write;
use std::process::exit;
use std::str::FromStr;
Expand Down Expand Up @@ -95,15 +97,19 @@ async fn main() -> anyhow::Result<()> {
println!("Mint added successfully ");
}
Command::Info => {
let wallet_version = env!("CARGO_PKG_VERSION");
let wallet_version = style(env!("CARGO_PKG_VERSION")).cyan();
let mint_urls = wallet.get_mint_urls().await?;
println!("Version: {}\nDB: {}", wallet_version, db_path,);
let db_path = style(db_path).cyan();
let term = Term::stdout();
term.write_line(&format!("Version: {wallet_version}"))?;
term.write_line(&format!("DB: {db_path}"))?;

if mint_urls.is_empty() {
println!("No mints found.");
term.write_line("No mints found.")?;
} else {
println!("Mints:");
term.write_line("Mints:")?;
for mint in mint_urls {
println!(" - {}", mint);
term.write_line(&format!(" - {}", mint))?;
}
}
}
Expand Down Expand Up @@ -381,7 +387,17 @@ async fn main() -> anyhow::Result<()> {
quote,
..
} = wallet.create_quote_bolt11(&mint_url, amount).await?;
println!("Pay invoice to mint tokens:\n\n{payment_request}");

let term = Term::stdout();
term.write_line(&format!("Pay invoice to mint tokens:\n\n{payment_request}"))?;

let image = QrCode::new(payment_request)?
.render::<unicode::Dense1x2>()
.dark_color(unicode::Dense1x2::Dark)
.light_color(unicode::Dense1x2::Light)
.build();

term.write_line(&image)?;
quote
}
};
Expand Down
1 change: 0 additions & 1 deletion moksha-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::{
};
use lightning_invoice::Bolt11Invoice as LNInvoice;
use std::{
any::Any,
collections::{HashMap, HashSet},
str::FromStr,
vec,
Expand Down

0 comments on commit 33b226e

Please sign in to comment.