mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-04 13:52:35 +00:00
refactor(core/ui): rename confirm_payment_request to should_...
Because confirm_* returns None and raises on false. but this layout is actually a prompt akin to should_show_more
This commit is contained in:
parent
34965ca2cb
commit
fd3919254c
@ -248,9 +248,10 @@ class BasicApprover(Approver):
|
|||||||
if msg.amount is None:
|
if msg.amount is None:
|
||||||
raise DataError("Missing payment request amount.")
|
raise DataError("Missing payment request amount.")
|
||||||
|
|
||||||
result = await helpers.confirm_payment_request(msg, self.coin, self.amount_unit)
|
result = await helpers.should_show_payment_request_details(
|
||||||
# When user wants to see more info, the result will be False.
|
msg, self.coin, self.amount_unit
|
||||||
self.show_payment_req_details = result is False
|
)
|
||||||
|
self.show_payment_req_details = result is True
|
||||||
|
|
||||||
async def approve_orig_txids(
|
async def approve_orig_txids(
|
||||||
self, tx_info: TxInfo, orig_txs: list[OriginalTxInfo]
|
self, tx_info: TxInfo, orig_txs: list[OriginalTxInfo]
|
||||||
|
@ -85,8 +85,8 @@ class UiConfirmPaymentRequest(UiConfirm):
|
|||||||
self.amount_unit = amount_unit
|
self.amount_unit = amount_unit
|
||||||
self.coin = coin
|
self.coin = coin
|
||||||
|
|
||||||
def confirm_dialog(self) -> Awaitable[Any]:
|
def confirm_dialog(self) -> Awaitable[bool]:
|
||||||
return layout.confirm_payment_request(
|
return layout.should_show_payment_request_details(
|
||||||
self.payment_req, self.coin, self.amount_unit
|
self.payment_req, self.coin, self.amount_unit
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ def confirm_decred_sstx_submission(output: TxOutput, coin: CoinInfo, amount_unit
|
|||||||
return (yield UiConfirmDecredSSTXSubmission(output, coin, amount_unit))
|
return (yield UiConfirmDecredSSTXSubmission(output, coin, amount_unit))
|
||||||
|
|
||||||
|
|
||||||
def confirm_payment_request(payment_req: TxAckPaymentRequest, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[Any]: # type: ignore [awaitable-is-generator]
|
def should_show_payment_request_details(payment_req: TxAckPaymentRequest, coin: CoinInfo, amount_unit: AmountUnit) -> Awaitable[bool]: # type: ignore [awaitable-is-generator]
|
||||||
return (yield UiConfirmPaymentRequest(payment_req, coin, amount_unit))
|
return (yield UiConfirmPaymentRequest(payment_req, coin, amount_unit))
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,8 +18,6 @@ from ..common import (
|
|||||||
from ..keychain import address_n_to_name
|
from ..keychain import address_n_to_name
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from trezor.enums import AmountUnit
|
from trezor.enums import AmountUnit
|
||||||
from trezor.messages import TxAckPaymentRequest, TxOutput
|
from trezor.messages import TxAckPaymentRequest, TxOutput
|
||||||
from trezor.ui.layouts import LayoutType
|
from trezor.ui.layouts import LayoutType
|
||||||
@ -152,11 +150,11 @@ async def confirm_decred_sstx_submission(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_payment_request(
|
async def should_show_payment_request_details(
|
||||||
msg: TxAckPaymentRequest,
|
msg: TxAckPaymentRequest,
|
||||||
coin: CoinInfo,
|
coin: CoinInfo,
|
||||||
amount_unit: AmountUnit,
|
amount_unit: AmountUnit,
|
||||||
) -> Any:
|
) -> bool:
|
||||||
from trezor import wire
|
from trezor import wire
|
||||||
|
|
||||||
memo_texts: list[str] = []
|
memo_texts: list[str] = []
|
||||||
@ -172,7 +170,7 @@ async def confirm_payment_request(
|
|||||||
|
|
||||||
assert msg.amount is not None
|
assert msg.amount is not None
|
||||||
|
|
||||||
return await layouts.confirm_payment_request(
|
return await layouts.should_show_payment_request_details(
|
||||||
msg.recipient_name,
|
msg.recipient_name,
|
||||||
format_coin_amount(msg.amount, coin, amount_unit),
|
format_coin_amount(msg.amount, coin, amount_unit),
|
||||||
memo_texts,
|
memo_texts,
|
||||||
|
@ -740,18 +740,19 @@ def tutorial(br_code: ButtonRequestType = BR_TYPE_OTHER) -> Awaitable[None]:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def confirm_payment_request(
|
async def should_show_payment_request_details(
|
||||||
recipient_name: str,
|
recipient_name: str,
|
||||||
amount: str,
|
amount: str,
|
||||||
memos: list[str],
|
memos: list[str],
|
||||||
) -> Awaitable[None]:
|
) -> bool:
|
||||||
memos_str = "\n".join(memos)
|
memos_str = "\n".join(memos)
|
||||||
return _placeholder_confirm(
|
await _placeholder_confirm(
|
||||||
"confirm_payment_request",
|
"confirm_payment_request",
|
||||||
TR.send__title_confirm_sending,
|
TR.send__title_confirm_sending,
|
||||||
description=f"{amount} to\n{recipient_name}\n{memos_str}",
|
description=f"{amount} to\n{recipient_name}\n{memos_str}",
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
br_code=ButtonRequestType.ConfirmOutput,
|
||||||
)
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def should_show_more(
|
async def should_show_more(
|
||||||
|
@ -657,11 +657,16 @@ async def confirm_output(
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def confirm_payment_request(
|
async def should_show_payment_request_details(
|
||||||
recipient_name: str,
|
recipient_name: str,
|
||||||
amount: str,
|
amount: str,
|
||||||
memos: list[str],
|
memos: list[str],
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
"""Return True if the user wants to show payment request details (they click a
|
||||||
|
special button) and False when the user wants to continue without showing details.
|
||||||
|
|
||||||
|
Raises ActionCancelled if the user cancels.
|
||||||
|
"""
|
||||||
result = await interact(
|
result = await interact(
|
||||||
RustLayout(
|
RustLayout(
|
||||||
trezorui2.confirm_with_info(
|
trezorui2.confirm_with_info(
|
||||||
@ -676,12 +681,10 @@ async def confirm_payment_request(
|
|||||||
ButtonRequestType.ConfirmOutput,
|
ButtonRequestType.ConfirmOutput,
|
||||||
)
|
)
|
||||||
|
|
||||||
# When user pressed INFO, returning False, which gets processed in higher function
|
|
||||||
# to differentiate it from CONFIRMED. Raising otherwise.
|
|
||||||
if result is CONFIRMED:
|
if result is CONFIRMED:
|
||||||
return True
|
|
||||||
elif result is INFO:
|
|
||||||
return False
|
return False
|
||||||
|
elif result is INFO:
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
raise ActionCancelled
|
raise ActionCancelled
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user