1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

refactor(core): return FlowMsg::Choice and FlowMsg::Text as plain values

instead of tuples
This commit is contained in:
matejcik 2024-09-24 13:28:52 +02:00 committed by matejcik
parent 2661dbb3d1
commit 6cbba09d1d
4 changed files with 14 additions and 25 deletions

View File

@ -616,8 +616,8 @@ impl TryFrom<FlowMsg> for crate::micropython::obj::Obj {
FlowMsg::Confirmed => Ok(result::CONFIRMED.as_obj()), FlowMsg::Confirmed => Ok(result::CONFIRMED.as_obj()),
FlowMsg::Cancelled => Ok(result::CANCELLED.as_obj()), FlowMsg::Cancelled => Ok(result::CANCELLED.as_obj()),
FlowMsg::Info => Ok(result::INFO.as_obj()), FlowMsg::Info => Ok(result::INFO.as_obj()),
FlowMsg::Choice(i) => (result::CONFIRMED.as_obj(), i.try_into()?).try_into(), FlowMsg::Choice(i) => i.try_into(),
FlowMsg::Text(s) => (result::CONFIRMED.as_obj(), s.as_str().try_into()?).try_into(), FlowMsg::Text(s) => s.as_str().try_into(),
} }
} }
} }

View File

@ -1436,18 +1436,8 @@ async def request_passphrase_on_device(max_len: int) -> str:
if result is CANCELLED: if result is CANCELLED:
raise ActionCancelled("Passphrase entry cancelled") raise ActionCancelled("Passphrase entry cancelled")
if __debug__: assert isinstance(result, str)
if not isinstance(result, tuple): return result
# TODO: DebugLink problem, better comment or solution?
result = (CONFIRMED, str(result))
status, value = result
if status == CONFIRMED:
assert isinstance(value, str)
return value
else:
# flow_request_pin returns either CANCELLED or (CONFIRMED, str) so this branch shouldn't be taken
raise ActionCancelled("Passphrase entry cancelled")
async def request_pin_on_device( async def request_pin_on_device(

View File

@ -70,8 +70,8 @@ async def confirm_fido(
# The Rust side returns either an int or `CANCELLED`. We detect the int situation # The Rust side returns either an int or `CANCELLED`. We detect the int situation
# and assume cancellation otherwise. # and assume cancellation otherwise.
if isinstance(result, tuple): if isinstance(result, int):
return result[1] return result
# Late import won't get executed on the happy path. # Late import won't get executed on the happy path.
from trezor.wire import ActionCancelled from trezor.wire import ActionCancelled

View File

@ -176,15 +176,14 @@ async def _prompt_number(
) )
) )
if __debug__: if __debug__ and result is CONFIRMED:
if not isinstance(result, tuple): # sent by debuglink. debuglink does not change the number of shares anyway
# DebugLink currently can't send number of shares and it doesn't # so use the initial one
# change the counter either so just use the initial value. return count
result = (result, count)
status, value = result if result is not trezorui2.CANCELLED:
if status == CONFIRMED: assert isinstance(result, int)
assert isinstance(value, int) return result
return value
else: else:
raise ActionCancelled # user cancelled request number prompt raise ActionCancelled # user cancelled request number prompt