Add available balance to choose recipient step
This commit is contained in:
parent
683294da1e
commit
ecd35d2bd1
@ -109,7 +109,7 @@ impl CreateSpendPanel {
|
||||
draft: step::TransactionDraft::default(),
|
||||
current: 0,
|
||||
steps: vec![
|
||||
Box::new(step::ChooseRecipients::default()),
|
||||
Box::new(step::ChooseRecipients::new(coins)),
|
||||
Box::new(step::ChooseCoins::new(
|
||||
coins.to_vec(),
|
||||
timelock,
|
||||
|
||||
@ -42,22 +42,30 @@ pub trait Step {
|
||||
}
|
||||
|
||||
pub struct ChooseRecipients {
|
||||
balance_available: Amount,
|
||||
recipients: Vec<Recipient>,
|
||||
is_valid: bool,
|
||||
is_duplicate: bool,
|
||||
}
|
||||
|
||||
impl std::default::Default for ChooseRecipients {
|
||||
fn default() -> Self {
|
||||
impl ChooseRecipients {
|
||||
pub fn new(coins: &[Coin]) -> Self {
|
||||
Self {
|
||||
balance_available: coins
|
||||
.iter()
|
||||
.filter_map(|coin| {
|
||||
if coin.spend_info.is_none() {
|
||||
Some(coin.amount)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.sum(),
|
||||
recipients: vec![Recipient::default()],
|
||||
is_valid: false,
|
||||
is_duplicate: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ChooseRecipients {
|
||||
fn check_valid(&mut self) {
|
||||
self.is_valid = !self.recipients.is_empty();
|
||||
self.is_duplicate = false;
|
||||
@ -117,6 +125,7 @@ impl Step for ChooseRecipients {
|
||||
|
||||
fn view<'a>(&'a self, _cache: &'a Cache) -> Element<'a, view::Message> {
|
||||
view::spend::step::choose_recipients_view(
|
||||
&self.balance_available,
|
||||
self.recipients
|
||||
.iter()
|
||||
.enumerate()
|
||||
|
||||
@ -23,12 +23,13 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
pub fn choose_recipients_view(
|
||||
recipients: Vec<Element<Message>>,
|
||||
pub fn choose_recipients_view<'a>(
|
||||
balance_available: &'a Amount,
|
||||
recipients: Vec<Element<'a, Message>>,
|
||||
total_amount: Amount,
|
||||
is_valid: bool,
|
||||
duplicate: bool,
|
||||
) -> Element<Message> {
|
||||
) -> Element<'a, Message> {
|
||||
modal(
|
||||
false,
|
||||
None,
|
||||
@ -53,8 +54,14 @@ pub fn choose_recipients_view(
|
||||
.spacing(20)
|
||||
.align_items(Alignment::Center)
|
||||
.push(
|
||||
Container::new(text(format!("{}", total_amount)).bold())
|
||||
.width(Length::Fill),
|
||||
Container::new(
|
||||
Row::new()
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(5)
|
||||
.push(text(format!("{}", total_amount)).bold())
|
||||
.push(text(format!("/ {}", balance_available))),
|
||||
)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.push_maybe(if duplicate {
|
||||
Some(text("Two recipient addresses are the same").style(color::WARNING))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user