-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create action transfer as community (#112)
- Loading branch information
Showing
9 changed files
with
286 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
pub mod members; | ||
pub mod treasury; | ||
pub mod voting; | ||
pub mod transfer; | ||
pub use transfer::TransferAction; | ||
pub use members::MembersAction; | ||
pub use treasury::TreasuryAction; | ||
pub use voting::VotingAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use crate::{ | ||
components::atoms::{ | ||
dropdown::ElementSize, icon_button::Variant, AddPlus, Icon, IconButton, | ||
Input, MinusCircle, | ||
}, | ||
hooks::use_initiative::{use_initiative, ActionItem, CommunityTransferAction, TransferItem}, | ||
}; | ||
use dioxus::prelude::*; | ||
use dioxus_std::{i18n::use_i18, translate}; | ||
#[derive(PartialEq, Props, Clone)] | ||
pub struct VotingProps { | ||
index: usize, | ||
meta: CommunityTransferAction, | ||
} | ||
const KUSAMA_PRECISION_DECIMALS: u64 = 1_000_000_000_000; | ||
pub fn TransferAction(props: VotingProps) -> Element { | ||
let i18 = use_i18(); | ||
let mut initiative = use_initiative(); | ||
rsx!( | ||
ul { class: "form__inputs form__inputs--combo", | ||
{ | ||
props.meta.transfers.iter().enumerate().map(|(index_meta, transfer)| { | ||
rsx!( | ||
li { | ||
div { | ||
style: " | ||
width: 100%; | ||
display: flex; | ||
gap: 4px; | ||
", | ||
Input { | ||
message: transfer.account.clone(), | ||
size: ElementSize::Small, | ||
placeholder: translate!(i18, "initiative.steps.actions.community_transfer.dest.placeholder"), | ||
error: None, | ||
on_input: move |event: Event<FormData>| { | ||
if let ActionItem::CommunityTransfer(ref mut meta) = initiative.get_action(props.index) { | ||
meta.transfers[index_meta].account = event.value() ; | ||
initiative.update_action(props.index, ActionItem::CommunityTransfer(meta.clone())); | ||
} | ||
}, | ||
on_keypress: move |_| {}, | ||
on_click: move |_| {}, | ||
} | ||
Input { | ||
message: (transfer.value / KUSAMA_PRECISION_DECIMALS).to_string(), | ||
size: ElementSize::Small, | ||
placeholder: translate!(i18, "initiative.steps.actions.community_transfer.amount.placeholder"), | ||
error: None, | ||
right_text: { | ||
rsx!( | ||
span { class: "input--right__text", | ||
"KSM" | ||
} | ||
) | ||
}, | ||
on_input: move |event: Event<FormData>| { | ||
if let ActionItem::CommunityTransfer(ref mut meta) = initiative.get_action(props.index) { | ||
// Scale amount | ||
let amount = event.value().parse::<f64>().unwrap_or(0.0); | ||
let scaled_amount = amount * KUSAMA_PRECISION_DECIMALS as f64; | ||
meta.transfers[index_meta].value = scaled_amount as u64 ; | ||
initiative.update_action(props.index, ActionItem::CommunityTransfer(meta.clone())); | ||
} | ||
}, | ||
on_keypress: move |_| {}, | ||
on_click: move |_| {}, | ||
} | ||
} | ||
IconButton { | ||
variant: Variant::Round, | ||
size: ElementSize::Small, | ||
class: "button--avatar", | ||
body: rsx!( | ||
Icon { | ||
icon: MinusCircle, | ||
height: 24, | ||
width: 24, | ||
fill: "var(--state-primary-active)" | ||
} | ||
), | ||
on_click: move |_| { | ||
if let ActionItem::CommunityTransfer(ref mut meta) = initiative.get_action(props.index) { | ||
meta.transfers.remove(index_meta); | ||
initiative.update_action(props.index, ActionItem::CommunityTransfer(meta.clone())); | ||
} | ||
} | ||
} | ||
} | ||
) | ||
}) | ||
}, | ||
IconButton { | ||
variant: Variant::Round, | ||
size: ElementSize::Small, | ||
class: "button--avatar", | ||
body: rsx!( | ||
Icon { icon : AddPlus, height : 24, width : 24, fill : | ||
"var(--state-primary-active)" } | ||
), | ||
on_click: move |_| { | ||
if let ActionItem::CommunityTransfer(ref mut meta) = initiative | ||
.get_action(props.index) | ||
{ | ||
meta.add_transfer(TransferItem::default()); | ||
initiative | ||
.update_action(props.index, ActionItem::CommunityTransfer(meta.clone())); | ||
} | ||
} | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.