Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yew Subxt WASM examples #968

Merged
merged 6 commits into from
May 26, 2023
Merged

Conversation

tadeohepperle
Copy link
Contributor

@tadeohepperle tadeohepperle commented May 19, 2023

relates to #920

Added an example Yew Application showcasing some of the functionality of Subxt.
The main focus is to show users a working configuration that enables them to start building WASM apps with Subxt.

To run the app locally, navigate to examples/wasm_examples and use Trunk, a WASM bundler:

cargo install --locked trunk

Run the app locally:

trunk serve --open

You need to have a local polkadot/substrate node with it's JSON-RPC HTTP server running at 127.0.0.1:9933 in order for the examples to be working.

@tadeohepperle tadeohepperle requested a review from a team as a code owner May 19, 2023 16:35
Cargo.toml Outdated Show resolved Hide resolved
Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good just move this example outside the subxt workspace then all good from my side

.gitignore Outdated
@@ -2,3 +2,4 @@
**/*.rs.bk
**/.DS_Store
cargo-timing*
/examples/wasm-example/dist
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
/examples/wasm-example/dist
/examples/wasm-example/dist

[dependencies]
futures = "0.3.28"
subxt = { path = "../../subxt", default-features = false, features = ["jsonrpsee-web"], target_arch = "wasm32" }
yew = { git = "https://github.com/yewstack/yew/", features = ["csr"] }
Copy link
Collaborator

@lexnv lexnv May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DQ: does yew = {version = "0.20.0", features = ["csr"] } provides enough features here?

//! Also make sure your browser supports WASM.
use futures::{self, FutureExt};

use yew::prelude::*;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we need to import everything here?


button:hover{
background-color: $secondary;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

html! {
<div>
if let Some(operation_title) = &self.operation_title{
<button onclick={reload}>{"🡄 Back"}</button>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the prefixed characters do not render properly on my machine, could we change it to something else?
Maybe plain Back or with some other chars?

let decoded_ext = ext.as_root_extrinsic::<polkadot::Call>();

writeln!(output, " Extrinsic #{idx}:").ok();
writeln!(output, " Bytes: {bytes_hex}").ok();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is there something we could do here to wrap the bytes on the screens width?

I'm seeing the bytes exceeding the green and black boxes on my machine

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly a word-wrap: break-word; in the css

Copy link
Collaborator

@lexnv lexnv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely example! It's so nice to see subxt visually in a browser subscribing to the blockchain's finalized blocks!

Left a few suggestions that we could tackle another time if they turn out to be difficult to adjust, mostly some visual tweaks

//! ```
//! Run the app locally:
//! ```
//! trunk serve --open
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After running this command on the repo trunk serve --open the Cargo.lock will get modified leading to some git uncommitted changes. Could we make sure that the Cargo.lock is up to date before merging this? Thanks!

Comment on lines 15 to 17
# This cannot be a workspace dependency, because it requires
# mutually exclusive jsonrpsee features to work, and workspaces
# will aggregate features used across crates:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this comment should probbaly be tweaked/added to

Comment on lines +5 to +6
/examples/wasm-example/dist
/examples/wasm-example/target
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth doing the same for the other excluded crate, testing/wasm-tests?

@jsdw
Copy link
Collaborator

jsdw commented May 26, 2023

At a quick glance I can't see any guidance on how to run this example in the code; am I missing something? If not, I think a README.md in the wasm-example folder on how to start it would be super handy for people :)

@tadeohepperle
Copy link
Contributor Author

I merge it now, I keep all of your comments in mind for a second PR I am going to put out today adding a singer example, where I fix the nits as well.

@tadeohepperle tadeohepperle merged commit e8612dd into master May 26, 2023
@tadeohepperle tadeohepperle deleted the tadeo-hepperle-yew-wasm-examples branch May 26, 2023 09:14
@jsdw jsdw mentioned this pull request Jun 1, 2023
tadeohepperle added a commit that referenced this pull request Jun 1, 2023
* add wasm examples

* cargo fmt

* change crate name

* resolve workspace conflicts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants