Skip to content

Commit

Permalink
fmt and add dummy PROJECT_ID
Browse files Browse the repository at this point in the history
  • Loading branch information
dougEfresh committed Dec 4, 2024
1 parent 44e1ce6 commit d556e08
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
rust: stable
env:
RUST_BACKTRACE: full
PROJECT_ID: "dummy"
steps:
- uses: actions/checkout@v3

Expand Down
40 changes: 22 additions & 18 deletions wasm_websocket_demo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
mod utils;

use std::fmt::Display;
use std::fmt::Formatter;
use walletconnect_sdk::client::{
error::ClientError,
websocket::{Client, CloseFrame, ConnectionHandler, PublishedMessage},
ConnectionOptions,
};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::spawn_local;
use web_sys::console;

use rand::rngs::OsRng;
use std::time::Duration;
use walletconnect_sdk::rpc::{
auth::{ed25519_dalek::SigningKey, AuthToken},
domain::Topic,
use {
rand::rngs::OsRng,
std::{
fmt::{Display, Formatter},
time::Duration,
},
walletconnect_sdk::{
client::{
error::ClientError,
websocket::{Client, CloseFrame, ConnectionHandler, PublishedMessage},
ConnectionOptions,
},
rpc::{
auth::{ed25519_dalek::SigningKey, AuthToken},
domain::Topic,
},
},
wasm_bindgen::prelude::*,
wasm_bindgen_futures::spawn_local,
web_sys::console,
};

enum ClientId {
Expand All @@ -32,7 +36,7 @@ impl Display for ClientId {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
ClientId::WC1 => write!(f, "wc1"),
ClientId::WC2 => write!(f, "wc2")
ClientId::WC2 => write!(f, "wc2"),
}
}
}
Expand All @@ -45,6 +49,7 @@ impl Handler {
fn new(name: ClientId) -> Self {
Self { client_id: name }
}

fn error_div(&self) -> String {
self.client_id.div("error")
}
Expand Down Expand Up @@ -145,4 +150,3 @@ pub fn run() {
console::log_1(&"done".into());
});
}

42 changes: 25 additions & 17 deletions wasm_websocket_demo/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use crate::ClientId;
use gloo_timers::future::TimeoutFuture;
use std::sync::Arc;
use std::time::Duration;
use walletconnect_sdk::client::websocket::Client;
use walletconnect_sdk::client::ConnectionOptions;
use walletconnect_sdk::rpc::domain::Topic;
use wasm_bindgen::JsValue;
use web_sys::console;
use {
crate::ClientId,
gloo_timers::future::TimeoutFuture,
std::{sync::Arc, time::Duration},
walletconnect_sdk::{
client::{websocket::Client, ConnectionOptions},
rpc::domain::Topic,
},
wasm_bindgen::JsValue,
web_sys::console,
};

// Helper function to set text in the result div
pub fn set_result_text(div: &str, text: &str) -> Result<(), JsValue> {
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let result_div = document.get_element_by_id(div).expect("should have result element");
let result_div = document
.get_element_by_id(div)
.expect("should have result element");

result_div.set_inner_html("");

Expand Down Expand Up @@ -54,13 +58,17 @@ pub async fn connect(id: &str, client: &Client, opts: &ConnectionOptions) {
pub async fn publish(id: ClientId, client: Client, topic: Topic) {
for i in 1..9 {
let msg = format!("{i}");
if let Err(e) = client.publish(topic.clone(),
Arc::from(msg.as_str()),
None,
0,
Duration::from_secs(60),
false,
).await {
if let Err(e) = client
.publish(
topic.clone(),
Arc::from(msg.as_str()),
None,
0,
Duration::from_secs(60),
false,
)
.await
{
let error_msg = format!("Failed message send {e}");
let _ = set_result_text(&id.div("error"), &error_msg);
return;
Expand Down

0 comments on commit d556e08

Please sign in to comment.