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

App rework, pt 1 - updates to new user workflow #95

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
756 changes: 387 additions & 369 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ json-gettext = "3.2.8"
strfmt = "0.1.6"
once_cell = "1.6.0"
lazy_static = "1"
serde = { version = "1.0", features=['derive'] }
serde_json = "1.0.59"
serde = { version = "1", features=['derive'] }
serde_json = "1"
reqwest = { version = "0.11", features = ["json", "blocking"] }
uuid = "0.8.2"

Expand Down
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ regex = "1.4.3"
fancy-regex = "0.5.0" # Regex with backtracking
async-std = { version = "1.9.0", features = ["unstable"] }
dirs-next = "2.0.0"
serde = { version = "1.0.123", features = ['derive'] }
serde = { version = "1", features = ['derive'] }
serde_yaml = "0.8.17"
serde_json = "1.0.62"
serde_urlencoded = "0.7"
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct Config {
#[serde(default = "default_true")]
pub alternating_row_colors: bool,

//TODO: These default values aren't working
#[serde(default = "default_true")]
pub is_keybindings_enabled: bool,

Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub enum GrinWalletInterfaceError {
InvalidTxLogState,
#[error("Invalid Invoice Proof")]
InvalidInvoiceProof,
#[error("Invalid Recovery Phrase")]
InvalidRecoveryPhrase,
#[error("Can't read wallet config file at {file}")]
ConfigReadError { file: String },
}
Expand Down
6 changes: 4 additions & 2 deletions crates/core/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub use save::PersistentData;
#[cfg(feature = "default")]
pub use theme::{import_theme, load_user_themes};

pub const GRINGUI_CONFIG_DIR: &str = ".grin-gui";

pub static CONFIG_DIR: Lazy<Mutex<PathBuf>> = Lazy::new(|| {
// Returns the location of the config directory. Will create if it doesn't
// exist.
Expand All @@ -24,7 +26,7 @@ pub static CONFIG_DIR: Lazy<Mutex<PathBuf>> = Lazy::new(|| {
#[cfg(not(windows))]
{
let home = env::var("HOME").expect("user home directory not found.");
let config_dir = PathBuf::from(&home).join(".grin/gui");
let config_dir = PathBuf::from(&home).join(&format!("{}/gui", GRINGUI_CONFIG_DIR));

Mutex::new(config_dir)
}
Expand All @@ -36,7 +38,7 @@ pub static CONFIG_DIR: Lazy<Mutex<PathBuf>> = Lazy::new(|| {
#[cfg(windows)]
{
let config_dir = dirs_next::home_dir()
.map(|path| path.join(".grin"))
.map(|path| path.join(GRINGUI_CONFIG_DIR))
.map(|path| path.join("gui"))
.expect("user home directory not found.");

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/fs/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub trait PersistentData: DeserializeOwned + Serialize {
/// Load from `PersistentData::path()`.
fn load() -> Result<Self> {
let path = Self::path()?;
println!("{:?}", path);

if path.exists() {
let file = fs::File::open(&path)?;
Expand All @@ -39,7 +40,6 @@ pub trait PersistentData: DeserializeOwned + Serialize {
/// and return that object.
fn load_or_default<T: PersistentData + Default>() -> Result<T> {
let load_result = <T as PersistentData>::load();

match load_result {
Ok(deser) => Ok(deser),
_ => Ok(get_default_and_save()?),
Expand Down
8 changes: 2 additions & 6 deletions crates/core/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::time::Duration;

use chrono::prelude::Utc;

use crate::logger;
use crate::{fs::GRINGUI_CONFIG_DIR, logger};

pub use global::ChainTypes;

Expand All @@ -30,10 +30,6 @@ pub use grin_core::core::{amount_from_hr_string, amount_to_hr_string};
pub use grin_keychain::Identifier;
pub use grin_servers::ServerStats;

/// TODO - this differs from the default directory in 5.x,
/// need to reconcile this with existing installs somehow
const GRIN_HOME: &str = ".grin";

pub const GRIN_TOP_LEVEL_DIR: &str = "grin_node";

pub const GRIN_DEFAULT_DIR: &str = "default";
Expand All @@ -51,7 +47,7 @@ fn get_grin_node_default_path(chain_type: &global::ChainTypes) -> PathBuf {
Some(p) => p,
None => PathBuf::new(),
};
grin_path.push(GRIN_HOME);
grin_path.push(GRINGUI_CONFIG_DIR);
grin_path.push(chain_type.shortname());
grin_path.push(GRIN_TOP_LEVEL_DIR);
grin_path.push(GRIN_DEFAULT_DIR);
Expand Down
4 changes: 4 additions & 0 deletions crates/core/src/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod scrollable;
pub mod table_header;
pub mod table_row;
pub mod text;
pub mod text_editor;
pub mod text_input;

pub use button::ButtonStyle;
Expand All @@ -35,6 +36,7 @@ pub use radio::RadioStyle;
pub use scrollable::ScrollableStyle;
pub use table_header::TableHeaderStyle;
pub use table_row::TableRowStyle;
pub use text_editor::TextEditorStyle;
pub use text_input::TextInputStyle;

pub async fn load_user_themes() -> Vec<Theme> {
Expand All @@ -56,6 +58,8 @@ pub type Column<'a, Message> = iced::widget::Column<'a, Message, Theme, Renderer
pub type Row<'a, Message> = iced::widget::Row<'a, Message, Theme, Renderer>;
pub type Text<'a> = iced::widget::Text<'a, Theme, Renderer>;
pub type TextInput<'a, Message> = iced::widget::TextInput<'a, Message, Theme, Renderer>;
pub type TextEditor<'a, Message, Theme, Renderer> =
iced::widget::TextEditor<'a, Message, Theme, Renderer>;
pub type Button<'a, Message> = iced::widget::Button<'a, Message, Theme, Renderer>;
pub type Scrollable<'a, Message> = iced::widget::Scrollable<'a, Message, Theme, Renderer>;
pub type PickList<'a, T, L, V, Message> =
Expand Down
88 changes: 88 additions & 0 deletions crates/core/src/theme/text_editor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use super::Theme;
use iced::widget::text_editor;
use iced::{Background, Color};
use iced_core::Border;

#[derive(Debug, Clone, Copy, Default)]
pub enum TextEditorStyle {
#[default]
Default,
}

impl text_editor::StyleSheet for Theme {
type Style = TextEditorStyle;

/// Produces the style of an active text input.
fn active(&self, style: &Self::Style) -> text_editor::Appearance {
match style {
TextEditorStyle::Default => text_editor::Appearance {
background: Background::Color(self.palette.base.foreground),
border: Border {
color: self.palette.normal.primary,
width: 1.0,
radius: 2.0.into(),
},
},
}
}

/// Produces the style of a focused text input.
fn focused(&self, style: &Self::Style) -> text_editor::Appearance {
match style {
TextEditorStyle::Default => text_editor::Appearance {
background: Background::Color(self.palette.base.foreground),
border: Border {
color: self.palette.bright.primary,
width: 1.0,
radius: 2.0.into(),
},
},
}
}

fn disabled(&self, style: &Self::Style) -> text_editor::Appearance {
match style {
TextEditorStyle::Default => text_editor::Appearance {
background: Background::Color(self.palette.base.foreground),
border: Border {
color: self.palette.normal.primary,
width: 1.0,
radius: 2.0.into(),
},
},
}
}

fn placeholder_color(&self, style: &Self::Style) -> Color {
match style {
TextEditorStyle::Default => self.palette.normal.surface,
_ => todo!("default"),
}
}

fn value_color(&self, style: &Self::Style) -> Color {
match style {
TextEditorStyle::Default => self.palette.bright.primary,
_ => todo!("default"),
}
}

fn selection_color(&self, style: &Self::Style) -> Color {
match style {
TextEditorStyle::Default => self.palette.bright.secondary,
_ => todo!("default"),
}
}

fn disabled_color(&self, style: &Self::Style) -> Color {
match style {
TextEditorStyle::Default => self.palette.normal.secondary,
_ => todo!("default"),
}
}

/// Produces the style of an hovered text editor.
fn hovered(&self, style: &Self::Style) -> text_editor::Appearance {
self.focused(style)
}
}
16 changes: 13 additions & 3 deletions crates/core/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use grin_core::global;
use grin_core::{self};
use grin_keychain as keychain;
use grin_util::{file, Mutex, ZeroingString};
use keychain::mnemonic;

use super::node::amount_to_hr_string;
use std::path::PathBuf;
Expand All @@ -37,14 +38,15 @@ pub use grin_wallet_libwallet::contract::proofs::InvoiceProof;
use crate::error::GrinWalletInterfaceError;
use crate::logger;

use crate::fs::GRINGUI_CONFIG_DIR;

use std::convert::TryFrom;

/// Wallet configuration file name
pub const WALLET_CONFIG_FILE_NAME: &str = "grin-wallet.toml";

const WALLET_LOG_FILE_NAME: &str = "grin-wallet.log";

const GRIN_HOME: &str = ".grin";
/// Wallet data directory
pub const GRIN_WALLET_DIR: &str = "wallet_data";
/// Wallet top level directory
Expand All @@ -65,7 +67,7 @@ pub fn get_grin_wallet_default_path(chain_type: &global::ChainTypes) -> PathBuf
Some(p) => p,
None => PathBuf::new(),
};
grin_path.push(GRIN_HOME);
grin_path.push(GRINGUI_CONFIG_DIR);
grin_path.push(chain_type.shortname());
grin_path.push(GRIN_WALLET_TOP_LEVEL_DIR);
grin_path.push(GRIN_WALLET_DEFAULT_DIR);
Expand All @@ -79,7 +81,7 @@ pub fn create_grin_wallet_path(chain_type: &global::ChainTypes, sub_dir: &str) -
Some(p) => p,
None => PathBuf::new(),
};
grin_path.push(GRIN_HOME);
grin_path.push(GRINGUI_CONFIG_DIR);
grin_path.push(chain_type.shortname());
grin_path.push(GRIN_WALLET_TOP_LEVEL_DIR);
grin_path.push(sub_dir);
Expand Down Expand Up @@ -144,6 +146,14 @@ pub fn get_wallet_config(path: &str) -> Result<GlobalWalletConfig, GrinWalletInt
}
}

pub fn validate_mnemonic(mnemonic: String) -> Result<(), GrinWalletInterfaceError> {
let result = mnemonic::to_entropy(&mnemonic);
match result {
Ok(_) => Ok(()),
Err(_) => Err(GrinWalletInterfaceError::InvalidRecoveryPhrase),
}
}

impl<L, C> WalletInterface<L, C>
where
L: WalletLCProvider<'static, C, grin_keychain::keychain::ExtKeychain>,
Expand Down
3 changes: 2 additions & 1 deletion locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"remote-release-channel": "Veröffentlichungskanal",
"reset-columns": "Spalten zurücksetzen",
"restore-from-seed": "Restore this wallet from an existing seed phrase",
"enter-seed-phrase": "Enter Seed Phrase",
"retry": "Erneut versuchen",
"scale": "Skalierung",
"search-for-addon": "Suche nach einem Addon",
Expand Down Expand Up @@ -224,7 +225,7 @@
"info-awaiting-confirmation": "Awaiting Confirmation",
"info-awaiting-finalization": "Awaiting Finalization",
"info-locked": "Locked",
"wallet-default-name": "Default",
"wallet-default-name": "My Grin Wallet",
"wallet-create-tx": "Start",
"wallet-apply-tx": "Continue",
"wallet-create-contract": "Create Contract",
Expand Down
3 changes: 2 additions & 1 deletion locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"remote-release-channel": "Release channel",
"reset-columns": "Reset Columns",
"restore-from-seed": "Restore this wallet from an existing seed phrase (TBD)",
"enter-seed-phrase": "Enter Seed Phrase",
"retry": "Retry",
"scale": "Scale",
"search-for-addon": "Search for an addon...",
Expand Down Expand Up @@ -208,7 +209,7 @@
"status-line-title-main": "Status Mainnet",
"status-line-title-test": "Status Testnet",
"wallet-list": "Wallets",
"wallet-default-name": "Default",
"wallet-default-name": "My Grin Wallet",
"yes": "Yes",
"no": "No",
"cancel": "Cancel",
Expand Down
14 changes: 13 additions & 1 deletion src/gui/element/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,18 @@ pub fn data_container<'a>(

if let Some(e) = error {
// Displays an error + detail button, if any has occured.
let error_text = Text::new(e.to_string()).size(DEFAULT_FONT_SIZE);

let mut error_string = e.to_string();
let mut causes = e.chain();

let count = causes.clone().count();
let top_level_cause = causes.next();

if count > 1 {
error_string = format!("{} - {}", error_string, causes.next().unwrap());
}

let error_text = Text::new(error_string).size(DEFAULT_FONT_SIZE);

let error_detail_button: Button<Interaction> = Button::new(
Text::new(localized_string("more-error-detail"))
Expand All @@ -168,6 +179,7 @@ pub fn data_container<'a>(
error_column = Column::with_children(vec![
Space::with_height(Length::Fixed(5.0)).into(),
error_text.into(),
Space::with_height(Length::Fixed(5.0)).into(),
error_detail_button.map(Message::Interaction),
])
.align_items(Alignment::Center);
Expand Down
Loading
Loading