diff --git a/ssr/src/page/post_view/bet.rs b/ssr/src/page/post_view/bet.rs index 7ee66f14..f56087f9 100644 --- a/ssr/src/page/post_view/bet.rs +++ b/ssr/src/page/post_view/bet.rs @@ -1,9 +1,3 @@ -use candid::Principal; -use leptos::*; -use leptos_icons::*; -use leptos_use::use_interval_fn; -use web_time::Duration; - use crate::{ canister::individual_user_template::{BettingStatus, PlaceBetArg, Result2}, component::{ @@ -20,6 +14,11 @@ use crate::{ MockPartialEq, }, }; +use candid::Principal; +use leptos::*; +use leptos_icons::*; +use leptos_use::use_interval_fn; +use web_time::Duration; #[derive(Clone, Copy, Debug, PartialEq)] enum CoinState { @@ -122,13 +121,13 @@ fn HNButton( view! { } @@ -176,54 +175,81 @@ fn HNButtonOverlay( can_place_bet.set(false) } }); + let log_coin = { move || logging::log!("coin get: {:?}", coin.get()) }; + log_coin(); // This ensures you're tracking `coin.get()` inside a reactive closure. + let tracked_coin1 = + { move || logging::log!("coin tracked: {:?}", coin.with_untracked(|v| *v)) }; + tracked_coin1(); + let tracked_coin = move || coin.with_untracked(|v| u64::from(*v)); view! { - - { - create_effect(move |_| { - let Some(bet_direction) = bet_direction() else { - return; - }; - let bet_amount = coin.get_untracked().into(); - place_bet_action.dispatch((canisters.clone(), bet_direction, bet_amount)); - }); - } - -
- -
-
- - - -
- // Bottom row: Hot Not - // most of the CSS is for alignment with above icons -
-

Hot

-
- + + { + create_effect(move |_| { + let Some(bet_direction) = bet_direction() else { + return; + }; + let bet_amount = coin.get_untracked().into(); + place_bet_action.dispatch((canisters.clone(), bet_direction, bet_amount)); + }); + } + +
+ +
+
+ + + +
+ // Bottom row: Hot Not + // most of the CSS is for alignment with above icons +
+

Hot

+
+ +
+

Not

+
+ + +
+
+
+

+ You staked {tracked_coin()} tokens on + {if let Some(bet_kind) = bet_direction() { + if bet_kind == BetKind::Hot { + "Hot" + } else { + "Not" + } + } else { + "?" + }}. Result is still pending +

+
-

Not

- - } +
+ + } } #[component] fn WinBadge() -> impl IntoView { view! { - @@ -261,16 +287,16 @@ fn HNWonLost(participation: BetDetails) -> impl IntoView { let hn_icon = if is_hot { HotIcon } else { NotIcon }; view! { -
+
- +
// -
+
// -
+

You staked {bet_amount}tokens on {if is_hot { "Hot" } else { "Not" }}.

{if let Some(reward) = participation.reward() { @@ -317,7 +343,7 @@ fn BetTimer(post: PostDetails, participation: BetDetails, refetch_bet: Trigger) view! {

@@ -348,33 +374,59 @@ fn HNAwaitingResults( }; view! { -
-
+
+
+
-

- You staked {bet_amount}tokens on {bet_direction_text}Result is still pending +

+ You staked {bet_amount} tokens on {bet_direction_text} Result is still pending

} } - #[component] pub fn HNUserParticipation( post: PostDetails, participation: BetDetails, refetch_bet: Trigger, ) -> impl IntoView { + let place_bet_action = create_action( + move |(canisters, bet_direction, bet_amount): &(Canisters, BetKind, u64)| { + let post_can_id = post.canister_id; + let post_id = post.post_id; + let cans = canisters.clone(); + let bet_amount = *bet_amount; + let bet_direction = *bet_direction; + async move { + match bet_on_post(cans, bet_amount, bet_direction, post_id, post_can_id).await { + Ok(_) => Some(()), + Err(e) => { + log::error!("{e}"); + None + } + } + } + }, + ); + let place_bet_res = place_bet_action.value(); + create_effect(move |_| { + if place_bet_res().flatten().is_some() { + refetch_bet.notify(); + } + }); + let running = place_bet_action.pending(); view! { + {match participation.outcome { BetOutcome::AwaitingResult => { view! { } @@ -386,6 +438,8 @@ pub fn HNUserParticipation( BetOutcome::Lost => { view! { } } + + } .into_view()} @@ -454,7 +508,7 @@ fn LoaderWithShadowBg() -> impl IntoView { fn ShadowBg() -> impl IntoView { view! {
}