Skip to content

Commit

Permalink
dynamic fee
Browse files Browse the repository at this point in the history
  • Loading branch information
miralandlabs committed Aug 10, 2024
1 parent f0171cd commit 8ea3a0d
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 210 deletions.
2 changes: 1 addition & 1 deletion src/components/claim/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn ClaimConfirm(amount: u64, claim_step: Signal<ClaimStep>) -> Element {
let gateway = use_gateway();

use_future(move || async move {
let price = gateway::get_recent_priority_fee_estimate(true).await;
let price = gateway::get_recent_priority_fee_estimate().await.unwrap();
priority_fee.set(PriorityFee(price));
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/miner_toolbar/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub async fn try_start_mining(
toolbar_state: &mut Signal<MinerToolbarState>,
) -> GatewayResult<()> {
loop {
if gateway.register_ore().await.is_ok() {
if gateway.open_ore().await.is_ok() {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/send/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn SendConfirm(
let gateway = use_gateway();

use_future(move || async move {
let price = gateway::get_recent_priority_fee_estimate(true).await;
let price = gateway::get_recent_priority_fee_estimate().await.unwrap();
priority_fee.set(PriorityFee(price));
});

Expand Down
108 changes: 73 additions & 35 deletions src/components/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use solana_client_wasm::solana_sdk::native_token::lamports_to_sol;

use crate::{
components::{Appearance, BackupKeypairWarning, Copyable},
gateway::RPC_URL,
gateway::{FEE_URL, RPC_URL},
hooks::{
use_appearance, use_explorer, use_pubkey, use_rpc_url, use_show_backup_warning,
use_sol_balance, Explorer, RpcUrl,
use_appearance, use_explorer, use_pubkey, use_fee_url, use_rpc_url,
use_show_backup_warning, use_sol_balance, Explorer, FeeUrl, RpcUrl,
},
route::Route,
};
Expand All @@ -26,6 +26,12 @@ pub fn Settings() -> Element {
let mut rpc_url_error = use_signal::<Option<String>>(|| None);
let is_rpc_url_edited = rpc_url.read().0.ne(&*rpc_url_input.read());

// MI
let mut fee_url = use_fee_url();
let mut fee_url_input = use_signal(|| fee_url.read().0.clone());
let mut fee_url_error = use_signal::<Option<String>>(|| None);
let is_fee_url_edited = fee_url.read().0.ne(&*fee_url_input.read());

let container_class = "flex flex-row gap-8 justify-between w-full sm:px-1";
let section_title_class = "text-lg md:text-2xl font-bold";
let data_title_class = "font-medium text-sm opacity-50 my-auto";
Expand Down Expand Up @@ -226,38 +232,70 @@ pub fn Settings() -> Element {
}
}
}
// div {
// class: "flex flex-shrink gap-2 justify-end",
// if let Some(err_str) = rpc_url_error.read().clone() {
// p {
// class: "text-sm text-red-500 text-right",
// "{err_str}"
// }
// }
// div {
// class: "flex flex-row gap-2",
// if rpc_url.read().0.ne(RPC_URL) {
// button {
// class: "hover-100 active-200 rounded shrink ml-auto transition-colors px-2 py-1",
// onclick: move |_| {
// rpc_url.set(RpcUrl(RPC_URL.to_string()));
// rpc_url_input.set(RPC_URL.to_string());
// rpc_url_error.set(None);
// },
// "Reset to default"
// }
// }
// if is_rpc_url_edited && rpc_url_error.read().is_none() {
// button {
// class: "bg-green-500 hover:bg-green-600 active:bg-green-700 text-white rounded shrink ml-auto transition-colors px-2 py-1",
// onclick: move |_| {
// rpc_url.set(RpcUrl(rpc_url_input.read().clone()));
// },
// "Save"
// }
// }
// }
// }
// MI
div {
class: "{container_class} flex-auto",
div {
p {
class: "{data_title_class}",
"Priority fee estimate"
}
p {
class: "text-left text-orange-500 max-w-144",
"This url is free for now and provided as-is. You are encouraged to use your own fee estimation url instead."
}
}
div {
class: "flex flex-auto flex-col gap-2",
input {
autofocus: false,
class: "w-full text-right placeholder-gray-300 dark:placeholder-gray-800 bg-transparent",
value: "{fee_url_input}",
placeholder: "{FEE_URL}",
oninput: move |evt| {
let s = evt.value();
fee_url_input.set(s.clone());
if !is_url(&s) {
fee_url_error.set(Some("Invalid url".to_string()));
} else {
fee_url_error.set(None);
}
},
}
div {
class: "flex flex-shrink gap-2 justify-end",
if let Some(err_str) = fee_url_error.read().clone() {
p {
class: "text-sm text-red-500 text-right",
"{err_str}"
}
}
div {
class: "flex flex-row gap-2",
if fee_url.read().0.ne(FEE_URL) {
button {
class: "hover-100 active-200 rounded shrink ml-auto transition-colors px-2 py-1 font-semibold",
onclick: move |_| {
fee_url.set(FeeUrl(FEE_URL.to_string()));
fee_url_input.set(FEE_URL.to_string());
fee_url_error.set(None);
},
"Reset to default"
}
}
if is_fee_url_edited && fee_url_error.read().is_none() {
button {
class: "bg-green-500 hover:bg-green-600 active:bg-green-700 text-white rounded shrink ml-auto transition-colors px-2 py-1",
onclick: move |_| {
fee_url.set(FeeUrl(fee_url_input.read().clone()));
},
"Save"
}
}
}
}
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/stake/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn StakeConfirm(amount: u64, stake_step: Signal<StakeStep>) -> Element {
let gateway = use_gateway();

use_future(move || async move {
let price = gateway::get_recent_priority_fee_estimate(true).await;
let price = gateway::get_recent_priority_fee_estimate().await.unwrap();
priority_fee.set(PriorityFee(price));
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/upgrade/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn UpgradeConfirm(amount: u64, upgrade_step: Signal<UpgradeStep>) -> Element
let gateway = use_gateway();

use_future(move || async move {
let price = gateway::get_recent_priority_fee_estimate(true).await;
let price = gateway::get_recent_priority_fee_estimate().await.unwrap();
priority_fee.set(PriorityFee(price));
});

Expand Down
2 changes: 1 addition & 1 deletion src/gateway/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub type GatewayResult<T> = Result<T, GatewayError>;
pub enum GatewayError {
FailedDeserialization,
FailedAta,
FailedRegister,
FailedOpen,
TransactionTimeout,
NetworkUnavailable,
AccountNotFound,
Expand Down
Loading

0 comments on commit 8ea3a0d

Please sign in to comment.