From b99aad3cde5b0bdbb5de2d135357648e287fcbd4 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Wed, 27 Mar 2024 14:07:07 -0500 Subject: [PATCH] remove all websockets and poll --- Cargo.toml | 2 +- public/tailwind.css | 41 +++++++++++------ .../miner_toolbar_insufficient_sol.rs | 8 ++-- src/hooks/use_account.rs | 7 +-- src/hooks/use_sol_balance.rs | 46 +++++-------------- tailwind.config.js | 2 +- 6 files changed, 49 insertions(+), 57 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25cac222..284cb5c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ readme = "./README.md" keywords = ["solana", "crypto", "mining"] [features] -default = [] +default = ["web"] bundle = [] desktop = [ "async-tungstenite", diff --git a/public/tailwind.css b/public/tailwind.css index 7ad6c2ce..9fcf0ec8 100644 --- a/public/tailwind.css +++ b/public/tailwind.css @@ -840,6 +840,11 @@ h2:where(.dark, .dark *) { height: 2rem; } +.h-fit { + height: -moz-fit-content; + height: fit-content; +} + .h-full { height: 100%; } @@ -954,10 +959,22 @@ h2:where(.dark, .dark *) { max-width: 100%; } +.flex-auto { + flex: 1 1 auto; +} + +.flex-none { + flex: none; +} + .flex-shrink { flex-shrink: 1; } +.flex-shrink-0 { + flex-shrink: 0; +} + .shrink { flex-shrink: 1; } @@ -1200,6 +1217,11 @@ h2:where(.dark, .dark *) { background-position: center; } +.object-contain { + -o-object-fit: contain; + object-fit: contain; +} + .p-2 { padding: 0.5rem; } @@ -1733,11 +1755,6 @@ h2:where(.dark, .dark *) { background-color: rgb(49 49 51 / var(--tw-bg-opacity)); } -.hover\:bg-green-500:hover { - --tw-bg-opacity: 1; - background-color: rgb(10 207 134 / var(--tw-bg-opacity)); -} - .hover\:bg-green-600:hover { --tw-bg-opacity: 1; background-color: rgb(0 184 124 / var(--tw-bg-opacity)); @@ -1849,10 +1866,6 @@ h2:where(.dark, .dark *) { gap: 4rem; } - .sm\:gap-3 { - gap: 0.75rem; - } - .sm\:gap-4 { gap: 1rem; } @@ -2065,7 +2078,7 @@ h2:where(.dark, .dark *) { .dark\:bg-gray-700:where(.dark, .dark *) { --tw-bg-opacity: 1; - background-color: rgb(90 90 92 / var(--tw-bg-opacity)); + background-color: rgb(112 112 113 / var(--tw-bg-opacity)); } .dark\:bg-gray-900:where(.dark, .dark *) { @@ -2085,7 +2098,7 @@ h2:where(.dark, .dark *) { .dark\:text-gray-700:where(.dark, .dark *) { --tw-text-opacity: 1; - color: rgb(90 90 92 / var(--tw-text-opacity)); + color: rgb(112 112 113 / var(--tw-text-opacity)); } .dark\:text-gray-900:where(.dark, .dark *) { @@ -2100,12 +2113,12 @@ h2:where(.dark, .dark *) { .dark\:placeholder-gray-700:where(.dark, .dark *)::-moz-placeholder { --tw-placeholder-opacity: 1; - color: rgb(90 90 92 / var(--tw-placeholder-opacity)); + color: rgb(112 112 113 / var(--tw-placeholder-opacity)); } .dark\:placeholder-gray-700:where(.dark, .dark *)::placeholder { --tw-placeholder-opacity: 1; - color: rgb(90 90 92 / var(--tw-placeholder-opacity)); + color: rgb(112 112 113 / var(--tw-placeholder-opacity)); } .dark\:placeholder-gray-800:where(.dark, .dark *)::-moz-placeholder { @@ -2130,6 +2143,6 @@ h2:where(.dark, .dark *) { .dark\:active\:bg-gray-700:active:where(.dark, .dark *) { --tw-bg-opacity: 1; - background-color: rgb(90 90 92 / var(--tw-bg-opacity)); + background-color: rgb(112 112 113 / var(--tw-bg-opacity)); } diff --git a/src/components/miner_toolbar/miner_toolbar_insufficient_sol.rs b/src/components/miner_toolbar/miner_toolbar_insufficient_sol.rs index 8ea0594f..a2a94b0b 100644 --- a/src/components/miner_toolbar/miner_toolbar_insufficient_sol.rs +++ b/src/components/miner_toolbar/miner_toolbar_insufficient_sol.rs @@ -85,11 +85,11 @@ pub fn MinerToolbarInsufficientBalanceOpen(cx: Scope) -> Element { } p { class: "text-lg", - "Scan the QR code from your Solana wallet to fund your miner." + "Scan the QR code from your Solana wallet to top up your miner." } p { - class: "text-sm text-gray-300 dark:text-gray-700", - "Top up with 0.1 SOL to begin mining." + class: "text-sm text-gray-300", + "Your miner keypair is stored on your local device and can be exported at anytime from settings." } } div { @@ -111,7 +111,7 @@ pub fn MinerToolbarInsufficientBalanceOpen(cx: Scope) -> Element { // TODO Get referal code href: "https://www.coinbase.com/price/solana", target: "_blank", - class: "font-medium text-center text-sm text-gray-300 dark:text-gray-700 hover:underline", + class: "font-medium text-center text-sm text-gray-300 hover:underline", "Help! I don't have any SOL." } } diff --git a/src/hooks/use_account.rs b/src/hooks/use_account.rs index a234f614..7e3d4f67 100644 --- a/src/hooks/use_account.rs +++ b/src/hooks/use_account.rs @@ -26,7 +26,6 @@ pub fn use_account< let gateway = use_gateway(cx); let f = use_future(cx, (), |_| { - log::info!("Refetching account: {:?}", address); let acc = acc.clone(); let gateway = gateway.clone(); async move { @@ -42,8 +41,10 @@ pub fn use_account< let f = f.clone(); async move { if let Some(d) = poll { - async_std::task::sleep(Duration::from_secs(d)).await; - f.restart(); + loop { + async_std::task::sleep(Duration::from_secs(d)).await; + f.restart(); + } } } }); diff --git a/src/hooks/use_sol_balance.rs b/src/hooks/use_sol_balance.rs index fd821a27..0a4d4d10 100644 --- a/src/hooks/use_sol_balance.rs +++ b/src/hooks/use_sol_balance.rs @@ -1,5 +1,9 @@ use dioxus::prelude::*; use dioxus_std::utils::rw::use_rw; +#[cfg(feature = "deskstop")] +use std::time::Duration; +#[cfg(feature = "web")] +use web_time::Duration; use crate::gateway::AsyncResult; @@ -22,7 +26,7 @@ pub fn use_sol_balance_provider(cx: &ScopeState) { let gateway = use_gateway(cx); // Fetch initial balance. - use_future(cx, (), |_| { + let f = use_future(cx, (), |_| { let balance = balance.clone(); let gateway = gateway.clone(); async move { @@ -32,41 +36,15 @@ pub fn use_sol_balance_provider(cx: &ScopeState) { } }); - // Subscribe to balance changes + // Poll for future balance changes use_future(cx, (), |_| { - #[cfg(feature = "web")] - let gateway = gateway.clone(); - let balance_ = balance_.clone(); + let f = f.clone(); + let poll = 3; async move { - #[cfg(feature = "web")] - let _ = gateway - .rpc - .account_subscribe(address, move |account| { - let lamports = account.value.unwrap().lamports; - balance_.write(AsyncResult::Ok(SolBalance(lamports))).ok(); - }) - .await; - - #[cfg(feature = "desktop")] - std::thread::spawn(move || { - match PubsubClient::account_subscribe( - RPC_WSS_URL, - &address, - Some(solana_client::rpc_config::RpcAccountInfoConfig::default()), - ) { - Ok((mut _sub, rx)) => { - while let Ok(ui_account) = rx.recv() { - let lamports = ui_account.value.lamports; - balance_ - .write(AsyncResult::Ok(SolBalance(lamports))) - .unwrap(); - } - } - Err(err) => { - log::error!("Failed to subscribe to account: {:?}", err) - } - }; - }); + loop { + async_std::task::sleep(Duration::from_secs(poll)).await; + f.restart(); + } } }); diff --git a/tailwind.config.js b/tailwind.config.js index 6e5dcfed..202bef95 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -26,7 +26,7 @@ module.exports = { 100: '#e8e8ea', 200: '#d6d6d8', 300: '#b0b0b2', - 700: '#5a5a5c', + 700: '#707071', 800: '#464648', 900: '#313133', },