style: format UI files and remove lint excludes

- Remove app/components/ and app/pages/ from ruff/black excludes
- Pre-commit reformatted multi-line strings for consistency
- All files now follow the same code style
This commit is contained in:
Bu5hm4nn
2026-04-01 13:55:55 +02:00
parent 9af654d9f2
commit 6bcf78e5df
9 changed files with 94 additions and 59 deletions

View File

@@ -119,10 +119,12 @@ def _render_event_comparison_page(workspace_id: str | None = None) -> None:
ui.label(
"Changing the preset resets strategy templates to that preset's default comparison set."
).classes("text-xs text-slate-500 dark:text-slate-400")
ui.label(
"Underlying units will be calculated from initial value ÷ entry spot."
).classes("text-xs text-slate-500 dark:text-slate-400")
initial_value_input = ui.number("Initial portfolio value ($)", value=default_units * default_entry_spot, min=0.01, step=1000).classes("w-full")
ui.label("Underlying units will be calculated from initial value ÷ entry spot.").classes(
"text-xs text-slate-500 dark:text-slate-400"
)
initial_value_input = ui.number(
"Initial portfolio value ($)", value=default_units * default_entry_spot, min=0.01, step=1000
).classes("w-full")
loan_input = ui.number("Loan amount", value=default_loan, min=0, step=1000).classes("w-full")
ltv_input = ui.number(
"Margin call LTV",
@@ -183,7 +185,11 @@ def _render_event_comparison_page(workspace_id: str | None = None) -> None:
# Show validation errors (units_error takes priority, then entry_spot_error)
display_error = units_error or entry_spot_error
if display_error:
tone_class = "text-rose-600 dark:text-rose-300" if "must be positive" in display_error else "text-amber-700 dark:text-amber-300"
tone_class = (
"text-rose-600 dark:text-rose-300"
if "must be positive" in display_error
else "text-amber-700 dark:text-amber-300"
)
ui.label(display_error).classes(f"text-sm {tone_class}")
def render_result_state(title: str, message: str, *, tone: str = "info") -> None:
@@ -243,7 +249,7 @@ def _render_event_comparison_page(workspace_id: str | None = None) -> None:
scenario_label.set_text(units_error)
render_selected_summary(entry_spot=preview_entry_spot, entry_spot_error=units_error)
return units_error
if workspace_id and config is not None and reseed_units:
# Recalculate from workspace config
workspace_units = asset_quantity_from_workspace_config(
@@ -322,7 +328,7 @@ def _render_event_comparison_page(workspace_id: str | None = None) -> None:
validation_label.set_text(units_error)
render_result_state("Input validation failed", units_error, tone="warning")
return
report = service.run_read_only_comparison(
preset_slug=str(preset_select.value or ""),
template_slugs=template_slugs,

View File

@@ -88,9 +88,7 @@ async def _resolve_hedge_spot(workspace_id: str | None = None) -> tuple[dict[str
data_service = get_data_service()
underlying = config.underlying or "GLD"
quote = await data_service.get_quote(underlying)
spot, source, updated_at = resolve_portfolio_spot_from_quote(
config, quote, fallback_symbol=underlying
)
spot, source, updated_at = resolve_portfolio_spot_from_quote(config, quote, fallback_symbol=underlying)
portfolio = portfolio_snapshot(config, runtime_spot_price=spot)
return portfolio, source, updated_at
except Exception as exc:
@@ -114,14 +112,14 @@ async def _render_hedge_page(workspace_id: str | None = None) -> None:
}
display_mode = portfolio.get("display_mode", "XAU")
if display_mode == "GLD":
spot_unit = "/share"
spot_desc = "GLD share price"
else:
spot_unit = "/oz"
spot_desc = "converted collateral spot"
if quote_source == "configured_entry_price":
spot_label = f"Current spot reference: ${portfolio['spot_price']:,.2f}{spot_unit} (configured entry price)"
else:
@@ -251,7 +249,7 @@ async def _render_hedge_page(workspace_id: str | None = None) -> None:
def render_summary() -> None:
metrics = strategy_metrics(selected["strategy"], selected["scenario_pct"], portfolio=portfolio)
strategy = metrics["strategy"]
# Display mode-aware labels
if display_mode == "GLD":
weight_unit = "shares"
@@ -261,7 +259,7 @@ async def _render_hedge_page(workspace_id: str | None = None) -> None:
weight_unit = "oz"
price_unit = "/oz"
hedge_cost_unit = "/oz"
summary.clear()
with summary:
ui.label("Scenario Summary").classes("text-lg font-semibold text-slate-900 dark:text-slate-100")

View File

@@ -88,9 +88,7 @@ async def options_page() -> None:
def filtered_rows() -> list[dict[str, Any]]:
return [
row
for row in chain_state["rows"]
if strike_range["min"] <= float(row["strike"]) <= strike_range["max"]
row for row in chain_state["rows"] if strike_range["min"] <= float(row["strike"]) <= strike_range["max"]
]
def render_selection() -> None:
@@ -186,7 +184,9 @@ async def options_page() -> None:
next_chain = await data_service.get_options_chain_for_expiry("GLD", expiry)
chain_state["data"] = next_chain
chain_state["rows"] = list(next_chain.get("rows") or [*next_chain.get("calls", []), *next_chain.get("puts", [])])
chain_state["rows"] = list(
next_chain.get("rows") or [*next_chain.get("calls", []), *next_chain.get("puts", [])]
)
min_value, max_value = strike_bounds(chain_state["rows"])
strike_range["min"] = min_value

View File

@@ -124,11 +124,13 @@ def welcome_page(request: Request):
if turnstile.uses_test_keys
else ""
)
ui.html(f"""<form method="post" action="/workspaces/bootstrap" class="flex items-center gap-4">
ui.html(
f"""<form method="post" action="/workspaces/bootstrap" class="flex items-center gap-4">
{hidden_token}
<div class="cf-turnstile" data-sitekey="{turnstile.site_key}"></div>
<button type="submit" class="rounded-lg bg-slate-900 px-5 py-3 text-sm font-semibold text-white no-underline dark:bg-slate-100 dark:text-slate-900">Get started</button>
</form>""")
</form>"""
)
ui.label("You can always create a fresh workspace later if a link is lost.").classes(
"text-sm text-slate-500 dark:text-slate-400"
)
@@ -174,7 +176,11 @@ async def overview_page(workspace_id: str) -> None:
current_values[str(pos.id)] = pos.entry_value
total_annual_storage_cost = calculate_total_storage_cost(positions, current_values)
portfolio["annual_storage_cost"] = float(total_annual_storage_cost)
portfolio["storage_cost_pct"] = (float(total_annual_storage_cost) / float(portfolio["gold_value"]) * 100) if portfolio["gold_value"] > 0 else 0.0
portfolio["storage_cost_pct"] = (
(float(total_annual_storage_cost) / float(portfolio["gold_value"]) * 100)
if portfolio["gold_value"] > 0
else 0.0
)
alert_status = AlertService().evaluate(config, portfolio)
ltv_history_service = LtvHistoryService(repository=LtvHistoryRepository(base_path=repo.base_path))
@@ -197,7 +203,7 @@ async def overview_page(workspace_id: str) -> None:
ltv_history_csv = ""
ltv_history_notice = "Historical LTV is temporarily unavailable due to a storage error."
display_mode = portfolio.get("display_mode", "XAU")
if portfolio["quote_source"] == "configured_entry_price":
if display_mode == "GLD":
quote_status = "Live quote source: configured entry price fallback (GLD shares) · Last updated Unavailable"
@@ -342,7 +348,7 @@ async def overview_page(workspace_id: str) -> None:
"w-full rounded-2xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900"
):
ui.label("Portfolio Snapshot").classes("text-lg font-semibold text-slate-900 dark:text-slate-100")
# Display mode-aware labels
if display_mode == "GLD":
spot_label = "GLD Share Price"
@@ -352,7 +358,7 @@ async def overview_page(workspace_id: str) -> None:
spot_label = "Collateral Spot Price"
spot_unit = "/oz"
margin_label = "Margin Call Price"
with ui.grid(columns=1).classes("w-full gap-4 sm:grid-cols-2 lg:grid-cols-1 xl:grid-cols-2"):
summary_cards = [
(

View File

@@ -263,9 +263,9 @@ def settings_page(workspace_id: str) -> None:
value=config.display_mode,
label="Display mode",
).classes("w-full")
ui.separator().classes("my-4")
ui.label("Data Sources").classes("text-lg font-semibold text-slate-900 dark:text-slate-100")
underlying = ui.select(
{
@@ -384,8 +384,12 @@ def settings_page(workspace_id: str) -> None:
).classes("w-full")
ui.separator().classes("my-3")
ui.label("Storage Costs (optional)").classes("text-sm font-semibold text-slate-700 dark:text-slate-300")
ui.label("For physical gold (XAU), defaults to 0.12% annual vault storage.").classes("text-xs text-slate-500 dark:text-slate-400 mb-2")
ui.label("Storage Costs (optional)").classes(
"text-sm font-semibold text-slate-700 dark:text-slate-300"
)
ui.label("For physical gold (XAU), defaults to 0.12% annual vault storage.").classes(
"text-xs text-slate-500 dark:text-slate-400 mb-2"
)
pos_storage_cost_basis = ui.number(
"Storage cost (% per year or fixed $)",
@@ -401,8 +405,12 @@ def settings_page(workspace_id: str) -> None:
).classes("w-full")
ui.separator().classes("my-3")
ui.label("Premium & Spread (optional)").classes("text-sm font-semibold text-slate-700 dark:text-slate-300")
ui.label("For physical gold, accounts for dealer markup and bid/ask spread.").classes("text-xs text-slate-500 dark:text-slate-400 mb-2")
ui.label("Premium & Spread (optional)").classes(
"text-sm font-semibold text-slate-700 dark:text-slate-300"
)
ui.label("For physical gold, accounts for dealer markup and bid/ask spread.").classes(
"text-xs text-slate-500 dark:text-slate-400 mb-2"
)
pos_purchase_premium = ui.number(
"Purchase premium over spot (%)",
@@ -429,10 +437,14 @@ def settings_page(workspace_id: str) -> None:
try:
underlying = str(pos_underlying.value)
storage_cost_basis_val = float(pos_storage_cost_basis.value)
storage_cost_basis = Decimal(str(storage_cost_basis_val)) if storage_cost_basis_val > 0 else None
storage_cost_basis = (
Decimal(str(storage_cost_basis_val)) if storage_cost_basis_val > 0 else None
)
storage_cost_period = str(pos_storage_cost_period.value) if storage_cost_basis else None
purchase_premium_val = float(pos_purchase_premium.value)
purchase_premium = Decimal(str(purchase_premium_val / 100)) if purchase_premium_val > 0 else None
purchase_premium = (
Decimal(str(purchase_premium_val / 100)) if purchase_premium_val > 0 else None
)
bid_ask_spread_val = float(pos_bid_ask_spread.value)
bid_ask_spread = Decimal(str(bid_ask_spread_val / 100)) if bid_ask_spread_val > 0 else None