Skip to content

Commit

Permalink
Removing external illuminodes crates from workspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
42pupusas committed Dec 8, 2024
1 parent c2f71a6 commit ecc4968
Show file tree
Hide file tree
Showing 28 changed files with 377 additions and 297 deletions.
14 changes: 4 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ resolver = "2"
fuente = { path = "fuente" }

# ILLUMINODES stack
nostr-minions = "0.1.1"
nostr-minions = "0.1.4"
bright-lightning = "0.1.1"
nostro2 = "0.1.35"
nostro2 = "0.2.2"

anyhow = "1.0.94"
async-channel = "2.2.0"
Expand Down
2 changes: 1 addition & 1 deletion admin/Trunk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
watch = ["../fuente", "src", "index.html", "styles"]

[serve]
port = 7200
port = 8003
open = false
104 changes: 104 additions & 0 deletions admin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link data-trunk rel="tailwind-css" href="./styles/output.css">
<link data-trunk rel="copy-dir" href="../public">
<link data-trunk rel="copy-file" href="manifest.json">
<link data-trunk rel="copy-file" href="serviceWorker.js">

<title>Fuente.ai Admin</title>
<link rel="manifest" href="manifest.json">
<link rel="icon" href="/public/assets/img/logo.png" />

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>

</head>

<body href="/">
<div id="spinner" class="fixed z-50 flex flex-col gap-4 items-center justify-center w-dvw h-dvh bg-white">
<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<style>
.spinner_HIK5 {
transform-origin: center;
animation: spinner_XVY9 1s cubic-bezier(0.36, .6, .31, 1) infinite
}

@keyframes spinner_XVY9 {
50% {
transform: rotate(180deg)
}

100% {
transform: rotate(360deg)
}
}
</style>
<circle cx="12" cy="12" r="3" />
<g class="spinner_HIK5">
<circle cx="4" cy="12" r="3" />
<circle cx="20" cy="12" r="3" />
</g>
</svg>
</div>
</body>

<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker
.register('/service-worker.js')
.then((registration) => {
console.log('Service Worker registered with scope: ', registration.scope);
})
.catch((error) => {
console.error('Service Worker registration failed: ', error);
});
});
}
window.addEventListener('beforeunload', (event) => {
// This will trigger before the page is unloaded or refreshed.
// You can intercept it and reroute to `/`.
if (window.location.pathname !== '/') {
event.preventDefault(); // Prevent default refresh or unload action
window.location.href = '/'; // Redirect to the root (index.html)
}
});
</script>
<script>

// Function to hide the spinner
function hideSpinner() {
// completely remove the spinener from the dom
var el = document.getElementById('spinner');
if (el) {
el.remove();
}
}

// // Show the spinner when the page starts loading
// showSpinner();

// Polling function to check if the WASM module is loaded
function checkWasmLoaded() {
if (window.hasOwnProperty('wasmBindings')) {
// WASM module has been loaded and bindings are available
hideSpinner(); // Hide the spinner once the WASM module is ready
} else {
// Continue polling every 200ms until it's loaded
setTimeout(checkWasmLoaded, 200);
}
}

// Start polling for WASM readiness
checkWasmLoaded();
</script>

</html>
2 changes: 1 addition & 1 deletion admin/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn login_check(props: &ChildrenProps) -> Html {
if !server_ctx.is_loaded() {
return html! {<LoadingScreen />};
}
if !ADMIN_WHITELIST.contains(&keys.unwrap().get_public_key().as_str()) {
if !ADMIN_WHITELIST.contains(&keys.unwrap().public_key().as_str()) {
return html! {
<div class="flex justify-center items-center flex-1">
<h2 class="text-2xl px-8 py-4 font-bold text-center">{"You are not authorized to access this page"}</h2>
Expand Down
101 changes: 49 additions & 52 deletions admin/src/config_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ use fuente::models::{
NOSTR_KIND_SERVER_CONFIG, TEST_PUB_KEY,
};
use nostr_minions::{key_manager::NostrIdStore, relay_pool::NostrProps};
use nostro2::{notes::SignedNote, relays::EndOfSubscriptionEvent, userkeys::UserKeys};
use nostro2::{
keypair::NostrKeypair,
notes::{NostrNote, NostrTag},
relays::EndOfSubscriptionEvent,
};
use yew::prelude::*;

#[derive(Clone, Debug, PartialEq)]
pub struct ServerConfigs {
admin_whitelist: Vec<String>,
commerce_whitelist: Vec<String>,
commerces: Vec<SignedNote>,
couriers: Vec<SignedNote>,
commerces: Vec<NostrNote>,
couriers: Vec<NostrNote>,
couriers_whitelist: Vec<String>,
consumer_blacklist: Vec<String>,
user_registrations: Vec<String>,
Expand All @@ -29,28 +33,28 @@ impl ServerConfigs {
pub fn set_exchange_rate(&mut self, rate: f64) {
self.exchange_rate = rate;
}
pub fn get_unregistered_commerces(&self) -> Vec<SignedNote> {
pub fn get_unregistered_commerces(&self) -> Vec<NostrNote> {
let mut unregistered_users = vec![];
for note in self.commerces.iter() {
if !self.commerce_whitelist.contains(&note.get_pubkey()) {
if !self.commerce_whitelist.contains(&note.pubkey) {
unregistered_users.push(note.clone());
}
}
unregistered_users
}
pub fn get_whitelisted_commerces(&self) -> Vec<SignedNote> {
pub fn get_whitelisted_commerces(&self) -> Vec<NostrNote> {
let mut commerces = vec![];
for note in self.commerces.iter() {
if self.commerce_whitelist.contains(&note.get_pubkey()) {
if self.commerce_whitelist.contains(&note.pubkey) {
commerces.push(note.clone());
}
}
commerces
}
pub fn get_whitelisted_couriers(&self) -> Vec<SignedNote> {
pub fn get_whitelisted_couriers(&self) -> Vec<NostrNote> {
let mut couriers = vec![];
for note in self.couriers.iter() {
if self.couriers_whitelist.contains(&note.get_pubkey()) {
if self.couriers_whitelist.contains(&note.pubkey) {
couriers.push(note.clone());
}
}
Expand Down Expand Up @@ -90,8 +94,8 @@ pub enum ServerConfigsAction {
UpdateExchangeRate(f64),
UpdateCommerceWhitelist(Vec<String>),
UpdateCouriersWhitelist(Vec<String>),
AddCommerce(SignedNote),
AddCourier(SignedNote),
AddCommerce(NostrNote),
AddCourier(NostrNote),
}

impl Reducible for ServerConfigs {
Expand Down Expand Up @@ -121,17 +125,13 @@ impl Reducible for ServerConfigs {
}
ServerConfigsAction::AddCommerce(note) => {
let mut new_state = (*self).clone();
new_state
.commerces
.retain(|n| n.get_pubkey() != note.get_pubkey());
new_state.commerces.retain(|n| n.pubkey != note.pubkey);
new_state.commerces.push(note);
Rc::new(new_state)
}
ServerConfigsAction::AddCourier(note) => {
let mut new_state = (*self).clone();
new_state
.couriers
.retain(|n| n.get_pubkey() != note.get_pubkey());
new_state.couriers.retain(|n| n.pubkey != note.pubkey);
new_state.couriers.push(note);
Rc::new(new_state)
}
Expand Down Expand Up @@ -194,60 +194,57 @@ pub fn key_handler(props: &ServerConfigsChildren) -> Html {
let ctx_clone = ctx.clone();
use_effect_with(relay_ctx.unique_notes.clone(), move |notes| {
let driver_hub_key =
UserKeys::new(DRIVER_HUB_PRIV_KEY).expect("Failed to create user keys");
NostrKeypair::new(DRIVER_HUB_PRIV_KEY).expect("Failed to create user keys");
if let (Some(note), Some(_key_clone)) = (notes.last(), key_clone.get_nostr_key()) {
if note.get_kind() == NOSTR_KIND_COMMERCE_PROFILE {
if note.kind == NOSTR_KIND_COMMERCE_PROFILE {
if let Ok(_) = CommerceProfile::try_from(note.clone()) {
ctx_clone.dispatch(ServerConfigsAction::AddCommerce(note.clone()));
}
}
if note.get_kind() == NOSTR_KIND_CONSUMER_GIFTWRAP {
if note.kind == NOSTR_KIND_CONSUMER_GIFTWRAP {
gloo::console::log!("Driver profile");
let cleartext = driver_hub_key
.decrypt_nip_04_content(&note)
.expect("Failed to decrypt");
let giftwrapped_note = SignedNote::try_from(cleartext).expect("Failed to parse");
let giftwrapped_note = NostrNote::try_from(cleartext).expect("Failed to parse");

if let Ok(_) = DriverProfile::try_from(giftwrapped_note.clone()) {
ctx_clone.dispatch(ServerConfigsAction::AddCourier(note.clone()));
gloo::console::log!("Courier added");
}
}
if note.get_kind() == NOSTR_KIND_SERVER_CONFIG {
if let Some(conf_type_tags) = note.get_tags_by_id("d") {
if let Some(conf_type_str) = conf_type_tags.get(2) {
let conf_type = AdminConfigurationType::try_from(conf_type_str.as_str())
.expect("Failed to parse conf type");
match conf_type {
AdminConfigurationType::ExchangeRate => {
if let Ok(rate) = note.get_content().parse::<f64>() {
ctx_clone
.dispatch(ServerConfigsAction::UpdateExchangeRate(rate));
gloo::console::log!("Exchange rate updated");
}
if note.kind == NOSTR_KIND_SERVER_CONFIG {
if let Some(conf_type_str) = note.tags.find_tags(NostrTag::Parameterized).get(2) {
let conf_type = AdminConfigurationType::try_from(conf_type_str.as_str())
.expect("Failed to parse conf type");
match conf_type {
AdminConfigurationType::ExchangeRate => {
if let Ok(rate) = note.content.parse::<f64>() {
ctx_clone.dispatch(ServerConfigsAction::UpdateExchangeRate(rate));
gloo::console::log!("Exchange rate updated");
}
AdminConfigurationType::CommerceWhitelist => {
if let Ok(whitelist) =
serde_json::from_str::<Vec<String>>(&note.get_content())
{
ctx_clone.dispatch(
ServerConfigsAction::UpdateCommerceWhitelist(whitelist),
);
gloo::console::log!("Commerce whitelist updated");
}
}
AdminConfigurationType::CommerceWhitelist => {
if let Ok(whitelist) =
serde_json::from_str::<Vec<String>>(&note.content)
{
ctx_clone.dispatch(ServerConfigsAction::UpdateCommerceWhitelist(
whitelist,
));
gloo::console::log!("Commerce whitelist updated");
}
AdminConfigurationType::CourierWhitelist => {
if let Ok(whitelist) =
serde_json::from_str::<Vec<String>>(&note.get_content())
{
ctx_clone.dispatch(
ServerConfigsAction::UpdateCouriersWhitelist(whitelist),
);
gloo::console::log!("Courier whitelist updated");
}
}
AdminConfigurationType::CourierWhitelist => {
if let Ok(whitelist) =
serde_json::from_str::<Vec<String>>(&note.content)
{
ctx_clone.dispatch(ServerConfigsAction::UpdateCouriersWhitelist(
whitelist,
));
gloo::console::log!("Courier whitelist updated");
}
_ => {}
}
_ => {}
}
}
}
Expand Down
Loading

0 comments on commit ecc4968

Please sign in to comment.