Skip to content

Commit

Permalink
text cleanup and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 16, 2023
1 parent c9a9f33 commit ed136df
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions views/flipbip_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
#define TEXT_RECEIVE_ADDRESS "receive address:"
#define TEXT_DEFAULT_DERIV "m/44'/X'/0'/0"
const char* TEXT_INFO = "-Scroll pages with up/down-"
"p1,2) Mnemonic/Seed "
"p3) xprv Root Key "
"p4,5) xprv/xpub Accnt Keys"
"p6,7) xprv/xpub Extnd Keys"
"p1,2) BIP39 Mnemonic/Seed"
"p3) BIP32 Root Key "
"p4,5) Prv/Pub Account Keys"
"p6,7) Prv/Pub BIP32 Keys "
"p8+) Receive Addresses ";

// #define TEXT_SAVE_QR "Save QR"
Expand Down Expand Up @@ -157,8 +157,13 @@ static void flipbip_scene_1_init_address(
//s_busy = false;
}

static void flipbip_scene_1_draw_generic(const char* text, size_t line_len) {
static void
flipbip_scene_1_draw_generic(const char* text, const size_t line_len, const bool chunk) {
// Split the text into parts
size_t len = line_len;
if(len > 30) {
len = 30;
}
for(size_t si = 1; si <= 6; si++) {
char* ptr = NULL;

Expand All @@ -176,10 +181,17 @@ static void flipbip_scene_1_draw_generic(const char* text, size_t line_len) {
ptr = s_disp_text6;

memzero(ptr, 30 + 1);
if(line_len > 30) {
strncpy(ptr, text + ((si - 1) * 30), 30);
} else {
strncpy(ptr, text + ((si - 1) * line_len), line_len);
strncpy(ptr, text + ((si - 1) * len), len);
// add a space every 4 characters and shift the text
if(len < 23 && chunk) {
for(size_t i = 0; i < strlen(ptr); i++) {
if(i % 5 == 0) {
for(size_t j = strlen(ptr); j > i; j--) {
ptr[j] = ptr[j - 1];
}
ptr[i] = ' ';
}
}
}
}
}
Expand Down Expand Up @@ -240,7 +252,7 @@ static void flipbip_scene_1_draw_seed(FlipBipScene1Model* const model) {
// Convert the seed to a hex string
flipbip_btox(model->seed, 64, seed_working);

flipbip_scene_1_draw_generic(seed_working, 22);
flipbip_scene_1_draw_generic(seed_working, 22, false);

// Free the working seed memory
memzero(seed_working, seed_working_len);
Expand All @@ -263,27 +275,28 @@ void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {

flipbip_scene_1_clear_text();
if(model->page == PAGE_INFO) {
flipbip_scene_1_draw_generic(TEXT_INFO, 27);
flipbip_scene_1_draw_generic(TEXT_INFO, 27, false);
} else if(model->page == PAGE_MNEMONIC) {
flipbip_scene_1_draw_mnemonic(model->mnemonic);
} else if(model->page == PAGE_SEED) {
flipbip_scene_1_draw_seed(model);
} else if(model->page == PAGE_XPRV_ROOT) {
flipbip_scene_1_draw_generic(model->xprv_root, 20);
flipbip_scene_1_draw_generic(model->xprv_root, 20, false);
} else if(model->page == PAGE_XPRV_ACCT) {
flipbip_scene_1_draw_generic(model->xprv_account, 20);
flipbip_scene_1_draw_generic(model->xprv_account, 20, false);
} else if(model->page == PAGE_XPUB_ACCT) {
flipbip_scene_1_draw_generic(model->xpub_account, 20);
flipbip_scene_1_draw_generic(model->xpub_account, 20, false);
} else if(model->page == PAGE_XPRV_EXTD) {
flipbip_scene_1_draw_generic(model->xprv_extended, 20);
flipbip_scene_1_draw_generic(model->xprv_extended, 20, false);
} else if(model->page == PAGE_XPUB_EXTD) {
flipbip_scene_1_draw_generic(model->xpub_extended, 20);
flipbip_scene_1_draw_generic(model->xpub_extended, 20, false);
} else if(model->page >= PAGE_ADDR_BEGIN && model->page <= PAGE_ADDR_END) {
uint32_t line_len = 12;
size_t line_len = 12;
if(model->coin == FlipBipCoinETH60) {
line_len = 14;
}
flipbip_scene_1_draw_generic(model->recv_addresses[model->page - PAGE_ADDR_BEGIN], line_len);
flipbip_scene_1_draw_generic(
model->recv_addresses[model->page - PAGE_ADDR_BEGIN], line_len, true);
}

if(model->page == PAGE_LOADING) {
Expand Down

0 comments on commit ed136df

Please sign in to comment.