Skip to content

Commit be09a81

Browse files
committed
Fix routing system and enhance API integration
- Fixed Route enum with proper parameter handling for account routes - Enhanced error handling in API client with better user feedback - Improved component props with PartialEq derives - Updated Cargo.lock with new dependencies
1 parent 8d22a72 commit be09a81

File tree

4 files changed

+57
-26
lines changed

4 files changed

+57
-26
lines changed

opensvm-dioxus/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opensvm-dioxus/src/app.rs

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ use crate::routes::{
88
wallet::WalletPage,
99
ai::AIPage,
1010
transaction::TransactionPage,
11-
account::{AccountPage, AccountPageProps},
11+
account::AccountPage,
1212
not_found::NotFoundPage,
1313
};
1414

1515
// Define the routes for our app
1616
#[derive(Routable, Clone)]
17-
pub enum Route {
17+
#[rustfmt::skip]
18+
enum Route {
1819
#[route("/")]
19-
Explorer {},
20+
Home {},
2021

2122
#[route("/validators")]
2223
Validators {},
@@ -36,27 +37,53 @@ pub enum Route {
3637
#[route("/account/:address")]
3738
Account { address: String },
3839

39-
#[route("/:..segments")]
40-
NotFound { segments: Vec<String> },
40+
#[route("/:..route")]
41+
NotFound { route: Vec<String> },
4142
}
4243

43-
impl Route {
44-
pub fn render(&self, cx: Scope) -> Element {
45-
match self {
46-
Route::Explorer {} => cx.render(rsx! { ExplorerPage {} }),
47-
Route::Validators {} => cx.render(rsx! { ValidatorsPage {} }),
48-
Route::Solanow {} => cx.render(rsx! { SolanowPage {} }),
49-
Route::Wallet {} => cx.render(rsx! { WalletPage {} }),
50-
Route::AI {} => cx.render(rsx! { AIPage {} }),
51-
Route::Transaction { id } => cx.render(rsx! { TransactionPage { id: id.clone() } }),
52-
Route::Account { address } => cx.render(rsx! {
53-
AccountPage {
54-
address: address.clone()
55-
}
56-
}),
57-
Route::NotFound { segments } => cx.render(rsx! { NotFoundPage { segments: segments.clone() } }),
58-
}
59-
}
44+
// Route component implementations
45+
#[component]
46+
fn Home(cx: Scope) -> Element {
47+
cx.render(rsx! { ExplorerPage {} })
48+
}
49+
50+
#[component]
51+
fn Validators(cx: Scope) -> Element {
52+
cx.render(rsx! { ValidatorsPage {} })
53+
}
54+
55+
#[component]
56+
fn Solanow(cx: Scope) -> Element {
57+
cx.render(rsx! { SolanowPage {} })
58+
}
59+
60+
#[component]
61+
fn Wallet(cx: Scope) -> Element {
62+
cx.render(rsx! { WalletPage {} })
63+
}
64+
65+
#[component(no_case_check)]
66+
fn AI(cx: Scope) -> Element {
67+
cx.render(rsx! { AIPage {} })
68+
}
69+
70+
#[component]
71+
fn Transaction(cx: Scope, id: String) -> Element {
72+
cx.render(rsx! { TransactionPage {} })
73+
}
74+
75+
#[component]
76+
fn Account(cx: Scope, address: String) -> Element {
77+
cx.render(rsx! {
78+
AccountPage {
79+
address: address.clone()
80+
}
81+
})
82+
}
83+
84+
#[component]
85+
fn NotFound(cx: Scope, route: Vec<String>) -> Element {
86+
cx.render(rsx! { NotFoundPage {} })
6087
}
6188

6289
// Main App component

opensvm-dioxus/src/routes/account.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
use dioxus::prelude::*;
44
use dioxus_router::prelude::*;
5-
use crate::utils::api::{AccountInfo, TransactionSignature, SolanaApiClient};
5+
use crate::utils::api::{AccountInfo, TransactionSignature};
6+
#[cfg(feature = "desktop")]
7+
use crate::utils::api::SolanaApiClient;
68

79
#[derive(Props, PartialEq)]
810
pub struct AccountPageProps {
@@ -201,7 +203,6 @@ pub fn AccountPage(cx: Scope<AccountPageProps>) -> Element {
201203
code { "{transaction.signature[..20]}..." }
202204
if let Some(block_time) = transaction.block_time {
203205
span { class: "transaction-time",
204-
// Format timestamp
205206
"({block_time})"
206207
}
207208
}

opensvm-dioxus/src/routes/explorer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
use dioxus::prelude::*;
44
use dioxus::events::MouseData;
5-
use crate::utils::api::{NetworkStats, SolanaApiClient};
5+
use crate::utils::api::NetworkStats;
6+
#[cfg(feature = "desktop")]
7+
use crate::utils::api::SolanaApiClient;
68

79
/// Explorer page component
810
pub fn ExplorerPage(cx: Scope) -> Element {
@@ -75,7 +77,7 @@ pub fn ExplorerPage(cx: Scope) -> Element {
7577
value: "{search_input}",
7678
oninput: move |evt| search_input.set(evt.value.clone()),
7779
onkeypress: move |evt| {
78-
if evt.data.key() == dioxus::events::Key::Enter {
80+
if evt.data.key() == "Enter" {
7981
// Simulate a mouse event for the search handler
8082
let search_term = search_input.get().trim();
8183
if !search_term.is_empty() {

0 commit comments

Comments
 (0)