Skip to content

Commit

Permalink
eth compatibility!
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 4, 2023
1 parent a978a37 commit 95455c3
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 91 deletions.
4 changes: 2 additions & 2 deletions crypto/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

// support Ethereum operations
#ifndef USE_ETHEREUM
#define USE_ETHEREUM 0
#define USE_ETHEREUM 1
#endif

// support NEM operations
Expand All @@ -83,7 +83,7 @@

// support Keccak hashing
#ifndef USE_KECCAK
#define USE_KECCAK 0
#define USE_KECCAK 1
#endif

// add way how to mark confidential data
Expand Down
3 changes: 2 additions & 1 deletion flipbip.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ FlipBip* flipbip_app_alloc() {
view_dispatcher_set_custom_event_callback(app->view_dispatcher, flipbip_custom_event_callback);
app->submenu = submenu_alloc();

// Settings
app->haptic = 1;
//app->speaker = 1;
app->led = 1;
app->bip39_strength = 2; // 256 bits (24 words)
app->bip44_coin = 0; // 0 (BTC)

view_dispatcher_add_view(app->view_dispatcher, FlipBipViewIdMenu, submenu_get_view(app->submenu));
app->flipbip_startscreen = flipbip_startscreen_alloc();
Expand Down
12 changes: 6 additions & 6 deletions flipbip.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ typedef struct {
FlipBipScene1* flipbip_scene_1;
// FlipBipScene2* flipbip_scene_2;
int haptic;
// int speaker;
int led;
int bip39_strength;
int bip44_coin;
} FlipBip;

typedef enum {
Expand All @@ -44,11 +44,6 @@ typedef enum {
FlipBipHapticOn,
} FlipBipHapticState;

// typedef enum {
// FlipBipSpeakerOff,
// FlipBipSpeakerOn,
// } FlipBipSpeakerState;

typedef enum {
FlipBipLedOff,
FlipBipLedOn,
Expand All @@ -59,3 +54,8 @@ typedef enum {
FlipBipStrength192,
FlipBipStrength256,
} FlipBipStrengthState;

typedef enum {
FlipBipCoinBTC0,
FlipBipCoinETH60,
} FlipBipCoinState;
7 changes: 6 additions & 1 deletion scenes/flipbip_scene_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ void flipbip_scene_menu_submenu_callback(void* context, uint32_t index) {
void flipbip_scene_menu_on_enter(void* context) {
FlipBip* app = context;

submenu_add_item(app->submenu, "Generate wallet", SubmenuIndexScene1, flipbip_scene_menu_submenu_callback, app);
if (app->bip44_coin == FlipBipCoinBTC0) { // BTC
submenu_add_item(app->submenu, "Generate BTC wallet", SubmenuIndexScene1, flipbip_scene_menu_submenu_callback, app);
}
if (app->bip44_coin == FlipBipCoinETH60) { // ETH
submenu_add_item(app->submenu, "Generate ETH wallet", SubmenuIndexScene1, flipbip_scene_menu_submenu_callback, app);
}
//submenu_add_item(app->submenu, "Scene 2", SubmenuIndexScene2, flipbip_scene_menu_submenu_callback, app);
submenu_add_item(app->submenu, "Settings", SubmenuIndexSettings, flipbip_scene_menu_submenu_callback, app);

Expand Down
56 changes: 28 additions & 28 deletions scenes/flipbip_scene_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

// enum SettingsIndex {
// SettingsIndexBip39Strength = 10,
// SettingsIndexBip44Coin,
// SettingsIndexHaptic,
// SettingsIndexValue1,
// SettingsIndexValue2,
// };

const char* const haptic_text[2] = {
Expand All @@ -17,15 +17,6 @@ const uint32_t haptic_value[2] = {
FlipBipHapticOn,
};

// const char* const speaker_text[2] = {
// "OFF",
// "ON",
// };
// const uint32_t speaker_value[2] = {
// FlipBipSpeakerOff,
// FlipBipSpeakerOn,
// };

const char* const led_text[2] = {
"OFF",
"ON",
Expand All @@ -46,20 +37,22 @@ const uint32_t bip39_strength_value[3] = {
FlipBipStrength256,
};

const char* const bip44_coin_text[2] = {
"BTC",
"ETH",
};
const uint32_t bip44_coin_value[2] = {
FlipBipCoinBTC0,
FlipBipCoinETH60,
};

static void flipbip_scene_settings_set_haptic(VariableItem* item) {
FlipBip* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, haptic_text[index]);
app->haptic = haptic_value[index];
}

// static void flipbip_scene_settings_set_speaker(VariableItem* item) {
// FlipBip* app = variable_item_get_context(item);
// uint8_t index = variable_item_get_current_value_index(item);
// variable_item_set_current_value_text(item, speaker_text[index]);
// app->speaker = speaker_value[index];
// }

static void flipbip_scene_settings_set_led(VariableItem* item) {
FlipBip* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
Expand All @@ -74,6 +67,13 @@ static void flipbip_scene_settings_set_bip39_strength(VariableItem* item) {
app->bip39_strength = bip39_strength_value[index];
}

static void flipbip_scene_settings_set_bip44_coin(VariableItem* item) {
FlipBip* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, bip44_coin_text[index]);
app->bip44_coin = bip44_coin_value[index];
}

void flipbip_scene_settings_submenu_callback(void* context, uint32_t index) {
FlipBip* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
Expand All @@ -95,6 +95,17 @@ void flipbip_scene_settings_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, bip39_strength_text[value_index]);

// BIP44 Coin
item = variable_item_list_add(
app->variable_item_list,
"BIP44 Coin:",
2,
flipbip_scene_settings_set_bip44_coin,
app);
value_index = value_index_uint32(app->bip44_coin, bip44_coin_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, bip44_coin_text[value_index]);

// Vibro on/off
item = variable_item_list_add(
app->variable_item_list,
Expand All @@ -106,17 +117,6 @@ void flipbip_scene_settings_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, haptic_text[value_index]);

// // Sound on/off
// item = variable_item_list_add(
// app->variable_item_list,
// "Sound:",
// 2,
// flipbip_scene_settings_set_speaker,
// app);
// value_index = value_index_uint32(app->speaker, speaker_value, 2);
// variable_item_set_current_value_index(item, value_index);
// variable_item_set_current_value_text(item, speaker_text[value_index]);

// LED Effects on/off
item = variable_item_list_add(
app->variable_item_list,
Expand Down
Loading

0 comments on commit 95455c3

Please sign in to comment.