Skip to content

Commit

Permalink
text input flow cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 9, 2023
1 parent a376ba9 commit b149ebc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
21 changes: 14 additions & 7 deletions flipbip.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ static void text_input_callback(void* context) {
furi_assert(context);
FlipBip* app = context;

if(app->passphrase == FlipBipPassphraseOn && strlen(app->input) > 0) {
strcpy(app->passphrase_text, app->input);
} else {
memzero(app->passphrase_text, TEXT_BUFFER_SIZE);
// check that there is text in the input
if(strlen(app->input_text) > 0) {
if(app->input_state == FlipBipTextInputPassphrase) {
if(app->passphrase == FlipBipPassphraseOn) {
strcpy(app->passphrase_text, app->input_text);
}
view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdSettings);
}
}
memzero(app->input, TEXT_BUFFER_SIZE);

view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdSettings);
// clear input text
memzero(app->input_text, TEXT_BUFFER_SIZE);
// reset input state
app->input_state = FlipBipTextInputDefault;
}

FlipBip* flipbip_app_alloc() {
Expand Down Expand Up @@ -62,6 +68,7 @@ FlipBip* flipbip_app_alloc() {
app->bip39_strength = FlipBipStrength256; // 256 bits (24 words)
app->bip44_coin = FlipBipCoinBTC0; // 0 (BTC)
app->overwrite_saved_seed = 0;
app->input_state = FlipBipTextInputDefault;

view_dispatcher_add_view(
app->view_dispatcher, FlipBipViewIdMenu, submenu_get_view(app->submenu));
Expand All @@ -84,7 +91,7 @@ FlipBip* flipbip_app_alloc() {
app->text_input,
text_input_callback,
(void*)app,
app->input,
app->input_text,
TEXT_BUFFER_SIZE,
//clear default text
true);
Expand Down
13 changes: 10 additions & 3 deletions flipbip.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ typedef struct {
SceneManager* scene_manager;
VariableItemList* variable_item_list;
TextInput* text_input;
char input[TEXT_BUFFER_SIZE];
FlipBipStartscreen* flipbip_startscreen;
FlipBipScene1* flipbip_scene_1;
int haptic;
int led;
int passphrase;
char passphrase_text[TEXT_BUFFER_SIZE];
int bip39_strength;
int bip44_coin;
int overwrite_saved_seed;
int input_state;
char passphrase_text[TEXT_BUFFER_SIZE];
char input_text[TEXT_BUFFER_SIZE];
} FlipBip;

typedef enum {
Expand Down Expand Up @@ -76,4 +77,10 @@ typedef enum {
FlipBipCoinBTC0,
FlipBipCoinETH60,
FlipBipCoinDOGE3,
} FlipBipCoin;
} FlipBipCoin;

typedef enum {
FlipBipTextInputDefault,
FlipBipTextInputPassphrase,
FlipBipTextInputMnemonic
} FlipBipTextInputState;
11 changes: 4 additions & 7 deletions scenes/flipbip_scene_settings.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#include "../flipbip.h"
#include "../crypto/memzero.h"
#include <lib/toolbox/value_index.h>

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

const char* const haptic_text[2] = {
"OFF",
"ON",
Expand Down Expand Up @@ -74,7 +68,10 @@ static void flipbip_scene_settings_set_passphrase(VariableItem* item) {
app->passphrase = passphrase_value[index];

if(app->passphrase == FlipBipPassphraseOn) {
app->input_state = FlipBipTextInputPassphrase;
view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdTextInput);
} else {
memzero(app->passphrase_text, TEXT_BUFFER_SIZE);
}
}

Expand Down

0 comments on commit b149ebc

Please sign in to comment.