diff --git a/src/lib.rs b/src/lib.rs index 6a2e14f..9f166a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ pub mod pages { pub mod middlewares { pub mod is_chain_available; pub mod is_dao_owner; + pub mod is_signer_ready; } pub mod layouts { pub mod authenticated; @@ -34,8 +35,8 @@ pub mod hooks { pub mod use_notification; pub mod use_onboard; pub mod use_our_navigator; - pub mod use_session; pub mod use_paginator; + pub mod use_session; pub mod use_spaces_client; pub mod use_startup; pub mod use_theme; diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 19b4ab0..0832336 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -477,7 +477,8 @@ "title": "鈿狅笍Attention: This information is for you", "middleware": { "has_dao": "We're sorry! 馃槥 You cannot create more organizations associated with this account.", - "chain_unavailable": "At this time, it is not possible to complete this action." + "chain_unavailable": "At this time, it is not possible to complete this action.", + "signer_not_found": "We're sorry! 馃槥 You cannot perform this action, you must authenticate first." } }, "utils": { diff --git a/src/locales/es-ES.json b/src/locales/es-ES.json index a89d091..b5bff4b 100644 --- a/src/locales/es-ES.json +++ b/src/locales/es-ES.json @@ -491,7 +491,8 @@ "title": "鈿狅笍Atenci贸n: Est谩 informaci贸n es para ti", "middleware": { "has_dao": "隆Lo sentimos! 馃槥 No puedes crear m谩s organizaciones asociadas a esta cuenta.", - "chain_unavailable": "En este momento no es posible completar est谩 acci贸n." + "chain_unavailable": "En este momento no es posible completar est谩 acci贸n.", + "signer_not_found": "隆Lo sentimos! 馃槥 No puedes realizar esta acci贸n, primero debes autenticarte." } }, "errors": { diff --git a/src/middlewares/is_signer_ready.rs b/src/middlewares/is_signer_ready.rs new file mode 100644 index 0000000..11b6971 --- /dev/null +++ b/src/middlewares/is_signer_ready.rs @@ -0,0 +1,17 @@ +use crate::hooks::{use_accounts::UseAccountsState, use_notification::UseNotificationState}; +use dioxus_std::{i18n::UseI18, translate}; +pub fn is_signer_ready( + i18: UseI18, + accounts: UseAccountsState, + mut notification: UseNotificationState, +) -> impl FnOnce() -> Result<(), &'static str> { + move || { + if accounts.get_account().is_none() { + notification.handle_warning(&translate!(i18, "warnings.middleware.signer_not_found")); + Err("Failed to get account to sign") + } else { + log::debug!("Signer is ready"); + Ok(()) + } + } +} diff --git a/src/pages/deposit.rs b/src/pages/deposit.rs index a712c38..8892149 100644 --- a/src/pages/deposit.rs +++ b/src/pages/deposit.rs @@ -7,16 +7,14 @@ use crate::{ dropdown::{DropdownItem, ElementSize}, AccountButton, BankCardLine, Button, CheckboxCard, Dropdown, Icon, Input, KusamaLogo, PaymentMethod, PaypalLogo, PolygonLogo, Tab, Title, - }, - hooks::{ + }, hooks::{ use_accounts::use_accounts, use_communities::use_communities, use_deposit::{use_deposit, DepositError, DepositTo}, use_notification::use_notification, use_our_navigator::use_our_navigator, use_tooltip::{use_tooltip, TooltipItem}, - }, - pages::onboarding::convert_to_jsvalue, + }, middlewares::is_signer_ready::is_signer_ready, pages::onboarding::convert_to_jsvalue }; use wasm_bindgen::prelude::*; @@ -62,6 +60,12 @@ pub fn Deposit() -> Element { let mut dropdown_value = use_signal::>(|| None); + use_coroutine(move |_: UnboundedReceiver<()>| async move { + if let Err(_) = is_signer_ready(i18, accounts, notification)() { + nav.push(vec![], "/login"); + }; + }); + let mut items = vec![]; for account in accounts.get().into_iter() { let address = account.address(); diff --git a/src/pages/initiative.rs b/src/pages/initiative.rs index 44f0319..98a249a 100644 --- a/src/pages/initiative.rs +++ b/src/pages/initiative.rs @@ -7,8 +7,20 @@ use crate::{ molecules::{InitiativeActions, InitiativeInfo}, }, hooks::{ - use_initiative::{use_initiative, ActionItem, InitiativeData, InitiativeInfoContent, InitiativeInitContent, TransferItem}, use_notification::use_notification, use_our_navigator::use_our_navigator, use_session::use_session, use_spaces_client::use_spaces_client, use_tooltip::{use_tooltip, TooltipItem} + use_accounts::use_accounts, + use_initiative::{ + use_initiative, ActionItem, InitiativeData, InitiativeInfoContent, + InitiativeInitContent, KusamaTreasury, KusamaTreasuryPeriod, TransferItem, + VotingOpenGov, + }, + use_notification::use_notification, + use_our_navigator::use_our_navigator, + use_session::use_session, + use_spaces_client::use_spaces_client, + use_tooltip::{use_tooltip, TooltipItem}, + }, + middlewares::is_signer_ready::is_signer_ready, pages::onboarding::convert_to_jsvalue, services::{ kreivo::{community_referenda::referendum_count, timestamp::now}, @@ -47,6 +59,7 @@ extern "C" { pub fn Initiative(id: u16) -> Element { let i18 = use_i18(); let mut initiative = use_initiative(); + let accounts = use_accounts(); let session = use_session(); let nav = use_our_navigator(); let mut tooltip = use_tooltip(); @@ -57,6 +70,11 @@ pub fn Initiative(id: u16) -> Element { use_before_render(move || { initiative.default(); }); + use_coroutine(move |_: UnboundedReceiver<()>| async move { + if let Err(_) = is_signer_ready(i18, accounts, notification)() { + nav.push(vec![], &format!("/dao/{}/initiatives", id)); + }; + }); rsx! { div { class: "page--initiative", div { class: "progress progress--steps-cube", diff --git a/src/pages/withdraw.rs b/src/pages/withdraw.rs index eadac19..11d0b6d 100644 --- a/src/pages/withdraw.rs +++ b/src/pages/withdraw.rs @@ -17,6 +17,7 @@ use crate::{ use_tooltip::{use_tooltip, TooltipItem}, use_withdraw::use_withdraw, }, + middlewares::is_signer_ready::is_signer_ready, pages::onboarding::convert_to_jsvalue, }; use wasm_bindgen::prelude::*; @@ -58,6 +59,12 @@ pub fn Withdraw() -> Element { let mut dropdown_value = use_signal::>(|| None); + use_coroutine(move |_: UnboundedReceiver<()>| async move { + if let Err(_) = is_signer_ready(i18, accounts, notification)() { + nav.push(vec![], "/login"); + }; + }); + let mut items = vec![]; for account in accounts.get().into_iter() { let address = account.address();