Skip to content

Commit

Permalink
donations panel
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Dec 20, 2023
1 parent 5318750 commit ef30620
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 9 deletions.
105 changes: 105 additions & 0 deletions core/src/modules/donations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use std::{borrow::Cow, collections::hash_map::Entry};

use crate::imports::*;
pub struct Donations {
qr : HashMap<String, (String,load::Bytes)>,
}

impl Donations {

pub const ADDRESS: &'static str = "kaspatest:qqdr2mv4vkes6kvhgy8elsxhvzwde42629vnpcxe4f802346rnfkklrhz0x7x";

pub fn new(_runtime: Runtime) -> Self {
Self {
qr : Default::default(),
}
}

fn qr(&mut self) -> (String,load::Bytes) {

let (uri,qr) = match self.qr.entry(theme_color().name.clone()) {
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => {
let uri = format!("bytes://{}-{}.svg", Self::ADDRESS, theme_color().name);
let qr = render_qrcode(&Self::ADDRESS, 128, 128);
entry.insert((uri, qr.as_bytes().to_vec().into()))
},
};

(uri.clone(),qr.clone())
}

}

impl ModuleT for Donations {

fn style(&self) -> ModuleStyle {
ModuleStyle::Mobile
}

fn render(
&mut self,
core: &mut Core,
_ctx: &egui::Context,
_frame: &mut eframe::Frame,
ui: &mut egui::Ui,
) {
let (uri, qr) = self.qr();
let back = Rc::new(RefCell::new(false));

Panel::new(self)
.with_caption("Supporting Kaspa NG")
.with_back_enabled(core.has_stack(), |_|{
*back.borrow_mut() = true;
})
.with_close_enabled(false, |_|{
})
// .with_header(|_ctx,ui| {

// })
.with_body(|_ctx,ui| {
use egui_phosphor::light::CLIPBOARD_TEXT;

ui.add_space(8.);
ui.label("This project relies on the support of the community in all areas including development, testing and funding.");
ui.label(" ");
ui.label("If you are able to contribute by donating, we would greatly appreciate your support.");
ui.label(" ");
ui.label("You can send donations to the following address:");
ui.label(" ");

ui.add(
Image::new(ImageSource::Bytes { uri : Cow::Owned(uri), bytes: qr })
.fit_to_original_size(1.0)
.texture_options(TextureOptions::NEAREST)
);

ui.label(" ");

if ui
.add(Label::new(format!("{} {CLIPBOARD_TEXT}", format_address_string(Self::ADDRESS, Some(12)))).sense(Sense::click()))
.on_hover_ui_at_pointer(|ui|{
ui.vertical(|ui|{
ui.label("Click to copy the donation address to clipboard".to_string());
});
})
.clicked() {
ui.output_mut(|o| o.copied_text = Self::ADDRESS.to_owned());
runtime().notify(UserNotification::info(format!("{CLIPBOARD_TEXT} {}", i18n("Copied to clipboard"))).short())
}

})
.with_footer(|_this,ui| {
if ui.large_button("Close").clicked() {
*back.borrow_mut() = true;
}
})
.render(ui);

if *back.borrow_mut() {
core.back();
}

}

}
3 changes: 2 additions & 1 deletion core/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ kaspa_ng_macros::register_modules!(
account_manager,
block_dag,
changelog,
donations,
export,
import,
metrics,
Expand All @@ -19,8 +20,8 @@ kaspa_ng_macros::register_modules!(
settings,
testing,
wallet_create,
wallet_secret,
wallet_open,
wallet_secret,
welcome,
]
);
Expand Down
8 changes: 3 additions & 5 deletions core/src/modules/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Overview {
let top = 32.;
let logo_rect = Rect::from_min_size(Pos2::new(left, top), logo_size);

if screen_rect.width() > 768.0 {
if screen_rect.width() > 768.0 && !core.device().single_pane() {
Image::new(ImageSource::Bytes { uri : Cow::Borrowed("bytes://logo.svg"), bytes : Bytes::Static(crate::app::KASPA_NG_LOGO_SVG)})
.maintain_aspect_ratio(true)
.max_size(logo_size)
Expand Down Expand Up @@ -328,10 +328,8 @@ impl Overview {
.default_open(true)
.show(ui, |ui| {
ui.label("Please support Kaspa NG development");
// if ui.link("kaspatest:qqdr2mv4vkes6kvhgy8elsxhvzwde42629vnpcxe4f802346rnfkklrhz0x7x").clicked() {
let donation_address = "kaspatest:qqdr2mv4vkes6kvhgy8elsxhvzwde42629vnpcxe4f802346rnfkklrhz0x7x";
if ui.link(format_address(&Address::try_from(donation_address).unwrap(), Some(12))).clicked() {
println!("link clicked...");
if ui.link(format_address_string(modules::Donations::ADDRESS, Some(12))).clicked() {
core.select::<modules::Donations>();
}
});
});
Expand Down
9 changes: 6 additions & 3 deletions core/src/utils/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ pub fn format_duration(millis: u64) -> String {
}
}

pub fn format_address(address: &Address, range: Option<usize>) -> String {
let address = address.to_string();

pub fn format_address_string(address: impl Into<String>, range: Option<usize>) -> String {
let address = address.into();
let parts = address.split(':').collect::<Vec<&str>>();
let prefix = parts[0];
let payload = parts[1];
Expand All @@ -38,6 +37,10 @@ pub fn format_address(address: &Address, range: Option<usize>) -> String {
format!("{prefix}:{left}....{right}")
}

pub fn format_address(address: &Address, range: Option<usize>) -> String {
format_address_string(address, range)
}

/// SOMPI (u64) to KASPA (string) with suffix layout job generator
pub fn s2kws_layout_job(
enable: bool,
Expand Down

0 comments on commit ef30620

Please sign in to comment.