@@ -49,7 +49,7 @@ ledger_device_sdk::set_panic!(ledger_device_sdk::exiting_panic);
49
49
extern crate alloc;
50
50
51
51
#[ cfg( any( target_os = "stax" , target_os = "flex" ) ) ]
52
- use ledger_device_sdk:: nbgl:: init_comm;
52
+ use ledger_device_sdk:: nbgl:: { init_comm, NbglReviewStatus , StatusType } ;
53
53
54
54
// P2 for last APDU to receive.
55
55
const P2_SIGN_TX_LAST : u8 = 0x00 ;
@@ -62,6 +62,7 @@ const P1_SIGN_TX_MAX: u8 = 0x03;
62
62
63
63
// Application status words.
64
64
#[ repr( u16 ) ]
65
+ #[ derive( Clone , Copy , PartialEq ) ]
65
66
pub enum AppSW {
66
67
Deny = 0x6985 ,
67
68
WrongP1P2 = 0x6A86 ,
@@ -76,6 +77,7 @@ pub enum AppSW {
76
77
KeyDeriveFail = 0xB009 ,
77
78
VersionParsingFail = 0xB00A ,
78
79
WrongApduLength = StatusWords :: BadLen as u16 ,
80
+ Ok = 0x9000 ,
79
81
}
80
82
81
83
impl From < AppSW > for Reply {
@@ -126,6 +128,26 @@ impl TryFrom<ApduHeader> for Instruction {
126
128
}
127
129
}
128
130
131
+ #[ cfg( any( target_os = "stax" , target_os = "flex" ) ) ]
132
+ fn show_status_if_needed ( ins : & Instruction , tx_ctx : & TxContext , status : & AppSW ) {
133
+ let ( show_status, status_type) = match ( ins, status) {
134
+ ( Instruction :: GetPubkey { display : true } , AppSW :: Deny | AppSW :: Ok ) => {
135
+ ( true , StatusType :: Address )
136
+ }
137
+ ( Instruction :: SignTx { .. } , AppSW :: Deny | AppSW :: Ok ) if tx_ctx. finished ( ) => {
138
+ ( true , StatusType :: Transaction )
139
+ }
140
+ ( _, _) => ( false , StatusType :: Transaction ) ,
141
+ } ;
142
+
143
+ if show_status {
144
+ let success = * status == AppSW :: Ok ;
145
+ NbglReviewStatus :: new ( )
146
+ . status_type ( status_type)
147
+ . show ( success) ;
148
+ }
149
+ }
150
+
129
151
#[ no_mangle]
130
152
extern "C" fn sample_main ( ) {
131
153
// Create the communication manager, and configure it to accept only APDU from the 0xe0 class.
@@ -150,22 +172,32 @@ extern "C" fn sample_main() {
150
172
// Wait for either a specific button push to exit the app
151
173
// or an APDU command
152
174
if let Event :: Command ( ins) = ui_menu_main ( & mut comm) {
153
- match handle_apdu ( & mut comm, ins, & mut tx_ctx) {
154
- Ok ( ( ) ) => comm. reply_ok ( ) ,
155
- Err ( sw) => comm. reply ( sw) ,
156
- }
175
+ let result = handle_apdu ( & mut comm, & ins, & mut tx_ctx) ;
176
+ let _status: AppSW = match result {
177
+ Ok ( ( ) ) => {
178
+ comm. reply_ok ( ) ;
179
+ AppSW :: Ok
180
+ }
181
+ Err ( sw) => {
182
+ comm. reply ( sw) ;
183
+ sw
184
+ }
185
+ } ;
186
+
187
+ #[ cfg( any( target_os = "stax" , target_os = "flex" ) ) ]
188
+ show_status_if_needed ( & ins, & tx_ctx, & _status) ;
157
189
}
158
190
}
159
191
}
160
192
161
- fn handle_apdu ( comm : & mut Comm , ins : Instruction , ctx : & mut TxContext ) -> Result < ( ) , AppSW > {
193
+ fn handle_apdu ( comm : & mut Comm , ins : & Instruction , ctx : & mut TxContext ) -> Result < ( ) , AppSW > {
162
194
match ins {
163
195
Instruction :: GetAppName => {
164
196
comm. append ( env ! ( "CARGO_PKG_NAME" ) . as_bytes ( ) ) ;
165
197
Ok ( ( ) )
166
198
}
167
199
Instruction :: GetVersion => handler_get_version ( comm) ,
168
- Instruction :: GetPubkey { display } => handler_get_public_key ( comm, display) ,
169
- Instruction :: SignTx { chunk, more } => handler_sign_tx ( comm, chunk, more, ctx) ,
200
+ Instruction :: GetPubkey { display } => handler_get_public_key ( comm, * display) ,
201
+ Instruction :: SignTx { chunk, more } => handler_sign_tx ( comm, * chunk, * more, ctx) ,
170
202
}
171
203
}
0 commit comments