Skip to content

Commit

Permalink
Bagl: use standard app ui flow
Browse files Browse the repository at this point in the history
Instead of the ux_variable_display hack to display a dynamic number of screens
  • Loading branch information
spalmer25 committed Mar 19, 2024
1 parent 1d76454 commit 5fa3d45
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 352 deletions.
44 changes: 5 additions & 39 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
void clear_apdu_globals(void);

/**
* @brief string_generation_callback for chains
* @brief Converts a chain id to string
*
* @param out: output buffer
* @param out_size: output size
Expand All @@ -47,7 +47,9 @@ void clear_apdu_globals(void);
void copy_chain(char *out, size_t out_size, chain_id_t *chain_id);

/**
* @brief string_generation_callback for keys
* @brief Converts a baking key to string
*
* if the baking is empty, copies "No Key Authorized" in the output
*
* @param out: output buffer
* @param out_size: output size
Expand All @@ -56,7 +58,7 @@ void copy_chain(char *out, size_t out_size, chain_id_t *chain_id);
void copy_key(char *out, size_t out_size, bip32_path_with_curve_t *baking_key);

/**
* @brief string_generation_callback for high watermarks
* @brief Converts a high watermark to string
*
* @param out: output buffer
* @param out_size: output size
Expand Down Expand Up @@ -126,53 +128,17 @@ typedef struct {
struct parse_state parse_state; ///< current parser state
} apdu_sign_state_t;

/**
* @brief This structure represents data used to compute what we need to display on the screen.
*
*/
struct screen_data {
char *title; ///< title of the screen
string_generation_callback callback_fn; ///< callback to convert the data to string
void *data; ///< value to display on the screen
};

/**
* @brief State of the dynamic display
*
* Used to keep track on whether we are displaying screens inside the stack, or outside the
* stack (for example confirmation screens)
*
*/
enum e_state {
STATIC_SCREEN,
DYNAMIC_SCREEN,
};

/**
* @brief This structure holds all structure needed
*
*/
typedef struct {
/// dynamic display state
struct {
struct screen_data screen_stack[MAX_SCREEN_STACK_SIZE];
enum e_state current_state; ///< State of the dynamic display

/// Size of the screen stack
uint8_t screen_stack_size;

/// Current index in the screen_stack.
uint8_t formatter_index;

/// Callback function if user accepted prompt.
ui_callback_t ok_callback;
/// Callback function if user rejected prompt.
ui_callback_t cxl_callback;

/// Title to be displayed on the screen.
char screen_title[PROMPT_WIDTH + 1u];
/// Value to be displayed on the screen.
char screen_value[VALUE_WIDTH + 1u];
/// Screensaver is on/off.
bool is_blank_screen;
} dynamic_display;
Expand Down
2 changes: 0 additions & 2 deletions src/to_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

#define TEZOS_HASH_CHECKSUM_SIZE 4u

#define TICKER_WITH_SPACE " XTZ"

static void pkh_to_string(char *const buff,
size_t const buff_size,
signature_type_t const signature_type,
Expand Down
2 changes: 2 additions & 0 deletions src/to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "types.h"
#include "ui.h"

#define TICKER_WITH_SPACE " XTZ"

/**
* @brief Converts a key to a public key hash string using its public key
*
Expand Down
17 changes: 0 additions & 17 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,6 @@ static chain_id_t const mainnet_chain_id = {.v = 0x7A06A770};
*/
typedef bool (*ui_callback_t)(void);

/**
* @brief String generator callback
*
* Uses K&R style declaration to avoid being stuck on const
* void *, to avoid having to cast the function pointers
*
* @param buffer: output buffer
* @param buffer_size: output size
* @param data: data
*/
typedef void (*string_generation_callback)(
/* char *buffer, size_t buffer_size, const void *data */);

/**
* @brief Pair of public and private key
*
Expand Down Expand Up @@ -232,10 +219,6 @@ typedef struct {
#define PROTOCOL_HASH_BASE58_STRING_SIZE \
sizeof("ProtoBetaBetaBetaBetaBetaBetaBetaBetaBet11111a5ug96")

#define MAX_SCREEN_STACK_SIZE 7u // Maximum number of screens in a flow.
#define PROMPT_WIDTH 16u
#define VALUE_WIDTH PROTOCOL_HASH_BASE58_STRING_SIZE

// TODO: Rename to KEY_HASH_SIZE
#define HASH_SIZE 20u

Expand Down
42 changes: 21 additions & 21 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,6 @@

#include "keys.h"

/**
* @brief Initializes the formatter stack
*
* Must be called once before calling `push_ui_callback()` for the first time
*
*/
void init_screen_stack(void);

/**
* @brief Pushes a new screen to the flow
*
* Must call `init_screen_stack()` before calling this function for the first time
*
* @param title: title of the screen
* @param cb: callback to generate the string version of the data
* @param data: data to display on the screen
*/
void push_ui_callback(const char *title, string_generation_callback cb, const void *data);

/**
* @brief Starts the idle flow
*
Expand All @@ -68,11 +49,30 @@ void exit_app(void);
void update_baking_idle_screens(void);

/**
* @brief Prepare confirmation screens
* @brief Prepare confirmation screens callbacks
*
* @param ok_c: accept callback
* @param cxl_c: cancel callback
*/
void ux_confirm_screen(ui_callback_t ok_c, ui_callback_t cxl_c);
void ux_prepare_confirm_callbacks(ui_callback_t ok_c, ui_callback_t cxl_c);

/**
* @brief Confirmation flow
*
* - Initial screen
* - Values
* - Reject screen
* - Accept screen
*
*/
extern const ux_flow_step_t ux_eye_step;
extern const ux_flow_step_t ux_prompt_flow_reject_step;
extern const ux_flow_step_t ux_prompt_flow_accept_step;
#define UX_CONFIRM_FLOW(flow_name, ...) \
UX_FLOW(flow_name, \
&ux_eye_step, \
__VA_ARGS__, \
&ux_prompt_flow_reject_step, \
&ux_prompt_flow_accept_step)

#endif // HAVE_BAGL
Loading

0 comments on commit 5fa3d45

Please sign in to comment.