From f770e94be83540bbdaca722198370087b20d9eb7 Mon Sep 17 00:00:00 2001 From: Kariy Date: Thu, 28 Sep 2023 14:16:53 +0700 Subject: [PATCH] clippy --- crates/torii/client/src/client/mod.rs | 13 ++++++----- .../torii/client/src/client/subscription.rs | 2 +- crates/torii/client/wasm/src/lib.rs | 3 --- crates/torii/client/wasm/src/utils.rs | 23 ------------------- crates/torii/client/wasm/tests/wasm.rs | 20 ---------------- 5 files changed, 8 insertions(+), 53 deletions(-) delete mode 100644 crates/torii/client/wasm/src/utils.rs delete mode 100644 crates/torii/client/wasm/tests/wasm.rs diff --git a/crates/torii/client/src/client/mod.rs b/crates/torii/client/src/client/mod.rs index d1cf15496a..bf03f15d66 100644 --- a/crates/torii/client/src/client/mod.rs +++ b/crates/torii/client/src/client/mod.rs @@ -90,13 +90,14 @@ impl ClientBuilder { let provider = JsonRpcClient::new(HttpTransport::new(Url::parse(&rpc_url)?)); let world_reader = WorldContractReader::new(world, &provider); - for EntityComponent { component, keys } in subbed_entities.entities.read().iter() { + // TODO: change this to querying the gRPC endpoint instead + let subbed_entities = subbed_entities.entities.read().clone(); + for EntityComponent { component, keys } in subbed_entities { let component_reader = - world_reader.component(component, BlockId::Tag(BlockTag::Pending)).await?; - let values = component_reader - .entity(keys.to_owned(), BlockId::Tag(BlockTag::Pending)) - .await?; - client_storage.set_entity((component.to_owned(), keys.to_owned()), values)?; + world_reader.component(&component, BlockId::Tag(BlockTag::Pending)).await?; + let values = + component_reader.entity(keys.clone(), BlockId::Tag(BlockTag::Pending)).await?; + client_storage.set_entity((component, keys), values)?; } } diff --git a/crates/torii/client/src/client/subscription.rs b/crates/torii/client/src/client/subscription.rs index 082d425b2a..ded23d2552 100644 --- a/crates/torii/client/src/client/subscription.rs +++ b/crates/torii/client/src/client/subscription.rs @@ -269,6 +269,6 @@ mod tests { subscribed_entities.subscribed_storage_addresses.read().len(); assert_eq!(actual_storage_addresses_count_after, 0); - assert!(subscribed_entities.entities.read().contains(&entity) == false); + assert!(!subscribed_entities.entities.read().contains(&entity)); } } diff --git a/crates/torii/client/wasm/src/lib.rs b/crates/torii/client/wasm/src/lib.rs index 480b8c8fd1..544743029f 100644 --- a/crates/torii/client/wasm/src/lib.rs +++ b/crates/torii/client/wasm/src/lib.rs @@ -1,11 +1,8 @@ use std::str::FromStr; -use futures::FutureExt; use starknet::core::types::FieldElement; use wasm_bindgen::prelude::*; -mod utils; - type JsFieldElement = JsValue; type JsEntityComponent = JsValue; diff --git a/crates/torii/client/wasm/src/utils.rs b/crates/torii/client/wasm/src/utils.rs deleted file mode 100644 index 94baac13eb..0000000000 --- a/crates/torii/client/wasm/src/utils.rs +++ /dev/null @@ -1,23 +0,0 @@ -use wasm_bindgen::JsValue; -use web_sys::WorkerGlobalScope; - -pub async fn sleep(delay: i32) -> Result<(), JsValue> { - use wasm_bindgen::JsCast; - let mut cb = |resolve: js_sys::Function, _reject: js_sys::Function| { - // if we are in a worker, use the global worker's scope - // otherwise, use the window's scope - if let Ok(worker_scope) = js_sys::global().dyn_into::() { - worker_scope - .set_timeout_with_callback_and_timeout_and_arguments_0(&resolve, delay) - .expect("should register `setTimeout`"); - } else { - web_sys::window() - .unwrap() - .set_timeout_with_callback_and_timeout_and_arguments_0(&resolve, delay) - .expect("should register `setTimeout`"); - } - }; - let p = js_sys::Promise::new(&mut cb); - wasm_bindgen_futures::JsFuture::from(p).await?; - Ok(()) -} diff --git a/crates/torii/client/wasm/tests/wasm.rs b/crates/torii/client/wasm/tests/wasm.rs deleted file mode 100644 index 01c50729d6..0000000000 --- a/crates/torii/client/wasm/tests/wasm.rs +++ /dev/null @@ -1,20 +0,0 @@ -use starknet::macros::felt; -use wasm_bindgen_test::wasm_bindgen_test; - -#[wasm_bindgen_test] -async fn test_spawn_client() { - let url = "http://localhost:5000"; - let world_address = "0x398c6b4f479e2a6181ae895ad34333b44e419e48098d2a9622f976216d044dd"; - let initial_entities_to_sync = - serde_wasm_bindgen::to_value(&dojo_types::component::EntityComponent { - component: "Position".into(), - keys: vec![felt!("0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973")], - }) - .map(|v| vec![v]) - .unwrap(); - - assert!( - torii_client_wasm::spawn_client(url, world_address, initial_entities_to_sync).await.is_ok(), - "failed to spawn client" - ) -}