Better separation between EIP-191 UI & business logic

This commit is contained in:
Alexandre Paillier
2022-09-08 18:41:49 +02:00
parent 4bbc142ee5
commit e93d82c104
6 changed files with 79 additions and 88 deletions

View File

@@ -1,7 +1,36 @@
#include "shared_context.h"
#include "ui_callbacks.h"
#include "ui_flow_signMessage.h"
#include "sign_message.h"
static uint8_t ui_pos;
static void dummy_pre_cb(void)
{
if (ui_pos == UI_191_POS_REVIEW)
{
question_switcher();
}
else
{
ux_flow_prev();
ui_pos = UI_191_POS_REVIEW;
}
}
static void dummy_post_cb(void)
{
if (ui_pos == UI_191_POS_QUESTION)
{
continue_displaying_message();
}
else // UI_191_END
{
ui_191_switch_to_message_end();
}
}
// clang-format off
UX_STEP_NOCB(
@@ -29,7 +58,7 @@ UX_STEP_INIT(
UX_STEP_CB(
ux_191_step_theres_more,
bn,
theres_more_click_cb(),
skip_rest_of_message(),
{
"More to see!",
"Double-click to skip"
@@ -61,7 +90,7 @@ UX_STEP_CB(
});
// clang-format on
UX_FLOW(ux_sign_flow,
UX_FLOW(ux_191_flow,
&ux_191_step_review,
&ux_191_step_message,
&ux_191_step_dummy_pre,
@@ -71,23 +100,33 @@ UX_FLOW(ux_sign_flow,
&ux_191_step_cancel);
void ui_191_start(void)
{
ux_flow_init(0, ux_191_flow, NULL);
ui_pos = UI_191_POS_REVIEW;
}
void ui_191_switch_to_message(void)
{
ux_flow_init(0, ux_sign_flow, &ux_191_step_message);
ux_flow_init(0, ux_191_flow, &ux_191_step_message);
ui_pos = UI_191_POS_REVIEW;
}
void ui_191_switch_to_message_end(void)
{
ux_flow_init(0, ux_sign_flow, &ux_191_step_dummy_pre);
// with pos != REVIEW, automatically goes back to previous step
// Force it to a value that will make it automatically do a prev()
ui_pos = UI_191_POS_QUESTION;
ux_flow_init(0, ux_191_flow, &ux_191_step_dummy_pre);
}
void ui_191_switch_to_sign(void)
{
ux_flow_init(0, ux_sign_flow, &ux_191_step_sign);
ux_flow_init(0, ux_191_flow, &ux_191_step_sign);
ui_pos = UI_191_POS_END;
}
void ui_191_switch_to_question(void)
{
ux_flow_init(0, ux_sign_flow, &ux_191_step_theres_more);
ux_flow_init(0, ux_191_flow, &ux_191_step_theres_more);
ui_pos = UI_191_POS_QUESTION;
}