104 lines
3.5 KiB
Python
104 lines
3.5 KiB
Python
|
from aiogram_dialog import Dialog, Window
|
||
|
from aiogram_dialog.widgets.kbd import Row, Start, Button
|
||
|
from aiogram_dialog.widgets.text import Format, Const
|
||
|
from aiogram_dialog.widgets.input import TextInput, ManagedTextInput
|
||
|
from aiogram_dialog import DialogManager
|
||
|
from aiogram.types import Message
|
||
|
|
||
|
from bot.services import check_pay_crypto_bot, check_pay_lolz
|
||
|
from bot.getters import getter_amount, getter_amount_cryptobot
|
||
|
from bot.states import UpBalanceCryptoSG, UpBalanceSG, UpBalanceLolzSG, ProfileSG
|
||
|
from bot.validations import error_number_handler
|
||
|
from typing import Any
|
||
|
|
||
|
|
||
|
class UpBalanceWindow(Window):
|
||
|
def __init__(self, text: str, state: Any, on_error: Any, **kwargs):
|
||
|
super().__init__(
|
||
|
Const(text=text),
|
||
|
TextInput(
|
||
|
id="count",
|
||
|
type_factory=str,
|
||
|
on_success=self._on_success_callback,
|
||
|
on_error=on_error,
|
||
|
),
|
||
|
state=state,
|
||
|
**kwargs
|
||
|
)
|
||
|
|
||
|
async def _on_success_callback(self, message: Message, widget: ManagedTextInput, dialog_manager: DialogManager, data: str):
|
||
|
if not dialog_manager.current_context().dialog_data.get("error"):
|
||
|
await dialog_manager.next()
|
||
|
|
||
|
|
||
|
class PaymentWindow(Window):
|
||
|
def __init__(self, state: Any, check_pay_function: Any, getter: Any, **kwargs):
|
||
|
super().__init__(
|
||
|
Format(text="{paylink}", when=lambda data, widget, manager: not data.get("error")),
|
||
|
Format(text="{error}", when=lambda data, widget, manager: data.get("error") is not None),
|
||
|
Button(
|
||
|
Const("🔍 Проверить оплату"),
|
||
|
id="check_pay_button",
|
||
|
on_click=check_pay_function,
|
||
|
when=lambda data, widget, manager: not data.get("error") and data.get("paylink") is not None
|
||
|
),
|
||
|
Button(
|
||
|
Const("🔙 Отмена"),
|
||
|
id="cancel_button",
|
||
|
on_click=lambda callback, button, manager: manager.switch_to(ProfileSG.profile),
|
||
|
when=lambda data, widget, manager: data.get("error") is not None
|
||
|
),
|
||
|
state=state,
|
||
|
getter=getter,
|
||
|
**kwargs
|
||
|
)
|
||
|
|
||
|
|
||
|
up_balance_dialog = Dialog(
|
||
|
Window(
|
||
|
Const("Выберите через что хотите пополнить баланс:"),
|
||
|
Row(
|
||
|
Start(
|
||
|
Const("💸 Lolz"),
|
||
|
id="paymethod_lolz",
|
||
|
state=UpBalanceLolzSG.up_balance_lolz,
|
||
|
),
|
||
|
Start(
|
||
|
Const("💸 CryptoBot"),
|
||
|
id="paymethod_crypto",
|
||
|
state=UpBalanceCryptoSG.up_balance_crypto,
|
||
|
),
|
||
|
),
|
||
|
Start(Const("🔙 Назад"), id="back", state=ProfileSG.profile),
|
||
|
state=UpBalanceSG.up_balance,
|
||
|
)
|
||
|
)
|
||
|
|
||
|
|
||
|
up_balance_lolz_dialog = Dialog(
|
||
|
UpBalanceWindow(
|
||
|
text="💸 Введите сумму пополнения",
|
||
|
state=UpBalanceLolzSG.up_balance_lolz,
|
||
|
on_error=error_number_handler,
|
||
|
),
|
||
|
PaymentWindow(
|
||
|
state=UpBalanceLolzSG.pay_link,
|
||
|
check_pay_function=check_pay_lolz,
|
||
|
getter=getter_amount,
|
||
|
)
|
||
|
|
||
|
)
|
||
|
|
||
|
|
||
|
up_balance_cryptobot_dialog = Dialog(
|
||
|
UpBalanceWindow(
|
||
|
text="💸 Введите сумму пополнения",
|
||
|
state=UpBalanceCryptoSG.up_balance_crypto,
|
||
|
on_error=error_number_handler
|
||
|
),
|
||
|
PaymentWindow(
|
||
|
state=UpBalanceCryptoSG.pay_link,
|
||
|
check_pay_function=check_pay_crypto_bot,
|
||
|
getter=getter_amount_cryptobot,
|
||
|
),
|
||
|
)
|