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

UI improvements #26

Merged
merged 9 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions src/commands/deriveaddress/da_ui_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
#include "../../ui/ui_main.h"
#include "../../ui/display.h"

#define PK_APPID_ADDR_SIZE \
MAX_BIP32_STRING_LEN + APPLICATION_ID_STR_LEN + 13 + 1 + P2PK_ADDRESS_STRING_MAX_LEN + 9 + 1
char pk_appid_addr[PK_APPID_ADDR_SIZE];
char addr_buf[P2PK_ADDRESS_STRING_MAX_LEN];
char app_id_buf[APPLICATION_ID_STR_LEN];

void ui_display_address_confirm(bool approved) {
set_flow_response(approved);
}

void ui_address_flow_end(void) {
set_flow_response(true);
}

int ui_display_address(derive_address_ctx_t* ctx,
bool send,
uint32_t app_access_token,
Expand Down Expand Up @@ -64,44 +67,41 @@ int ui_display_address(derive_address_ctx_t* ctx,
return res_error(SW_BIP32_BAD_PATH);
}

int bip32_str_len = strlen(ctx->bip32_path);
int n_pairs = 0;

pairs_global[n_pairs].item = "Derivation path";
pairs_global[n_pairs].value = ctx->bip32_path;
n_pairs++;

memset(pk_appid_addr, 0, PK_APPID_ADDR_SIZE);
strncpy(pk_appid_addr, ctx->bip32_path, bip32_str_len);
int offset = 0;
if (app_access_token != 0) {
pk_appid_addr[bip32_str_len] = '\n';
offset += APPLICATION_ID_STR_LEN + 13;
snprintf(*(&pk_appid_addr) + bip32_str_len + 1,
APPLICATION_ID_STR_LEN + 13,
"Application: 0x%08x",
app_access_token);
pairs_global[n_pairs++] = ui_application_id_screen(app_access_token, app_id_buf);
}

if (!send) {
pk_appid_addr[bip32_str_len + offset] = '\n';
strncpy(*(&pk_appid_addr) + bip32_str_len + offset + 1, "Address: ", 9);
strncpy(*(&pk_appid_addr) + bip32_str_len + offset + 1 + 9,
ctx->address,
MEMBER_SIZE(derive_address_ctx_t, address));
strncpy(addr_buf, ctx->address, MEMBER_SIZE(derive_address_ctx_t, address));
}

pair_list.nbMaxLinesForValue = 0;
pair_list.nbPairs = n_pairs;
pair_list.pairs = pairs_global;

if (send) {
// Confirm Send Address
nbgl_useCaseChoice(&WHEEL_ICON,
"Address Export",
pk_appid_addr,
"Confirm",
"Cancel",
ui_display_address_confirm);
nbgl_useCaseReviewLight(STATUS_TYPE_ADDRESS_VERIFIED,
&pair_list,
&WHEEL_ICON,
"Address Export",
NULL,
"Confirm address export",
ui_display_address_confirm);
} else {
// Confirm Address
nbgl_useCaseChoice(&INFO_I_ICON,
"Confirm Address",
pk_appid_addr,
"Confirm",
"Cancel",
ui_display_address_confirm);
nbgl_useCaseAddressReview(addr_buf,
&pair_list,
&C_app_logo_64px,
"Verify Ergo address",
NULL,
ui_display_address_confirm);
}

memmove(ctx->raw_address, raw_address, P2PK_ADDRESS_LEN);
Expand All @@ -116,11 +116,15 @@ int ui_display_address(derive_address_ctx_t* ctx,
app_set_current_command(CMD_NONE);
res_ok();
}
nbgl_useCaseReviewStatus(STATUS_TYPE_ADDRESS_VERIFIED, ui_address_flow_end);
} else {
app_set_current_command(CMD_NONE);
res_deny();
nbgl_useCaseReviewStatus(STATUS_TYPE_ADDRESS_REJECTED, ui_address_flow_end);
}

io_ui_process();

ui_menu_main();

return 0;
Expand Down
63 changes: 15 additions & 48 deletions src/commands/signtx/operations/stx_op_p2pk.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,37 +324,28 @@ bool stx_operation_p2pk_should_show_output_confirm_screen(

// ===========================
// UI
#ifdef HAVE_BAGL
static NOINLINE void ui_stx_operation_p2pk_approve_action(void *context) {
sign_transaction_ui_aprove_ctx_t *ctx = (sign_transaction_ui_aprove_ctx_t *) context;
ui_stx_operation_approve_reject(true, ctx);
}
#endif

#ifdef HAVE_NBGL
void p2pk_review(bool approved) {
set_flow_response(approved);
}
#endif

static uint8_t signtx_screen = 0;
static uint8_t signtx_outputs_screen = 0;
uint16_t ui_stx_operation_p2pk_show_token_and_path(sign_transaction_operation_p2pk_ctx_t *ctx,
uint32_t app_access_token,
bool is_known_application,
void *sign_tx_ctx) {
uint8_t screen = 0;
signtx_screen = 0;
signtx_outputs_screen = 0;
#ifdef HAVE_BAGL
const ux_flow_step_t *b32_step = ui_bip32_path_screen(
ctx->bip32.path,
ctx->bip32.len,
"P2PK Signing",
"Start Signing",
ctx->ui_approve.bip32_path,
MEMBER_SIZE(sign_transaction_operation_p2pk_ui_approve_data_ctx_t, bip32_path),
ui_stx_operation_p2pk_approve_action,
&ctx->ui_approve.ui_approve);
NULL,
NULL);
if (b32_step == NULL) {
return SW_BIP32_FORMATTING_FAILED;
}
ui_add_screen(b32_step, &screen);
ui_add_screen(b32_step, &signtx_screen);
#elif HAVE_NBGL
bool res = ui_bip32_path_screen(
ctx->bip32.path,
Expand All @@ -364,34 +355,15 @@ uint16_t ui_stx_operation_p2pk_show_token_and_path(sign_transaction_operation_p2
if (!res) {
return SW_BIP32_FORMATTING_FAILED;
}
// pairs_global[0].item = "P2PK Signing";
// pairs_global[0].value = ctx->ui_approve.bip32_path;
// screen++;
nbgl_useCaseReviewStreamingStart(TYPE_TRANSACTION,
&C_app_logo_64px,
"P2PK Signing",
ctx->ui_approve.bip32_path,
p2pk_review);
bool approved = io_ui_process();
if (!approved) {
res_deny();
ui_menu_main();
return SW_BIP32_FORMATTING_FAILED;
}
#endif

if (!ui_stx_add_operation_approve_screens(&ctx->ui_approve.ui_approve,
&screen,
&signtx_screen,
app_access_token,
is_known_application,
sign_tx_ctx)) {
return SW_SCREENS_BUFFER_OVERFLOW;
}
#ifdef HAVE_BAGL
if (!ui_stx_display_screens(screen)) {
return SW_SCREENS_BUFFER_OVERFLOW;
}
#endif
return SW_OK;
}

Expand All @@ -400,20 +372,15 @@ uint16_t ui_stx_operation_p2pk_show_output_confirm_screen(
CHECK_PROPER_STATES(ctx,
SIGN_TRANSACTION_OPERATION_P2PK_STATE_OUTPUTS_STARTED,
SIGN_TRANSACTION_OPERATION_P2PK_STATE_TX_FINISHED);
uint8_t screen = 0;

if (!ui_stx_add_output_screens(&ctx->transaction.ui.ui,
&screen,
&signtx_screen,
&signtx_outputs_screen,
&ctx->transaction.ui.output,
&ctx->transaction.last_approved_change,
ctx->network_id)) {
return SW_SCREENS_BUFFER_OVERFLOW;
}
#ifdef HAVE_BAGL
if (!ui_stx_display_screens(screen)) {
return SW_SCREENS_BUFFER_OVERFLOW;
}
#endif
return SW_OK;
}

Expand Down Expand Up @@ -469,19 +436,19 @@ static NOINLINE uint16_t ui_stx_operation_p2pk_show_tx_screen(uint8_t index,
uint16_t ui_stx_operation_p2pk_show_confirm_screen(sign_transaction_operation_p2pk_ctx_t *ctx) {
CHECK_PROPER_STATE(ctx, SIGN_TRANSACTION_OPERATION_P2PK_STATE_TX_FINISHED);
ctx->state = SIGN_TRANSACTION_OPERATION_P2PK_STATE_FINALIZED;
uint8_t screen = 0;

if (!ui_stx_add_transaction_screens(&ctx->ui_confirm,
&screen,
&signtx_screen,
&signtx_outputs_screen,
&ctx->amounts,
1,
0,
ui_stx_operation_p2pk_show_tx_screen,
ui_stx_operation_p2pk_send_response,
(void *) ctx)) {
return SW_SCREENS_BUFFER_OVERFLOW;
}
#ifdef HAVE_BAGL
if (!ui_stx_display_screens(screen)) {
if (!ui_stx_display_screens(signtx_screen)) {
return SW_SCREENS_BUFFER_OVERFLOW;
}
#endif
Expand Down
10 changes: 5 additions & 5 deletions src/commands/signtx/operations/stx_op_p2pk.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ typedef struct {
cx_blake2b_t tx_hash;
uint8_t network_id;
sign_transaction_amounts_ctx_t amounts;
union {
sign_transaction_operation_p2pk_transaction_ctx_t transaction;
sign_transaction_operation_p2pk_ui_approve_data_ctx_t ui_approve;
sign_transaction_ui_sign_confirm_ctx_t ui_confirm;
};

sign_transaction_operation_p2pk_transaction_ctx_t transaction;
sign_transaction_operation_p2pk_ui_approve_data_ctx_t ui_approve;
sign_transaction_ui_sign_confirm_ctx_t ui_confirm;

} sign_transaction_operation_p2pk_ctx_t;

//****************** OPERATION CALLS ****************
Expand Down
2 changes: 2 additions & 0 deletions src/commands/signtx/stx_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bool ui_stx_add_operation_approve_screens(sign_transaction_ui_aprove_ctx_t* ctx,
*/
bool ui_stx_add_output_screens(sign_transaction_ui_output_confirm_ctx_t* ctx,
uint8_t* screen,
uint8_t* output_screen,
const sign_transaction_output_info_ctx_t* output,
sign_transaction_bip32_path_t* last_approved_change,
uint8_t network_id);
Expand All @@ -40,6 +41,7 @@ bool ui_stx_add_output_screens(sign_transaction_ui_output_confirm_ctx_t* ctx,
*/
bool ui_stx_add_transaction_screens(sign_transaction_ui_sign_confirm_ctx_t* ctx,
uint8_t* screen,
uint8_t* output_screen,
const sign_transaction_amounts_ctx_t* amounts,
uint8_t op_screen_count,
ui_sign_transaction_operation_show_screen_cb screen_cb,
Expand Down
Loading
Loading