Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Dec 11, 2023
1 parent 1ef2231 commit 5654fd9
Show file tree
Hide file tree
Showing 65 changed files with 2,242 additions and 1,522 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ kaspa-bip32 = { path = "../rusty-kaspa/wallet/bip32" }
kaspa-cli = { path = "../rusty-kaspa/cli" }
kaspa-consensus-core = { path = "../rusty-kaspa/consensus/core" }
kaspa-core = { path = "../rusty-kaspa/core" }
kaspa-metrics = { path = "../rusty-kaspa/metrics/metrics" }
kaspa-metrics-core = { path = "../rusty-kaspa/metrics/core" }
kaspa-notify = { path = "../rusty-kaspa/notify" }
kaspa-rpc-core = { path = "../rusty-kaspa/rpc/core" }
kaspa-rpc-service = { path = "../rusty-kaspa/rpc/service" }
Expand All @@ -78,7 +78,7 @@ kaspad = { path = "../rusty-kaspa/kaspad" }
# kaspa-cli = { git = "https://github.com/kaspanet/rusty-kaspa.git", branch = "master" }
# kaspa-consensus-core = { git = "https://github.com/kaspanet/rusty-kaspa.git", branch = "master" }
# kaspa-core = { git = "https://github.com/kaspanet/rusty-kaspa.git", branch = "master" }
# kaspa-metrics = { git = "https://github.com/kaspanet/rusty-kaspa.git", branch = "master" }
# kaspa-metrics-core = { git = "https://github.com/kaspanet/rusty-kaspa.git", branch = "master" }
# kaspa-notify = { git = "https://github.com/kaspanet/rusty-kaspa.git", branch = "master" }
# kaspa-rpc-core = { git = "https://github.com/kaspanet/rusty-kaspa.git", branch = "master" }
# kaspa-rpc-service = { git = "https://github.com/kaspanet/rusty-kaspa.git", branch = "master" }
Expand Down
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<body>
<canvas id="kaspa-ng"></canvas>
<!-- script>
// Disable caching during the development.
// Caching is disabled during the development.
if ('serviceWorker' in navigator && window.location.hash !== "#dev") {
window.addEventListener('load', function () {
navigator.serviceWorker.register('./pwa.js');
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ kaspa-bip32.workspace = true
kaspa-cli.workspace = true
kaspa-consensus-core.workspace = true
kaspa-core.workspace = true
kaspa-metrics.workspace = true
kaspa-metrics-core.workspace = true
kaspa-ng-macros.workspace = true
kaspa-notify.workspace = true
kaspa-rpc-core.workspace = true
Expand Down
7 changes: 2 additions & 5 deletions core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ cfg_if! {
viewport: egui::ViewportBuilder::default()
.with_resizable(true)
.with_title(i18n("Kaspa NG"))
.with_min_inner_size([400.0,320.0])
.with_inner_size([1000.0,600.0])
.with_icon(svg_to_icon_data(KASPA_NG_ICON_SVG, FitTo::Size(256,256))),
..Default::default()
Expand Down Expand Up @@ -274,17 +275,13 @@ cfg_if! {
Settings::default()
});

// init_i18n(settings.language_code.as_str()).expect("failed to init i18n");

i18n::Builder::new(settings.language_code.as_str(), "en")
.with_static_json_data(I18N_EMBEDDED)
// .with_store(move |json_data: &str| {
// })
.try_init()?;

// wasm_bindgen_futures::spawn_local(async {
use workflow_log::*;
log_info!("starting");
log_info!("Welcome to Kaspa NG! Have a great day!");
eframe::WebRunner::new()
.start(
"kaspa-ng",
Expand Down
134 changes: 96 additions & 38 deletions core/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::imports::*;
use crate::market::*;
use crate::mobile::MobileMenu;
use egui::load::Bytes;
use egui_notify::Toasts;
use kaspa_metrics::MetricsSnapshot;
use kaspa_metrics_core::MetricsSnapshot;
use kaspa_wallet_core::api::TransactionDataGetResponse;
use kaspa_wallet_core::events::Events as CoreWallet;
use kaspa_wallet_core::storage::{Binding, Hint, PrvKeyDataInfo};
Expand Down Expand Up @@ -42,8 +43,11 @@ pub struct Core {
pub wallet_list: Vec<WalletDescriptor>,
pub prv_key_data_map: Option<HashMap<PrvKeyDataId, Arc<PrvKeyDataInfo>>>,
pub account_collection: Option<AccountCollection>,
// pub selected_account: Option<Account>,
pub release: Option<Release>,

pub device: Device,
pub market: Market,
pub debug: bool,
}

impl Core {
Expand Down Expand Up @@ -173,6 +177,10 @@ impl Core {
exception: None,

release: None,

device: Device::default(),
market: Market::default(),
debug: false,
};

modules.values().for_each(|module| {
Expand Down Expand Up @@ -270,6 +278,14 @@ impl Core {
&self.metrics
}

pub fn device(&self) -> &Device {
&self.device
}

pub fn device_mut(&mut self) -> &mut Device {
&mut self.device
}

pub fn module(&self) -> &Module {
&self.module
}
Expand Down Expand Up @@ -380,17 +396,45 @@ impl eframe::App for Core {
}
}

let device = runtime().device();
// let device = runtime().device();

if !self.module.modal() && !device.is_single_pane() {
self.device_mut().set_screen_size(&ctx.screen_rect());

// if ctx.screen_rect().width() < ctx.screen_rect().height() || ctx.screen_rect().width() < 540.0 {
// self.device.orientation = Orientation::Portrait;
// } else {
// self.device.orientation = Orientation::Landscape;
// }
// device.enable_portrait_desired(ctx.screen_rect().width() < 540.0);

// if !self.module.modal() && !device.single_pane() {
if !self.module.modal() && !self.device.mobile() {
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
Menu::new(self).render(ui);
// self.render_menu(ui, frame);
});
}

if device.is_single_pane() {
if !device.is_mobile() {
if self.device.orientation() == Orientation::Portrait {
CentralPanel::default()
.frame(Frame::default().fill(ctx.style().visuals.panel_fill))
.show(ctx, |ui| {
egui::TopBottomPanel::bottom("portrait_bottom_panel").show_inside(ui, |ui| {
Status::new(self).render(ui);
});

if self.device.mobile() {
egui::TopBottomPanel::bottom("mobile_menu_panel").show_inside(ui, |ui| {
MobileMenu::new(self).render(ui);
});
}

egui::CentralPanel::default().show_inside(ui, |ui| {
self.module.clone().render(self, ctx, frame, ui);
});
});
} else if self.device.single_pane() {
if !self.device.mobile() {
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
Status::new(self).render(ui);
egui::warn_if_debug_build(ui);
Expand Down Expand Up @@ -422,7 +466,7 @@ impl eframe::App for Core {
Status::new(self).render(ui);
});

if device.is_mobile() {
if self.device.mobile() {
egui::TopBottomPanel::bottom("mobile_menu_panel").show_inside(ui, |ui| {
MobileMenu::new(self).render(ui);
});
Expand Down Expand Up @@ -450,7 +494,6 @@ impl eframe::App for Core {
self.module.clone().render(self, ctx, frame, ui);
});
}

// if false {
// egui::Window::new("Window").show(ctx, |ui| {
// ui.label("Windows can be moved by dragging them.");
Expand Down Expand Up @@ -533,6 +576,14 @@ impl Core {
_frame: &mut eframe::Frame,
) -> Result<()> {
match event {
Events::Market(update) => match update {
MarketUpdate::Price(price) => {
self.market.price.replace(price);
}
MarketUpdate::Ohlc(ohlc) => {
self.market.ohlc.replace(ohlc);
}
},
Events::ThemeChange => {
if let Some(account_collection) = self.account_collection.as_ref() {
account_collection
Expand Down Expand Up @@ -581,6 +632,9 @@ impl Core {
}
Events::Wallet { event } => {
match *event {
CoreWallet::Error { message } => {
println!("{message}");
}
CoreWallet::UtxoProcStart => {}
CoreWallet::UtxoProcStop => {}
CoreWallet::UtxoProcError { message: _ } => {
Expand Down Expand Up @@ -678,8 +732,9 @@ impl Core {
.as_mut()
.expect("account collection")
.push_unchecked(account.clone());
let device = self.device().clone();
self.get_mut::<modules::AccountManager>()
.select(Some(account.clone()));
.select(Some(account.clone()), device);
self.select::<modules::AccountManager>();

let wallet = self.wallet().clone();
Expand Down Expand Up @@ -713,36 +768,36 @@ impl Core {
self.state.current_daa_score.replace(current_daa_score);
}
// Ignore scan notifications
CoreWallet::Scan { record: _ } => {}
CoreWallet::Discovery { record: _ } => {}
// Ignore stasis notifications
CoreWallet::Stasis { record: _ } => {}
// This notification is for a UTXO change, which is
// a part of the Outgoing transaction, we ignore it.
CoreWallet::Change { record: _ } => {}
// A transaction has been confirmed
CoreWallet::Maturity { record } => match record.binding().clone() {
Binding::Account(id) => {
self.account_collection
.as_ref()
.and_then(|account_collection| {
account_collection.get(&id).map(|account| {
println!();
println!("$$$ RECEIVING MATURITY");
println!();
account.transactions().replace_or_insert(
Transaction::new_confirmed(Arc::new(record)),
);
})
});
CoreWallet::Maturity { record } => {
if record.is_change() {
return Ok(());
}
Binding::Custom(_) => {
panic!("custom binding not supported");

match record.binding().clone() {
Binding::Account(id) => {
self.account_collection
.as_ref()
.and_then(|account_collection| {
account_collection.get(&id).map(|account| {
println!();
println!("$$$ RECEIVING MATURITY");
println!();
account.transactions().replace_or_insert(
Transaction::new_confirmed(Arc::new(record)),
);
})
});
}
Binding::Custom(_) => {
panic!("custom binding not supported");
}
}
},
// Observing a new, unconfirmed transaction
CoreWallet::External { record }
| CoreWallet::Outgoing { record }
| CoreWallet::Pending { record } => match record.binding().clone() {
}
CoreWallet::Pending { record } => match record.binding().clone() {
Binding::Account(id) => {
self.account_collection
.as_ref()
Expand Down Expand Up @@ -911,10 +966,13 @@ impl Core {
self.select::<modules::WalletCreate>();
}
Key::M => {
runtime().device().toggle_mobile();
self.device_mut().toggle_mobile();
}
Key::P => {
runtime().device().toggle_portrait();
self.device_mut().toggle_portrait();
}
Key::D => {
self.debug = !self.debug;
}
_ => {}
}
Expand All @@ -926,10 +984,10 @@ impl Core {
self.select::<modules::Testing>();
}
Key::M => {
runtime().device().toggle_mobile();
self.device_mut().toggle_mobile();
}
Key::P => {
runtime().device().toggle_portrait();
self.device_mut().toggle_portrait();
}
_ => {}
}
Expand Down
69 changes: 69 additions & 0 deletions core/src/device.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use crate::imports::*;

#[derive(Default, Clone, Copy, Debug, Eq, PartialEq)]
pub enum Orientation {
#[default]
Landscape,
Portrait,
}

#[derive(Default, Clone)]
pub struct Device {
pub mobile_device: bool,
pub mobile_forced: bool,
pub orientation: Orientation,
pub orientation_forced: Option<Orientation>,
pub screen_size: Vec2,
}

impl Device {
pub fn new() -> Self {
Self {
mobile_device: false,
mobile_forced: false,
orientation: Orientation::default(),
orientation_forced: None,
screen_size: Vec2::ZERO,
}
}

pub fn set_screen_size(&mut self, rect: &Rect) {
let size = rect.size();

if size.x < size.y || size.x < 540.0 {
self.orientation = Orientation::Portrait;
} else {
self.orientation = Orientation::Landscape;
}

self.screen_size = rect.size();
}

pub fn orientation(&self) -> Orientation {
self.orientation_forced.unwrap_or(self.orientation)
}

pub fn mobile(&self) -> bool {
self.mobile_device || self.mobile_forced
}

pub fn toggle_portrait(&mut self) {
if self.orientation_forced.is_none() {
self.orientation_forced = Some(Orientation::Portrait);
} else {
self.orientation_forced = None;
}
}

pub fn toggle_mobile(&mut self) {
self.mobile_forced = !self.mobile_forced;
}

pub fn single_pane(&self) -> bool {
self.mobile_forced || self.mobile_device || self.orientation() == Orientation::Portrait
}

pub fn force_orientation(&mut self, orientation: Option<Orientation>) {
self.orientation_forced = orientation;
}
}
Loading

0 comments on commit 5654fd9

Please sign in to comment.