mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-06-07 01:29:27 +00:00
fix: recent blocks fix
This commit is contained in:
parent
6101d791e3
commit
818eebb99f
@ -83,6 +83,17 @@ pub async fn get_block_by_id(block_id: BlockId) -> Result<Block, ServerFnError>
|
|||||||
.map_err(|e| ServerFnError::ServerError(format!("RPC error: {}", e)))
|
.map_err(|e| ServerFnError::ServerError(format!("RPC error: {}", e)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get latest block ID
|
||||||
|
#[server]
|
||||||
|
pub async fn get_latest_block_id() -> Result<BlockId, ServerFnError> {
|
||||||
|
use indexer_service_rpc::RpcClient as _;
|
||||||
|
let client = expect_context::<IndexerRpcClient>();
|
||||||
|
client
|
||||||
|
.get_last_finalized_block_id()
|
||||||
|
.await
|
||||||
|
.map_err(|e| ServerFnError::ServerError(format!("RPC error: {}", e)))
|
||||||
|
}
|
||||||
|
|
||||||
/// Get block by hash
|
/// Get block by hash
|
||||||
#[server]
|
#[server]
|
||||||
pub async fn get_block_by_hash(block_hash: HashType) -> Result<Block, ServerFnError> {
|
pub async fn get_block_by_hash(block_hash: HashType) -> Result<Block, ServerFnError> {
|
||||||
|
|||||||
@ -7,6 +7,8 @@ use crate::{
|
|||||||
components::{AccountPreview, BlockPreview, TransactionPreview},
|
components::{AccountPreview, BlockPreview, TransactionPreview},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const RECENT_BLOCKS_LIMIT: u64 = 10;
|
||||||
|
|
||||||
/// Main page component
|
/// Main page component
|
||||||
#[component]
|
#[component]
|
||||||
pub fn MainPage() -> impl IntoView {
|
pub fn MainPage() -> impl IntoView {
|
||||||
@ -38,7 +40,21 @@ pub fn MainPage() -> impl IntoView {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Load recent blocks on mount
|
// Load recent blocks on mount
|
||||||
let recent_blocks_resource = Resource::new(|| (), |_| async { api::get_blocks(0, 10).await });
|
let recent_blocks_resource = Resource::new(
|
||||||
|
|| (),
|
||||||
|
|_| async {
|
||||||
|
match api::get_latest_block_id().await {
|
||||||
|
Ok(last_id) => {
|
||||||
|
api::get_blocks(
|
||||||
|
std::cmp::max(last_id.saturating_sub(RECENT_BLOCKS_LIMIT) as u32, 1),
|
||||||
|
RECENT_BLOCKS_LIMIT as u32,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Handle search - update URL parameter
|
// Handle search - update URL parameter
|
||||||
let on_search = move |ev: SubmitEvent| {
|
let on_search = move |ev: SubmitEvent| {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user