-
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.
- Loading branch information
Rodrigo Sanchez
committed
May 15, 2023
1 parent
733ef95
commit 60f4d78
Showing
22 changed files
with
229 additions
and
54 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
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,3 +1,4 @@ | ||
pub mod radio_button; | ||
pub mod select; | ||
pub mod text_input; | ||
pub mod textarea; |
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,40 @@ | ||
use anyhow::{anyhow, Context, Result}; | ||
use wasm_bindgen::JsCast; | ||
use web_sys::{Event, HtmlInputElement}; | ||
use yew::prelude::*; | ||
|
||
#[derive(Clone, PartialEq, Properties, Eq)] | ||
pub struct Props { | ||
pub id: Option<String>, | ||
pub value: String, | ||
pub label: String, | ||
pub name: String, | ||
pub checked: bool, | ||
} | ||
|
||
pub fn get_value_from_radio_event(event: Event) -> Result<String> { | ||
let event_target = event.target().context("Error accessing tareget")?; | ||
let target: HtmlInputElement = event_target | ||
.dyn_into() | ||
.map_err(|_| anyhow!("Error accessing input element"))?; | ||
Ok(target.value()) | ||
} | ||
|
||
#[function_component(RadioButton)] | ||
pub fn radio_button(props: &Props) -> Html { | ||
let Props { | ||
id, | ||
value, | ||
label, | ||
name, | ||
checked, | ||
} = props.clone(); | ||
|
||
let for_name = name.clone(); | ||
html! { | ||
<div> | ||
<input type="radio" {id} {name} {value} {checked} /> | ||
<label for={for_name}>{label}</label> | ||
</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
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,53 @@ | ||
use signer::{storage::SettingsStorage, Network}; | ||
use std::str::FromStr; | ||
use yew::prelude::*; | ||
use yew_router::prelude::use_navigator; | ||
|
||
use crate::{ | ||
components::radio_button::{get_value_from_radio_event, RadioButton}, | ||
switch::Route, | ||
utils::storage::LocalStorage, | ||
}; | ||
|
||
#[function_component(Settings)] | ||
pub fn settings() -> Html { | ||
let storage = SettingsStorage::read(LocalStorage::default()); | ||
let navigator = use_navigator().unwrap(); | ||
let network = use_state(|| storage.get_network()); | ||
let error = use_state(String::new); | ||
let network_value = *network; | ||
let error_value = (*error).clone(); | ||
|
||
let on_network_change = Callback::from(move |input_event: Event| { | ||
let value = get_value_from_radio_event(input_event).unwrap(); | ||
network.set(Network::from_str(&value).unwrap()); | ||
}); | ||
|
||
let onclick_save = { | ||
Callback::from(move |_| { | ||
let mut storage = SettingsStorage::read(LocalStorage::default()); | ||
storage.set_network(&network_value.to_string()); | ||
let stored = storage.save(); | ||
|
||
if stored.is_err() { | ||
error.set("Unable to save settings".to_string()); | ||
} else { | ||
navigator.push(&Route::Home); | ||
} | ||
}) | ||
}; | ||
|
||
html! { | ||
<> | ||
<fieldset onchange={on_network_change} > | ||
<legend>{"Select a network"}</legend> | ||
<RadioButton id="mainnet" name="mainnet" value={Network::Bitcoin.to_string()} checked={network_value == Network::Bitcoin} label="Mainnet" /> | ||
<RadioButton id="regtest" name="regtest" value={Network::Regtest.to_string()} checked={network_value == Network::Regtest} label="Regtest" /> | ||
<RadioButton id="signet" name="signet" value={Network::Signet.to_string()} checked={network_value == Network::Signet} label="Signet" /> | ||
<RadioButton id="testnet" name="testnet" value={Network::Testnet.to_string()} checked={network_value == Network::Testnet} label="Testnet" /> | ||
</fieldset> | ||
<div class="error">{error_value}</div> | ||
<button onclick={onclick_save}>{"Save"}</button> | ||
</> | ||
} | ||
} |
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
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,19 +1,7 @@ | ||
use bitcoin::Network; | ||
pub use bitcoin::Network; | ||
|
||
pub mod psbt_details; | ||
pub mod signer; | ||
pub mod storage; | ||
pub mod utils; | ||
pub mod wallet; | ||
|
||
#[cfg(feature = "regtest")] | ||
pub const NETWORK: Network = Network::Regtest; | ||
|
||
#[cfg(feature = "testnet")] | ||
pub const NETWORK: Network = Network::Testnet; | ||
|
||
#[cfg(feature = "signet")] | ||
pub const NETWORK: Network = Network::Signet; | ||
|
||
#[cfg(not(any(feature = "regtest", feature = "testnet", feature = "signet")))] | ||
pub const NETWORK: Network = Network::Bitcoin; |
Oops, something went wrong.