From 74e4d85d20a151d8c4a3ca394a41c1ee42dabf30 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 17 Oct 2024 23:40:41 +0200 Subject: [PATCH] to fix error on refresh inspect and auth page --- packages/svelte/package.json | 1 + .../svelte/src/lib/components/Footer.svelte | 9 --- packages/svelte/src/lib/gun/avatar.ts | 7 +- packages/svelte/src/lib/gun/relay.ts | 4 +- packages/svelte/src/routes/+page.svelte | 2 +- packages/svelte/src/routes/docs/+page.svelte | 66 +++++++++---------- .../svelte/src/routes/inspect/+page.svelte | 31 +++++---- packages/svelte/vite.config.js | 7 +- yarn.lock | 11 ++++ 9 files changed, 76 insertions(+), 62 deletions(-) diff --git a/packages/svelte/package.json b/packages/svelte/package.json index 8944559..7ed2757 100644 --- a/packages/svelte/package.json +++ b/packages/svelte/package.json @@ -82,6 +82,7 @@ "tiny-secp256k1": "^2.2.3", "url-regex": "^5.0.0", "viem": "^2.21.7", + "vis-data": "^7.1.9", "vis-network": "^9.1.9", "vite-plugin-svelte": "^3.0.1" } diff --git a/packages/svelte/src/lib/components/Footer.svelte b/packages/svelte/src/lib/components/Footer.svelte index c235ea1..5788037 100644 --- a/packages/svelte/src/lib/components/Footer.svelte +++ b/packages/svelte/src/lib/components/Footer.svelte @@ -52,15 +52,6 @@ > Scobru - at - - Plancia - ยท
diff --git a/packages/svelte/src/lib/gun/avatar.ts b/packages/svelte/src/lib/gun/avatar.ts index ce39d3f..2a79ae8 100644 --- a/packages/svelte/src/lib/gun/avatar.ts +++ b/packages/svelte/src/lib/gun/avatar.ts @@ -3,6 +3,7 @@ import { useGun } from "./gun"; import { useUser } from "./user"; import SEA from "gun/sea"; import { gunAvatar } from "gun-avatar" +import { browser } from '$app/environment'; export function useAvatar(pub: string, size: number) { const gun = useGun(); @@ -55,8 +56,12 @@ export function useAvatar(pub: string, size: number) { }); }; + const setDefaultAvatar = () => { - avatar.set(gunAvatar({ pub, size })); + const avatarUrl = gunAvatar({ pub, size }); + + avatar.set(avatarUrl); + }; gun diff --git a/packages/svelte/src/lib/gun/relay.ts b/packages/svelte/src/lib/gun/relay.ts index d93e3e9..0c17429 100644 --- a/packages/svelte/src/lib/gun/relay.ts +++ b/packages/svelte/src/lib/gun/relay.ts @@ -4,7 +4,7 @@ * @group Database */ -import { useGun } from "./gun"; +import { useGun } from "$lib/gun/gun"; import { derived, writable, get } from "svelte/store"; import { browser } from "$app/environment"; import ms from "ms"; @@ -101,6 +101,7 @@ relay.subscribe($relay => { * @returns {{relay: Writable, setPeer: (url: string) => void, resetPeer: () => void}} */ export function useRelay() { + if (browser) { const gun = useGun(); const $relay = get(relay); @@ -116,6 +117,7 @@ export function useRelay() { } }); } +} return { relay, setPeer: relay.setPeer, resetPeer: relay.resetPeer }; } \ No newline at end of file diff --git a/packages/svelte/src/routes/+page.svelte b/packages/svelte/src/routes/+page.svelte index d714991..5581b04 100644 --- a/packages/svelte/src/routes/+page.svelte +++ b/packages/svelte/src/routes/+page.svelte @@ -212,7 +212,7 @@ Learn More About Becoming a RelayLearn More About Becoming a Relay (soon)
diff --git a/packages/svelte/src/routes/docs/+page.svelte b/packages/svelte/src/routes/docs/+page.svelte index ae893ed..be3eee5 100644 --- a/packages/svelte/src/routes/docs/+page.svelte +++ b/packages/svelte/src/routes/docs/+page.svelte @@ -26,20 +26,18 @@ -
-
-

Getting Started

+
+
+

Getting Started


 <script>
-  import { useGun, useUser } from '@your-org/se-2gun';
   import { createAccount } from "@byteatatime/wagmi-svelte";
 
   const gun = useGun(); // Initialize GunDB
   const { user } = useUser()
 
   
-  
+
-

Authentication

-

SE-2Gun provides Ethereum-based authentication:

+

Authentication

+

SE-2Gun provides Ethereum-based authentication:


 import { signIn, login, logout } from "$lib/gun/auth";
@@ -97,10 +95,10 @@
   
-
+
-

User Profile Management

-

Manage user profiles with these functions:

+

User Profile Management

+

Manage user profiles with these functions:


 import { loadUserProfile, saveUserProfile, addProfileField }
 
   
-  
+
-

SHINE (Secure Hash Integrity Network Ethereum)

-

Use SHINE for data verification on the blockchain:

+

SHINE (Secure Hash Integrity Network Ethereum)

+

Use SHINE for data verification on the blockchain:


 async function saveMessage() {
   const gunInstance = 
 
   
-  
+
-

Components

+

Components

-

AccountProfile.svelte

-

+

AccountProfile.svelte

+

Displays account information including the public key, color, pulse, blink status, and last login.


@@ -191,8 +189,8 @@
           >={userPublicKey} />
       
-

AccountAvatar.svelte

-

Shows the user's avatar with options to upload a new one if it's the current user's profile.

+

AccountAvatar.svelte

+

Shows the user's avatar with options to upload a new one if it's the current user's profile.


 import AccountAvatar from={2} />
       
-

ProfileDisplay.svelte

-

+

ProfileDisplay.svelte

+

Allows viewing and editing user profile information with dynamic addition and removal of fields.


@@ -216,8 +214,8 @@
 <ProfileDisplay />
       
-

Usage Example

-

Here's how you might use these components together on a user profile page:

+

Usage Example

+

Here's how you might use these components together on a user profile page:


 <script>
 import { useUser } div class="w-full md:w-1/3">
-    <AccountAvatar pubAccountAvatar pub={$user.pub} size={128} />
-    <AccountProfile pubAccountProfile pub={$user.pub} />
   </div>
   <div class="w-full md:w-2/3">
-    <ProfileDisplay />
+    <ProfileDisplay />
   </div>
 </div>
       
@@ -260,12 +258,12 @@
-
+
-

Additional Functions

+

Additional Functions

-

User Functions

-
    +

    User Functions

    +
    • selectedUser: A writable store that holds the currently selected user's public key.
    • userPub: A derived store that always contains the current user's public key.
    • @@ -287,8 +285,8 @@ store.
    -

    Account Functions

    -
      +

      Account Functions

      +
      • useAccount(pubKey: string): Sets up and manages an account for the given public key, including profile data and online status. diff --git a/packages/svelte/src/routes/inspect/+page.svelte b/packages/svelte/src/routes/inspect/+page.svelte index d24df8a..a5cf7b8 100644 --- a/packages/svelte/src/routes/inspect/+page.svelte +++ b/packages/svelte/src/routes/inspect/+page.svelte @@ -3,11 +3,11 @@ import "gun/sea"; import { onMount } from "svelte"; import { get, writable } from "svelte/store"; - import { currentUser, gun } from "$lib/stores"; + import { gun } from "$lib/stores"; import { Network } from "vis-network/standalone"; - import type { IGunInstance } from "gun"; + import { browser } from "$app/environment"; - let gunInstance: IGunInstance | null = null; + let gunInstance: any; let nodeData = writable({}); let nodePath = writable(""); let errorMessage = ""; @@ -21,11 +21,11 @@ function initGun() { if (get(gun) === null) { - gunInstance = gun.set(Gun(get(customRelay))); + gunInstance = gun.set(new Gun(get(customRelay))); } else { gunInstance = get(gun); } - gunInstance.on("hi", peer => { + gunInstance.on("hi", (peer: any) => { console.log("Connected to peer:", peer); }); initNetwork(); @@ -54,14 +54,18 @@ stabilization: { iterations: 150 }, }, }; - network = new Network(container, data, options); - network.on("click", function (params) { - if (params.nodes.length > 0) { - const nodeId = params.nodes[0]; - nodePath.set(nodeId); // Aggiorna l'input box - loadNodeData(nodeId); // Carica i dati del nodo - } - }); + if (browser) { + network = new Network(container, data, options); + } + if (network) { + network.on("click", function (params) { + if (params.nodes.length > 0) { + const nodeId = params.nodes[0]; + nodePath.set(nodeId); // Aggiorna l'input box + loadNodeData(nodeId); // Carica i dati del nodo + } + }); + } } async function loadNodeData(path = $nodePath) { @@ -183,7 +187,6 @@ Current Relay: {$customRelay}