Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hive/clive
1 result
Show changes
Commits on Source (2)
......@@ -2,17 +2,107 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from textual.widgets import TabPane
from textual import on
from textual.containers import Horizontal, ScrollableContainer, Vertical
from textual.widgets import Checkbox, Static, TabPane
from clive.__private.ui.widgets.clive_widget import CliveWidget
from clive.__private.ui.data_providers.hive_power_data_provider import HivePowerDataProvider
from clive.__private.ui.get_css import get_css_from_relative_path
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_CLASS_NAME,
ODD_CLASS_NAME,
CliveCheckerboardTable,
CliveCheckerBoardTableCell,
CliveCheckerboardTableRow,
)
from clive.__private.ui.widgets.inputs.account_name_input import AccountNameInput
from clive.__private.ui.widgets.inputs.clive_validated_input import CliveValidatedInput
from clive.__private.ui.widgets.inputs.percent_input import PercentInput
from schemas.operations import SetWithdrawVestingRouteOperation
if TYPE_CHECKING:
from rich.text import TextType
from textual.app import ComposeResult
from textual.widget import Widget
from clive.__private.core.commands.data_retrieval.hive_power_data import HivePowerData
from schemas.apis.database_api.fundaments_of_reponses import WithdrawVestingRoutesFundament as WithdrawRouteSchema
class WithdrawRoutes(TabPane, CliveWidget):
class PlaceTaker(Static):
pass
class WithdrawRoutesHeader(Horizontal):
def compose(self) -> ComposeResult:
yield Static("To", classes=ODD_CLASS_NAME)
yield Static("Percent", classes=EVEN_CLASS_NAME)
yield Static("Auto vest", classes=ODD_CLASS_NAME)
yield PlaceTaker()
class WithdrawRoute(CliveCheckerboardTableRow):
"""Row of the `WithdrawRoutesTable`."""
def __init__(self, withdraw_route: WithdrawRouteSchema) -> None:
super().__init__(
CliveCheckerBoardTableCell(withdraw_route.to_account),
CliveCheckerBoardTableCell(f"{withdraw_route.percent / 100} %"),
CliveCheckerBoardTableCell(f"{withdraw_route.auto_vest}"),
CliveCheckerBoardTableCell(CliveButton("Remove", classes="remove-withdraw-route-button", variant="error")),
)
self._withdraw_route = withdraw_route
@on(CliveButton.Pressed, ".remove-withdraw-route-button")
def push_operation_summary_screen(self) -> None:
self.app.push_screen(RemoveWithdrawVestingRoute(self._withdraw_route))
class WithdrawRoutesTable(CliveCheckerboardTable):
"""Table with WithdrawRoutes."""
def __init__(self) -> None:
super().__init__(
Static("Current withdraw routes", id="withdraw-routes-table-title"), WithdrawRoutesHeader(), dynamic=True
)
self._withdraw_routes: list[WithdrawRouteSchema] | None = None
def create_dynamic_rows(self, content: HivePowerData) -> list[CliveCheckerboardTableRow]:
self._withdraw_routes = content.withdraw_routes
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:
return Static("You have no withdraw routes", id="no-withdraw-routes-info")
@property
def provider(self) -> HivePowerDataProvider:
return self.screen.query_one(HivePowerDataProvider)
@property
def check_if_should_be_updated(self) -> bool:
return self.provider.content.withdraw_routes != self._withdraw_routes
@property
def is_anything_to_display(self) -> bool:
return len(self.provider.content.withdraw_routes) != 0
@property
def working_account(self) -> str:
return self.app.world.profile_data.working_account.name
class WithdrawRoutes(TabPane, OperationActionBindings):
"""TabPane with all content about setting withdraw routes."""
DEFAULT_CSS = get_css_from_relative_path(__file__)
def __init__(self, title: TextType):
"""
Initialize a TabPane.
......@@ -22,3 +112,30 @@ class WithdrawRoutes(TabPane, CliveWidget):
title: Title of the TabPane (will be displayed in a tab label).
"""
super().__init__(title=title)
self._account_input = AccountNameInput()
self._percent_input = PercentInput("Percent")
self._auto_vest_checkbox = Checkbox("Auto vest")
def compose(self) -> ComposeResult:
with ScrollableContainer():
yield Static("Set withdraw route", id="set-withdraw-route-title")
with Vertical(id="inputs-container"):
yield self._account_input
with Horizontal(id="input-with-checkbox"):
yield self._percent_input
yield self._auto_vest_checkbox
yield WithdrawRoutesTable()
def _create_operation(self) -> SetWithdrawVestingRouteOperation | None:
CliveValidatedInput.validate_many(self._account_input, self._percent_input)
return SetWithdrawVestingRouteOperation(
from_account=self.working_account,
to_account=self._account_input.value_or_error,
percent=self._percent_input.value_or_error * 100,
auto_vest=self._auto_vest_checkbox.value,
)
@property
def working_account(self) -> str:
return self.app.world.profile_data.working_account.name
WithdrawRoutes {
height: 1fr;
}
WithdrawRoutes Static {
text-style: bold;
width: 1fr;
text-align: center;
}
/* Set withdraw route */
#set-withdraw-route-title {
background: $primary;
width: 1fr;
height: 1;
}
#inputs-container {
background: $panel;
padding: 2 4;
height: auto;
}
#input-with-checkbox {
margin-top: 1;
height: auto;
}
#input-with-checkbox IntegerInput {
width: 1fr;
}
#input-with-checkbox Checkbox {
width: 17;
}
AccountNameInput KnownAccount {
margin-left: 3;
}
/* Withdraw routes table */
WithdrawRoutesHeader {
height: auto;
}
WithdrawRoutesTable {
margin-top: 1;
height: auto;
}
#no-withdraw-routes-info {
background: $primary;
height: auto;
}
#withdraw-routes-table-title {
background: $primary;
width: 1fr;
}
WithdrawRoute {
height: auto;
}
WithdrawRoute .remove-withdraw-route-button {
background: $error-darken-1;
width: 1fr;
}
from __future__ import annotations
from typing import TYPE_CHECKING, ClassVar, Final
from clive.__private.ui.operations.operation_summary.operation_summary import OperationSummary
from clive.__private.ui.widgets.inputs.labelized_input import LabelizedInput
from schemas.operations import SetWithdrawVestingRouteOperation
if TYPE_CHECKING:
from textual.app import ComposeResult
from schemas.apis.database_api.fundaments_of_reponses import WithdrawVestingRoutesFundament as WithdrawRoute
WITHDRAW_ROUTE_REMOVE_PERCENT: Final[int] = 0
class RemoveWithdrawVestingRoute(OperationSummary):
"""Screen to remove withdraw vesting route."""
BIG_TITLE: ClassVar[str] = "Remove withdraw vesting route"
def __init__(self, withdraw_route: WithdrawRoute) -> None:
super().__init__()
self._withdraw_route = withdraw_route
def content(self) -> ComposeResult:
yield LabelizedInput("From account", self.working_account)
yield LabelizedInput("To account", self._withdraw_route.to_account)
yield LabelizedInput("Percent", str(self._withdraw_route.percent / 100))
yield LabelizedInput("Auto vest", str(self._withdraw_route.auto_vest))
def _create_operation(self) -> SetWithdrawVestingRouteOperation | None:
return SetWithdrawVestingRouteOperation(
from_account=self.working_account,
to_account=self._withdraw_route.to_account,
auto_vest=self._withdraw_route.auto_vest,
percent=WITHDRAW_ROUTE_REMOVE_PERCENT,
)
@property
def working_account(self) -> str:
return self.app.world.profile_data.working_account.name