Skip to content

Commit

Permalink
sol balance
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmizz committed Feb 25, 2025
1 parent a04b01a commit 167d985
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
mod wallet_adapter_native;
#[cfg(feature = "web")]
mod wallet_adapter_web;
#[cfg(not(feature = "web"))]
// #[cfg(not(feature = "web"))]
mod wallet_drawer_native;
#[cfg(feature = "web")]
mod wallet_drawer_web;
Expand Down
25 changes: 23 additions & 2 deletions src/components/wallet/wallet_drawer_native.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
use dioxus::prelude::*;

use crate::hooks::{use_wallet, Wallet};
use crate::{
components::Row,
hooks::{on_transaction_done, use_sol_balance, use_wallet, Wallet},
};

#[component]
pub fn WalletDrawer(on_close: EventHandler<MouseEvent>) -> Element {
let wallet = use_wallet();
let mut pubkey = use_signal(|| "missing pubkey".to_string());
let mut sol_balance = use_sol_balance();
let sol_balance_string = use_signal::<String>(|| match sol_balance.cloned() {
Some(Ok(str)) => str
.ui_amount
.map(|f| f.to_string())
.unwrap_or("0".to_string()),
_ => "0".to_string(),
});
use_effect(move || {
if let Wallet::Connected(pk) = *wallet.read() {
pubkey.set(pk.to_string());
}
});
on_transaction_done(move |_sig| {
sol_balance.restart();
});
rsx! {
div {
class: "flex flex-col gap-8 h-full sm:w-96 w-screen elevated elevated-border text-white py-8 z-50",
style: "padding-left: 20px; padding-right: 20px;",
onclick: move |e| e.stop_propagation(),
// "TODO: Wallet address + copy button"
div { "{pubkey}" }
div {
"{pubkey}"
}
Row {
span { class: "mr-2", "SOL:" }
span { "{sol_balance_string}" }
}
}
}
}
2 changes: 1 addition & 1 deletion src/hooks/resources/use_token_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn use_token_balances_for_liquidity_pair(
(token_a_balance, token_b_balance)
}

pub fn _use_sol_balance() -> Resource<GatewayResult<UiTokenAmount>> {
pub fn use_sol_balance() -> Resource<GatewayResult<UiTokenAmount>> {
return use_token_balance(Token::sol().mint);
}

Expand Down

0 comments on commit 167d985

Please sign in to comment.