From f902e6fafa4f60c3ebdf8d563143217bef10ce9b Mon Sep 17 00:00:00 2001 From: scobru Date: Tue, 15 Oct 2024 23:56:55 +0200 Subject: [PATCH] stable --- packages/svelte/src/app.pcss | 34 -- .../src/lib/components/ScaffoldEthApp.svelte | 6 +- .../gun/profile/ProfileDisplay.svelte | 99 +++- packages/svelte/src/lib/gun/user.ts | 77 +++- packages/svelte/src/routes/+page.svelte | 239 ++++++---- packages/svelte/src/routes/auth/+page.svelte | 44 +- packages/svelte/src/routes/docs/+page.svelte | 428 +++++++++++++----- .../svelte/src/routes/inspect/+page.svelte | 26 +- packages/svelte/src/routes/shine/+page.svelte | 81 +++- packages/svelte/tailwind.config.cjs | 2 +- 10 files changed, 726 insertions(+), 310 deletions(-) diff --git a/packages/svelte/src/app.pcss b/packages/svelte/src/app.pcss index 15717c8..90bc663 100644 --- a/packages/svelte/src/app.pcss +++ b/packages/svelte/src/app.pcss @@ -8,38 +8,4 @@ background: oklch(var(--b2)); } -p { - margin: 1rem 0; -} - -:root { - --primary-color: #4a90e2; - --secondary-color: #50e3c2; - --background-color: #f5f7fa; - --text-color: #333; -} - -body { - background-color: var(--background-color); - color: var(--text-color); -} -h1, -h2, -h3, -h4, -h5, - - -@keyframes fadeIn { - from { - opacity: 0; - } - to { - opacity: 1; - } -} - -.container { - animation: fadeIn 1s ease-in-out; -} diff --git a/packages/svelte/src/lib/components/ScaffoldEthApp.svelte b/packages/svelte/src/lib/components/ScaffoldEthApp.svelte index 24d6015..3b27d3d 100644 --- a/packages/svelte/src/lib/components/ScaffoldEthApp.svelte +++ b/packages/svelte/src/lib/components/ScaffoldEthApp.svelte @@ -28,10 +28,10 @@ }); -
+
-
+
-
+
\ No newline at end of file diff --git a/packages/svelte/src/lib/components/gun/profile/ProfileDisplay.svelte b/packages/svelte/src/lib/components/gun/profile/ProfileDisplay.svelte index 91bf010..c9c4677 100644 --- a/packages/svelte/src/lib/components/gun/profile/ProfileDisplay.svelte +++ b/packages/svelte/src/lib/components/gun/profile/ProfileDisplay.svelte @@ -38,30 +38,29 @@ }); -
-

Profile

- +
+

Profile

{#each profileFields as [key, value]} -
-

{key}

+
+

{key}

{#if !editMode[key]} -
+
{value}
{:else} -
+
{/each} -
+
+ \ No newline at end of file diff --git a/packages/svelte/src/lib/gun/user.ts b/packages/svelte/src/lib/gun/user.ts index ccc48ec..bc39ed0 100644 --- a/packages/svelte/src/lib/gun/user.ts +++ b/packages/svelte/src/lib/gun/user.ts @@ -168,17 +168,28 @@ function init() { gun.user().get("epub").put(get(user).is.epub); - gun.user().get("pulse").on((d) => { - user.update(u => ({ ...u, blink: !u.blink, pulse: d })); - }); + gun + .user() + .get("pulse") + .on(d => { + user.update(u => ({ ...u, blink: !u.blink, pulse: d })); + }); - gun.user().get("safe").map().on((d, k) => { - user.update(u => ({ ...u, safe: { ...u.safe, [k]: d } })); - }); + gun + .user() + .get("safe") + .map() + .on((d, k) => { + user.update(u => ({ ...u, safe: { ...u.safe, [k]: d } })); + }); - gun.user().get("profile").get("name").on((d) => { - user.update(u => ({ ...u, name: d })); - }); + gun + .user() + .get("profile") + .get("name") + .on(d => { + user.update(u => ({ ...u, name: d })); + }); user.update(u => ({ ...u, pulser, initiated: true })); } @@ -251,20 +262,48 @@ export function loadUserProfile() { const userStore = get(user); if (userStore?.is && userStore?.is?.pub) { - gun.user().get("profile").map().on((data, key) => { - if (data !== null && data !== undefined && key !== "_" && key !== "#" && key !== ">") { + gun + .user() + .get("profile") + .map() + .on((data, key) => { + if (data !== null && data !== undefined && key !== "_" && key !== "#" && key !== ">") { + user.update(u => ({ + ...u, + profile: { ...u.profile, [key]: data }, + })); + } + }); + } +} + +export function addProfileField(title: string, initialValue: string = "") { + const gun = useGun(); + const userStore = get(user); + + // Verifica se il campo esiste già nel profilo + if (userStore.profile && userStore.profile.hasOwnProperty(title)) { + console.warn(`Il campo '${title}' esiste già nel profilo. Non verrà aggiunto.`); + return; + } + + // Se il campo non esiste, lo aggiungiamo + gun + .user() + .get("profile") + .get(title) + .put(initialValue, ack => { + if (ack.err) { + console.error(`Errore nell'aggiunta del campo '${title}':`, ack.err); + } else { + console.log(`Campo '${title}' aggiunto con successo al profilo`); + // Aggiorna lo store locale user.update(u => ({ ...u, - profile: { ...u.profile, [key]: data } + profile: { ...u.profile, [title]: initialValue }, })); } }); - } -} - -export function addProfileField(title: string) { - const gun = useGun(); - gun.user().get("profile").get(title).put(""); } export function updateProfileField(field: string, value: string): Promise { @@ -339,4 +378,4 @@ export function saveUserProfile(profile: { [s: string]: unknown } | ArrayLike ({ ...u, profile })); console.log("Store utente aggiornato con l'intero profilo"); -} \ No newline at end of file +} diff --git a/packages/svelte/src/routes/+page.svelte b/packages/svelte/src/routes/+page.svelte index 1edf26e..d714991 100644 --- a/packages/svelte/src/routes/+page.svelte +++ b/packages/svelte/src/routes/+page.svelte @@ -4,16 +4,14 @@ import { Icon, DocumentCheck } from "svelte-hero-icons"; const { address } = $derived.by(createAccount()); import logo from "$lib/assets/logo.svg"; - -
+

Welcome to Scaffold-ETH2Gun - - +

Connected Address:

@@ -21,7 +19,7 @@
-
+

Live on Optimism Sepolia!

@@ -44,7 +42,7 @@
-
+ -
-
-
-

What is SE-2Gun?

-

- SE-2Gun is a cutting-edge decentralized application (dApp) built with Svelte and GunDB, seamlessly integrated with - Ethereum for robust authentication and data encryption. This project aims to provide a fully decentralized - platform where users can create unique pair and store into GunDB. By leveraging Ethereum signatures, SE-2Gun - ensures data integrity and privacy through advanced encryption techniques. -

-
+
-
-
-
-
-

Why SE-2Gun?

-
    -

    - Fully Decentralized: SE-2Gun is designed to be a completely decentralized application, - eliminating the need for centralized servers and ensuring that users have full control over their data. +

    + +
    +
    +

    Project Origin and Documentation

    +

    + SE-2Gun is based on Scaffold-ETH, a framework for rapid development of decentralized applications (dApps) on + Ethereum.

    -

    - Efficient Data Storage: By using GunDB, SE-2Gun stores only the necessary data on - the blockchain, optimizing storage costs and improving performance. +

    + The project integrates GunDB for decentralized data management and Wagmi for Ethereum interaction.

    -

    - Ethereum-Based Encryption: SE-2Gun generates cryptographic pairs using Ethereum addresses, - providing a secure and reliable method for data encryption and user authentication. +

    + +
    +
    +
    +

    What is SE-2Gun?

    +

    + SE-2Gun is a cutting-edge decentralized application (dApp) built with Svelte and GunDB, seamlessly integrated + with Ethereum for robust authentication and data encryption. This project aims to provide a fully decentralized + platform where users can create unique pair and store into GunDB. By leveraging Ethereum signatures, SE-2Gun + ensures data integrity and privacy through advanced encryption techniques.

    -
-
-
-
-
-

Technology Stack

-
    -

    GunDB: A decentralized database for secure data storage and retrieval.

    -

    - Scaffold-ETH: A development framework that combines Svelte and Hardhat for building - and deploying Ethereum smart contracts. -

    -

    - Svelte: A modern JavaScript framework for building fast and reactive user interfaces. -

    -

    - Hardhat: A development environment for Ethereum software, allowing for testing, deployment, - and debugging of smart contracts. -

    -
+
+
+
+

Why SE-2Gun?

+
    +

    + Fully Decentralized: SE-2Gun is designed to be a completely decentralized application, + eliminating the need for centralized servers and ensuring that users have full control over their data. +

    +

    + Efficient Data Storage: By using GunDB, SE-2Gun stores only the necessary data on + the blockchain, optimizing storage costs and improving performance. +

    +

    + Ethereum-Based Encryption: SE-2Gun generates cryptographic pairs using Ethereum + addresses, providing a secure and reliable method for data encryption and user authentication. +

    +
+
+
+
+
+
+
+

Technology Stack

+
    +

    GunDB: A decentralized database for secure data storage and retrieval.

    +

    + Scaffold-ETH: A development framework that combines Svelte and Hardhat for building + and deploying Ethereum smart contracts. +

    +

    + Svelte: A modern JavaScript framework for building fast and reactive user interfaces. +

    +

    + Hardhat: A development environment for Ethereum software, allowing for testing, + deployment, and debugging of smart contracts. +

    +
-
-
-
-

Contribute as a Relay

-

- SE-2Gun relies on a network of relays to ensure data availability and resilience. By becoming a relay, you can - play a crucial role in maintaining the decentralized nature of the network. Here's how you can contribute: -

-
    -

    - Set Up a Node: Install and configure a GunDB node on your server or personal computer. -

    -

    - Connect to the Network: Use the provided configuration to connect your node to the - SE-2Gun network. -

    -

    - Maintain Uptime: Ensure your node remains online to contribute to the network's reliability. -

    -

    - Monitor Performance: Keep an eye on your node's performance and resource usage. +

    +
    +
    +

    Contribute as a Relay

    +

    + SE-2Gun relies on a network of relays to ensure data availability and resilience. By becoming a relay, you can + play a crucial role in maintaining the decentralized nature of the network. Here's how you can contribute:

    -
-

- By running a relay, you help distribute data across the network, improving access speeds and ensuring data - persistence. Your contribution strengthens the decentralized infrastructure that powers SE-2Gun. -

- +
    +

    + Set Up a Node: Install and configure a GunDB node on your server or personal computer. +

    +

    + Connect to the Network: Use the provided configuration to connect your node to the + SE-2Gun network. +

    +

    + Maintain Uptime: Ensure your node remains online to contribute to the network's + reliability. +

    +

    + Monitor Performance: Keep an eye on your node's performance and resource usage. +

    +
+

+ By running a relay, you help distribute data across the network, improving access speeds and ensuring data + persistence. Your contribution strengthens the decentralized infrastructure that powers SE-2Gun. +

+
diff --git a/packages/svelte/src/routes/auth/+page.svelte b/packages/svelte/src/routes/auth/+page.svelte index e056b98..4a863c7 100644 --- a/packages/svelte/src/routes/auth/+page.svelte +++ b/packages/svelte/src/routes/auth/+page.svelte @@ -40,7 +40,7 @@ if (result) { setErrorMessage(result); } else { - notification.success("Registrazione completata con successo!"); + notification.success("Registration completed successfully!"); loadUserProfile(); } } @@ -50,7 +50,7 @@ if (result) { setErrorMessage(result); } else { - notification.success("Accesso effettuato con successo!"); + notification.success("Login successful!"); loadUserProfile(); } } @@ -58,7 +58,7 @@ function handleLogout() { logout(); userPair = null; - notification.info("Logout effettuato"); + notification.info("Logout successful!"); } async function handleViewPair() { @@ -66,28 +66,28 @@ const account = getAccount(wagmiConfig); if (!account.isConnected) { - setErrorMessage("Per favore connetti il tuo portafoglio Ethereum"); + setErrorMessage("Please connect your Ethereum wallet"); return; } try { const signature = await gunInstance.createSignature("Accesso a GunDB con Ethereum"); if (!signature) { - setErrorMessage("Errore durante la firma del messaggio"); + setErrorMessage("Error signing message"); return; } userPair = await gunInstance.getAndDecryptPair(account.address, signature); if (!userPair) { - setErrorMessage("Impossibile recuperare i dati dell'utente"); + setErrorMessage("Unable to retrieve user data"); } } catch (error) { - setErrorMessage("Errore durante il recupero del pair: " + error.message); + setErrorMessage("Error retrieving pair: " + error.message); } } -
+
{#if errorMessage}