Skip to content

Commit

Permalink
wip - random remote server connectivity
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jan 12, 2024
1 parent fb1c00d commit 428d898
Show file tree
Hide file tree
Showing 29 changed files with 980 additions and 509 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ This is an alpha release, please help us test this software.

One of the best ways to test this application is to build both desktop and web versions and run them side-by-side, connecting the web app to the node running within the desktop app. You can then create a wallet in both instances and transfer funds between them.

### Known Issues

- [ ] The Web App does not currently preserve transaction history. Reloading the page or the wallet will result in the blank transaction list (this does not affect the wallet functionality). The Web Browser transaction history storage backend is currently under development in the Rusty Kaspa wallet framework.
- [ ] When the Web App goes off screen or in the background tab, browser will suspend it preventing it from processing updates. There is a workaround for this, but it is not yet implemented.


## License

Licensed under a [PROPRIETARY MIT-style Open Source LICENSE](LICENSE) with the following restrictions:
Expand Down
28 changes: 9 additions & 19 deletions Servers.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@

[[server]]
name = "kaspa-ng.org"
location = "EU"
protocol = "borsh"
network = ["mainnet"]
address = "wss://kaspa-ng.org:443/mainnet"
network = "mainnet"
address = "wss://eu-1.kaspa-ng.org:443/mainnet"

[[server]]
name = "kaspa-ng.org"
location = "EU"
protocol = "borsh"
network = ["testnet-11"]
address = "wss://kaspa-ng.org:443/testnet-11"
network = "testnet-10"
address = "wss://eu-1.kaspa-ng.org:443/testnet-10"

[[server]]
name = "localhost"
protocol = "borsh"
network = ["mainnet"]
address = "127.0.0.1"

[[server]]
name = "localhost"
protocol = "borsh"
network = ["testnet-10"]
address = "127.0.0.1"

[[server]]
name = "localhost"
name = "kaspa-ng.org"
location = "EU"
protocol = "borsh"
network = ["testnet-11"]
address = "127.0.0.1"
network = "testnet-11"
address = "wss://eu-1.kaspa-ng.org:443/testnet-11"

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ log.workspace = true
pad.workspace = true
passwords.workspace = true
qrcode.workspace = true
rand.workspace = true
rfd.workspace = true
ritehash.workspace = true
separator.workspace = true
Expand Down
10 changes: 7 additions & 3 deletions core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use std::sync::Arc;
use workflow_i18n::*;
use workflow_log::*;

pub const KASPA_NG_ICON_SVG: &[u8] = include_bytes!("../../resources/images/kaspa.svg");
// pub const KASPA_NG_ICON_SVG: &[u8] = include_bytes!("../../resources/images/kaspa.svg");
pub const KASPA_NG_ICON_SVG: &[u8] = include_bytes!("../../resources/images/kaspa-node.svg");
pub const KASPA_NG_LOGO_SVG: &[u8] = include_bytes!("../../resources/images/kaspa-ng.svg");
pub const I18N_EMBEDDED: &str = include_str!("../../resources/i18n/i18n.json");
pub const BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
Expand All @@ -28,8 +29,8 @@ cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
use kaspad_lib::daemon::{
create_core,
DESIRED_DAEMON_SOFT_FD_LIMIT,
MINIMUM_DAEMON_SOFT_FD_LIMIT
// DESIRED_DAEMON_SOFT_FD_LIMIT,
// MINIMUM_DAEMON_SOFT_FD_LIMIT
};
use kaspad_lib::args::Args as NodeArgs;
use kaspa_utils::fd_budget;
Expand All @@ -39,6 +40,9 @@ cfg_if! {
use runtime::panic::*;
use std::fs;

const DESIRED_DAEMON_SOFT_FD_LIMIT: u64 = 4 * 1024;
const MINIMUM_DAEMON_SOFT_FD_LIMIT: u64 = 2 * 1024;

#[derive(Debug)]
enum I18n {
Import,
Expand Down
55 changes: 26 additions & 29 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::frame::window_frame;
use crate::imports::*;
use crate::market::*;
use crate::mobile::MobileMenu;
use crate::servers::parse_default_servers;
use egui::load::Bytes;
use egui_notify::Toasts;
use kaspa_metrics_core::MetricsSnapshot;
Expand Down Expand Up @@ -52,7 +51,6 @@ pub struct Core {

pub device: Device,
pub market: Option<Market>,
pub servers: Arc<Vec<Server>>,
pub debug: bool,
pub window_frame: bool,
callback_map: CallbackMap,
Expand Down Expand Up @@ -188,7 +186,6 @@ impl Core {

device: Device::new(window_frame),
market: None,
servers: parse_default_servers().clone(),
debug: false,
window_frame,
callback_map: CallbackMap::default(),
Expand All @@ -199,7 +196,8 @@ impl Core {
module.init(&mut this);
});

this.update_servers();
load_public_servers();

this.wallet_update_list();

#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -337,6 +335,18 @@ impl Core {
.expect("unable to downcast_mut module")
})
}

pub fn change_current_network(&mut self, network: Network) {
if self.settings.node.network != network {
self.settings.node.network = network;
self.get_mut::<modules::Settings>()
.change_current_network(network);
self.store_settings();
self.runtime
.kaspa_service()
.update_services(&self.settings.node);
}
}
}

impl eframe::App for Core {
Expand Down Expand Up @@ -422,19 +432,15 @@ impl Core {

window_frame(self.window_frame && !is_fullscreen, ctx, "Kaspa NG", |ui| {
if !self.settings.initialized {
cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
egui::CentralPanel::default().show_inside(ui, |ui| {
self.modules
.get(&TypeId::of::<modules::Welcome>())
.unwrap()
.clone()
.render(self, ctx, frame, ui);
});
egui::CentralPanel::default().show_inside(ui, |ui| {
self.modules
.get(&TypeId::of::<modules::Welcome>())
.unwrap()
.clone()
.render(self, ctx, frame, ui);
});

return;
}
}
return;
}

if !self.module.modal() && !self.device.mobile() {
Expand Down Expand Up @@ -604,9 +610,6 @@ impl Core {
) -> Result<()> {
match event {
Events::VisibilityChange(_state) => {}
Events::ServerList { server_list } => {
self.servers = server_list;
}
Events::Market(update) => {
if self.market.is_none() {
self.market = Some(Market::default());
Expand Down Expand Up @@ -693,6 +696,8 @@ impl Core {
self.state.is_connected = true;
self.state.url = url;
self.state.network_id = Some(network_id);

self.module.clone().connect(self);
}
#[allow(unused_variables)]
CoreWallet::Disconnect {
Expand All @@ -709,6 +714,8 @@ impl Core {
self.state.network_load = None;
self.metrics = Some(Box::default());
self.network_load_samples.clear();

self.module.clone().disconnect(self);
}
CoreWallet::UtxoIndexNotEnabled { url } => {
self.exception = Some(Exception::UtxoIndexNotEnabled { url });
Expand Down Expand Up @@ -1102,17 +1109,7 @@ impl Core {
ui.style_mut().text_styles = self.default_style.text_styles.clone();
}

pub fn update_servers(&self) {
let runtime = self.runtime.clone();
spawn(async move {
let server_list = load_servers().await?;
runtime.send(Events::ServerList { server_list }).await?;
Ok(())
});
}

pub fn register_visibility_handler(&self) {
use workflow_dom::utils::document;
use workflow_wasm::callback::*;

let block_dag_background_state = self.get::<modules::BlockDag>().background_state();
Expand Down
35 changes: 34 additions & 1 deletion core/src/egui/composite_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct CompositeButton<'a> {
padding: Option<Vec2>,
selected: bool,
show_loading_spinner: Option<bool>,
pulldown_selector: bool,
}

impl<'a> CompositeButton<'a> {
Expand Down Expand Up @@ -113,6 +114,7 @@ impl<'a> CompositeButton<'a> {
selected: false,
show_loading_spinner: None,
secondary_text,
pulldown_selector: false,
}
}

Expand Down Expand Up @@ -213,6 +215,12 @@ impl<'a> CompositeButton<'a> {
self.show_loading_spinner = Some(show);
self
}

#[inline]
pub fn with_pulldown_selector(mut self, pulldown_selector: bool) -> Self {
self.pulldown_selector = pulldown_selector;
self
}
}

impl Widget for CompositeButton<'_> {
Expand All @@ -234,6 +242,7 @@ impl Widget for CompositeButton<'_> {
selected,
show_loading_spinner,
secondary_text,
pulldown_selector,
} = self;

let frame = frame.unwrap_or_else(|| ui.visuals().button_frame);
Expand All @@ -247,6 +256,8 @@ impl Widget for CompositeButton<'_> {
button_padding.y = 0.0;
}

let pulldown_padding = if pulldown_selector { 20.0 } else { 0.0 };

let space_available_for_image = if let Some(text) = &text {
let font_height = ui.fonts(|fonts| font_height(text, fonts, ui.style()));
Vec2::splat(font_height) // Reasonable?
Expand Down Expand Up @@ -286,7 +297,7 @@ impl Widget for CompositeButton<'_> {
let shortcut_text = (!shortcut_text.is_empty())
.then(|| shortcut_text.into_galley(ui, Some(false), f32::INFINITY, TextStyle::Button));

let mut desired_size = Vec2::ZERO;
let mut desired_size = Vec2::new(pulldown_padding, 0.0); //Vec2::ZERO;
let mut img_plus_spacing_width = 0.0;
if image.is_some() {
desired_size.x += image_size.x;
Expand Down Expand Up @@ -449,6 +460,28 @@ impl Widget for CompositeButton<'_> {
ui.visuals().weak_text_color(),
);
}

if pulldown_selector {
let galley = WidgetText::RichText(RichText::new("⏷").size(14.)).into_galley(
ui,
wrap,
text_wrap_width,
TextStyle::Button,
);
let image_rect = Rect::from_min_size(
pos2(
rect.max.x - button_padding.x - 20.0,
rect.center().y - 0.5 - (galley.size().y / 2.0),
),
galley.size(),
);

galley.paint_with_fallback_color(
ui.painter(),
image_rect.min,
visuals.fg_stroke.color,
);
}
}

if let Some(cursor) = ui.visuals().interact_cursor {
Expand Down
8 changes: 8 additions & 0 deletions core/src/egui/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,11 @@ impl WidgetSpacerExtension for Ui {
self.add_space(theme_style().widget_spacing);
}
}

pub fn set_menu_style(style: &mut Style) {
style.spacing.button_padding = vec2(2.0, 0.0);
style.visuals.widgets.active.bg_stroke = Stroke::NONE;
style.visuals.widgets.hovered.bg_stroke = Stroke::NONE;
style.visuals.widgets.inactive.weak_bg_fill = Color32::TRANSPARENT;
style.visuals.widgets.inactive.bg_stroke = Stroke::NONE;
}
24 changes: 21 additions & 3 deletions core/src/egui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct PopupPanel<'panel> {
caption: Option<String>,
with_close_button: bool,
close_on_interaction: bool,
above_or_below: AboveOrBelow,
with_padding: bool,
}

impl<'panel> PopupPanel<'panel> {
Expand All @@ -32,6 +34,8 @@ impl<'panel> PopupPanel<'panel> {
caption: None,
with_close_button: false,
close_on_interaction: false,
above_or_below: AboveOrBelow::Below,
with_padding: true,
}
}

Expand Down Expand Up @@ -60,6 +64,16 @@ impl<'panel> PopupPanel<'panel> {
self
}

pub fn with_above_or_below(mut self, above_or_below: AboveOrBelow) -> Self {
self.above_or_below = above_or_below;
self
}

pub fn with_padding(mut self, with_padding: bool) -> Self {
self.with_padding = with_padding;
self
}

pub fn build(self, ui: &mut Ui) {
let response = (self.widget)(ui);
if response.clicked() {
Expand All @@ -74,7 +88,7 @@ impl<'panel> PopupPanel<'panel> {
ui,
self.id,
&response,
AboveOrBelow::Below,
self.above_or_below,
self.close_on_interaction,
|ui| {
if let Some(width) = self.min_width {
Expand All @@ -101,14 +115,18 @@ impl<'panel> PopupPanel<'panel> {
});

ui.separator();
ui.space();
if self.with_padding {
ui.space();
}
}

let mut close_popup = false;
(self.content)(ui, &mut close_popup);

if self.with_close_button {
ui.space();
if self.with_padding {
ui.space();
}
ui.separator();

ui.add_space(8.);
Expand Down
4 changes: 2 additions & 2 deletions core/src/egui/theme/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl ThemeColor {
market_down_color: Color32::from_rgb(255, 136, 136),

raised_text_color: Color32::from_rgb(255, 255, 255),
raised_text_shadow: Color32::from_rgb(0, 0, 0),
raised_text_shadow: Color32::from_rgba(0, 0, 0, 96),

qr_background: Color32::from_rgba(0, 0, 0, 0),
qr_foreground: Color32::WHITE,
Expand Down Expand Up @@ -163,7 +163,7 @@ impl ThemeColor {
market_down_color: Color32::from_rgb(77, 41, 41),

raised_text_color: Color32::from_rgb(0, 0, 0),
raised_text_shadow: Color32::from_rgb(255, 255, 255),
raised_text_shadow: Color32::from_rgba(255, 255, 255, 64),

qr_background: Color32::from_rgba(255, 255, 255, 0),
qr_foreground: Color32::BLACK,
Expand Down
Loading

0 comments on commit 428d898

Please sign in to comment.