-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from elsirion/2024-05-menu-overhaul
Clean up menu, select LN or e-cash in a second step
- Loading branch information
Showing
13 changed files
with
208 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use leptos::*; | ||
|
||
use crate::components::SegmentedButton; | ||
|
||
#[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
pub enum Protocol { | ||
OnChain, | ||
Lightning, | ||
ECash, | ||
} | ||
|
||
impl Protocol { | ||
fn from_idx(idx: usize) -> Protocol { | ||
match idx { | ||
0 => Protocol::OnChain, | ||
1 => Protocol::Lightning, | ||
2 => Protocol::ECash, | ||
_ => panic!("Out of bounds"), | ||
} | ||
} | ||
|
||
fn into_idx(self) -> usize { | ||
match self { | ||
Protocol::OnChain => 0, | ||
Protocol::Lightning => 1, | ||
Protocol::ECash => 2, | ||
} | ||
} | ||
} | ||
#[component] | ||
pub fn ProtocolSelector<F>( | ||
#[prop(default = Protocol::Lightning)] active_protocol: Protocol, | ||
on_change: F, | ||
) -> impl IntoView | ||
where | ||
F: Fn(Protocol) + 'static + Copy, | ||
{ | ||
view! { | ||
<SegmentedButton | ||
active_idx=active_protocol.into_idx() | ||
segments=vec!["On-Chain".into(), "Lightning".into(), "E-Cash".into()] | ||
on_change=move |idx| on_change(Protocol::from_idx(idx)) | ||
/> | ||
} | ||
} |
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,32 @@ | ||
use leptos::*; | ||
|
||
use crate::components::{Protocol, ProtocolSelector, ReceiveEcash, ReceiveLn}; | ||
|
||
#[component] | ||
pub fn Receive() -> impl IntoView { | ||
const DEFAULT_PROTOCOL: Protocol = Protocol::Lightning; | ||
let (active_protocol, set_active_protocol) = create_signal(DEFAULT_PROTOCOL); | ||
|
||
let active_protocol_view = move || match active_protocol.get() { | ||
Protocol::OnChain => view! { | ||
"TODO" | ||
} | ||
.into_view(), | ||
Protocol::Lightning => view! { | ||
<ReceiveLn /> | ||
} | ||
.into_view(), | ||
Protocol::ECash => view! { | ||
<ReceiveEcash /> | ||
} | ||
.into_view(), | ||
}; | ||
|
||
view! { | ||
<ProtocolSelector | ||
active_protocol=DEFAULT_PROTOCOL | ||
on_change=move |protocol| set_active_protocol.set(protocol) | ||
/> | ||
{active_protocol_view} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use itertools::Itertools; | ||
use leptos::*; | ||
|
||
#[component] | ||
pub fn SegmentedButton<F>( | ||
#[prop(default = 0)] active_idx: usize, | ||
segments: Vec<String>, | ||
on_change: F, | ||
) -> impl IntoView | ||
where | ||
F: Fn(usize) + 'static + Copy, | ||
{ | ||
const ALL_CLASS: &str = "px-4 py-2 focus:outline-none flex-1 text-center"; | ||
const FIRST_CLASS: &str = "rounded-l-full"; | ||
const LAST_CLASS: &str = "rounded-r-full"; | ||
const ACTIVE_CLASS: &str = "text-white bg-blue-500"; | ||
const INACTIVE_CLASS: &str = "text-blue-500 bg-transparent"; | ||
|
||
let (active_idx, set_active_idx) = create_signal(active_idx); | ||
let num_segments = segments.len(); | ||
|
||
let buttons = segments | ||
.into_iter() | ||
.enumerate() | ||
.map(|(idx, name)| { | ||
let class = move || { | ||
let is_first = idx == 0; | ||
let is_last = idx == num_segments - 1; | ||
let is_active = idx == active_idx.get(); | ||
|
||
std::iter::once(ALL_CLASS) | ||
.chain(is_first.then(|| FIRST_CLASS)) | ||
.chain(is_last.then(|| LAST_CLASS)) | ||
.chain(is_active.then(|| ACTIVE_CLASS)) | ||
.chain((!is_active).then(|| INACTIVE_CLASS)) | ||
.join(" ") | ||
}; | ||
view! { | ||
<button | ||
class=class | ||
on:click=move |_| { | ||
set_active_idx.set(idx); | ||
on_change(idx); | ||
} | ||
> | ||
{name} | ||
</button> | ||
} | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
view! { | ||
<div class="bg-white p-1 rounded-full shadow flex w-full mb-8"> | ||
{buttons} | ||
</div> | ||
} | ||
} |
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,32 @@ | ||
use leptos::*; | ||
|
||
use crate::components::{Protocol, ProtocolSelector, SendEcash, SendLn}; | ||
|
||
#[component] | ||
pub fn Send() -> impl IntoView { | ||
const DEFAULT_PROTOCOL: Protocol = Protocol::Lightning; | ||
let (active_protocol, set_active_protocol) = create_signal(DEFAULT_PROTOCOL); | ||
|
||
let active_protocol_view = move || match active_protocol.get() { | ||
Protocol::OnChain => view! { | ||
"TODO" | ||
} | ||
.into_view(), | ||
Protocol::Lightning => view! { | ||
<SendLn /> | ||
} | ||
.into_view(), | ||
Protocol::ECash => view! { | ||
<SendEcash /> | ||
} | ||
.into_view(), | ||
}; | ||
|
||
view! { | ||
<ProtocolSelector | ||
active_protocol=DEFAULT_PROTOCOL | ||
on_change=move |protocol| set_active_protocol.set(protocol) | ||
/> | ||
{active_protocol_view} | ||
} | ||
} |
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