reset: refactor code into layoutResetWord

This commit is contained in:
Pavol Rusnak 2017-09-04 08:12:33 +02:00
parent c796800b2b
commit 30367bfad1
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 63 additions and 42 deletions

View File

@ -220,6 +220,61 @@ void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address)
str[0], str[1], str[2], str[3], NULL, NULL);
}
void layoutResetWord(const char *word, int pass, int word_pos, bool last)
{
layoutLast = layoutResetWord;
oledSwipeLeft();
const char *btnYes;
if (last) {
if (pass == 1) {
btnYes = _("Finish");
} else {
btnYes = _("Again");
}
} else {
btnYes = _("Next");
}
const char *action;
if (pass == 1) {
action = _("Please check the seed");
} else {
action = _("Write down the seed");
}
char index_str[] = "##th word is:";
if (word_pos < 10) {
index_str[0] = ' ';
} else {
index_str[0] = '0' + word_pos / 10;
}
index_str[1] = '0' + word_pos % 10;
if (word_pos == 1 || word_pos == 21) {
index_str[2] = 's'; index_str[3] = 't';
} else
if (word_pos == 2 || word_pos == 22) {
index_str[2] = 'n'; index_str[3] = 'd';
} else
if (word_pos == 3 || word_pos == 23) {
index_str[2] = 'r'; index_str[3] = 'd';
}
int left = 0;
oledClear();
oledDrawBitmap(0, 0, &bmp_icon_info);
left = bmp_icon_info.width + 4;
oledDrawString(left, 0 * 9, action);
oledDrawString(left, 2 * 9, word_pos < 10 ? index_str + 1 : index_str);
oledDrawStringDouble(left, 3 * 9, word);
oledHLine(OLED_HEIGHT - 13);
oledDrawString(OLED_WIDTH - fontCharWidth('\x06') - 1, OLED_HEIGHT - 8, "\x06");
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 3, OLED_HEIGHT - 8, btnYes);
oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
oledRefresh();
}
void layoutAddress(const char *address, const char *desc, bool qrcode)
{
if (layoutLast != layoutAddress) {

View File

@ -40,6 +40,7 @@ void layoutVerifyMessage(const uint8_t *msg, uint32_t len);
void layoutCipherKeyValue(bool encrypt, const char *key);
void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing);
void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address);
void layoutResetWord(const char *word, int pass, int word_pos, bool last);
void layoutAddress(const char *address, const char *desc, bool qrcode);
void layoutPublicKey(const uint8_t *pubkey);
void layoutSignIdentity(const IdentityType *identity, const char *challenge);

View File

@ -106,7 +106,7 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len)
}
static char current_word[10], current_word_display[11];
static char current_word[10];
// separated == true if called as a separate workflow via BackupMessage
void reset_backup(bool separated)
@ -133,40 +133,7 @@ void reset_backup(bool separated)
if (storage.mnemonic[i] != 0) {
i++;
}
char desc[] = "##th word is:";
if (word_pos < 10) {
desc[0] = ' ';
} else {
desc[0] = '0' + word_pos / 10;
}
desc[1] = '0' + word_pos % 10;
if (word_pos == 1 || word_pos == 21) {
desc[2] = 's'; desc[3] = 't';
} else
if (word_pos == 2 || word_pos == 22) {
desc[2] = 'n'; desc[3] = 'd';
} else
if (word_pos == 3 || word_pos == 23) {
desc[2] = 'r'; desc[3] = 'd';
}
current_word_display[0] = 0x01;
for (j = 0; current_word[j]; j++) {
current_word_display[j + 1] = current_word[j] + 'A' - 'a';
}
current_word_display[j + 1] = 0;
if (storage.mnemonic[i] == 0) { // last word
if (pass == 1) {
layoutDialogSwipe(&bmp_icon_info, NULL, _("Finish"), NULL, _("Please check the seed"), NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL);
} else {
layoutDialogSwipe(&bmp_icon_info, NULL, _("Again"), NULL, _("Write down the seed"), NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL);
}
} else {
if (pass == 1) {
layoutDialogSwipe(&bmp_icon_info, NULL, _("Next"), NULL, _("Please check the seed"), NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL);
} else {
layoutDialogSwipe(&bmp_icon_info, NULL, _("Next"), NULL, _("Write down the seed"), NULL, (word_pos < 10 ? desc + 1 : desc), current_word_display, NULL, NULL);
}
}
layoutResetWord(current_word, pass, word_pos, storage.mnemonic[i] == 0);
if (!protectButton(ButtonRequestType_ButtonRequest_ConfirmWord, true)) {
if (!separated) {
storage_reset();

7
oled.c
View File

@ -281,14 +281,9 @@ int oledStringWidth(const char *text) {
return l;
}
void oledDrawString(int x, int y, const char* text)
void oledDrawStringSize(int x, int y, const char* text, int size)
{
if (!text) return;
int size = 1;
if (*text == 0x01) { // double size
text++;
size = 2;
}
int l = 0;
for (; *text; text++) {
char c = oledConvertChar(*text);

5
oled.h
View File

@ -42,7 +42,10 @@ void oledClearPixel(int x, int y);
void oledInvertPixel(int x, int y);
void oledDrawChar(int x, int y, char c, int zoom);
int oledStringWidth(const char *text);
void oledDrawString(int x, int y, const char* text);
#define oledDrawString(x, y, text) oledDrawStringSize((x), (y), (text), 1)
#define oledDrawStringDouble(x, y, text) oledDrawStringSize((x), (y), (text), 2)
void oledDrawStringSize(int x, int y, const char* text, int size);
void oledDrawStringCenter(int y, const char* text);
void oledDrawStringRight(int x, int y, const char* text);
void oledDrawBitmap(int x, int y, const BITMAP *bmp);