Skip to content

Commit

Permalink
remove all websockets and poll
Browse files Browse the repository at this point in the history
  • Loading branch information
HardhatChad committed Mar 27, 2024
1 parent 667014f commit b99aad3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readme = "./README.md"
keywords = ["solana", "crypto", "mining"]

[features]
default = []
default = ["web"]
bundle = []
desktop = [
"async-tungstenite",
Expand Down
41 changes: 27 additions & 14 deletions public/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ h2:where(.dark, .dark *) {
height: 2rem;
}

.h-fit {
height: -moz-fit-content;
height: fit-content;
}

.h-full {
height: 100%;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -1849,10 +1866,6 @@ h2:where(.dark, .dark *) {
gap: 4rem;
}

.sm\:gap-3 {
gap: 0.75rem;
}

.sm\:gap-4 {
gap: 1rem;
}
Expand Down Expand Up @@ -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 *) {
Expand All @@ -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 *) {
Expand All @@ -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 {
Expand All @@ -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));
}

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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."
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/use_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
}
}
});
Expand Down
46 changes: 12 additions & 34 deletions src/hooks/use_sol_balance.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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 {
Expand All @@ -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();
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
100: '#e8e8ea',
200: '#d6d6d8',
300: '#b0b0b2',
700: '#5a5a5c',
700: '#707071',
800: '#464648',
900: '#313133',
},
Expand Down

0 comments on commit b99aad3

Please sign in to comment.