Skip to content

Commit

Permalink
fixup! fix(core): fix missing refresh in progress layout
Browse files Browse the repository at this point in the history
  • Loading branch information
TychoVrahe committed Jan 2, 2024
1 parent 02dd81b commit 5c1cd50
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
34 changes: 29 additions & 5 deletions core/src/apps/bitcoin/sign_tx/approvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
from .tx_info import OriginalTxInfo

if TYPE_CHECKING:
from typing import Optional

from trezor.crypto import bip32
from trezor.messages import SignTx, TxAckPaymentRequest, TxInput, TxOutput

from apps.common.coininfo import CoinInfo
from apps.common.keychain import Keychain

from ..authorization import CoinJoinAuthorization
from .bitcoin import Bitcoin
from .payment_request import PaymentRequestVerifier
from .tx_info import TxInfo

Expand Down Expand Up @@ -132,7 +135,12 @@ async def approve_orig_txids(
) -> None:
raise NotImplementedError

async def approve_tx(self, tx_info: TxInfo, orig_txs: list[OriginalTxInfo]) -> None:
async def approve_tx(
self,
tx_info: TxInfo,
orig_txs: list[OriginalTxInfo],
signer: Optional[Bitcoin],
) -> None:
self.finish_payment_request()


Expand Down Expand Up @@ -268,13 +276,18 @@ def _replacement_title(
else:
return "Update transaction"

async def approve_tx(self, tx_info: TxInfo, orig_txs: list[OriginalTxInfo]) -> None:
async def approve_tx(
self,
tx_info: TxInfo,
orig_txs: list[OriginalTxInfo],
signer: Optional[Bitcoin],
) -> None:
from trezor.wire import NotEnoughFunds

coin = self.coin # local_cache_attribute
amount_unit = self.amount_unit # local_cache_attribute

await super().approve_tx(tx_info, orig_txs)
await super().approve_tx(tx_info, orig_txs, signer)

if self.has_unverified_external_input:
await helpers.confirm_unverified_external_input()
Expand Down Expand Up @@ -333,6 +346,9 @@ async def approve_tx(self, tx_info: TxInfo, orig_txs: list[OriginalTxInfo]) -> N
"Original transactions must have same effective nLockTime as replacement transaction."
)

if signer is not None:
signer.init_signing()

if not self.is_payjoin():
title = self._replacement_title(tx_info, orig_txs)
# Not a PayJoin: Show the actual fee difference, since any difference in the fee is
Expand Down Expand Up @@ -361,6 +377,9 @@ async def approve_tx(self, tx_info: TxInfo, orig_txs: list[OriginalTxInfo]) -> N
tx_info.tx.lock_time, tx_info.lock_time_disabled()
)

if signer is not None:
signer.init_signing()

if not self.external_in:
await helpers.confirm_total(
total,
Expand Down Expand Up @@ -509,10 +528,15 @@ def _verify_coinjoin_request(self, tx_info: TxInfo):
self.h_request.get_digest(),
)

async def approve_tx(self, tx_info: TxInfo, orig_txs: list[OriginalTxInfo]) -> None:
async def approve_tx(
self,
tx_info: TxInfo,
orig_txs: list[OriginalTxInfo],
signer: Optional[Bitcoin],
) -> None:
from ..authorization import FEE_RATE_DECIMALS

await super().approve_tx(tx_info, orig_txs)
await super().approve_tx(tx_info, orig_txs, signer)

if not self._verify_coinjoin_request(tx_info):
raise DataError("Invalid signature in coinjoin request.")
Expand Down
37 changes: 22 additions & 15 deletions core/src/apps/bitcoin/sign_tx/bitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@


class Bitcoin:
def init_signing(self) -> None:
# Next shown progress bar is already signing progress, but it isn't shown until approval from next dialog
progress.init_signing(
len(self.external),
len(self.segwit),
len(self.presigned),
self.taproot_only,
self.serialize,
self.coin,
self.tx_info.tx,
self.orig_txs,
)
self.signing = True

async def signer(self) -> None:
progress.init(
self.tx_info.tx, is_coinjoin=isinstance(self.approver, CoinJoinApprover)
Expand All @@ -55,23 +69,13 @@ async def signer(self) -> None:
# sum of output amounts.
await self.step2_approve_outputs()

# Next shown progress bar is already signing progress, but it isn't shown until approval from next dialog
progress.init_signing(
len(self.external),
len(self.segwit),
len(self.presigned),
self.taproot_only,
self.serialize,
self.coin,
self.tx_info.tx,
self.orig_txs,
)

# Check fee, approve lock_time and total.
await self.approver.approve_tx(self.tx_info, self.orig_txs)
await self.approver.approve_tx(self.tx_info, self.orig_txs, self)

# Make sure proprer progress is shown, in case dialog was not required
progress.report_init()
# Make sure proper progress is shown, in case dialog was not required
if not self.signing:
self.init_signing()
progress.report_init()
progress.report()

# Following steps can take a long time, make sure autolock doesn't kick in.
Expand Down Expand Up @@ -134,6 +138,9 @@ def __init__(
# indicates whether all internal inputs are Taproot
self.taproot_only = True

# indicates whether the transaction is being signed
self.signing = False

# transaction and signature serialization
_SERIALIZED_TX_BUFFER[:] = bytes()
self.serialized_tx = _SERIALIZED_TX_BUFFER
Expand Down
2 changes: 1 addition & 1 deletion core/tests/test_apps.bitcoin.approver.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_coinjoin_lots_of_inputs(self):
else:
await_result(approver.add_external_output(txo, script_pubkey=bytes(22)))

await_result(approver.approve_tx(TxInfo(signer, tx), []))
await_result(approver.approve_tx(TxInfo(signer, tx), [], None))

def test_coinjoin_input_account_depth_mismatch(self):
txi = TxInput(
Expand Down

0 comments on commit 5c1cd50

Please sign in to comment.