Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
transaction_check_ui.c
Go to the documentation of this file.
1/*****************************************************************************
2 * (c) 2026 Ledger SAS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17/* Includes ------------------------------------------------------------------*/
18#include <string.h>
19#include "os_helpers.h"
20#include "os_print.h"
21#include "io.h"
22#include "macros.h"
23#include "status_words.h"
24#include "nbgl_use_case.h"
25#include "transaction_check.h"
28
29#if defined(HAVE_TX_CHECK)
30
31/* Private defines------------------------------------------------------------*/
32#define HOW_IT_WORKS_NB 3
33
34/* Private variables ---------------------------------------------------------*/
36// The reply is sent by the SDK (SDK APDU), else by the app
37static bool s_sdk_reply;
38
39// "How it works" page, displayed from the opt-in screen
43
44/* Private functions ---------------------------------------------------------*/
50static void send_opt_in_reply(bool enabled)
51{
52 uint8_t reply = enabled;
53 io_send_response_pointer(&reply, sizeof(reply), SWO_SUCCESS);
54}
55
63
69static void opt_in_choice_cb(bool enable)
70{
74 }
77 if (s_sdk_reply) {
78 send_opt_in_reply(state);
79 }
80 else {
82 }
83 }
84 if (enable) {
85 nbgl_useCaseStatus("Transaction Check enabled", true, finalize_opt_in);
86 }
87 else {
89 }
90}
91
99static tx_check_status_t start_opt_in(bool response_expected, bool sdk_reply)
100{
101 if (tx_check_in_swap()) {
102 PRINTF("[TX CHECK] Not available in a swap\n");
104 }
106 PRINTF("[TX CHECK] Already opted in\n");
107 return TX_CHECK_SUCCESS;
108 }
109 // The opt-in screen would replace a flow on screen
110 if (response_expected && !handle_tx_check_is_idle()) {
111 PRINTF("[TX CHECK] Opt-in requested while a flow is on screen\n");
113 }
114 s_response_expected = response_expected;
115 s_sdk_reply = sdk_reply;
116
117 s_how_it_works_texts[0] = "Transaction is checked for threats before signing.";
119 = "The result is displayed: Critical threat, potential risk or no threat.";
121 = "Scan the QR Code on your Ledger device for details on any threat or risk.";
122 s_how_it_works_icons[0] = &PRIVACY_ICON;
123 s_how_it_works_icons[1] = &WARNING_ICON;
124 s_how_it_works_icons[2] = &QRCODE_ICON;
125
126 memset(&s_how_it_works, 0, sizeof(s_how_it_works));
128 s_how_it_works.leftContent.title = "How it works";
129 s_how_it_works.leftContent.nbRows = HOW_IT_WORKS_NB;
130 s_how_it_works.leftContent.rowTexts = s_how_it_works_texts;
131 s_how_it_works.leftContent.rowIcons = s_how_it_works_icons;
132
134 &QUESTION_CIRCLE_ICON,
135 "Enable\nTransaction Check?",
136 "Real-time warnings powered\nby 3rd service providers.",
137 "By enabling, you accept T&Cs: ledger.com/tx-check",
138 "Yes, enable",
139 "Maybe later",
142 return TX_CHECK_PENDING;
143}
144
145/* Exported functions --------------------------------------------------------*/
152{
153 send_opt_in_reply(enabled);
154}
155
162tx_check_status_t tx_check_opt_in(bool response_expected)
163{
164 return start_opt_in(response_expected, false);
165}
166
167#if defined(HAVE_TX_CHECK_APDU)
174{
175 return start_opt_in(true, true);
176}
177#endif // HAVE_TX_CHECK_APDU
178#endif // HAVE_TX_CHECK
static int io_send_response_pointer(const uint8_t *ptr, size_t size, uint16_t sw)
Definition io.h:79
#define WEAK
Definition macros.h:12
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
API of the Advanced BOLOS Graphical Library, for typical application use-cases.
@ LEFT_CONTENT_WARNING
left-aligned title and icon/text rows (touch devices only)
struct nbgl_genericDetails_s nbgl_genericDetails_t
The necessary parameters to build the page(s) displayed when the top-right button is touched in intro...
void nbgl_useCaseAdvancedChoiceWithDetails(const nbgl_icon_details_t *centerIcon, const nbgl_icon_details_t *headerIcon, const char *title, const char *message, const char *subMessage, const char *confirmText, const char *cancelText, nbgl_warningDetails_t *details, nbgl_choiceCallback_t callback)
void nbgl_useCaseStatus(const char *message, bool isSuccess, nbgl_callback_t quitCallback)
Transaction Check: risk report from a security provider, displayed during the review.
@ TX_CHECK_SETTING_OPT_IN
The user has seen the opt-in screen.
@ TX_CHECK_SETTING_ENABLE
Transaction Check is enabled.
tx_check_status_t
@ TX_CHECK_PENDING
Opt-in screen displayed, the choice comes later.
@ TX_CHECK_NOT_ALLOWED
Report bound to the review in progress, swap, or app busy.
@ TX_CHECK_SUCCESS
Descriptor stored, or opt-in already done.
void finalize_ui_tx_check_opt_in(bool response_expected)
Leave the opt-in flow.
bool handle_tx_check_get_setting(tx_check_setting_t setting)
Read a persistent Transaction Check setting.
bool handle_tx_check_is_idle(void)
Tell whether the app is idle, so that the opt-in screen can be displayed.
void handle_tx_check_set_setting(tx_check_setting_t setting, bool value)
Write a persistent Transaction Check setting.
Transaction Check functions shared between the SDK sources, not exposed to the apps.
static bool tx_check_in_swap(void)
Tell whether the app runs a swap started by the Exchange app.
WEAK void handle_tx_check_opt_in_response(bool enabled)
Default reply to an opt-in request on the app APDU: the 1-byte enable state.
static bool s_sdk_reply
#define HOW_IT_WORKS_NB
static const nbgl_icon_details_t * s_how_it_works_icons[HOW_IT_WORKS_NB]
static void send_opt_in_reply(bool enabled)
Send the 1-byte enable state with SWO_SUCCESS.
static bool s_response_expected
static const char * s_how_it_works_texts[HOW_IT_WORKS_NB]
static tx_check_status_t start_opt_in(bool response_expected, bool sdk_reply)
Display the opt-in screen if allowed and not seen yet.
static void opt_in_choice_cb(bool enable)
Store the user choice, send the pending reply, then display the status.
static nbgl_genericDetails_t s_how_it_works
tx_check_status_t tx_check_opt_in_sdk_apdu(void)
Display the opt-in screen for the SDK APDU, replied by the SDK.
tx_check_status_t tx_check_opt_in(bool response_expected)
Display the opt-in screen, from the settings or for an app APDU.
static void finalize_opt_in(void)
Hand the end of the opt-in flow over to the app.