mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-27 02:12:35 +00:00
refactor(core): add maybe_get_context
[no changelog]
(cherry picked from commit 3bb3b774c1
)
This commit is contained in:
parent
092c86083c
commit
607d73b7da
@ -10,16 +10,15 @@ if TYPE_CHECKING:
|
||||
async def unpair(msg: BleUnpair) -> None:
|
||||
from trezor.messages import Success
|
||||
from trezor.ui.layouts import confirm_action
|
||||
from trezor.wire.context import get_context
|
||||
from trezor.wire.context import maybe_get_context
|
||||
|
||||
if msg.all:
|
||||
await confirm_action("erase bonds", TR.ble__unpair_title, TR.ble__unpair_all)
|
||||
else:
|
||||
await confirm_action("unpair", TR.ble__unpair_title, TR.ble__unpair_current)
|
||||
|
||||
ctx = get_context()
|
||||
|
||||
await ctx.write(Success(message="Erasing.."))
|
||||
if ctx := maybe_get_context():
|
||||
await ctx.write(Success(message="Erasing..."))
|
||||
|
||||
if msg.all:
|
||||
ble.erase_bonds()
|
||||
|
@ -107,6 +107,13 @@ def get_context() -> Context:
|
||||
return CURRENT_CONTEXT
|
||||
|
||||
|
||||
def maybe_get_context() -> Context | None:
|
||||
"""Variant of the function above, same limitations apply. Needed in special cases
|
||||
where a handler might be invoked over wire or from a homescreen menu (e.g. wipe).
|
||||
"""
|
||||
return CURRENT_CONTEXT
|
||||
|
||||
|
||||
def with_context(ctx: Context, workflow: loop.Task) -> Generator:
|
||||
"""Run a workflow in a particular context.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user