Skip to content

Commit

Permalink
Merge pull request #29 from flomang/master
Browse files Browse the repository at this point in the history
Balance History Chart
  • Loading branch information
yeastplume authored Dec 12, 2022
2 parents 4830273 + 85d909d commit 181c567
Show file tree
Hide file tree
Showing 16 changed files with 1,032 additions and 205 deletions.
496 changes: 393 additions & 103 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ debug = ["iced/debug"]
grin-gui-core = { version = "0.1.0", path = "crates/core", features=['gui'] }
grin-gui-widgets = { version = "0.1.0", path = "crates/widgets" }

iced = { version = "0.5.2", default-features = false }
iced = { version = "0.5.2", features = ["canvas", "tokio"] }
iced_futures = { version = "0.5.1", features = ["async-std"] }
iced_style = {version = "0.5.0"}
iced_native = { version = "0.6.1" }
#iced_aw = { version = "0.2.0", default-features = false, features = ["card", "modal"]}
iced_aw = { git = "https://github.com/iced-rs/iced_aw"}
plotters-iced = "0.4"
plotters="0.3"
plotters-backend = "0.3"
rand = "0.8.3"

async-std = "1.6.2"
isahc = { version = "0.9.6", features = ["json"] }
Expand All @@ -42,6 +46,9 @@ strfmt = "0.1.6"
once_cell = "1.6.0"
lazy_static = "1"
serde = { version = "1.0", features=['derive'] }
serde_json = "1.0.59"
reqwest = { version = "0.11", features = ["json", "blocking"] }


[target.'cfg(target_os = "linux")'.dependencies]
native-dialog = "0.5.5"
Expand Down
60 changes: 60 additions & 0 deletions crates/core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ pub struct Config {
/// Current wallet
pub current_wallet_index: Option<usize>,

/// Current theme of GUI
pub theme: Option<String>,

/// User preferred currency
pub currency: Currency,

#[serde(default)]
pub tx_column_config: ColumnConfig,

Expand Down Expand Up @@ -182,6 +186,62 @@ impl Default for Language {
}
}


#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Hash, PartialOrd, Ord)]
pub enum Currency {
#[default]
GRIN,
BTC,
USD,
}

impl std::fmt::Display for Currency {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Currency::BTC => "Bitcoin",
Currency::USD => "US Dollar",
Currency::GRIN => "Grin",
}
)
}
}

impl Currency {
// Alphabetically sorted based on their local name (@see `impl Display`).
pub const ALL: [Currency; 3] = [
Currency::BTC,
Currency::GRIN,
Currency::USD,
];

pub fn shortname(&self) -> String {
match *self {
Currency::BTC => "btc".to_owned(),
Currency::GRIN => "grin".to_owned(),
Currency::USD => "usd".to_owned(),
}
}

pub fn symbol(&self) -> String {
match *self {
Currency::BTC => "₿".to_owned(),
Currency::GRIN => "".to_owned(),
Currency::USD => "$".to_owned(),
}
}

pub fn precision(&self) -> usize {
match *self {
Currency::BTC => 8,
Currency::GRIN => 9,
Currency::USD => 4,
}
}
}

/// Returns a Config.
///
/// This functions handles the initialization of a Config.
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ extern crate log;

// Re-exports
pub use grin_util::logger::{LoggingConfig, LogEntry};
pub use grin_core::consensus::GRIN_BASE;
6 changes: 4 additions & 2 deletions crates/core/src/theme/table_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ impl StyleSheet for Theme {
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
offset_left: 10.0,
offset_right: 25.0,
// offset_left: 10.0,
// offset_right: 25.0,
offset_left: 0.0,
offset_right: 0.0,
},
TableRowStyle::TableRowAlternate => Appearance {
background: Some(Background::Color(Color {
Expand Down
8 changes: 5 additions & 3 deletions crates/core/src/theme/text.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use iced::widget::text;
use super::Theme;

use iced::widget::text;

impl text::StyleSheet for Theme {
type Style = iced_style::theme::Text;

// TODO extend the color palette to support text colors
fn appearance(&self, style: Self::Style) -> text::Appearance {
//text::Appearance {
// color: Some(self.palette.text.primary),
//}
Default::default()
}
}

Binary file added fonts/notosans-bold.ttf
Binary file not shown.
Binary file added fonts/notosans-regular.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"copy-to-clipboard": "Copy to Clipboard",
"completed": "Abgeschlossen",
"create-wallet": "New Wallet",
"currency": "Currency",
"delete": "Löschen",
"delete-saved-variables": "Lösche gespeicherte Einstellungen wenn Addons gelöscht werden",
"description": "Beschreibung",
Expand Down
1 change: 1 addition & 0 deletions locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"columns": "Columns",
"copy-to-clipboard": "Copy to Clipboard",
"completed": "Completed",
"currency": "Currency",
"create-wallet": "New Wallet",
"delete": "Delete",
"delete-saved-variables": "Delete SavedVariables when deleting addons",
Expand Down
46 changes: 46 additions & 0 deletions src/gui/element/settings/general.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use futures::future;
use grin_gui_core::config::Currency;

use {
super::{DEFAULT_FONT_SIZE, DEFAULT_PADDING},
crate::gui::{GrinGui, Interaction, Message},
Expand Down Expand Up @@ -84,6 +87,7 @@ impl Default for ScaleState {
#[derive(Debug, Clone)]
pub enum LocalViewInteraction {
ThemeSelected(String),
CurrencySelected(Currency),
LanguageSelected(Language),
ScaleUp,
ScaleDown,
Expand All @@ -106,6 +110,22 @@ pub fn handle_message(
) -> Result<Command<Message>> {
let state = &mut grin_gui.general_settings_state;
match message {
LocalViewInteraction::CurrencySelected(currency) => {
log::debug!(
"settings::general::LocalViewInteraction::CurrencySelected({:?})",
&currency
);

grin_gui.config.currency = currency;
let _ = grin_gui.config.save();

return Ok(Command::perform(future::ready(()), |r| {
// update the prices
Message::Interaction(Interaction::WalletOperationHomeViewInteraction(
crate::gui::element::wallet::operation::home::LocalViewInteraction::UpdatePrices,
))
}));
}
LocalViewInteraction::ThemeSelected(theme_name) => {
log::debug!(
"settings::general::LocalViewInteraction::ThemeSelected({:?})",
Expand Down Expand Up @@ -258,6 +278,30 @@ pub fn data_container<'a>(state: &'a StateContainer, config: &Config) -> Contain
.push(container)
};

let currency_container = {
let title = Container::new(Text::new(localized_string("currency")).size(DEFAULT_FONT_SIZE))
.style(grin_gui_core::theme::ContainerStyle::NormalBackground);

let pick_list = PickList::new(&Currency::ALL[..], Some(config.currency), |c| {
Message::Interaction(Interaction::GeneralSettingsViewInteraction(
LocalViewInteraction::CurrencySelected(c),
))
})
.text_size(14)
.width(Length::Units(120))
.style(grin_gui_core::theme::PickListStyle::Primary);

let container = Container::new(pick_list)
.center_y()
.width(Length::Units(120))
.style(grin_gui_core::theme::ContainerStyle::NormalBackground);

Column::new()
.push(title)
.push(Space::new(Length::Units(0), Length::Units(5)))
.push(container)
};

let theme_column = {
let title_container =
Container::new(Text::new(localized_string("theme")).size(DEFAULT_FONT_SIZE))
Expand Down Expand Up @@ -470,6 +514,8 @@ pub fn data_container<'a>(state: &'a StateContainer, config: &Config) -> Contain
.spacing(1)
.push(language_container)
.push(Space::new(Length::Units(0), Length::Units(10)))
.push(currency_container)
.push(Space::new(Length::Units(0), Length::Units(10)))
.push(theme_scale_row)
.push(Space::new(Length::Units(0), Length::Units(10)))
.push(open_theme_row)
Expand Down
Loading

0 comments on commit 181c567

Please sign in to comment.