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:
parent
2661dbb3d1
commit
6cbba09d1d
@ -616,8 +616,8 @@ impl TryFrom<FlowMsg> for crate::micropython::obj::Obj {
|
||||
FlowMsg::Confirmed => Ok(result::CONFIRMED.as_obj()),
|
||||
FlowMsg::Cancelled => Ok(result::CANCELLED.as_obj()),
|
||||
FlowMsg::Info => Ok(result::INFO.as_obj()),
|
||||
FlowMsg::Choice(i) => (result::CONFIRMED.as_obj(), i.try_into()?).try_into(),
|
||||
FlowMsg::Text(s) => (result::CONFIRMED.as_obj(), s.as_str().try_into()?).try_into(),
|
||||
FlowMsg::Choice(i) => i.try_into(),
|
||||
FlowMsg::Text(s) => s.as_str().try_into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1436,18 +1436,8 @@ async def request_passphrase_on_device(max_len: int) -> str:
|
||||
if result is CANCELLED:
|
||||
raise ActionCancelled("Passphrase entry cancelled")
|
||||
|
||||
if __debug__:
|
||||
if not isinstance(result, tuple):
|
||||
# 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")
|
||||
assert isinstance(result, str)
|
||||
return result
|
||||
|
||||
|
||||
async def request_pin_on_device(
|
||||
|
@ -70,8 +70,8 @@ async def confirm_fido(
|
||||
|
||||
# The Rust side returns either an int or `CANCELLED`. We detect the int situation
|
||||
# and assume cancellation otherwise.
|
||||
if isinstance(result, tuple):
|
||||
return result[1]
|
||||
if isinstance(result, int):
|
||||
return result
|
||||
|
||||
# Late import won't get executed on the happy path.
|
||||
from trezor.wire import ActionCancelled
|
||||
|
@ -176,15 +176,14 @@ async def _prompt_number(
|
||||
)
|
||||
)
|
||||
|
||||
if __debug__:
|
||||
if not isinstance(result, tuple):
|
||||
# DebugLink currently can't send number of shares and it doesn't
|
||||
# change the counter either so just use the initial value.
|
||||
result = (result, count)
|
||||
status, value = result
|
||||
if status == CONFIRMED:
|
||||
assert isinstance(value, int)
|
||||
return value
|
||||
if __debug__ and result is CONFIRMED:
|
||||
# sent by debuglink. debuglink does not change the number of shares anyway
|
||||
# so use the initial one
|
||||
return count
|
||||
|
||||
if result is not trezorui2.CANCELLED:
|
||||
assert isinstance(result, int)
|
||||
return result
|
||||
else:
|
||||
raise ActionCancelled # user cancelled request number prompt
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user