@@ -80,6 +80,55 @@ impl<'a> Into<nbgl_icon_details_t> for &NbglGlyph<'a> {
80
80
}
81
81
}
82
82
83
+ pub enum TransactionType {
84
+ Transaction ,
85
+ Message ,
86
+ Operation ,
87
+ }
88
+
89
+ impl TransactionType {
90
+ pub fn to_c_type ( & self , blind : bool , skippable : bool ) -> nbgl_operationType_t {
91
+ let mut tx_type = match self {
92
+ TransactionType :: Transaction => TYPE_TRANSACTION . into ( ) ,
93
+ TransactionType :: Message => TYPE_MESSAGE . into ( ) ,
94
+ TransactionType :: Operation => TYPE_OPERATION . into ( ) ,
95
+ } ;
96
+ if blind {
97
+ tx_type |= BLIND_OPERATION ;
98
+ }
99
+ if skippable {
100
+ tx_type |= SKIPPABLE_OPERATION ;
101
+ }
102
+ tx_type
103
+ }
104
+
105
+ pub fn to_message ( & self , success : bool ) -> nbgl_reviewStatusType_t {
106
+ match self {
107
+ TransactionType :: Transaction => {
108
+ if success {
109
+ STATUS_TYPE_TRANSACTION_SIGNED
110
+ } else {
111
+ STATUS_TYPE_TRANSACTION_REJECTED
112
+ }
113
+ }
114
+ TransactionType :: Message => {
115
+ if success {
116
+ STATUS_TYPE_MESSAGE_SIGNED
117
+ } else {
118
+ STATUS_TYPE_MESSAGE_REJECTED
119
+ }
120
+ }
121
+ TransactionType :: Operation => {
122
+ if success {
123
+ STATUS_TYPE_OPERATION_SIGNED
124
+ } else {
125
+ STATUS_TYPE_OPERATION_REJECTED
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+
83
132
/// Initialize the global COMM_REF variable with the provided Comm instance.
84
133
/// This function should be called from the main function of the application.
85
134
/// The COMM_REF variable is used by the NBGL API to detect touch events and
@@ -290,6 +339,8 @@ pub struct NbglReview<'a> {
290
339
subtitle : CString ,
291
340
finish_title : CString ,
292
341
glyph : Option < & ' a NbglGlyph < ' a > > ,
342
+ tx_type : TransactionType ,
343
+ blind : bool ,
293
344
}
294
345
295
346
impl < ' a > NbglReview < ' a > {
@@ -299,6 +350,19 @@ impl<'a> NbglReview<'a> {
299
350
subtitle : CString :: new ( "" ) . unwrap ( ) ,
300
351
finish_title : CString :: new ( "" ) . unwrap ( ) ,
301
352
glyph : None ,
353
+ tx_type : TransactionType :: Transaction ,
354
+ blind : false ,
355
+ }
356
+ }
357
+
358
+ pub fn tx_type ( self , tx_type : TransactionType ) -> NbglReview < ' a > {
359
+ NbglReview { tx_type, ..self }
360
+ }
361
+
362
+ pub fn blind ( self ) -> NbglReview < ' a > {
363
+ NbglReview {
364
+ blind : true ,
365
+ ..self
302
366
}
303
367
}
304
368
@@ -358,7 +422,7 @@ impl<'a> NbglReview<'a> {
358
422
359
423
// Show the review on the device.
360
424
let sync_ret = ledger_secure_sdk_sys:: ux_sync_review (
361
- TYPE_TRANSACTION . into ( ) ,
425
+ self . tx_type . to_c_type ( self . blind , false ) ,
362
426
& tag_value_list as * const nbgl_contentTagValueList_t ,
363
427
& icon as * const nbgl_icon_details_t ,
364
428
self . title . as_ptr ( ) as * const c_char ,
@@ -369,11 +433,11 @@ impl<'a> NbglReview<'a> {
369
433
// Return true if the user approved the transaction, false otherwise.
370
434
match sync_ret {
371
435
ledger_secure_sdk_sys:: UX_SYNC_RET_APPROVED => {
372
- ledger_secure_sdk_sys:: ux_sync_reviewStatus ( STATUS_TYPE_TRANSACTION_SIGNED ) ;
436
+ ledger_secure_sdk_sys:: ux_sync_reviewStatus ( self . tx_type . to_message ( true ) ) ;
373
437
return true ;
374
438
}
375
439
_ => {
376
- ledger_secure_sdk_sys:: ux_sync_reviewStatus ( STATUS_TYPE_TRANSACTION_REJECTED ) ;
440
+ ledger_secure_sdk_sys:: ux_sync_reviewStatus ( self . tx_type . to_message ( false ) ) ;
377
441
return false ;
378
442
}
379
443
}
@@ -749,6 +813,10 @@ impl From<&NbglPageContent>
749
813
}
750
814
}
751
815
816
+ /// A wrapper around the synchronous NBGL ux_sync_genericReview C API binding.
817
+ /// Used to display custom built review screens. User can add different kind of
818
+ /// contents (CenteredInfo, InfoLongPress, InfoButton, TagValueList, TagValueConfirm, InfosList)
819
+ /// to the review screen using the add_content method.
752
820
pub struct NbglGenericReview {
753
821
content_list : Vec < NbglPageContent > ,
754
822
}
@@ -821,6 +889,131 @@ impl NbglGenericReview {
821
889
}
822
890
}
823
891
892
+ /// A wrapper around the synchronous NBGL ux_sync_reviewStreaming (start, continue and finish)
893
+ /// C API binding. Used to display streamed transaction review screens.
894
+ pub struct NbglStreamingReview {
895
+ icon : nbgl_icon_details_t ,
896
+ tx_type : TransactionType ,
897
+ blind : bool ,
898
+ }
899
+
900
+ impl NbglStreamingReview {
901
+ pub fn new ( ) -> NbglStreamingReview {
902
+ NbglStreamingReview {
903
+ icon : nbgl_icon_details_t:: default ( ) ,
904
+ tx_type : TransactionType :: Transaction ,
905
+ blind : false ,
906
+ }
907
+ }
908
+
909
+ pub fn tx_type ( self , tx_type : TransactionType ) -> NbglStreamingReview {
910
+ NbglStreamingReview { tx_type, ..self }
911
+ }
912
+
913
+ pub fn blind ( self ) -> NbglStreamingReview {
914
+ NbglStreamingReview {
915
+ blind : true ,
916
+ ..self
917
+ }
918
+ }
919
+
920
+ pub fn glyph ( self , glyph : & NbglGlyph ) -> NbglStreamingReview {
921
+ NbglStreamingReview {
922
+ icon : glyph. into ( ) ,
923
+ ..self
924
+ }
925
+ }
926
+
927
+ pub fn start ( & mut self , title : & str , subtitle : & str ) -> bool {
928
+ unsafe {
929
+ let title = CString :: new ( title) . unwrap ( ) ;
930
+ let subtitle = CString :: new ( subtitle) . unwrap ( ) ;
931
+
932
+ let sync_ret = ux_sync_reviewStreamingStart (
933
+ self . tx_type . to_c_type ( self . blind , false ) ,
934
+ & self . icon as * const nbgl_icon_details_t ,
935
+ title. as_ptr ( ) as * const c_char ,
936
+ subtitle. as_ptr ( ) as * const c_char ,
937
+ ) ;
938
+
939
+ // Return true if the user approved the transaction, false otherwise.
940
+ match sync_ret {
941
+ UX_SYNC_RET_APPROVED => {
942
+ return true ;
943
+ }
944
+ _ => {
945
+ ux_sync_reviewStatus ( self . tx_type . to_message ( false ) ) ;
946
+ return false ;
947
+ }
948
+ }
949
+ }
950
+ }
951
+
952
+ pub fn continue_review ( & mut self , fields : & [ Field ] ) -> bool {
953
+ unsafe {
954
+ let v: Vec < CField > = fields
955
+ . iter ( )
956
+ . map ( |f| CField {
957
+ name : CString :: new ( f. name ) . unwrap ( ) ,
958
+ value : CString :: new ( f. value ) . unwrap ( ) ,
959
+ } )
960
+ . collect ( ) ;
961
+
962
+ // Fill the tag_value_array with the fields converted to nbgl_contentTagValue_t
963
+ let mut tag_value_array: Vec < nbgl_contentTagValue_t > = Vec :: new ( ) ;
964
+ for field in v. iter ( ) {
965
+ let val = nbgl_contentTagValue_t {
966
+ item : field. name . as_ptr ( ) as * const i8 ,
967
+ value : field. value . as_ptr ( ) as * const i8 ,
968
+ ..Default :: default ( )
969
+ } ;
970
+ tag_value_array. push ( val) ;
971
+ }
972
+
973
+ // Create the tag_value_list with the tag_value_array.
974
+ let tag_value_list = nbgl_contentTagValueList_t {
975
+ pairs : tag_value_array. as_ptr ( ) as * const nbgl_contentTagValue_t ,
976
+ nbPairs : fields. len ( ) as u8 ,
977
+ ..Default :: default ( )
978
+ } ;
979
+
980
+ let sync_ret = ux_sync_reviewStreamingContinue (
981
+ & tag_value_list as * const nbgl_contentTagValueList_t ,
982
+ ) ;
983
+
984
+ // Return true if the user approved the transaction, false otherwise.
985
+ match sync_ret {
986
+ UX_SYNC_RET_APPROVED => {
987
+ return true ;
988
+ }
989
+ _ => {
990
+ ux_sync_reviewStatus ( self . tx_type . to_message ( false ) ) ;
991
+ return false ;
992
+ }
993
+ }
994
+ }
995
+ }
996
+
997
+ pub fn finish ( & mut self , finish_title : & str ) -> bool {
998
+ unsafe {
999
+ let finish_title = CString :: new ( finish_title) . unwrap ( ) ;
1000
+ let sync_ret = ux_sync_reviewStreamingFinish ( finish_title. as_ptr ( ) as * const c_char ) ;
1001
+
1002
+ // Return true if the user approved the transaction, false otherwise.
1003
+ match sync_ret {
1004
+ ledger_secure_sdk_sys:: UX_SYNC_RET_APPROVED => {
1005
+ ux_sync_reviewStatus ( self . tx_type . to_message ( true ) ) ;
1006
+ return true ;
1007
+ }
1008
+ _ => {
1009
+ ux_sync_reviewStatus ( self . tx_type . to_message ( false ) ) ;
1010
+ return false ;
1011
+ }
1012
+ }
1013
+ }
1014
+ }
1015
+ }
1016
+
824
1017
/// A wrapper around the synchronous NBGL ux_sync_addressReview C API binding.
825
1018
/// Used to display address confirmation screens.
826
1019
pub struct NbglAddressReview < ' a > {
0 commit comments