Skip to content

Commit

Permalink
Merge pull request #57 from helius-labs/local-storage
Browse files Browse the repository at this point in the history
new commit from storage
  • Loading branch information
solhosty authored Sep 21, 2023
2 parents 4d9d81b + 1c250c1 commit 188bf13
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/lib/components/RPCMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script>
// @ts-nocheck
import { methods } from "$lib/types/all-methods.js";
import { currentMethod, currentRPC } from "$lib/stores/current-method.js";
import { fly } from "svelte/transition";
Expand All @@ -8,21 +7,35 @@
let questions = Object.keys(methods).map((method, index) => {
return { id: index + 1, text: method };
});
let rpcUrlValue = "";
export let answer = "";
if (typeof window !== 'undefined') {
// Initialize from localStorage
answer = localStorage.getItem('rpcUrl') || "";
}
let isVisible = false;
$: {
rpcUrlValue = answer;
if (!answer && typeof window !== 'undefined') {
answer = localStorage.getItem('rpcUrl') || "";
}
let rpcUrlValue = answer;
if (!rpcUrlValue) {
currentRPC.set("https://api.mainnet-beta.solana.com");
}
// Check if the URL starts with "https://"
if (!rpcUrlValue.startsWith("https://") && rpcUrlValue !== "") {
rpcUrlValue = "https://" + rpcUrlValue;
}
currentRPC.set(rpcUrlValue);
}
export let answer = "";
let isVisible = false;
if (typeof window !== 'undefined') {
localStorage.setItem('rpcUrl', rpcUrlValue); // Save to localStorage
}
}
onMount(() => {
setTimeout(() => {
Expand Down Expand Up @@ -62,7 +75,7 @@
type="text"
bind:value={answer}
placeholder="Drop a Solana RPC endpoint here"
class="input-bordered input input w-full border-zinc-900 bg-transparent text-gray-300"
class="input-bordered input w-full border-zinc-900 bg-transparent text-gray-300"
/>
</div>
</div>
Expand Down

0 comments on commit 188bf13

Please sign in to comment.