Skip to content

Commit

Permalink
refactor(core/ui): rename confirm_payment_request to should_...
Browse files Browse the repository at this point in the history
Because confirm_* returns None and raises on false.

but this layout is actually a prompt akin to should_show_more
  • Loading branch information
matejcik committed Mar 7, 2024
1 parent 34965ca commit fd39192
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
7 changes: 4 additions & 3 deletions core/src/apps/bitcoin/sign_tx/approvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,10 @@ async def add_payment_request(
if msg.amount is None:
raise DataError("Missing payment request amount.")

result = await helpers.confirm_payment_request(msg, self.coin, self.amount_unit)
# When user wants to see more info, the result will be False.
self.show_payment_req_details = result is False
result = await helpers.should_show_payment_request_details(
msg, self.coin, self.amount_unit
)
self.show_payment_req_details = result is True

async def approve_orig_txids(
self, tx_info: TxInfo, orig_txs: list[OriginalTxInfo]
Expand Down
6 changes: 3 additions & 3 deletions core/src/apps/bitcoin/sign_tx/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def __init__(
self.amount_unit = amount_unit
self.coin = coin

def confirm_dialog(self) -> Awaitable[Any]:
return layout.confirm_payment_request(
def confirm_dialog(self) -> Awaitable[bool]:
return layout.should_show_payment_request_details(
self.payment_req, self.coin, self.amount_unit
)

Expand Down Expand Up @@ -249,7 +249,7 @@ def confirm_decred_sstx_submission(output: TxOutput, coin: CoinInfo, 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))


Expand Down
8 changes: 3 additions & 5 deletions core/src/apps/bitcoin/sign_tx/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from ..keychain import address_n_to_name

if TYPE_CHECKING:
from typing import Any

from trezor.enums import AmountUnit
from trezor.messages import TxAckPaymentRequest, TxOutput
from trezor.ui.layouts import LayoutType
Expand Down Expand Up @@ -152,11 +150,11 @@ async def confirm_decred_sstx_submission(
)


async def confirm_payment_request(
async def should_show_payment_request_details(
msg: TxAckPaymentRequest,
coin: CoinInfo,
amount_unit: AmountUnit,
) -> Any:
) -> bool:
from trezor import wire

memo_texts: list[str] = []
Expand All @@ -172,7 +170,7 @@ async def confirm_payment_request(

assert msg.amount is not None

return await layouts.confirm_payment_request(
return await layouts.should_show_payment_request_details(
msg.recipient_name,
format_coin_amount(msg.amount, coin, amount_unit),
memo_texts,
Expand Down
7 changes: 4 additions & 3 deletions core/src/trezor/ui/layouts/tr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
amount: str,
memos: list[str],
) -> Awaitable[None]:
) -> bool:
memos_str = "\n".join(memos)
return _placeholder_confirm(
await _placeholder_confirm(
"confirm_payment_request",
TR.send__title_confirm_sending,
description=f"{amount} to\n{recipient_name}\n{memos_str}",
br_code=ButtonRequestType.ConfirmOutput,
)
return False


async def should_show_more(
Expand Down
13 changes: 8 additions & 5 deletions core/src/trezor/ui/layouts/tt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,16 @@ async def confirm_output(
return


async def confirm_payment_request(
async def should_show_payment_request_details(
recipient_name: str,
amount: str,
memos: list[str],
) -> 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(
RustLayout(
trezorui2.confirm_with_info(
Expand All @@ -676,12 +681,10 @@ async def confirm_payment_request(
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:
return True
elif result is INFO:
return False
elif result is INFO:
return True
else:
raise ActionCancelled

Expand Down

0 comments on commit fd39192

Please sign in to comment.