Skip to content

Commit

Permalink
to fix error on refresh inspect and auth page
Browse files Browse the repository at this point in the history
  • Loading branch information
scobru committed Oct 17, 2024
1 parent acce2ac commit 74e4d85
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 62 deletions.
1 change: 1 addition & 0 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
9 changes: 0 additions & 9 deletions packages/svelte/src/lib/components/Footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@
>
<span class="link">Scobru</span>
</a>
at
<a
class="flex items-center justify-center gap-1"
href="https://github.com/plancia/"
target="_blank"
rel="noreferrer"
>
<span class="link">Plancia</span>
</a>
</div>
<span>·</span>
<div class="text-center">
Expand Down
7 changes: 6 additions & 1 deletion packages/svelte/src/lib/gun/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/svelte/src/lib/gun/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -101,6 +101,7 @@ relay.subscribe($relay => {
* @returns {{relay: Writable<Relay>, setPeer: (url: string) => void, resetPeer: () => void}}
*/
export function useRelay() {
if (browser) {
const gun = useGun();
const $relay = get(relay);

Expand All @@ -116,6 +117,7 @@ export function useRelay() {
}
});
}
}

return { relay, setPeer: relay.setPeer, resetPeer: relay.resetPeer };
}
2 changes: 1 addition & 1 deletion packages/svelte/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<a
href="#"
class="btn btn-primary dark:text-base-content text-ableton-blue border-2 bg-transparent hover:bg-transparent hover:font-bold"
>Learn More About Becoming a Relay</a
>Learn More About Becoming a Relay (soon)</a
>
</div>
</article>
Expand Down
66 changes: 32 additions & 34 deletions packages/svelte/src/routes/docs/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@
</div>

<!-- Inizializzazione -->
<div class="bg-ableton-yellow mx-auto w-full p-10 text-black">
<section class="mb-12">
<h2 class="mb-4 text-3xl font-semibold">Getting Started</h2>
<div class="bg-ableton-yellow mx-auto w-full p-10 text-white">
<section class="mb-12 ">
<h2 class="mb-4 text-3xl font-semibold text-black">Getting Started</h2>
<pre class="overflow-x-auto rounded-lg bg-gray-900 p-4"><code class="language-svelte">
<span class="text-blue-600">&lt;script&gt;</span>
<span class="text-purple-600">import</span> <span class="text-orange-600">&#123; useGun, useUser &#125;</span> <span
class="text-purple-600">from</span
> <span class="text-green-600">'@your-org/se-2gun'</span>;
<span class="text-purple-600">import</span> <span class="text-orange-600">&#123; createAccount &#125;</span> <span
class="text-purple-600">from</span
> <span class="text-green-600">"@byteatatime/wagmi-svelte"</span>;

<span class="text-blue-600">const</span> <span class="text-orange-600">gun</span> = <span class="text-yellow-600"
>useGun()</span

>; <span class="text-gray-600">// Initialize GunDB</span>
<span class="text-blue-600">const</span> <span class="text-orange-600">&#123; user &#125;</span> = <span
class="text-yellow-600">useUser()</span
Expand All @@ -55,10 +53,10 @@
</div>

<!-- Autenticazione -->
<div class="bg-ableton-green w-full p-10 text-black">
<div class="bg-ableton-green w-full p-10 text-white">
<section class="mb-12">
<h2 class="mb-4 text-3xl font-semibold">Authentication</h2>
<p class="mb-4">SE-2Gun provides Ethereum-based authentication:</p>
<h2 class="mb-4 text-3xl font-semibold text-black">Authentication</h2>
<p class="mb-4 text-black">SE-2Gun provides Ethereum-based authentication:</p>
<pre class="overflow-x-auto rounded-lg bg-gray-900 p-4"><code>
<span class="text-purple-600">import</span> <span class="text-orange-600">&#123; signIn, login, logout &#125;</span
> <span class="text-purple-600">from</span> <span class="text-green-600">"$lib/gun/auth"</span>;
Expand Down Expand Up @@ -97,10 +95,10 @@
</div>

<!-- Gestione del profilo utente -->
<div class="bg-ableton-orange w-full p-10 text-black">
<div class="bg-ableton-orange w-full p-10 text-white">
<section class="mb-12">
<h2 class="mb-4 text-3xl font-semibold">User Profile Management</h2>
<p class="mb-4">Manage user profiles with these functions:</p>
<h2 class="mb-4 text-3xl font-semibold text-black">User Profile Management</h2>
<p class="mb-4 text-black">Manage user profiles with these functions:</p>
<pre class="overflow-x-auto rounded-lg bg-gray-900 p-4"><code class="language-javascript">
<span class="text-purple-600">import</span> <span class="text-orange-600"
>&#123; loadUserProfile, saveUserProfile, addProfileField &#125;</span
Expand All @@ -123,10 +121,10 @@
</div>

<!-- SHINE -->
<div class="bg-ableton-beige w-full p-10 text-black">
<div class="bg-ableton-beige w-full p-10 text-white">
<section class="mb-12">
<h2 class="mb-4 text-3xl font-semibold">SHINE (Secure Hash Integrity Network Ethereum)</h2>
<p class="mb-4">Use SHINE for data verification on the blockchain:</p>
<h2 class="mb-4 text-3xl font-semibold t text-black">SHINE (Secure Hash Integrity Network Ethereum)</h2>
<p class="mb-4 text-black">Use SHINE for data verification on the blockchain:</p>
<pre class="overflow-x-auto rounded-lg bg-gray-900 p-4"><code class="language-javascript">
<span class="text-blue-600">async function</span> <span class="text-yellow-600">saveMessage</span>() &#123;
<span class="text-blue-600">const</span> <span class="text-orange-600">gunInstance</span> = <span
Expand Down Expand Up @@ -174,12 +172,12 @@
</div>

<!-- Componenti -->
<div class="bg-ableton-light-blue w-full p-10 text-black">
<div class="bg-ableton-light-blue w-full p-10 text-white">
<section class="mb-12">
<h2 class="mb-4 text-3xl font-semibold">Components</h2>
<h2 class="mb-4 text-3xl font-semibold text-black">Components</h2>

<h3 class="mb-2 text-2xl font-medium">AccountProfile.svelte</h3>
<p class="mb-4">
<h3 class="mb-2 text-2xl font-medium text-black">AccountProfile.svelte</h3>
<p class="mb-4 text-black">
Displays account information including the public key, color, pulse, blink status, and last login.
</p>
<pre class="overflow-x-auto rounded-lg bg-gray-900 p-4"><code class="language-svelte">
Expand All @@ -191,8 +189,8 @@
>=&#123;userPublicKey&#125; /&gt;
</code></pre>

<h3 class="mb-2 mt-6 text-2xl font-medium">AccountAvatar.svelte</h3>
<p class="mb-4">Shows the user's avatar with options to upload a new one if it's the current user's profile.</p>
<h3 class="mb-2 mt-6 text-2xl font-medium text-black">AccountAvatar.svelte</h3>
<p class="mb-4 text-black">Shows the user's avatar with options to upload a new one if it's the current user's profile.</p>
<pre class="overflow-x-auto rounded-lg bg-gray-900 p-4"><code class="language-svelte">
<span class="text-purple-600">import</span> <span class="text-orange-600">AccountAvatar</span> <span
class="text-purple-600">from</span
Expand All @@ -204,8 +202,8 @@
>=&#123;2&#125; /&gt;
</code></pre>

<h3 class="mb-2 mt-6 text-2xl font-medium">ProfileDisplay.svelte</h3>
<p class="mb-4">
<h3 class="mb-2 mt-6 text-2xl font-medium text-black">ProfileDisplay.svelte</h3>
<p class="mb-4 text-black">
Allows viewing and editing user profile information with dynamic addition and removal of fields.
</p>
<pre class="overflow-x-auto rounded-lg bg-gray-900 p-4"><code class="language-svelte">
Expand All @@ -216,8 +214,8 @@
&lt;<span class="text-blue-600">ProfileDisplay</span> /&gt;
</code></pre>

<h3 class="mb-2 mt-6 text-2xl font-medium">Usage Example</h3>
<p class="mb-4">Here's how you might use these components together on a user profile page:</p>
<h3 class="mb-2 mt-6 text-2xl font-medium text-black">Usage Example</h3>
<p class="mb-4 text-black">Here's how you might use these components together on a user profile page:</p>
<pre class="overflow-x-auto rounded-lg bg-gray-900 p-4"><code class="language-svelte">
&lt;<span class="text-purple-600">script</span>&gt;
<span class="text-purple-600">import</span> &#123; <span class="text-orange-600">useUser</span> &#125; <span
Expand All @@ -244,28 +242,28 @@
&lt;<span class="text-blue-600">div</span> <span class="text-yellow-600">class</span>=<span class="text-green-600"
>"w-full md:w-1/3"</span
>&gt;
&lt;<span class="text-blue-600">AccountAvatar</span> <span class="text-yellow-600">pub</span
&lt;<span class="text-blue-600 text-black">AccountAvatar</span> <span class="text-yellow-600">pub</span
>=&#123;$user.pub&#125; <span class="text-yellow-600">size</span>=&#123;128&#125; /&gt;
&lt;<span class="text-blue-600">AccountProfile</span> <span class="text-yellow-600">pub</span
&lt;<span class="text-blue-600 text-black">AccountProfile</span> <span class="text-yellow-600">pub</span
>=&#123;$user.pub&#125; /&gt;
&lt;/<span class="text-blue-600">div</span>&gt;
&lt;<span class="text-blue-600">div</span> <span class="text-yellow-600">class</span>=<span class="text-green-600"
>"w-full md:w-2/3"</span
>&gt;
&lt;<span class="text-blue-600">ProfileDisplay</span> /&gt;
&lt;<span class="text-blue-600 text-black">ProfileDisplay</span> /&gt;
&lt;/<span class="text-blue-600">div</span>&gt;
&lt;/<span class="text-blue-600">div</span>&gt;
</code></pre>
</section>
</div>

<!-- Funzioni aggiuntive -->
<div class="bg-ableton-green w-full p-10 text-black">
<div class="bg-ableton-green w-full p-10 text-white">
<section class="mb-12">
<h2 class="mb-4 text-3xl font-semibold">Additional Functions</h2>
<h2 class="mb-4 text-3xl font-semibold text-black">Additional Functions</h2>

<h3 class="mb-2 text-2xl font-medium">User Functions</h3>
<ul class="list-disc space-y-2 pl-5">
<h3 class="mb-2 text-2xl font-medium text-black">User Functions</h3>
<ul class="list-disc space-y-2 pl-5 text-black ">
<li><strong>selectedUser:</strong> A writable store that holds the currently selected user's public key.</li>
<li><strong>userPub:</strong> A derived store that always contains the current user's public key.</li>
<li>
Expand All @@ -287,8 +285,8 @@
store.
</li>
</ul>
<h3 class="mb-2 mt-6 text-2xl font-medium">Account Functions</h3>
<ul class="list-disc space-y-2 pl-5">
<h3 class="mb-2 mt-6 text-2xl font-medium text-black">Account Functions</h3>
<ul class="list-disc space-y-2 pl-5 text-black">
<li>
<strong>useAccount(pubKey: string):</strong> Sets up and manages an account for the given public key, including
profile data and online status.
Expand Down
31 changes: 17 additions & 14 deletions packages/svelte/src/routes/inspect/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> | null = null;
let gunInstance: any;
let nodeData = writable({});
let nodePath = writable("");
let errorMessage = "";
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -183,7 +187,6 @@
<span class="block p-2 font-mono text-sm text-black">Current Relay: {$customRelay}</span>
<input
type="text"

class="input input-bordered w-full"
placeholder="Enter node path example: gun-eth/users"
bind:value={$nodePath}
Expand Down
7 changes: 5 additions & 2 deletions packages/svelte/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";
import commonjs from "@rollup/plugin-commonjs";


export default defineConfig({
plugins: [sveltekit(), commonjs()],
plugins: [sveltekit()],
define: {
"process.env": {}, // polyfill for web3modal
},
Expand All @@ -12,4 +12,7 @@ export default defineConfig({
allow: [".."],
},
},
ssr: {
noExternal: ['gun-avatar']
}
});
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,7 @@ __metadata:
url-regex: ^5.0.0
vercel: ^34.0.0
viem: ^2.21.7
vis-data: ^7.1.9
vis-network: ^9.1.9
vite: ^5.0.3
vite-plugin-svelte: ^3.0.1
Expand Down Expand Up @@ -15294,6 +15295,16 @@ __metadata:
languageName: node
linkType: hard

"vis-data@npm:^7.1.9":
version: 7.1.9
resolution: "vis-data@npm:7.1.9"
peerDependencies:
uuid: ^3.4.0 || ^7.0.0 || ^8.0.0 || ^9.0.0
vis-util: ^5.0.1
checksum: d299e5c9c301e9ecfaa3bd40eea0f89320ed2c8053e1105896d197561bc8927a08d715db33ba085efdedcaef08621b22fbdb32698fe611f94a2d9fac6e3f48b2
languageName: node
linkType: hard

"vis-network@npm:^9.1.9":
version: 9.1.9
resolution: "vis-network@npm:9.1.9"
Expand Down

0 comments on commit 74e4d85

Please sign in to comment.