From b3be9029523a24e56028149e13993064bea29f87 Mon Sep 17 00:00:00 2001 From: sergey-melnychuk <8093171+sergey-melnychuk@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:41:42 +0200 Subject: [PATCH] chore: clean up wasm && web --- web/README.md | 2 +- web/app.js | 36 +++++++++++++++++------------------- web/beerus-web/Cargo.lock | 23 ++--------------------- web/beerus-web/Cargo.toml | 5 ++++- web/beerus-web/src/lib.rs | 2 +- web/package-lock.json | 30 ------------------------------ web/package.json | 16 ---------------- 7 files changed, 25 insertions(+), 89 deletions(-) delete mode 100644 web/package-lock.json delete mode 100644 web/package.json diff --git a/web/README.md b/web/README.md index ae4eea8e..fe8f2812 100644 --- a/web/README.md +++ b/web/README.md @@ -3,7 +3,6 @@ cd web/beerus-web wasm-pack build --target web cd .. # go back to 'web' -npm i ./beerus-web/pkg npx parcel build index.html http-server dist/ @@ -14,3 +13,4 @@ node proxy.js & ## Now open localhost:8080 in a browser ``` +cd beerus-web && wasm-pack build --target web && cd .. && npx parcel build index.html && http-server dist/ diff --git a/web/app.js b/web/app.js index eeeb2dcf..2004288c 100644 --- a/web/app.js +++ b/web/app.js @@ -1,6 +1,20 @@ -import init, { get_state } from './node_modules/beerus/beerus_web.js'; +import init, { get_state } from './beerus-web/pkg/beerus_web.js'; -async function run() { +function dump(div, text, style) { + let p = document.createElement('p'); + if (style != undefined) { + p.className = style; + } + if (style === 'error') { + console.error(text); + } else { + console.log(text); + } + p.innerText = text; + div.appendChild(p); +} + +(async function () { await init(); const div = document.getElementById('log'); @@ -16,20 +30,4 @@ async function run() { } catch (err) { dump(div, "Error: " + err, 'error'); } -} - -function dump(div, text, style) { - let p = document.createElement('p'); - if (style != undefined) { - p.className = style; - } - if (style === 'error') { - console.error(text); - } else { - console.log(text); - } - p.innerText = text; - div.appendChild(p); -} - -run(); +})(); diff --git a/web/beerus-web/Cargo.lock b/web/beerus-web/Cargo.lock index 1a2a21d8..0240b744 100644 --- a/web/beerus-web/Cargo.lock +++ b/web/beerus-web/Cargo.lock @@ -482,7 +482,6 @@ dependencies = [ "toml", "tracing", "tracing-subscriber", - "ureq", "url", "validator", "wasm-bindgen", @@ -498,9 +497,11 @@ dependencies = [ "beerus", "ethers", "helios", + "js-sys", "reqwest 0.12.7", "serde", "serde_json", + "tokio", "wasm-bindgen", "wasm-bindgen-futures", "wasm-timer", @@ -5115,7 +5116,6 @@ checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64 0.22.1", "bytes", - "futures-channel", "futures-core", "futures-util", "http 1.1.0", @@ -5429,7 +5429,6 @@ version = "0.23.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ - "log", "once_cell", "ring 0.17.8", "rustls-pki-types", @@ -6984,24 +6983,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" -[[package]] -name = "ureq" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a" -dependencies = [ - "base64 0.22.1", - "flate2", - "log", - "once_cell", - "rustls 0.23.12", - "rustls-pki-types", - "serde", - "serde_json", - "url", - "webpki-roots 0.26.3", -] - [[package]] name = "url" version = "2.5.2" diff --git a/web/beerus-web/Cargo.toml b/web/beerus-web/Cargo.toml index e314c12c..104beefc 100644 --- a/web/beerus-web/Cargo.toml +++ b/web/beerus-web/Cargo.toml @@ -11,10 +11,12 @@ crate-type = ["cdylib", "rlib"] [dependencies] beerus = { path = "../..", default-features = false } -reqwest = { version = "0.12.3", default-features = false, features = ["json", "blocking"] } +reqwest = { version = "0.12.3", default-features = false, features = ["json"] } serde = "1.0.209" serde_json = "1.0.127" +tokio = { version = "1", features = ["sync", "macros", "io-util", "rt", "time"] } + wasm-timer = "0.2.5" web-sys = "0.3.69" wasm-bindgen = "0.2.92" @@ -22,3 +24,4 @@ wasm-bindgen-futures = "0.4.37" ethers = { git = "https://github.com/gakonst/ethers-rs", rev = "3bf1a9e0d698e9fdfc91d0353878901af5a5c5ef" } helios = { git = "https://github.com/sergey-melnychuk/helios", branch = "beerus-wasm", default-features = false, features = ["beerus-wasm"] } +js-sys = "0.3.70" diff --git a/web/beerus-web/src/lib.rs b/web/beerus-web/src/lib.rs index d25df5f5..78c0cab4 100644 --- a/web/beerus-web/src/lib.rs +++ b/web/beerus-web/src/lib.rs @@ -62,7 +62,7 @@ pub async fn get_state(config_json: &str) -> Result { root: state.root.as_ref().to_owned(), }; - let client = beerus::gen::client::blocking::Client::new(&config.starknet_rpc, beerus::client::Http(reqwest::Client::new())); + let client = beerus::gen::client::blocking::Client::new(&config.starknet_rpc, beerus::client::Http::new()); web_sys::console::log_1(&"beerus: rpc client ready".into()); let json = serde_json::json!({ "calldata": [], diff --git a/web/package-lock.json b/web/package-lock.json deleted file mode 100644 index 3ddd9253..00000000 --- a/web/package-lock.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "beerus-web", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "beerus-web", - "version": "1.0.0", - "license": "TBD", - "dependencies": { - "beerus": "file:beerus-web/pkg", - "beerus-web": "file:beerus-web/pkg" - } - }, - "beerus-web/pkg": { - "name": "beerus-web", - "version": "0.1.0", - "license": "MIT" - }, - "node_modules/beerus": { - "resolved": "beerus-web/pkg", - "link": true - }, - "node_modules/beerus-web": { - "resolved": "beerus-web/pkg", - "link": true - } - } -} diff --git a/web/package.json b/web/package.json deleted file mode 100644 index 6b76d4aa..00000000 --- a/web/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "beerus-web", - "version": "1.0.0", - "description": "", - "scripts": { - "start": "parcel", - "build": "parcel build" - }, - "keywords": [], - "author": "", - "license": "TBD", - "dependencies": { - "beerus": "file:beerus-web/pkg", - "beerus-web": "file:beerus-web/pkg" - } -}