From 6841751f2215190c0a1139d06f041c08390a408b Mon Sep 17 00:00:00 2001 From: Ken Kunz Date: Fri, 25 Oct 2024 09:26:43 -0500 Subject: [PATCH] hide strategies TVL chart for non-admin users close #842 --- src/routes/strategies/+page.server.ts | 18 +++++++++++------- src/routes/strategies/+page.svelte | 8 +++++--- src/routes/strategies/StrategyTvlChart.svelte | 2 -- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/routes/strategies/+page.server.ts b/src/routes/strategies/+page.server.ts index 953b9d2e1..8aaff07af 100644 --- a/src/routes/strategies/+page.server.ts +++ b/src/routes/strategies/+page.server.ts @@ -7,6 +7,15 @@ import { getCachedStrategies } from 'trade-executor/strategy/runtime-state'; import { fetchPublicApi } from '$lib/helpers/public-api'; +async function fetchTvlData() { + try { + return (await fetchPublicApi(fetch, 'impressive-numbers')).strategies_tvl; + } catch (e) { + console.error('Request failed; rendering page without TVL data.'); + console.error(e); + } +} + export async function load({ fetch, locals }) { const { admin } = locals; @@ -15,13 +24,8 @@ export async function load({ fetch, locals }) { return admin ? strategies : strategies.filter((s) => s.tags?.includes('live')); }); - // fail gracefully if TVL data doesn't load - const tvlData = fetchPublicApi(fetch, 'impressive-numbers') - .then((data) => data.strategies_tvl) - .catch((e) => { - console.error('Request failed; rendering page without TVL data.'); - console.error(e); - }); + // return TVL data for admins only + const tvlData = admin ? fetchTvlData() : undefined; return { strategies: await strategies, diff --git a/src/routes/strategies/+page.svelte b/src/routes/strategies/+page.svelte index 38e01a68b..913f65c24 100644 --- a/src/routes/strategies/+page.svelte +++ b/src/routes/strategies/+page.svelte @@ -91,9 +91,11 @@ {/if} -
- -
+ {#if admin} +
+ +
+ {/if}