Skip to content

Commit

Permalink
hide strategies TVL chart for non-admin users
Browse files Browse the repository at this point in the history
close #842
  • Loading branch information
kenkunz committed Oct 25, 2024
1 parent 82ce101 commit 6841751
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
18 changes: 11 additions & 7 deletions src/routes/strategies/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions src/routes/strategies/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@
{/if}
</Section>

<Section>
<StrategyTvlChart {tvlData} />
</Section>
{#if admin}
<Section>
<StrategyTvlChart {tvlData} />
</Section>
{/if}
</main>

<style>
Expand Down
2 changes: 0 additions & 2 deletions src/routes/strategies/StrategyTvlChart.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<script lang="ts">
import { utcDay } from 'd3-time';
import { type RawTick, ChartContainer, PerformanceChart, normalizeDataForInterval } from '$lib/chart';
import { Alert } from '$lib/components';
import { parseDate } from '$lib/helpers/date';
import { formatDollar } from '$lib/helpers/formatters';
export let tvlData: RawTick[] | undefined;
Expand Down

0 comments on commit 6841751

Please sign in to comment.