Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core/mercury): separate upy args parsing #4182

Merged
merged 3 commits into from
Nov 19, 2024

Conversation

obrusvit
Copy link
Contributor

@obrusvit obrusvit commented Sep 15, 2024

This PR separates the Rust flows from micropython layer.

The idea is to do the uPy argument parsing in ui/model_mercury/layout.rs and then pass them as regular arguments to code in ui/model_mercury/flow/**.rs, i.e. they won't be passed as args: &[Obj], kwargs: &Map. The goal is to keep the rust flows independent from micropython sub-crate. This separation is done for two reasons:

  • it simplifies the code in flows creation
  • it paves the way for apps done completely in Rust and for UiFeatures

This PR has no impact on UI or features.

Note:

  • there is a few places with the usage of Obj and IterBuf - last place is get_address.rs, postponing this for now

@obrusvit obrusvit added code Code improvements T3T1 Trezor Safe 5 labels Sep 15, 2024
@obrusvit obrusvit self-assigned this Sep 15, 2024
@obrusvit
Copy link
Contributor Author

Similar thing was done here for bootloader and "common". Need to take a look how to take the same/similar approach for firmware. #3658

@obrusvit obrusvit force-pushed the obrusvit/mercury/refactor-rust-layout-upy-parsing branch 4 times, most recently from b616b27 to 58347bc Compare September 30, 2024 10:28
@obrusvit obrusvit marked this pull request as ready for review September 30, 2024 10:30
@obrusvit obrusvit requested review from mmilata and removed request for prusnak September 30, 2024 10:30
@obrusvit
Copy link
Contributor Author

obrusvit commented Sep 30, 2024

The only conflict with #3686 should be: Layout::new moved to layout.rs and renamed to Layout::new_root

Copy link
Member

@mmilata mmilata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrote some thoughts inline but overall this should be a harmless refactor that can be merged when CI passes.

case_sensitive: bool,
account: Option<TString<'static>>,
path: Option<TString<'static>>,
xpubs: Obj, // TODO: get rid of Obj
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this can use some kind of closure?

@@ -1540,16 +1866,16 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// br_code: ButtonRequestType,
/// br_name: str,
/// ) -> LayoutObj[tuple[UiResult, int]]:
/// """Numer input with + and - buttons, description, and context menu with cancel and
/// """Numebr input with + and - buttons, description, and context menu with cancel and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// """Numebr input with + and - buttons, description, and context menu with cancel and
/// """Number input with + and - buttons, description, and context menu with cancel and

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a typo while fixing a typo.
Fixed on rebase.

@obrusvit obrusvit force-pushed the obrusvit/mercury/refactor-rust-layout-upy-parsing branch from 58347bc to 57d2b15 Compare October 26, 2024 12:23
Copy link

github-actions bot commented Oct 26, 2024

core UI changes device test click test persistence test
T2T1 Model T test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
T3B1 Safe 3 test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
T3T1 Safe 5 test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
All main(screens)

Copy link

github-actions bot commented Oct 26, 2024

legacy UI changes device test(screens) main(screens)

@obrusvit obrusvit changed the base branch from main to matejcik/global-layout-only3 October 26, 2024 12:24
@obrusvit
Copy link
Contributor Author

Re-targeting to GFL branch #3686 and it can go right after.

@obrusvit obrusvit removed the request for review from andrewkozlik October 26, 2024 12:25
@obrusvit obrusvit force-pushed the obrusvit/mercury/refactor-rust-layout-upy-parsing branch from 57d2b15 to 5086bd3 Compare October 27, 2024 11:55
@obrusvit obrusvit added the blocked Blocked by external force. Third party inputs required. label Nov 1, 2024
@matejcik matejcik force-pushed the matejcik/global-layout-only3 branch 4 times, most recently from 9297722 to 6b8585b Compare November 12, 2024 15:21
Base automatically changed from matejcik/global-layout-only3 to main November 12, 2024 15:55
@obrusvit obrusvit force-pushed the obrusvit/mercury/refactor-rust-layout-upy-parsing branch from 5086bd3 to 0d51a8e Compare November 18, 2024 12:37
@obrusvit obrusvit changed the base branch from main to ibz/20241112-cleanup November 18, 2024 12:38
@obrusvit obrusvit force-pushed the obrusvit/mercury/refactor-rust-layout-upy-parsing branch from 0d51a8e to 752c8b3 Compare November 18, 2024 12:40
@obrusvit obrusvit removed the blocked Blocked by external force. Third party inputs required. label Nov 18, 2024
@obrusvit obrusvit force-pushed the obrusvit/mercury/refactor-rust-layout-upy-parsing branch from 752c8b3 to 172af6d Compare November 18, 2024 12:55
@obrusvit obrusvit requested a review from ibz November 18, 2024 12:57

let mut account_params =
ShowInfoParams::new(TR::send__send_from.into()).with_cancel_button();
for pair in IterBuf::new().try_iterate(account_items)? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be extracted into a ShowInfoParams::add_items?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without making ShowInfoParams dependent on micropython crate.

Base automatically changed from ibz/20241112-cleanup to main November 19, 2024 11:36
- removes 2nd definition of ConfirmBlobParams, the choice of fields and
what supplied in ctor and what in `with_` methods should be thought
through again.

[no changelog]
@obrusvit obrusvit force-pushed the obrusvit/mercury/refactor-rust-layout-upy-parsing branch 2 times, most recently from bbb65ed to 320eb1f Compare November 19, 2024 13:38
@obrusvit
Copy link
Contributor Author

I had to use #[allow(clippy::too_many_arguments)] for a few SwipeFlow constructors.

This could be resolved as a part of #4322

Copy link
Contributor

@matejcik matejcik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@matejcik
Copy link
Contributor

i'm thinking though, when do we bite the bullet on proc macros? :)
jpochyla was strongly cautioning against it, but making a #[upy_function_call] fn confirm_action(title: TString, description: Option<TString>, ...) is the perfect usecase

Supply the rust layout with dedicated paremeter type instead of plain
micropython::Obj. The types used are ConfirmBlobParams and
ShowInfoParams.

[no changelog]
@obrusvit obrusvit force-pushed the obrusvit/mercury/refactor-rust-layout-upy-parsing branch from 320eb1f to abc7203 Compare November 19, 2024 14:39
@obrusvit obrusvit merged commit af55445 into main Nov 19, 2024
94 checks passed
@obrusvit obrusvit deleted the obrusvit/mercury/refactor-rust-layout-upy-parsing branch November 19, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Code improvements T3T1 Trezor Safe 5
Projects
Status: Approved
Development

Successfully merging this pull request may close these issues.

4 participants