From 09d4b2114ad3d95f810e2ddadfbb77bc19d9c732 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Mon, 5 Jun 2023 17:54:19 +0200 Subject: [PATCH] Improve transaction wording --- src_nbgl/ui_approve_tx.c | 46 ++++++++++++++++++++++++++++---- src_plugins/erc20/erc20_plugin.c | 4 +++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src_nbgl/ui_approve_tx.c b/src_nbgl/ui_approve_tx.c index 51a4c5c..44eb79b 100644 --- a/src_nbgl/ui_approve_tx.c +++ b/src_nbgl/ui_approve_tx.c @@ -1,4 +1,4 @@ - +#include #include #include "shared_context.h" #include "ui_callbacks.h" @@ -219,19 +219,55 @@ static void reviewContinueCommon(void) { reviewChoice); } +// Replace "Review" by "Sign" and add questionmark +static void prepare_sign_text(void) { + uint8_t sign_length = strlen("Sign"); + uint8_t review_length = strlen("Review"); + + memmove(staxSharedBuffer, "Sign", sign_length); + memmove(staxSharedBuffer + sign_length, + staxSharedBuffer + review_length, + strlen(staxSharedBuffer) - review_length + 1); + strlcat(staxSharedBuffer, "?", sizeof(staxSharedBuffer)); +} + +// Force operation to be lowercase +static void get_lowercase_operation(char *dst, size_t dst_len) { + const char *src = strings.common.fullAmount; + size_t idx; + + for (idx = 0; (idx < dst_len - 1) && (src[idx] != '\0'); ++idx) { + dst[idx] = (char) tolower((int) src[idx]); + } + dst[idx] = '\0'; +} + static void buildFirstPage(void) { if (tx_approval_context.fromPlugin) { + char op_name[sizeof(strings.common.fullAmount)]; plugin_ui_get_id(); - SPRINTF(staxSharedBuffer, - "Review %s\ntransaction:\n%s", - strings.common.fullAddress, - strings.common.fullAmount); + + get_lowercase_operation(op_name, sizeof(op_name)); + if (pluginType == EXTERNAL) { + snprintf(staxSharedBuffer, + sizeof(staxSharedBuffer), + "Review transaction\nto %s\non %s", + op_name, + strings.common.fullAddress); + } else { + snprintf(staxSharedBuffer, + sizeof(staxSharedBuffer), + "Review transaction\nto %s\n%s", + op_name, + strings.common.fullAddress); + } nbgl_useCaseReviewStart(get_app_icon(true), staxSharedBuffer, NULL, "Reject transaction", reviewContinue, rejectTransactionQuestion); + prepare_sign_text(); } else { nbgl_useCaseReviewStart(get_app_icon(true), "Review transaction", diff --git a/src_plugins/erc20/erc20_plugin.c b/src_plugins/erc20/erc20_plugin.c index 04062d8..220e05f 100644 --- a/src_plugins/erc20/erc20_plugin.c +++ b/src_plugins/erc20/erc20_plugin.c @@ -182,7 +182,11 @@ void erc20_plugin_call(int message, void *parameters) { case ETH_PLUGIN_QUERY_CONTRACT_ID: { ethQueryContractID_t *msg = (ethQueryContractID_t *) parameters; +#ifdef HAVE_NBGL + strlcpy(msg->name, "ERC20 token", msg->nameLength); +#else strlcpy(msg->name, "Type", msg->nameLength); +#endif strlcpy(msg->version, "Approve", msg->versionLength); msg->result = ETH_PLUGIN_RESULT_OK; } break;