fix(settings): preserve whole-dollar loan formatting
This commit is contained in:
@@ -60,6 +60,15 @@ def settings_page(workspace_id: str) -> None:
|
|||||||
return None
|
return None
|
||||||
return parsed if parsed >= 0 else None
|
return parsed if parsed >= 0 else None
|
||||||
|
|
||||||
|
def display_number_input_value(value: object) -> str:
|
||||||
|
try:
|
||||||
|
parsed = float(value)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return ""
|
||||||
|
if parsed.is_integer():
|
||||||
|
return str(int(parsed))
|
||||||
|
return str(parsed)
|
||||||
|
|
||||||
def build_preview_config() -> PortfolioConfig:
|
def build_preview_config() -> PortfolioConfig:
|
||||||
parsed_loan_amount = as_non_negative_float(loan_amount.value)
|
parsed_loan_amount = as_non_negative_float(loan_amount.value)
|
||||||
if parsed_loan_amount is None:
|
if parsed_loan_amount is None:
|
||||||
@@ -132,7 +141,7 @@ def settings_page(workspace_id: str) -> None:
|
|||||||
loan_amount = (
|
loan_amount = (
|
||||||
ui.input(
|
ui.input(
|
||||||
"Loan amount ($)",
|
"Loan amount ($)",
|
||||||
value=str(config.loan_amount),
|
value=display_number_input_value(config.loan_amount),
|
||||||
)
|
)
|
||||||
.props("type=number min=0 step=1000")
|
.props("type=number min=0 step=1000")
|
||||||
.classes("w-full")
|
.classes("w-full")
|
||||||
@@ -345,9 +354,12 @@ def settings_page(workspace_id: str) -> None:
|
|||||||
|
|
||||||
if collateral_value is not None and collateral_value > 0 and loan is not None:
|
if collateral_value is not None and collateral_value > 0 and loan is not None:
|
||||||
ltv = (loan / collateral_value) * 100
|
ltv = (loan / collateral_value) * 100
|
||||||
buffer = ((margin or 0.0) - loan / collateral_value) * 100 if margin is not None else 0.0
|
|
||||||
ltv_display.set_text(f"{ltv:.1f}%")
|
ltv_display.set_text(f"{ltv:.1f}%")
|
||||||
buffer_display.set_text(f"{buffer:.1f}%")
|
if margin is not None:
|
||||||
|
buffer = (margin - loan / collateral_value) * 100
|
||||||
|
buffer_display.set_text(f"{buffer:.1f}%")
|
||||||
|
else:
|
||||||
|
buffer_display.set_text("—")
|
||||||
else:
|
else:
|
||||||
ltv_display.set_text("—")
|
ltv_display.set_text("—")
|
||||||
buffer_display.set_text("—")
|
buffer_display.set_text("—")
|
||||||
|
|||||||
@@ -36,4 +36,7 @@ def test_settings_reject_invalid_loan_amount_without_silent_zero_fallback() -> N
|
|||||||
assert "Server error" not in settings_text
|
assert "Server error" not in settings_text
|
||||||
assert "Traceback" not in settings_text
|
assert "Traceback" not in settings_text
|
||||||
|
|
||||||
|
page.reload(wait_until="domcontentloaded", timeout=30000)
|
||||||
|
expect(page.get_by_label("Loan amount ($)")).to_have_value("145000")
|
||||||
|
|
||||||
browser.close()
|
browser.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user