Skip to content

Commit

Permalink
build again
Browse files Browse the repository at this point in the history
  • Loading branch information
kent-3 committed Aug 18, 2024
1 parent fec766a commit 3180e0a
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 55 deletions.
10 changes: 5 additions & 5 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />


<script type="module" nonce="8rfV4ySTC3s7ySxpqnDJTA==">
import init, * as bindings from 'https://kent-3.github.io/secret-leptos/secret-leptos-c6a3ab524ea5d406.js';
const wasm = await init('https://kent-3.github.io/secret-leptos/secret-leptos-c6a3ab524ea5d406_bg.wasm');
<script type="module" nonce="7FMyFJtSxiUhB+GeBXVGzA==">
import init, * as bindings from 'https://kent-3.github.io/secret-leptos/secret-leptos-a6c6fd9b4d31a18d.js';
const wasm = await init('https://kent-3.github.io/secret-leptos/secret-leptos-a6c6fd9b4d31a18d_bg.wasm');


window.wasmBindings = bindings;
Expand Down Expand Up @@ -39,8 +39,8 @@
});
</script>

<link rel="modulepreload" href="https://kent-3.github.io/secret-leptos/secret-leptos-c6a3ab524ea5d406.js" crossorigin=anonymous integrity="sha384-/7QjiLAm1h56CY95h1IZjhO8CMTzdDwa9McjgA0/rUXj61L0NWvyPLy341UZ82zu">
<link rel="preload" href="https://kent-3.github.io/secret-leptos/secret-leptos-c6a3ab524ea5d406_bg.wasm" crossorigin=anonymous integrity="sha384-LzlNHMUhY9F3mcHxOzmlvoc0LELwlXHUHYxRSSVL3QfGSdwIjGr2EJ81ZlRYr4Bx" as="fetch" type="application/wasm"></head>
<link rel="modulepreload" href="https://kent-3.github.io/secret-leptos/secret-leptos-a6c6fd9b4d31a18d.js" crossorigin=anonymous integrity="sha384-jRERt5wpq7c3IgcgCviHwLicEDT33Y7dITe70HpmbZjptSQga3w3ljCc7NwcysZ8">
<link rel="preload" href="https://kent-3.github.io/secret-leptos/secret-leptos-a6c6fd9b4d31a18d_bg.wasm" crossorigin=anonymous integrity="sha384-W9KQIgECqP6qPQ4tWbUwSgCJKU12mU9U1I3L9GZgne6q6kTpzTtEHGiooHi1V754" as="fetch" type="application/wasm"></head>

<style>
.spinner {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ function __wbg_get_imports() {
wasm.__wbindgen_export_5(arg0, arg1 * 4, 4);
console.error(...v0);
};
imports.wbg.__wbg_remove_81fdfdc9088ee033 = function(arg0) {
getObject(arg0).remove();
};
imports.wbg.__wbg_preventDefault_c55d86c27b2dfa6e = function(arg0) {
getObject(arg0).preventDefault();
};
Expand Down Expand Up @@ -1192,9 +1195,6 @@ function __wbg_get_imports() {
const ret = result;
return ret;
};
imports.wbg.__wbg_remove_81fdfdc9088ee033 = function(arg0) {
getObject(arg0).remove();
};
imports.wbg.__wbg_createElement_5921e9eb06b9ec89 = function() { return handleError(function (arg0, arg1, arg2) {
const ret = getObject(arg0).createElement(getStringFromWasm0(arg1, arg2));
return addHeapObject(ret);
Expand Down Expand Up @@ -1257,16 +1257,16 @@ function __wbg_get_imports() {
imports.wbg.__wbg_alert_c1d5ffe256491b29 = function() { return handleError(function (arg0, arg1, arg2) {
getObject(arg0).alert(getStringFromWasm0(arg1, arg2));
}, arguments) };
imports.wbg.__wbindgen_closure_wrapper2646 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 177, __wbg_adapter_46);
imports.wbg.__wbindgen_closure_wrapper2632 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 173, __wbg_adapter_46);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper2652 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 391, __wbg_adapter_49);
imports.wbg.__wbindgen_closure_wrapper2638 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_49);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper4265 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 420, __wbg_adapter_49);
imports.wbg.__wbindgen_closure_wrapper4250 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 415, __wbg_adapter_49);
return addHeapObject(ret);
};

Expand Down
Binary file added dist/secret-leptos-a6c6fd9b4d31a18d_bg.wasm
Binary file not shown.
Binary file removed dist/secret-leptos-c6a3ab524ea5d406_bg.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pub enum Error {

#[error(transparent)]
KeplrError(#[from] ::keplr::Error),

#[error("Keplr is not enabled!")]
KeplrDisabled,
}

impl From<rsecret::Error> for Error {
Expand Down
88 changes: 51 additions & 37 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// #![allow(unused)]
#![allow(unused)]

// use codee::string::FromToStringCodec;
// use leptos_use::storage::use_local_storage;

use ::keplr::{keplr_sys, Keplr, KeyInfo};
use leptos::{
ev::MouseEvent,
html::{Dialog, Input},
logging::log,
prelude::*,
Expand Down Expand Up @@ -161,7 +162,7 @@ pub fn App() -> impl IntoView {

// Node references

// let dialog_ref = NodeRef::<Dialog>::new();
let options_dialog_ref = NodeRef::<Dialog>::new();

// Effects

Expand Down Expand Up @@ -191,9 +192,21 @@ pub fn App() -> impl IntoView {
}
};

// let disconnect_button = move || {
// view! { <button on:click=disable_keplr>Disconnect Wallet</button> }
// };
let toggle_options_menu = move |_| match options_dialog_ref.get() {
Some(dialog) => match dialog.open() {
false => {
let _ = dialog.show_modal();
}
true => dialog.close(),
},
None => {
let _ = window().alert_with_message("Something is wrong!");
}
};

let options_button = move || {
view! { <button on:click=toggle_options_menu>"Options"</button> }
};

let key_name = move || {
keplr
Expand All @@ -207,7 +220,7 @@ pub fn App() -> impl IntoView {
<Router>
<header>
<div class="flex justify-between items-center">
<h1>"Hello World"</h1>
<h1>"Secret Leptos"</h1>
// terrible, but it works...
<Show when=move || {
keplr.key_info.get().and_then(|foo| Some(foo.is_ok())).unwrap_or_default()
Expand All @@ -217,7 +230,7 @@ pub fn App() -> impl IntoView {
</p>
</Show>
<Show when=move || keplr.enabled.get() fallback=connect_button>
<OptionsMenu />
{options_button}
</Show>
</div>
<hr />
Expand All @@ -234,6 +247,7 @@ pub fn App() -> impl IntoView {
</Routes>
</main>
<LoadingModal when=enable_keplr_action.pending() message="Requesting Connection" />
<OptionsMenu dialog_ref=options_dialog_ref toggle_menu=toggle_options_menu />
</Router>
}
}
Expand All @@ -253,7 +267,7 @@ pub fn LoadingModal(when: Memo<bool>, #[prop(into)] message: String) -> impl Int
});

view! {
<dialog node_ref=dialog_ref class="flex items-center">
<dialog node_ref=dialog_ref class="absolute inset-0 flex items-center">
<div class="inline-flex items-center">
<Spinner2 size="h-8 w-8" />
<div class="font-bold">{message}</div>
Expand All @@ -263,8 +277,13 @@ pub fn LoadingModal(when: Memo<bool>, #[prop(into)] message: String) -> impl Int
}

#[component]
pub fn OptionsMenu() -> impl IntoView {
let dialog_ref = NodeRef::<Dialog>::new();
pub fn OptionsMenu(
dialog_ref: NodeRef<Dialog>,
toggle_menu: impl Fn(MouseEvent) + 'static,
) -> impl IntoView {
info!("rendering <OptionsMenu/>");

// let dialog_ref = NodeRef::<Dialog>::new();
let input_element = NodeRef::<Input>::new();

let keplr = use_context::<KeplrSignals>().expect("keplr signals context missing!");
Expand All @@ -276,18 +295,6 @@ pub fn OptionsMenu() -> impl IntoView {
// keplr.key_info.set(None);
};

let toggle_options_menu = move |_| match dialog_ref.get() {
Some(dialog) => match dialog.open() {
false => {
let _ = dialog.show_modal();
}
true => dialog.close(),
},
None => {
let _ = window().alert_with_message("Something is wrong!");
}
};

let on_submit = move |ev: leptos::ev::SubmitEvent| {
// stop the page from reloading!
ev.prevent_default();
Expand All @@ -309,9 +316,8 @@ pub fn OptionsMenu() -> impl IntoView {
};

view! {
<button on:click=toggle_options_menu>"Options"</button>
<dialog node_ref=dialog_ref class="flex flex-col gap-4 items-center">
<button on:click=toggle_options_menu class="self-stretch">
<dialog node_ref=dialog_ref class="absolute inset-0 flex flex-col gap-4 items-center">
<button on:click=toggle_menu class="self-stretch">
"Close Menu"
</button>
<form class="flex gap-4" on:submit=on_submit>
Expand Down Expand Up @@ -362,9 +368,8 @@ fn Home() -> impl IntoView {
move |_| {
let tokens = token_map.clone();
SendWrapper::new(async move {
let enabled = keplr.enabled.get_untracked();
if enabled {
debug!("doing viewing_keys thing");
if keplr.enabled.get_untracked() {
debug!("gathering viewing_keys");
let mut keys = Vec::new();
for (_, token) in tokens.iter() {
let key_result =
Expand Down Expand Up @@ -393,8 +398,15 @@ fn Home() -> impl IntoView {
.await
.into_iter()
.map(|(name, address, key)| {
debug!("{name}");
view! { <li>{name} ", " {address} ", " {key}</li> }
view! {
<li>
<strong>{name}</strong>
", "
{address}
": "
{key}
</li>
}
})
.collect_view()
})
Expand Down Expand Up @@ -451,13 +463,11 @@ fn Home() -> impl IntoView {

view! {
<Show when=move || keplr.enabled.get() fallback=|| view! { <p>Nothing to see here</p> }>
<pre>{move || format!("{:#?}", keplr.key_info.get())}</pre>
<Show when=move || user_balance.get().is_some() fallback=|| ()>
{move || user_balance.get()}
</Show>
<Suspense>
<ul>{viewing_keys_list}</ul>
</Suspense>
<pre>
{move || {
format!("{:#?}", keplr.key_info.get().and_then(Result::ok).unwrap_or_default())
}}
</pre>
// the fallback receives a signal containing current errors
<ErrorBoundary fallback=|errors| {
view! {
Expand All @@ -479,6 +489,10 @@ fn Home() -> impl IntoView {
<p>{move || token_info.get()}</p>
<p>{move || user_balance.get()}</p>
</ErrorBoundary>
<Suspense>
<h2>"Viewing Keys"</h2>
<ul class="overflow-x-auto">{viewing_keys_list}</ul>
</Suspense>
</Show>
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl AsRef<HashMap<String, ContractInfo>> for TokenMap {
#[derive(Copy, Clone)]
pub struct KeplrSignals {
pub enabled: RwSignal<bool>,
pub key_info: Resource<Result<KeyInfo, Error>, JsonSerdeCodec>, // pub key_info: RwSignal<Option<KeyInfo>>,
pub key_info: Resource<Result<KeyInfo, Error>, JsonSerdeCodec>,
// pub key_info: RwSignal<Option<KeyInfo>>,
}

impl KeplrSignals {
Expand All @@ -74,11 +75,10 @@ impl KeplrSignals {
let key_info = Resource::new(enabled, move |enabled| {
SendWrapper::new(async move {
if enabled {
debug!("happy path");
debug!("keplr is enabled! getting key_info");
Keplr::get_key(CHAIN_ID).await.map_err(Into::into)
} else {
debug!("sad path");
Err(Error::generic("sad"))
Err(Error::KeplrDisabled)
}
})
});
Expand Down

0 comments on commit 3180e0a

Please sign in to comment.