Skip to content
Snippets Groups Projects

Prepare withdraw routes part of the HP managament

Merged Jakub Ziebinski requested to merge jziebinski/withdraw-routes-prepare into develop
Compare and Show latest version
6 files
+ 52
224
Compare changes
  • Side-by-side
  • Inline
Files
6
@@ -12,8 +12,8 @@ from clive.__private.ui.operations.bindings import OperationActionBindings
from clive.__private.ui.operations.operation_summary.remove_withdraw_vesting_route import RemoveWithdrawVestingRoute
from clive.__private.ui.widgets.clive_button import CliveButton
from clive.__private.ui.widgets.clive_checkerboard_table import (
EVEN_STYLE,
ODD_STYLE,
EVEN_CLASS_NAME,
ODD_CLASS_NAME,
CliveCheckerboardTable,
CliveCheckerBoardTableCell,
CliveCheckerboardTableRow,
@@ -38,30 +38,20 @@ class PlaceTaker(Static):
class WithdrawRoutesHeader(Horizontal):
def compose(self) -> ComposeResult:
yield Static("To", classes=ODD_STYLE)
yield Static("Percent", classes=EVEN_STYLE)
yield Static("Auto vest", classes=ODD_STYLE)
yield Static("To", classes=EVEN_CLASS_NAME)
yield Static("Percent", classes=ODD_CLASS_NAME)
yield Static("Auto vest", classes=EVEN_CLASS_NAME)
yield PlaceTaker()
class WithdrawRoute(CliveCheckerboardTableRow):
"""Row of the `WithdrawRoutesTable`."""
def __init__(self, withdraw_route: WithdrawRouteSchema, evenness: str = "odd") -> None:
"""
Initialize the WithdrawRoute row.
Args:
----
withdraw_route: Withdraw route data to display.
evenness: Evenness of the row.
"""
def __init__(self, withdraw_route: WithdrawRouteSchema) -> None:
super().__init__(
CliveCheckerBoardTableCell(withdraw_route.to_account, evenness="odd" if evenness == "odd" else "even"),
CliveCheckerBoardTableCell(
f"{withdraw_route.percent / 100} %", evenness="even" if evenness == "odd" else "odd"
),
CliveCheckerBoardTableCell(f"{withdraw_route.auto_vest}", evenness="odd" if evenness == "odd" else "even"),
CliveCheckerBoardTableCell(withdraw_route.to_account),
CliveCheckerBoardTableCell(f"{withdraw_route.percent / 100} %"),
CliveCheckerBoardTableCell(f"{withdraw_route.auto_vest}"),
CliveButton("Remove", classes="remove-withdraw-route-button", variant="error"),
)
self._withdraw_route = withdraw_route
@@ -78,14 +68,14 @@ class WithdrawRoutesTable(CliveCheckerboardTable):
super().__init__(
Static("Current withdraw routes", id="withdraw-routes-table-title"), WithdrawRoutesHeader(), dynamic=True
)
self._withdraw_routes: list[WithdrawRouteSchema] = []
self._withdraw_routes: list[WithdrawRouteSchema] | None = None
def create_dynamic_rows(self, content: HivePowerData) -> list[Widget]:
def create_dynamic_rows(self, content: HivePowerData) -> list[CliveCheckerboardTableRow]:
self._withdraw_routes = content.withdraw_routes
withdraw_routes: list[Widget] = []
for evenness, withdraw_route in enumerate(content.withdraw_routes):
withdraw_routes.append(WithdrawRoute(withdraw_route, "even" if evenness % 2 == 0 else "odd"))
withdraw_routes: list[CliveCheckerboardTableRow] = [
WithdrawRoute(withdraw_route) for withdraw_route in self._withdraw_routes
]
return withdraw_routes
def get_no_content_available_widget(self) -> Widget:
@@ -93,7 +83,7 @@ class WithdrawRoutesTable(CliveCheckerboardTable):
@property
def provider(self) -> HivePowerDataProvider:
return self.app.query_one(HivePowerDataProvider)
return self.screen.query_one(HivePowerDataProvider)
@property
def check_if_should_be_updated(self) -> bool:
@@ -101,9 +91,7 @@ class WithdrawRoutesTable(CliveCheckerboardTable):
@property
def is_anything_to_display(self) -> bool:
if len(self.provider.content.withdraw_routes) != 0:
return True
return False
return len(self.provider.content.withdraw_routes) != 0
@property
def working_account(self) -> str:
Loading