Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import scan issue #47

Merged
merged 13 commits into from
Dec 10, 2024
438 changes: 194 additions & 244 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,23 @@ egui-notify = { git = "https://github.com/aspectron/egui-notify", branch = "gam
# kaspa-txscript = { path = "../rusty-kaspa/crypto/txscript" }
# kaspad = { path = "../rusty-kaspa/kaspad" }

kaspa-addresses = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-alloc = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-bip32 = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-cli = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-consensus-core = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-core = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-metrics-core = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-notify = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-rpc-core = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-rpc-service = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-utils = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-wallet-core = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-wallet-keys = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-wrpc-client = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-wrpc-server = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-txscript = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspad = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "gamma" }
kaspa-addresses = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-alloc = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-bip32 = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-cli = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-consensus-core = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-core = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-metrics-core = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-notify = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-rpc-core = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-rpc-service = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-utils = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-wallet-core = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-wallet-keys = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-wrpc-client = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-wrpc-server = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspa-txscript = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }
kaspad = { git = "https://github.com/aspectron/rusty-kaspa.git", branch = "sigma" }

# kaspa-addresses = { git = "https://github.com/kaspanet/rusty-kaspa.git", branch = "master" }
# kaspa-alloc = { git = "https://github.com/kaspanet/rusty-kaspa.git", branch = "master" }
Expand Down
10 changes: 10 additions & 0 deletions core/resources/i18n/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3668,6 +3668,7 @@
"Activate custom daemon arguments": "Activate custom daemon arguments",
"Active p2p Peers": "Active p2p Peers",
"Add Account": "Add Account",
"Add a new account by importing a mnemonic": "Add a new account by importing a mnemonic",
"Address copied to clipboard": "Address copied to clipboard",
"Address derivation scan": "Address derivation scan",
"Address:": "Address:",
Expand Down Expand Up @@ -3723,8 +3724,10 @@
"Copied to clipboard": "Copied to clipboard",
"Copy": "Copy",
"Copy logs to clipboard": "Copy logs to clipboard",
"Create Account": "Create Account",
"Create New Wallet": "Create New Wallet",
"Create Wallet": "Create Wallet",
"Create an account by importing a private key.": "Create an account by importing a private key.",
"Create new wallet": "Create new wallet",
"Creating Account": "Creating Account",
"Creating Wallet": "Creating Wallet",
Expand All @@ -3749,6 +3752,7 @@
"Delete Data Folder": "Delete Data Folder",
"Dependencies": "Dependencies",
"Derivation Indexes": "Derivation Indexes",
"Derive a private key to create a new account.": "Derive a private key to create a new account.",
"Details": "Details",
"Developer Mode": "Developer Mode",
"Developer Resources": "Developer Resources",
Expand Down Expand Up @@ -3790,6 +3794,7 @@
"Enter your wallet secret": "Enter your wallet secret",
"Enter {suffix} amount to send": "Enter {suffix} amount to send",
"Error": "Error",
"Error creating a wallet": "Error creating a wallet",
"Error importing a wallet": "Error importing a wallet",
"Error processing mnemonic: {err}": "Error processing mnemonic: {err}",
"Exit Full Screen": "Exit Full Screen",
Expand Down Expand Up @@ -3818,6 +3823,7 @@
"IBD:": "IBD:",
"If not specified, the account will be represented by the numeric id.": "If not specified, the account will be represented by the numeric id.",
"If you are running locally, use: ": "If you are running locally, use: ",
"Import Account": "Import Account",
"Import Existing Private Key": "Import Existing Private Key",
"Import existing": "Import existing",
"Import existing file": "Import existing file",
Expand Down Expand Up @@ -3889,6 +3895,7 @@
"Network Peers": "Network Peers",
"Network Pressure: ~{number}%": "Network Pressure: ~{number}%",
"Never share your mnemonic with anyone!": "Never share your mnemonic with anyone!",
"No BIP-44 private keys found": "No BIP-44 private keys found",
"No peers": "No peers",
"No public node selected - please select a public node": "No public node selected - please select a public node",
"No transactions": "No transactions",
Expand Down Expand Up @@ -3918,6 +3925,7 @@
"Payment & Recovery Password": "Payment & Recovery Password",
"Payment Request": "Payment Request",
"Payment request to account: {account}": "Payment request to account: {account}",
"Payment secret is empty": "Payment secret is empty",
"Peers": "Peers",
"Pending: {amount}": "Pending: {amount}",
"Performance": "Performance",
Expand All @@ -3936,6 +3944,7 @@
"Please enter the wallet secret": "Please enter the wallet secret",
"Please enter {suffix} amount to send": "Please enter {suffix} amount to send",
"Please note, copying to clipboard carries a risk of exposing your mnemonic to malware.": "Please note, copying to clipboard carries a risk of exposing your mnemonic to malware.",
"Please provide BIP39 passphrase.": "Please provide BIP39 passphrase.",
"Please select 'Apply' and restart the application.": "Please select 'Apply' and restart the application.",
"Please select account to scan": "Please select account to scan",
"Please select an account type": "Please select an account type",
Expand Down Expand Up @@ -4130,6 +4139,7 @@
"gRPC Tx": "gRPC Tx",
"gRPC Tx/s": "gRPC Tx/s",
"of": "of",
"or by deriving an already imported BIP-44 private key.": "or by deriving an already imported BIP-44 private key.",
"p2p RPC": "p2p RPC",
"p2p Rx": "p2p Rx",
"p2p Rx/s": "p2p Rx/s",
Expand Down
19 changes: 14 additions & 5 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,16 +812,16 @@ impl Core {
match metrics {
MetricsUpdate::WalletMetrics {
mempool_size,
node_peers: peers,
network_tps: tps,
// node_peers: peers,
// network_tps: tps,
} => {
self.sender().try_send(Events::MempoolSize {
mempool_size: mempool_size as usize,
})?;

self.state.node_peers = Some(peers as usize);
// self.state.node_peers = None;
self.state.node_mempool_size = Some(mempool_size as usize);
self.state.network_tps = Some(tps);
// self.state.network_tps = None;
}
}
}
Expand Down Expand Up @@ -1115,7 +1115,7 @@ impl Core {
if let Some(account) = account_collection.get(&id.into()) {
account.update_balance(balance)?;
} else {
log_error!("unable to find account {}", id);
log_error!("unable to find account {} while updating balance.", id);
}
} else {
log_error!(
Expand Down Expand Up @@ -1298,6 +1298,15 @@ impl Core {
});

if let Some(first) = accounts.first() {
self.load_account_transactions_with_range(first, 0..TRANSACTION_PAGE_SIZE)
.map_err(|err| {
log_error!(
"error loading transactions for account {}: {}",
first.id(),
err
);
})
.ok();
let device = self.device().clone();
let wallet = self.wallet();
self.get_mut::<modules::AccountManager>().select(
Expand Down
2 changes: 1 addition & 1 deletion core/src/egui/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<'render> MnemonicPresenter<'render> {
.show(ui, |ui| {
let frame_width = ui.available_width();
let num_cols = (frame_width / width_per_col).max(1.0) as usize;
let num_rows = (words.len() + (num_cols - 1)) / num_cols;
let num_rows = words.len().div_ceil(num_cols);

ui.set_max_height(num_rows as f32 * 32.);

Expand Down
7 changes: 4 additions & 3 deletions core/src/egui/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ impl<'panel, Context> Panel<'panel, Context> {
}

pub fn render(self, ui: &mut Ui) {
let icon_size = theme_style().panel_icon_size();
let theme_style = theme_style();
let icon_size = theme_style.panel_icon_size();
let icon_padding = (icon_size.outer - icon_size.inner) / 2.0;
let panel_margin_size = theme_style().panel_margin_size();
let panel_margin_size = theme_style.panel_margin_size();
let panel_width = ui.available_width();
let inner_panel_width = panel_width - panel_margin_size * 2.;

Expand Down Expand Up @@ -190,7 +191,7 @@ impl<'panel, Context> Panel<'panel, Context> {
});
}

let padding = ui.available_height() - theme_style().panel_footer_height;
let padding = ui.available_height() - theme_style.panel_footer_height;
if padding > 0. {
ui.add_space(padding);
}
Expand Down
15 changes: 9 additions & 6 deletions core/src/egui/theme/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,20 @@ impl ThemeColor {
}
}

static mut THEME_COLOR_LIST: Option<HashMap<String, ThemeColor>> = None;
pub fn theme_colors() -> &'static HashMap<String, ThemeColor> {
unsafe {
THEME_COLOR_LIST.get_or_insert_with(|| {
static THEME_COLOR_LIST: Mutex<Option<Arc<HashMap<String, ThemeColor>>>> = Mutex::new(None);

#[inline(always)]
pub fn theme_colors() -> Arc<HashMap<String, ThemeColor>> {
let mut colors_lock = THEME_COLOR_LIST.lock().unwrap();
colors_lock
.get_or_insert_with(|| {
let mut themes = HashMap::new();
[ThemeColor::dark(), ThemeColor::light()]
.into_iter()
.for_each(|theme| {
themes.insert(theme.name.clone(), theme.clone());
});
themes
Arc::new(themes)
})
}
.clone()
}
47 changes: 27 additions & 20 deletions core/src/egui/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ use kaspa_metrics_core::MetricGroup;
mod color;
pub use color::*;
mod style;
pub use style::*;

use crate::imports::*;
pub use style::*;

#[derive(Clone)]
pub struct AppTheme {
pub color: ThemeColor,
pub style: ThemeStyle,
pub color: Arc<ThemeColor>,
pub style: Arc<ThemeStyle>,
}

impl AppTheme {
pub fn new(color: ThemeColor, style: ThemeStyle) -> Self {
pub fn new(color: Arc<ThemeColor>, style: Arc<ThemeStyle>) -> Self {
Self { color, style }
}

Expand All @@ -32,8 +31,8 @@ impl AppTheme {
impl Default for AppTheme {
fn default() -> Self {
Self {
color: ThemeColor::dark(),
style: ThemeStyle::rounded(),
color: Arc::new(ThemeColor::dark()),
style: Arc::new(ThemeStyle::rounded()),
}
}
}
Expand Down Expand Up @@ -68,20 +67,24 @@ impl AsRef<AppTheme> for AppTheme {
}
}

static mut THEME: Option<AppTheme> = None;
static THEME: Mutex<Option<Arc<AppTheme>>> = Mutex::new(None);

#[inline(always)]
pub fn theme() -> &'static AppTheme {
unsafe { THEME.get_or_insert_with(AppTheme::default) }
pub fn theme() -> Arc<AppTheme> {
let mut theme_lock = THEME.lock().unwrap();
theme_lock
.get_or_insert_with(|| Arc::new(AppTheme::default()))
.clone()
}

#[inline(always)]
pub fn theme_color() -> &'static ThemeColor {
&theme().color
pub fn theme_color() -> Arc<ThemeColor> {
Arc::clone(&theme().color)
}

#[inline(always)]
pub fn theme_style() -> &'static ThemeStyle {
&theme().style
pub fn theme_style() -> Arc<ThemeStyle> {
Arc::clone(&theme().style)
}

pub fn apply_theme_by_name(
Expand All @@ -107,7 +110,7 @@ pub fn apply_theme_by_name(
ThemeStyle::default()
});

apply_theme(ctx, AppTheme::new(theme_color, theme_style));
apply_theme(ctx, AppTheme::new(theme_color.into(), theme_style.into()));
}

pub fn apply_theme_color_by_name(ctx: &Context, theme_color_name: impl Into<String>) {
Expand All @@ -120,7 +123,10 @@ pub fn apply_theme_color_by_name(ctx: &Context, theme_color_name: impl Into<Stri
ThemeColor::default()
});

apply_theme(ctx, AppTheme::new(theme_color, theme_style().clone()));
apply_theme(
ctx,
AppTheme::new(theme_color.into(), theme_style().clone()),
);
}

pub fn apply_theme_style_by_name(ctx: &Context, theme_style_name: impl Into<String>) {
Expand All @@ -133,13 +139,14 @@ pub fn apply_theme_style_by_name(ctx: &Context, theme_style_name: impl Into<Stri
ThemeStyle::default()
});

apply_theme(ctx, AppTheme::new(theme_color().clone(), theme_style));
apply_theme(
ctx,
AppTheme::new(theme_color().clone(), theme_style.into()),
);
}

pub fn apply_theme(ctx: &Context, theme: AppTheme) {
unsafe {
THEME = Some(theme.clone());
}
let _ = THEME.lock().unwrap().insert(Arc::new(theme.clone()));
ctx.set_visuals(theme.as_ref().into());
runtime()
.application_events()
Expand Down
15 changes: 9 additions & 6 deletions core/src/egui/theme/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,20 @@ impl ThemeStyle {
}
}

static mut THEME_STYLE_LIST: Option<HashMap<String, ThemeStyle>> = None;
pub fn theme_styles() -> &'static HashMap<String, ThemeStyle> {
unsafe {
THEME_STYLE_LIST.get_or_insert_with(|| {
static THEME_STYLE_LIST: Mutex<Option<Arc<HashMap<String, ThemeStyle>>>> = Mutex::new(None);

#[inline(always)]
pub fn theme_styles() -> Arc<HashMap<String, ThemeStyle>> {
let mut theme_styles_lock = THEME_STYLE_LIST.lock().unwrap();
theme_styles_lock
.get_or_insert_with(|| {
let mut themes = HashMap::new();
[ThemeStyle::rounded(), ThemeStyle::sharp()]
.into_iter()
.for_each(|theme| {
themes.insert(theme.name.clone(), theme.clone());
});
themes
Arc::new(themes)
})
}
.clone()
}
6 changes: 4 additions & 2 deletions core/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@ impl<'core> Menu<'core> {
ui.label(i18n("Theme Color"));
ui.vertical(|ui| {
ui.horizontal(|ui| {
let current_theme_color_name = theme_color().name();
let theme_color = theme_color();
let current_theme_color_name = theme_color.name();
ui.menu_button(format!("{} ⏷", current_theme_color_name), |ui| {
theme_colors().keys().for_each(|name| {
if name.as_str() != current_theme_color_name
Expand All @@ -552,7 +553,8 @@ impl<'core> Menu<'core> {

ui.label(i18n("Theme Style"));
ui.horizontal(|ui| {
let current_theme_style_name = theme_style().name();
let theme_style = theme_style();
let current_theme_style_name = theme_style.name();
ui.menu_button(format!("{} ⏷", current_theme_style_name), |ui| {
theme_styles().keys().for_each(|name| {
if name.as_str() != current_theme_style_name
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl ModuleT for Changelog {
.auto_shrink([false; 2])
.max_height(max_height)
.show(ui, |ui| {
easy_mark(ui, self.changelog.as_str());
easy_mark(ui, self.changelog);
});

ui.vertical_centered(|ui|{
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl Overview {
});

if let Some(release) = core.release.as_ref() {
let is_greater = is_version_greater(crate::app::VERSION.as_str(), release.version.as_str()).ok().unwrap_or(false);
let is_greater = is_version_greater(crate::app::VERSION, release.version.as_str()).ok().unwrap_or(false);
if is_wasm() || !is_greater {
CollapsingHeader::new(i18n("Redistributables"))
.id_source("redistributables")
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Request {
Entry::Vacant(entry) => {
let uri = format!("bytes://{hash}.svg");
// let bits = qrcode::types::Mode::Alphanumeric.data_bits_count(request_uri.len());
let qr = render_qrcode_with_version(request_uri.as_str(), 192, 192, qrcode::Version::Normal(10));
let qr = render_qrcode_with_version(request_uri, 192, 192, qrcode::Version::Normal(10));
entry.insert((uri, qr.as_bytes().to_vec().into()))
},
};
Expand Down
Loading
Loading