1+ /*******************************************************************************
2+ * (c) 2018 - 2022 Zondax GmbH
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+ #include "os.h"
18+ #include "cx.h"
19+ #include "coin.h"
20+ #include "app_main.h"
21+ #include "tx.h"
22+ #include "view.h"
23+ #include "app_mode.h"
24+ #include "zxformat.h"
25+
26+ void account_accept () {
27+ #ifdef APP_ACCOUNT_MODE_ENABLED
28+ app_mode_set_account (!app_mode_account ());
29+ view_idle_show (0 , NULL );
30+ #endif
31+ }
32+
33+ static const char * RELAY_CHAIN_POLKADOT = "Polkadot" ;
34+ static const char * RELAY_CHAIN_KUSAMA = "Kusama" ;
35+ static const char * PARACHAIN = COIN_NAME ;
36+
37+ static const char * ACCOUNT_CROWDLOAN = "Crowdloan account." ;
38+ static const char * ACCOUNT_LEGACY = "Legacy account." ;
39+
40+ static const char * crowdloan_message_00 = "You are about to switch to" ;
41+ static const char * crowdloan_message_01 = "If you are not sure why you are here, reject or unplug your device immediately." ;
42+ static const char * crowdloan_message_02 = "Activating this mode will allow you to sign transactions using" ;
43+
44+ zxerr_t account_getNumItems (uint8_t * num_items ) {
45+ zemu_log_stack ("crowdloan_getNumItems" );
46+ * num_items = 1 ;
47+ return zxerr_ok ;
48+ }
49+
50+ zxerr_t account_getItem (int8_t displayIdx ,
51+ char * outKey , uint16_t outKeyLen ,
52+ char * outVal , uint16_t outValLen ,
53+ uint8_t pageIdx , uint8_t * pageCount ) {
54+ if (displayIdx != 0 ) {
55+ return zxerr_no_data ;
56+ }
57+
58+ snprintf (outKey , outKeyLen , "Warning!" );
59+
60+ char * account_str = (char * )PIC (ACCOUNT_CROWDLOAN );
61+ char * chain_str = (char * )PIC (RELAY_CHAIN_POLKADOT );
62+ const uint32_t derivation_path = HDPATH_1_RECOVERY & 0xFFF ;
63+ if (derivation_path == 0x1b2 ) {
64+ chain_str = (char * )PIC (RELAY_CHAIN_KUSAMA );
65+ }
66+ if (app_mode_account ()) {
67+ account_str = (char * )PIC (ACCOUNT_LEGACY );
68+ chain_str = (char * )PIC (PARACHAIN );
69+ }
70+
71+ char tmpBuf [250 ];
72+ snprintf (tmpBuf , sizeof (tmpBuf ), "%s %s %s %s, %s keys." ,
73+ (char * )PIC (crowdloan_message_00 ),
74+ account_str ,
75+ (char * )PIC (crowdloan_message_01 ),
76+ (char * )PIC (crowdloan_message_02 ),
77+ chain_str );
78+ pageString (outVal , outValLen , tmpBuf , pageIdx , pageCount );
79+ return zxerr_ok ;
80+ }
81+
82+ zxerr_t account_enabled () {
83+ #ifdef APP_ACCOUNT_MODE_ENABLED
84+ view_review_init (account_getItem , account_getNumItems , account_accept );
85+ view_review_show (0x00 );
86+ #endif
87+ return zxerr_ok ;
88+ }
0 commit comments