Skip to content

Commit

Permalink
hide (most) strategy errors from non-admin users
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkunz committed Sep 20, 2024
1 parent 87e4c9d commit 7d748f4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
12 changes: 10 additions & 2 deletions src/lib/trade-executor/components/StrategyError.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ Display an appropriate error message for a strategy when needed. There can be mu
<script context="module" lang="ts">
import type { StrategyRuntimeState } from 'trade-executor/strategy/runtime-state';
export function hasError(strategy: StrategyRuntimeState) {
return !strategy.connected || !strategy.executor_running || strategy.frozen_positions > 0;
export function adminOnlyError(strategy: StrategyRuntimeState) {
return strategy.connected && (!strategy.executor_running || strategy.frozen_positions > 0);
}
export function allUsersError(strategy: StrategyRuntimeState) {
return !strategy.connected;
}
export function shouldDisplayError(strategy: StrategyRuntimeState, admin = false) {
return allUsersError(strategy) || (admin && adminOnlyError(strategy));
}
</script>

Expand Down
3 changes: 2 additions & 1 deletion src/lib/trade-executor/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as KeyMetric } from './KeyMetric.svelte';
export { default as KeyMetricDescription } from './KeyMetricDescription.svelte';
export { default as StrategyIcon } from './StrategyIcon.svelte';
export { default as StrategyError, hasError } from './StrategyError.svelte';
export { default as StrategyError } from './StrategyError.svelte';
export * from './StrategyError.svelte';
14 changes: 11 additions & 3 deletions src/routes/strategies/StrategyTile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import { normalizeDataForInterval } from '$lib/chart';
import { getChain } from '$lib/helpers/chain.js';
import { Button, DataBadge, Tooltip } from '$lib/components';
import { StrategyIcon, StrategyError, hasError } from 'trade-executor/components';
import { StrategyIcon, StrategyError, shouldDisplayError, adminOnlyError } from 'trade-executor/components';
import StrategyBadges from './StrategyBadges.svelte';
import ChartThumbnail from './ChartThumbnail.svelte';
import StrategyDataSummary from './StrategyDataSummary.svelte';
import { getLogoUrl } from '$lib/helpers/assets';
import Alert from '$lib/components/Alert.svelte';
export let admin = false;
export let simplified = false;
Expand Down Expand Up @@ -51,10 +52,17 @@

{#if !simplified}
<div class="badges">
{#if hasError(strategy)}
{#if shouldDisplayError(strategy, admin)}
<Tooltip>
<DataBadge slot="trigger" status="error">Error</DataBadge>
<StrategyError slot="popup" {strategy} />
<svelte:fragment slot="popup">
{#if adminOnlyError(strategy)}
<p>
<Alert size="xs" status="info" title="Note">This error is only displayed to admin users.</Alert>
</p>
{/if}
<StrategyError {strategy} />
</svelte:fragment>
</Tooltip>
{/if}

Expand Down
18 changes: 14 additions & 4 deletions src/routes/strategies/[strategy]/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
import { page } from '$app/stores';
import Breadcrumbs from '$lib/breadcrumb/Breadcrumbs.svelte';
import { AlertList, PageHeading } from '$lib/components';
import { StrategyIcon, StrategyError, hasError } from 'trade-executor/components';
import { StrategyIcon, StrategyError, shouldDisplayError, adminOnlyError } from 'trade-executor/components';
import { menuOptions, default as StrategyNav } from './StrategyNav.svelte';
import StrategyBadges from '../StrategyBadges.svelte';
import { WalletWidget } from '$lib/wallet';
export let data;
$: ({ strategy, deferred } = data);
$: ({ admin, strategy, deferred } = data);
$: isOverviewPage = $page.url.pathname.endsWith(strategy.id);
$: hasStrategyError = shouldDisplayError(strategy, admin);
$: isOutdated = Boolean(strategy.new_version_id);
$: breadcrumbs = {
Expand All @@ -39,7 +41,7 @@
</div>
</PageHeading>

{#if isOverviewPage && (hasError(strategy) || isOutdated)}
{#if isOverviewPage && (hasStrategyError || isOutdated)}
<div class="error-wrapper">
<AlertList status="warning" size="md" let:AlertItem>
<AlertItem title="Outdated strategy" displayWhen={isOutdated}>
Expand All @@ -48,8 +50,11 @@
participants should consider tranfering deposits to the latest version (though there is no guarantee of
better performance).
</AlertItem>
<AlertItem title="Ongoing execution issues" displayWhen={hasError(strategy)}>
<AlertItem title="Ongoing execution issues" displayWhen={hasStrategyError}>
<StrategyError {strategy} />
{#if adminOnlyError(strategy)}
<p class="admin-error"><strong>Note:</strong> this error is only displayed to admin users.</p>
{/if}
</AlertItem>
</AlertList>
</div>
Expand Down Expand Up @@ -79,6 +84,11 @@
transform: translate(0, -0.375em);
}
.admin-error {
margin-top: 1rem;
opacity: 0.5;
}
.subpage {
display: grid;
gap: var(--space-ls);
Expand Down

0 comments on commit 7d748f4

Please sign in to comment.