-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdisplay.c
More file actions
87 lines (72 loc) · 2.63 KB
/
Copy pathdisplay.c
File metadata and controls
87 lines (72 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "display.h"
#include "../bitcoin_app_base/src/ui/display.h"
#include "../bitcoin_app_base/src/ui/menu.h"
#include "io_ext.h"
#include "nbgl_use_case.h"
static void review_choice(bool approved) {
set_ux_flow_response(approved); // sets the return value of io_ui_process
if (approved) {
// nothing to do in this case; after signing, the responsibility to show the main menu
// goes back to the base app's handler
} else {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
}
}
#define MAX_N_PAIRS 4
// These are kept static rather than on the stack because the NBGL library
// stores pointers to them that must remain valid long term.
static nbgl_layoutTagValue_t pairs[MAX_N_PAIRS];
static nbgl_layoutTagValueList_t pairList;
static char value_str[32], magic_value_str[32], fee_str[32];
bool display_transaction(dispatcher_context_t *dc,
int64_t value_spent,
uint64_t magic_input_value,
uint64_t fee) {
uint64_t value_spent_abs = value_spent < 0 ? -value_spent : value_spent;
format_sats_amount(COIN_COINID_SHORT, value_spent_abs, value_str);
format_sats_amount(COIN_COINID_SHORT, magic_input_value, magic_value_str);
format_sats_amount(COIN_COINID_SHORT, fee, fee_str);
int n_pairs = 0;
pairs[n_pairs++] = (nbgl_layoutTagValue_t){
.item = "Transaction type",
.value = "FOO",
};
if (value_spent >= 0) {
pairs[n_pairs++] = (nbgl_layoutTagValue_t){
.item = "Value spent",
.value = value_str,
};
} else {
pairs[n_pairs++] = (nbgl_layoutTagValue_t){
.item = "Value received",
.value = value_str,
};
}
pairs[n_pairs++] = (nbgl_layoutTagValue_t){
.item = "Magic value",
.value = magic_value_str,
};
pairs[n_pairs++] = (nbgl_layoutTagValue_t){
.item = "Fee",
.value = fee_str,
};
assert(n_pairs <= MAX_N_PAIRS);
// Setup list
pairList.nbMaxLinesForValue = 0;
pairList.nbPairs = n_pairs;
pairList.pairs = pairs;
nbgl_useCaseReview(TYPE_TRANSACTION,
&pairList,
&ICON_APP_ACTION,
"Review transaction\nto a FOO output",
NULL,
"Sign transaction\nto create a FOO output?",
review_choice);
// blocking call until the user approves or rejects the transaction
bool result = io_ui_process(dc);
if (!result) {
SEND_SW(dc, SW_DENY);
return false;
}
return true;
}