From 1ff90f09f954a0cfef41a7eb14c13c551a6a6253 Mon Sep 17 00:00:00 2001 From: hunter <104146303+solhosty@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:13:03 -0400 Subject: [PATCH 1/9] devnet additions --- .env.template | 1 - package-lock.json | 17 +++++++ package.json | 3 ++ src/lib/components/account-header.svelte | 9 +++- src/lib/components/account-info.svelte | 10 ++-- src/lib/components/collapse.svelte | 2 +- src/lib/components/copy-button.svelte | 2 +- src/lib/components/footer.svelte | 4 +- src/lib/components/json.svelte | 2 +- src/lib/components/modals.svelte | 2 +- src/lib/components/modals/menu.svelte | 13 ++++- .../modals/transaction-filter.svelte | 4 +- src/lib/components/modals/wallets.svelte | 2 +- src/lib/components/nav.svelte | 13 +++-- src/lib/components/network.svelte | 39 +++++++++++++++ src/lib/components/powered-by-helius.svelte | 2 +- .../providers/token-provider-2.svelte | 8 ---- .../providers/token-provider.svelte | 19 +++++--- src/lib/components/search.svelte | 42 ++++++++--------- src/lib/components/stats.svelte | 12 +++-- src/lib/components/transaction.svelte | 32 +++++++++---- src/lib/components/transactions.svelte | 26 ++++++---- src/lib/trpc/routes/account-info.ts | 13 ++--- src/lib/trpc/routes/asset.ts | 8 ++-- src/lib/trpc/routes/assets.ts | 8 ++-- src/lib/trpc/routes/balances.ts | 6 ++- src/lib/trpc/routes/block-transactions.ts | 8 ++-- src/lib/trpc/routes/cnft-transactions.ts | 10 ++-- src/lib/trpc/routes/concurrent-merkle-tree.ts | 11 +++-- src/lib/trpc/routes/current-slot.ts | 12 +++-- src/lib/trpc/routes/raw-transaction.ts | 11 +++-- src/lib/trpc/routes/token-2.ts | 0 src/lib/trpc/routes/token.ts | 10 ++-- src/lib/trpc/routes/token2022.ts | 10 ++-- src/lib/trpc/routes/tps.ts | 14 ++++-- src/lib/trpc/routes/transaction.ts | 5 +- src/lib/trpc/routes/transactions.ts | 6 ++- src/lib/util/get-api-url.ts | 4 ++ src/lib/util/get-rpc-url.ts | 4 ++ src/lib/util/stores/network.ts | 3 ++ src/lib/xray/lib/parser/types.ts | 4 +- .../xray/lib/parser/utils/group-actions.ts | 2 +- .../xray/lib/parser/utils/native-transfers.ts | 2 +- .../xray/lib/parser/utils/token-transfers.ts | 6 +-- src/lib/xray/lib/search.ts | 19 ++++++-- src/routes/+layout.svelte | 19 -------- src/routes/+page.svelte | 5 -- .../account/[...accounts]/assets/+page.svelte | 47 ------------------- src/routes/account/[account]/+layout.svelte | 34 ++++++++++---- src/routes/account/[account]/+page.svelte | 6 ++- .../account/[account]/assets/+page.svelte | 20 ++++++-- .../concurrent-merkle-tree/+page.svelte | 20 ++++++-- .../account/[account]/tokens/+page.svelte | 8 ++-- src/routes/api/search/[query]/+server.ts | 1 - src/routes/block/[slot]/+page.svelte | 18 +++++-- src/routes/token/[token]/+page.svelte | 28 ++++++----- src/routes/tx/[tx]/+page.svelte | 19 ++++++-- 57 files changed, 411 insertions(+), 254 deletions(-) delete mode 100644 .env.template create mode 100644 src/lib/components/network.svelte delete mode 100644 src/lib/components/providers/token-provider-2.svelte delete mode 100644 src/lib/trpc/routes/token-2.ts create mode 100644 src/lib/util/get-api-url.ts create mode 100644 src/lib/util/get-rpc-url.ts create mode 100644 src/lib/util/stores/network.ts delete mode 100644 src/routes/account/[...accounts]/assets/+page.svelte diff --git a/.env.template b/.env.template deleted file mode 100644 index a8b8d7ab..00000000 --- a/.env.template +++ /dev/null @@ -1 +0,0 @@ -HELIUS_KEY = "" \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0395a92d..b7121996 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,10 +19,12 @@ "@tanstack/svelte-query": "^4.24.9", "@trpc/client": "^10.12.0", "@trpc/server": "^10.12.0", + "cookie": "^0.5.0", "events": "^3.3.0", "helius-sdk": "^1.0.7", "highlight.js": "^11.7.0", "install": "^0.13.0", + "js-cookie": "^3.0.5", "json-format-highlight": "^1.0.4", "json-viewer-js": "^1.0.8", "svelte-highlight": "^7.1.2", @@ -39,6 +41,7 @@ "@sveltejs/adapter-auto": "^2.0.0", "@sveltejs/adapter-vercel": "^2.0.2", "@tailwindcss/typography": "^0.5.8", + "@types/js-cookie": "^3.0.3", "@typescript-eslint/eslint-plugin": "^5.59.11", "@typescript-eslint/parser": "^5.59.11", "autoprefixer": "^10.4.7", @@ -3966,6 +3969,12 @@ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==" }, + "node_modules/@types/js-cookie": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/js-cookie/-/js-cookie-3.0.3.tgz", + "integrity": "sha512-Xe7IImK09HP1sv2M/aI+48a20VX+TdRJucfq4vfRVy6nWN8PYPOEnlMRSgxJAgYQIXJVL8dZ4/ilAM7dWNaOww==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.12", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz", @@ -9478,6 +9487,14 @@ "jiti": "bin/jiti.js" } }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "engines": { + "node": ">=14" + } + }, "node_modules/js-sha3": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", diff --git a/package.json b/package.json index 00e2f0d2..f9f5628b 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "@sveltejs/adapter-auto": "^2.0.0", "@sveltejs/adapter-vercel": "^2.0.2", "@tailwindcss/typography": "^0.5.8", + "@types/js-cookie": "^3.0.3", "@typescript-eslint/eslint-plugin": "^5.59.11", "@typescript-eslint/parser": "^5.59.11", "autoprefixer": "^10.4.7", @@ -88,10 +89,12 @@ "@tanstack/svelte-query": "^4.24.9", "@trpc/client": "^10.12.0", "@trpc/server": "^10.12.0", + "cookie": "^0.5.0", "events": "^3.3.0", "helius-sdk": "^1.0.7", "highlight.js": "^11.7.0", "install": "^0.13.0", + "js-cookie": "^3.0.5", "json-format-highlight": "^1.0.4", "json-viewer-js": "^1.0.8", "svelte-highlight": "^7.1.2", diff --git a/src/lib/components/account-header.svelte b/src/lib/components/account-header.svelte index c58a88cd..fe343f4a 100644 --- a/src/lib/components/account-header.svelte +++ b/src/lib/components/account-header.svelte @@ -32,13 +32,20 @@ import Icon from "$lib/components/icon.svelte"; import Username from "$lib/components/providers/username-provider.svelte"; import ShortenAddress from "./shorten-address.svelte"; + import { isMainnet } from "$lib/util/stores/network"; const client = trpcWithQuery($page); export let account: string = ""; export let link: string = ""; - const accountInfo = client.accountInfo.createQuery(account); + const params = new URLSearchParams(window.location.search); + const network = params.get("network"); + const isMainnetValue = network !== "devnet"; + const accountInfo = client.accountInfo.createQuery([ + account, + isMainnetValue, + ]); const price = client.price.createQuery(SOL); const balance = tweened(0, { diff --git a/src/lib/components/account-info.svelte b/src/lib/components/account-info.svelte index fffcb259..9d863f4e 100644 --- a/src/lib/components/account-info.svelte +++ b/src/lib/components/account-info.svelte @@ -11,12 +11,16 @@ import CopyButton from "$lib/components/copy-button.svelte"; import Namor from "$lib/components/providers/namor-provider.svelte"; - export let account = ""; const client = trpcWithQuery($page); - - const accountInfo = client.accountInfo.createQuery(account); + const params = new URLSearchParams(window.location.search); + const network = params.get("network"); + const isMainnetValue = network !== "devnet"; + const accountInfo = client.accountInfo.createQuery([ + account, + isMainnetValue, + ]); const price = client.price.createQuery(SOL); const balance = tweened(0, { diff --git a/src/lib/components/collapse.svelte b/src/lib/components/collapse.svelte index f482e39c..338e2b1c 100644 --- a/src/lib/components/collapse.svelte +++ b/src/lib/components/collapse.svelte @@ -9,7 +9,7 @@ export let showDetails = false; -
+
{#each filterList as [key, value]}
{$cmt.data?.creationSlot.toLocaleString()} diff --git a/src/routes/account/[account]/tokens/+page.svelte b/src/routes/account/[account]/tokens/+page.svelte index f8cb24a7..cb5b3a33 100644 --- a/src/routes/account/[account]/tokens/+page.svelte +++ b/src/routes/account/[account]/tokens/+page.svelte @@ -12,10 +12,12 @@ const account = $page.params.account; const client = trpcWithQuery($page); + const params = new URLSearchParams(window.location.search); + const network = params.get("network"); + const isMainnetValue = network !== "devnet"; + const balances = client.balances.createQuery([account, isMainnetValue]); - const balances = client.balances.createQuery(account); - - const token2022 = client.token2022.createQuery(account); + const token2022 = client.token2022.createQuery([account, isMainnetValue]); const sol = client.price.createQuery(SOL); diff --git a/src/routes/api/search/[query]/+server.ts b/src/routes/api/search/[query]/+server.ts index abbfb5dd..958866e5 100644 --- a/src/routes/api/search/[query]/+server.ts +++ b/src/routes/api/search/[query]/+server.ts @@ -7,7 +7,6 @@ const { HELIUS_API_KEY } = process.env; // Consume a search, return what to do with it export async function GET({ params }: RequestEvent) { const conection = connect("mainnet", HELIUS_API_KEY); - const result = await search(params?.query || "", conection); return json(result); diff --git a/src/routes/block/[slot]/+page.svelte b/src/routes/block/[slot]/+page.svelte index 10bfc20b..c571e023 100644 --- a/src/routes/block/[slot]/+page.svelte +++ b/src/routes/block/[slot]/+page.svelte @@ -1,4 +1,5 @@ -
-

Transaction

-
- - +{#if $txn == true} +
+

Transaction

+
+ + +
-
- -{#if animate} -
- {#if $transaction.isLoading} - {#each Array(3) as _} -
- + {#if animate} +
+ {#if $transaction.isLoading} + {#each Array(3) as _} +
+ +
+ {/each} + {:else if data} +
+
- {/each} - {:else if data} -
- -
- {#if data.accounts} -
- - {#each data.accounts as account} - - {/each} - -
- {/if} + {#if data.accounts} +
+ + {#each data.accounts as account} + + {/each} + +
+ {/if} -
-
- {#if rawData?.transaction?.meta?.err} -
+
+
+ {#if rawData?.transaction?.meta?.err} +
+
+ +
+
- +
+

+ Status +

+

+ This transaction has failed. +

+
+
Error
-
-
-
-

- Status -

-

- This transaction has failed. -

+ {:else} +
+
+ +
-
Error
-
- {:else} +
+
+

+ Status +

+

+ This transaction has successfully + processed. +

+
+
+ Success +
+
+ {/if} +
+
+
+

- Status + Network Fee

- This transaction has successfully processed. + Cost for processing this transaction.

-
Success
-
- {/if} -
-
-
-
-
-
- -
-
-
-
-

- Network Fee -

-

- Cost for processing this transaction. -

+

{data.fee} SOL

-

{data.fee} SOL

-
-
- - {#if data?.raw?.description && !data?.raw?.description - .toLowerCase() - .includes("unknown")}
- {/if} -
- -
- -
+ {#if data?.raw?.description && !data?.raw?.description + .toLowerCase() + .includes("unknown")} +
+
+
+
+ +
+
+
+
+

+ Helius Description +

+

+ {data?.raw?.description} +

+
+
+
- {#if data?.raw} + {/if} + +
+
- {/if} -
- -
- -
- - {#if rawData} -
- - + {#if data?.raw} +
+ +
+
+ {/if} +
+ +
+ + {#if rawData} +
+ + + +
+ {/if} {/if} - {/if} -
+
+ {/if} +{:else} +

+ Transaction not found. Try selecting another network. +

{/if} From 8ea2c21e924483557c05be19ec92fdb582b0164f Mon Sep 17 00:00:00 2001 From: hunter <104146303+solhosty@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:25:17 -0400 Subject: [PATCH 4/9] txn fixes --- src/lib/components/network.svelte | 2 +- src/lib/components/search.svelte | 88 +++++++++++++++++-------------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/lib/components/network.svelte b/src/lib/components/network.svelte index 24c96a27..4c32efda 100644 --- a/src/lib/components/network.svelte +++ b/src/lib/components/network.svelte @@ -14,7 +14,7 @@ const network = params.get("network"); }); function toggleNetwork(event: Event) { - const isMainnetValue = (event.target as HTMLInputElement).checked; + isMainnetValue = (event.target as HTMLInputElement).checked; localStorage.setItem("isMainnet", JSON.stringify(isMainnetValue)); const params = new URLSearchParams(window.location.search); params.set("network", isMainnetValue ? "mainnet" : "devnet"); diff --git a/src/lib/components/search.svelte b/src/lib/components/search.svelte index 965d6316..c797423e 100644 --- a/src/lib/components/search.svelte +++ b/src/lib/components/search.svelte @@ -53,7 +53,6 @@ let connected = false; let isBackpack = false; let recent = [] as SearchResult[]; - let isMainnetValue: boolean; const dispatch = createEventDispatcher(); const searchFailed = () => { @@ -104,56 +103,63 @@ }; const newSearch = async () => { - searchError = ""; - isSearching = true; + searchError = ""; + isSearching = true; - try { - const response = await fetch( - `/api/search/${inputValue}?network=${ - isMainnetValue ? "mainnet" : "devnet" - }` - ); - - const data = await response.json(); + try { + const response = await fetch( + `/api/search/${inputValue}?network=${ + isMainnetValue ? "mainnet" : "devnet" + }` + ); - if (!data.valid) { - searchFailed(); - return; - } + const data = await response.json(); - selectSearch(data); - } catch (error) { + if (!data.valid) { searchFailed(); + return; } - }; - onMount(() => { - recent = getRecentSearches(); + selectSearch(data); + } catch (error) { + searchFailed(); + } +}; + + let isMainnetValue = true; - isBackpack = - window?.localStorage?.getItem("walletAdapter") === '"Backpack"'; +onMount(() => { + const params = new URLSearchParams(window.location.search); + const network = params.get("network"); + if (network !== null) { + isMainnetValue = network === "mainnet"; + } + recent = getRecentSearches(); + + isBackpack = + window?.localStorage?.getItem("walletAdapter") === '"Backpack"'; +}); + +$: if ($walletStore.connected && !connected) { + focusInput(); + const params = new URLSearchParams(window.location.search); + const network = params.get("network"); + isMainnetValue = network !== "devnet"; + inputValue = $walletStore.publicKey?.toBase58() || ""; + addRecent({ + address: inputValue, + search: inputValue, + type: "account", + url: `/account/${inputValue}?network=${ + isMainnetValue ? "mainnet" : "devnet" + }`, + valid: true, }); - $: if ($walletStore.connected && !connected) { - focusInput(); - const params = new URLSearchParams(window.location.search); - const network = params.get("network"); - isMainnetValue = network !== "devnet"; - inputValue = $walletStore.publicKey?.toBase58() || ""; - addRecent({ - address: inputValue, - search: inputValue, - type: "account", - url: `/account/${inputValue}?network=${ - isMainnetValue ? "mainnet" : "devnet" - }`, - valid: true, - }); - - window.location.href = `/account/${inputValue}`; + window.location.href = `/account/${inputValue}`; - connected = true; - } + connected = true; +}
From 0e470b5e1a1df8ce4b9f0d7dc13b1bf3fdc45999 Mon Sep 17 00:00:00 2001 From: hunter <104146303+solhosty@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:33:19 -0400 Subject: [PATCH 5/9] txn fixes --- src/lib/components/network.svelte | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/components/network.svelte b/src/lib/components/network.svelte index 4c32efda..dfe93b9f 100644 --- a/src/lib/components/network.svelte +++ b/src/lib/components/network.svelte @@ -10,9 +10,11 @@ } }); onMount(() => { - const params = new URLSearchParams(window.location.search); - const network = params.get("network"); - }); + const params = new URLSearchParams(window.location.search); + const network = params.get("network"); + isMainnetValue = network !== "devnet"; + localStorage.setItem("isMainnet", JSON.stringify(isMainnetValue)); +}); function toggleNetwork(event: Event) { isMainnetValue = (event.target as HTMLInputElement).checked; localStorage.setItem("isMainnet", JSON.stringify(isMainnetValue)); From acc9efa6e4017f6642b51314c1ad82fe06c73e89 Mon Sep 17 00:00:00 2001 From: hunter <104146303+solhosty@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:47:50 -0400 Subject: [PATCH 6/9] network button --- src/routes/tx/[tx]/+page.svelte | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/routes/tx/[tx]/+page.svelte b/src/routes/tx/[tx]/+page.svelte index 0bd9faa1..1b52d266 100644 --- a/src/routes/tx/[tx]/+page.svelte +++ b/src/routes/tx/[tx]/+page.svelte @@ -19,6 +19,7 @@ import LogMessages from "$lib/components/log-messages.svelte"; import Transaction from "$lib/components/transaction.svelte"; import Collapse from "$lib/components/collapse.svelte"; + import Network from "$lib/components/network.svelte"; let animate = false; @@ -341,4 +342,5 @@

Transaction not found. Try selecting another network.

+ {/if} From 75bc94c6dbec4c5c95bdaa4cda7dd769138f8587 Mon Sep 17 00:00:00 2001 From: hunter <104146303+solhosty@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:48:25 -0400 Subject: [PATCH 7/9] new commit --- src/routes/tx/[tx]/+page.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/tx/[tx]/+page.svelte b/src/routes/tx/[tx]/+page.svelte index 1b52d266..5ed8b0f3 100644 --- a/src/routes/tx/[tx]/+page.svelte +++ b/src/routes/tx/[tx]/+page.svelte @@ -339,7 +339,7 @@
{/if} {:else} -

+

Transaction not found. Try selecting another network.

From 9260871202df4b30d155b49b9041fb8610d6921f Mon Sep 17 00:00:00 2001 From: hunter <104146303+solhosty@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:50:34 -0400 Subject: [PATCH 8/9] menu change --- src/lib/components/modals/menu.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/components/modals/menu.svelte b/src/lib/components/modals/menu.svelte index eaccf1be..0a0b26b5 100644 --- a/src/lib/components/modals/menu.svelte +++ b/src/lib/components/modals/menu.svelte @@ -6,7 +6,7 @@ const isMainnetValue = network !== "devnet"; -{#each [{ name: "Home", url: `/?network=${isMainnetValue ? "mainnet" : "devnet"}` }, { name: "About Helius APIs", url: "https://helius.xyz" }, { name: "Contribute", url: "https://github.com/helius-labs/xray" }, { name: "Join Discord", url: "https://discord.gg/mV3dNPwDnZ" }] as { name, url }} +{#each [{ name: "Home", url: `/?network=${isMainnetValue ? "mainnet" : "devnet"}` }, { name: "About Helius APIs", url: "https://helius.xyz" }, { name: "Contribute", url: "https://github.com/helius-labs/xray" }, { name: "Join Discord", url: "https://discord.gg/nSkq35VUf5" }] as { name, url }} Date: Fri, 15 Sep 2023 16:25:56 -0400 Subject: [PATCH 9/9] token fix --- src/lib/components/account-header.svelte | 1 - src/lib/trpc/routes/asset.ts | 1 - src/lib/trpc/routes/token.ts | 5 +---- src/routes/token/[token]/+page.svelte | 3 +++ 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lib/components/account-header.svelte b/src/lib/components/account-header.svelte index fe343f4a..43414146 100644 --- a/src/lib/components/account-header.svelte +++ b/src/lib/components/account-header.svelte @@ -32,7 +32,6 @@ import Icon from "$lib/components/icon.svelte"; import Username from "$lib/components/providers/username-provider.svelte"; import ShortenAddress from "./shorten-address.svelte"; - import { isMainnet } from "$lib/util/stores/network"; const client = trpcWithQuery($page); diff --git a/src/lib/trpc/routes/asset.ts b/src/lib/trpc/routes/asset.ts index e2a68f22..9a7d74b5 100644 --- a/src/lib/trpc/routes/asset.ts +++ b/src/lib/trpc/routes/asset.ts @@ -4,7 +4,6 @@ import { z } from "zod"; const { HELIUS_API_KEY } = process.env; -import { connect } from "$lib/xray"; import { getRPCUrl } from "$lib/util/get-rpc-url"; // TODO: add output validation once this merges with the token endpoint diff --git a/src/lib/trpc/routes/token.ts b/src/lib/trpc/routes/token.ts index 30c40d35..925930d3 100644 --- a/src/lib/trpc/routes/token.ts +++ b/src/lib/trpc/routes/token.ts @@ -1,6 +1,5 @@ import { t } from "$lib/trpc/t"; import { getAPIUrl } from "$lib/util/get-api-url"; -import { isMainnet } from "$lib/util/stores/network"; import { z } from "zod"; @@ -16,13 +15,11 @@ export const token = t.procedure { body: JSON.stringify({ includeOffChain: true, - mintAccounts: token, + mintAccounts: [token], }), method: "POST", } ); - const json = await response.json(); - return json; }); diff --git a/src/routes/token/[token]/+page.svelte b/src/routes/token/[token]/+page.svelte index f0f125ac..ac7dafa8 100644 --- a/src/routes/token/[token]/+page.svelte +++ b/src/routes/token/[token]/+page.svelte @@ -9,6 +9,9 @@ transform: translate(-50%, 0); background-color: black; } + .img { + max-height: 25vh; + }