Skip to content

Commit

Permalink
wip - alternate server option in status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jan 13, 2024
1 parent f6669d5 commit 4c37a3d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 40 deletions.
83 changes: 46 additions & 37 deletions core/src/primitives/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct BlockDagGraphSettings {
pub y_dist: f64,
pub graph_length_daa: usize,
pub center_vspc: bool,
pub balance_vspc: bool,
pub show_vspc: bool,
pub show_daa: bool,
pub show_grid: bool,
Expand All @@ -16,10 +17,10 @@ impl Default for BlockDagGraphSettings {
fn default() -> Self {
Self {
y_scale: 10.0,
// y_dist: 70.0,
y_dist: 7.0,
graph_length_daa: 1024,
center_vspc: false,
balance_vspc: true,
show_vspc: true,
show_daa: true,
show_grid: true,
Expand Down Expand Up @@ -106,49 +107,57 @@ impl DaaBucket {
let y_distance = settings.y_dist;
let len = self.blocks.len();

#[allow(clippy::collapsible_else_if)]
if let Some(mut vspc_idx) = self.blocks.iter().position(|block| block.vspc) {
if settings.center_vspc && len > 2 {
let mid = len / 2;
if vspc_idx != mid {
self.blocks.swap(vspc_idx, mid);
vspc_idx = mid;
self.blocks.iter_mut().for_each(|block| {
block.settled = false;
});
if settings.balance_vspc {
#[allow(clippy::collapsible_else_if)]
if let Some(mut vspc_idx) = self.blocks.iter().position(|block| block.vspc) {
if settings.center_vspc && len > 2 {
let mid = len / 2;
if vspc_idx != mid {
self.blocks.swap(vspc_idx, mid);
vspc_idx = mid;
self.blocks.iter_mut().for_each(|block| {
block.settled = false;
});
}
}
}

let vspc_y = if settings.center_vspc {
0.0
} else {
self.blocks
.get(vspc_idx)
.map(|block| block.dst_y)
.unwrap_or_default()
};

let mut y = vspc_y;
(0..vspc_idx).rev().for_each(|idx| {
let block = &mut self.blocks[idx];
y -= y_distance;
block.dst_y = y;
});
y = vspc_y;
((vspc_idx + 1)..len).for_each(|idx| {
let block = &mut self.blocks[idx];
y += y_distance;
block.dst_y = y;
});
} else {
if len > 1 {
let mut y = -(len as f64 * y_distance / 2.0);
(0..len).for_each(|idx| {
let vspc_y = if settings.center_vspc {
0.0
} else {
self.blocks
.get(vspc_idx)
.map(|block| block.dst_y)
.unwrap_or_default()
};

let mut y = vspc_y;
(0..vspc_idx).rev().for_each(|idx| {
let block = &mut self.blocks[idx];
y -= y_distance;
block.dst_y = y;
});
y = vspc_y;
((vspc_idx + 1)..len).for_each(|idx| {
let block = &mut self.blocks[idx];
y += y_distance;
block.dst_y = y;
});
} else {
if len > 1 {
let mut y = -(len as f64 * y_distance / 2.0);
(0..len).for_each(|idx| {
let block = &mut self.blocks[idx];
y += y_distance;
block.dst_y = y;
});
}
}
} else {
(0..len).for_each(|idx| {
let block = &mut self.blocks[idx];
block.dst_y =
hash_to_y_coord(&block.data.header.hash, settings.y_scale) * y_distance * 0.3;
});
}
}

Expand Down
9 changes: 9 additions & 0 deletions core/src/runtime/services/kaspa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct KaspaService {
pub task_ctl: Channel<()>,
pub network: Mutex<Network>,
pub wallet: Arc<CoreWallet>,
pub services_start_instant: Mutex<Option<Instant>>,
#[cfg(not(target_arch = "wasm32"))]
pub kaspad: Mutex<Option<Arc<dyn Kaspad + Send + Sync + 'static>>>,
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -122,6 +123,7 @@ impl KaspaService {
task_ctl: Channel::oneshot(),
network: Mutex::new(settings.node.network),
wallet: Arc::new(wallet),
services_start_instant: Mutex::new(None),
#[cfg(not(target_arch = "wasm32"))]
kaspad: Mutex::new(None),
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -261,6 +263,8 @@ impl KaspaService {
}

pub async fn stop_all_services(&self) -> Result<()> {
self.services_start_instant.lock().unwrap().take();

if !self.wallet().has_rpc() {
return Ok(());
}
Expand Down Expand Up @@ -304,6 +308,11 @@ impl KaspaService {
}

pub async fn start_all_services(self: &Arc<Self>, rpc: Rpc, network: Network) -> Result<()> {
self.services_start_instant
.lock()
.unwrap()
.replace(Instant::now());

let rpc_api = rpc.rpc_api().clone();

self.wallet()
Expand Down
29 changes: 29 additions & 0 deletions core/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,41 @@ impl<'core> Status<'core> {
}
}
NodeConnectionConfigKind::PublicServerRandom => {
if let Some(instant) = runtime()
.kaspa_service()
.services_start_instant
.lock()
.unwrap()
.as_ref()
{
let elapsed = instant.elapsed();
if elapsed.as_millis() > 2_500 {
if ui
.add(
Label::new(RichText::new(i18n(
"Click to try an another server...",
)))
.sense(Sense::click()),
)
.clicked()
{
runtime()
.kaspa_service()
.update_services(&self.core.settings.node);
}

ui.separator();
}
}

if let Some(rpc_url) = runtime().kaspa_service().rpc_url() {
ui.label(format!(
"{} {} ...",
i18n("Connecting to"),
rpc_url
));

ui.ctx().request_repaint_after(Duration::from_millis(250));
}
}
},
Expand Down
7 changes: 4 additions & 3 deletions resources/i18n/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"sv": "Swedish",
"pa": "Panjabi",
"nl": "Dutch",
"es": "Español",
"uk": "Ukrainian",
"es": "Español",
"af": "Afrikaans",
"et": "Esti",
"en": "English",
Expand Down Expand Up @@ -65,10 +65,10 @@
"fa": {},
"lt": {},
"sv": {},
"es": {},
"pa": {},
"nl": {},
"uk": {},
"es": {},
"af": {},
"et": {},
"en": {
Expand Down Expand Up @@ -123,9 +123,9 @@
"Settings": "Settings",
"Check for Updates": "Check for Updates",
"wRPC Connection Settings": "wRPC Connection Settings",
"Custom Public Node": "Custom Public Node",
"p2p Rx/s": "p2p Rx/s",
"Theme Color": "Theme Color",
"Custom Public Node": "Custom Public Node",
"Remote Connection:": "Remote Connection:",
"Difficulty": "Difficulty",
"Uptime:": "Uptime:",
Expand Down Expand Up @@ -303,6 +303,7 @@
"Your default wallet private key mnemonic is:": "Your default wallet private key mnemonic is:",
"Select Wallet": "Select Wallet",
"Theme Color:": "Theme Color:",
"Click to try an another server...": "Click to try an another server...",
"Theme Style": "Theme Style",
"Show password": "Show password",
"Balance: N/A": "Balance: N/A",
Expand Down

0 comments on commit 4c37a3d

Please sign in to comment.