Add balance to panel home
This commit is contained in:
parent
157d9b3933
commit
7f9fd84bee
@ -2,15 +2,14 @@ mod settings;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use bitcoin::Amount;
|
||||
use iced::pure::{column, Element};
|
||||
use iced::{widget::qr_code, Command, Subscription};
|
||||
|
||||
use super::{cache::Cache, error::Error, menu::Menu, message::Message, view};
|
||||
|
||||
use crate::daemon::{model::Coin, Daemon};
|
||||
pub use settings::SettingsState;
|
||||
|
||||
use crate::daemon::Daemon;
|
||||
|
||||
pub trait State {
|
||||
fn view<'a>(&'a self, cache: &'a Cache) -> Element<'a, view::Message>;
|
||||
fn update(
|
||||
@ -27,12 +26,23 @@ pub trait State {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Home {}
|
||||
pub struct Home {
|
||||
balance: Amount,
|
||||
}
|
||||
|
||||
impl Home {
|
||||
pub fn new(coins: &Vec<Coin>) -> Self {
|
||||
Self {
|
||||
balance: Amount::from_sat(coins.iter().map(|coin| coin.amount.as_sat()).sum()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl State for Home {
|
||||
fn view<'a>(&self, _cache: &'a Cache) -> Element<'a, view::Message> {
|
||||
view::dashboard(&Menu::Home, None, column())
|
||||
fn view<'a>(&'a self, _cache: &'a Cache) -> Element<'a, view::Message> {
|
||||
view::dashboard(&Menu::Home, None, view::home::home_view(&self.balance))
|
||||
}
|
||||
|
||||
fn update(
|
||||
&mut self,
|
||||
_daemon: Arc<dyn Daemon + Sync + Send>,
|
||||
@ -41,6 +51,19 @@ impl State for Home {
|
||||
) -> Command<Message> {
|
||||
Command::none()
|
||||
}
|
||||
|
||||
fn load(&self, daemon: Arc<dyn Daemon + Sync + Send>) -> Command<Message> {
|
||||
let daemon = daemon.clone();
|
||||
Command::perform(
|
||||
async move {
|
||||
daemon
|
||||
.list_coins()
|
||||
.map(|res| res.coins)
|
||||
.map_err(|e| e.into())
|
||||
},
|
||||
Message::Coins,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Home> for Box<dyn State> {
|
||||
@ -140,7 +163,7 @@ mod tests {
|
||||
|
||||
let sandbox: Sandbox<ReceivePanel> = Sandbox::new(ReceivePanel::default());
|
||||
let client = Arc::new(Minisafed::new(daemon.run(), fake_daemon_config()));
|
||||
let sandbox = sandbox.load(client, &Cache { blockheight: 0 }).await;
|
||||
let sandbox = sandbox.load(client, &Cache::default()).await;
|
||||
|
||||
let panel = sandbox.state();
|
||||
assert_eq!(panel.address, Some(addr));
|
||||
|
||||
17
gui/src/app/view/home.rs
Normal file
17
gui/src/app/view/home.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use iced::{
|
||||
pure::{column, Element},
|
||||
Alignment,
|
||||
};
|
||||
|
||||
use crate::ui::component::text::*;
|
||||
|
||||
use super::message::Message;
|
||||
|
||||
pub fn home_view<'a>(balance: &'a bitcoin::Amount) -> Element<'a, Message> {
|
||||
column()
|
||||
.push(column().padding(40))
|
||||
.push(text(&format!("{} BTC", balance.as_btc())).bold().size(50))
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(20)
|
||||
.into()
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
mod message;
|
||||
mod warning;
|
||||
|
||||
pub mod home;
|
||||
pub mod receive;
|
||||
pub mod settings;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user