Skip to content

Commit 7031656

Browse files
authored
fix(legacy): fix ada issue and display issue (#597)
1 parent c1414c9 commit 7031656

File tree

6 files changed

+74
-30
lines changed

6 files changed

+74
-30
lines changed

legacy/buttons.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,5 @@ bool isLongPress(uint8_t key);
123123
default: \
124124
break; \
125125
} \
126+
enableLongPress(false); \
126127
return result;

legacy/firmware/ada.c

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,11 @@ static bool layoutToken(const CardanoToken *msg, bool is_mint) {
669669
if (0 == index) {
670670
oledDrawStringAdapter(0, 13, _("Asset Fingerprint:"), FONT_STANDARD);
671671
oledDrawStringAdapter(0, 13 + 10, fingerprint, FONT_STANDARD);
672-
oledDrawStringAdapter(0, 13 + 30, _("Token Amount:"), FONT_STANDARD);
673672
oledDrawBitmap(3 * OLED_WIDTH / 4 - 8, OLED_HEIGHT - 8,
674673
&bmp_bottom_middle_arrow_down);
675674
} else {
676-
oledDrawStringAdapter(0, 13, fingerprint, FONT_STANDARD);
677-
oledDrawStringAdapter(0, 13 + 20, _("Token Amount:"), FONT_STANDARD);
678-
oledDrawStringAdapter(0, 13 + 30, amount, FONT_STANDARD);
675+
oledDrawStringAdapter(0, 13, _("Token Amount:"), FONT_STANDARD);
676+
oledDrawStringAdapter(0, 13 + 10, amount, FONT_STANDARD);
679677
oledDrawBitmap(OLED_WIDTH / 4, OLED_HEIGHT - 8,
680678
&bmp_bottom_middle_arrow_up);
681679
}
@@ -805,8 +803,16 @@ bool txHashBuilder_addOutput(const CardanoTxOutput *output) {
805803
if (!get_address_bytes(output, address_bytes, &address_bytes_len))
806804
return false;
807805
bool has_datum_hash = output->has_datum_hash && output->datum_hash.size > 0;
808-
806+
bool has_inline_datum =
807+
output->has_inline_datum_size && output->inline_datum_size > 0;
808+
bool has_reference_script =
809+
output->has_reference_script_size && output->reference_script_size > 0;
810+
ada_signer.output_type = output->format;
809811
if (output->format == CardanoTxOutputSerializationFormat_ARRAY_LEGACY) {
812+
if (has_inline_datum || has_reference_script) {
813+
fsm_sendFailure(FailureType_Failure_ProcessError, "Invalid output");
814+
return false;
815+
}
810816
BUILDER_APPEND_CBOR(CBOR_TYPE_ARRAY, output_items_count);
811817

812818
BUILDER_APPEND_CBOR(CBOR_TYPE_BYTES, address_bytes_len);
@@ -845,25 +851,23 @@ bool txHashBuilder_addOutput(const CardanoTxOutput *output) {
845851
BUILDER_APPEND_DATA(address_bytes, address_bytes_len);
846852

847853
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED, BABBAGE_OUTPUT_KEY_AMOUNT);
848-
bool has_inline_datum =
849-
output->has_inline_datum_size && output->inline_datum_size > 0;
850-
bool has_reference_script =
851-
output->has_reference_script_size && output->reference_script_size > 0;
854+
852855
if (output->asset_groups_count == 0) {
853856
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED, output->amount);
854-
if (has_datum_hash || has_inline_datum) {
857+
if (has_datum_hash) {
855858
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED,
856859
BABBAGE_OUTPUT_KEY_DATUM_OPTION);
857860
BUILDER_APPEND_CBOR(CBOR_TYPE_ARRAY, 2);
858-
}
859-
if (has_datum_hash) {
860861
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED, BABBAGE_OUTPUT_KEY_DATUM_HASH);
861862
BUILDER_APPEND_CBOR(CBOR_TYPE_BYTES, output->datum_hash.size);
862863
BUILDER_APPEND_DATA(output->datum_hash.bytes, output->datum_hash.size);
863864
ada_signer.datum_hash_size = 0;
864865
ada_signer.inline_datum_size = 0;
865866
ada_signer.remainingInlineDatumChunksCount = 0;
866867
} else if (has_inline_datum) {
868+
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED,
869+
BABBAGE_OUTPUT_KEY_DATUM_OPTION);
870+
BUILDER_APPEND_CBOR(CBOR_TYPE_ARRAY, 2);
867871
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED,
868872
BABBAGE_OUTPUT_KEY_INLINE_DATUM);
869873
BUILDER_APPEND_CBOR(CBOR_TYPE_TAG, CBOR_TAG_EMBEDDED_CBOR_BYTE_STRING);
@@ -879,19 +883,15 @@ bool txHashBuilder_addOutput(const CardanoTxOutput *output) {
879883
ada_signer.datum_hash_size = 0;
880884
}
881885
if (has_reference_script) {
882-
if (!has_datum_hash) {
883-
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED,
884-
BABBAGE_OUTPUT_KEY_REFERENCE_SCRIPT);
885-
BUILDER_APPEND_CBOR(CBOR_TYPE_TAG,
886-
CBOR_TAG_EMBEDDED_CBOR_BYTE_STRING);
887-
BUILDER_APPEND_CBOR(CBOR_TYPE_BYTES, output->reference_script_size);
888-
ada_signer.outputState = STATE_OUTPUT_REFERENCE_SCRIPT_CHUNKS;
889-
} else {
886+
if (!has_inline_datum) {
890887
ada_signer.outputState = STATE_OUTPUT_REFERENCE_SCRIPT;
891888
}
892889
ada_signer.reference_script_size = output->reference_script_size;
893890
ada_signer.remainingReferenceScriptChunksCount =
894891
DIV_ROUND_UP(output->reference_script_size, MAX_CHUNK_SIZE);
892+
} else {
893+
ada_signer.remainingReferenceScriptChunksCount = 0;
894+
ada_signer.reference_script_size = 0;
895895
}
896896
if (ada_signer.remainingOutputs == 0 && !has_inline_datum &&
897897
!has_reference_script) {
@@ -1008,19 +1008,27 @@ bool txHashBuilder_addToken(const CardanoToken *msg) {
10081008
if (is_output_state) {
10091009
if ((ada_signer.remainingOutputAssetTokensCount == 0) &&
10101010
(ada_signer.remainingOutputAssetGroupsCount == 0)) {
1011-
if (ada_signer.datum_hash_size > 0 || ada_signer.inline_datum_size > 0) {
1012-
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED,
1013-
BABBAGE_OUTPUT_KEY_DATUM_OPTION);
1014-
BUILDER_APPEND_CBOR(CBOR_TYPE_ARRAY, 2);
1015-
}
10161011
if (ada_signer.datum_hash_size > 0) {
1012+
if (ada_signer.output_type ==
1013+
CardanoTxOutputSerializationFormat_MAP_BABBAGE) {
1014+
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED,
1015+
BABBAGE_OUTPUT_KEY_DATUM_OPTION);
1016+
BUILDER_APPEND_CBOR(CBOR_TYPE_ARRAY, 2);
1017+
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED,
1018+
BABBAGE_OUTPUT_KEY_DATUM_HASH);
1019+
ada_signer.outputState =
1020+
ada_signer.remainingReferenceScriptChunksCount > 0
1021+
? STATE_OUTPUT_REFERENCE_SCRIPT
1022+
: STATE_OUTPUT_FINISHED;
1023+
} else {
1024+
ada_signer.outputState = STATE_OUTPUT_FINISHED;
1025+
}
10171026
BUILDER_APPEND_CBOR(CBOR_TYPE_BYTES, ada_signer.datum_hash_size);
10181027
BUILDER_APPEND_DATA(ada_signer.datum_hash, ada_signer.datum_hash_size);
1019-
ada_signer.outputState =
1020-
ada_signer.remainingReferenceScriptChunksCount > 0
1021-
? STATE_OUTPUT_REFERENCE_SCRIPT
1022-
: STATE_OUTPUT_FINISHED;
10231028
} else if (ada_signer.inline_datum_size > 0) {
1029+
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED,
1030+
BABBAGE_OUTPUT_KEY_DATUM_OPTION);
1031+
BUILDER_APPEND_CBOR(CBOR_TYPE_ARRAY, 2);
10241032
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED,
10251033
BABBAGE_OUTPUT_KEY_INLINE_DATUM);
10261034
BUILDER_APPEND_CBOR(CBOR_TYPE_TAG, CBOR_TAG_EMBEDDED_CBOR_BYTE_STRING);

legacy/firmware/ada.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ struct AdaSigner {
161161
uint16_t datum_hash_size;
162162
uint32_t inline_datum_size;
163163
uint32_t reference_script_size;
164+
uint8_t output_type;
164165
};
165166
bool fsm_getCardanoIcaruNode(HDNode *node, const uint32_t *address_n,
166167
size_t address_n_count, uint32_t *fingerprint);

legacy/firmware/chinese.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void oledDrawStringRightAdapter(int x, int y, const char *text, uint8_t font) {
129129
}
130130
#include "memzero.h"
131131
#include "util.h"
132+
extern void drawScrollbar_ext(int pages, int index, int bar_start);
132133

133134
uint8_t oledDrawPageableStringAdapter(int x, int y, const char *text,
134135
uint8_t font, const BITMAP *btn_no_icon,
@@ -180,7 +181,7 @@ uint8_t oledDrawPageableStringAdapter(int x, int y, const char *text,
180181
}
181182
}
182183
// scrollbar
183-
drawScrollbar(rowcount - 2, index);
184+
drawScrollbar_ext(rowcount - 2, index, y1);
184185
// bottom button
185186
layoutButtonNoAdapter(NULL, btn_no_icon);
186187
layoutButtonYesAdapter(NULL, btn_yes_icon);

legacy/firmware/layout2.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,7 @@ void layoutResetWord(const char *word, int pass, int word_pos, bool last) {
13791379
void drawScrollbar(int pages, int index) {
13801380
int i, bar_start = 12, bar_end = 52;
13811381
int bar_heght = 40 - 2 * (pages - 1);
1382+
if (bar_heght < 6) bar_heght = 6;
13821383
for (i = bar_start; i < bar_end; i += 2) { // 40 pixel
13831384
oledDrawPixel(OLED_WIDTH - 1, i);
13841385
}
@@ -1389,6 +1390,28 @@ void drawScrollbar(int pages, int index) {
13891390
}
13901391
}
13911392

1393+
void drawScrollbar_ext(int pages, int index, int bar_start) {
1394+
int i, bar_end = 52;
1395+
int bar_heght = 40 - 2 * (pages - 1);
1396+
if (bar_heght < 6) bar_heght = 6;
1397+
for (i = bar_start; i < bar_end; i += 2) { // 40 pixel
1398+
oledDrawPixel(OLED_WIDTH - 1, i);
1399+
}
1400+
if (index <= 12) {
1401+
for (i = bar_start + 2 * ((int)index);
1402+
i < (bar_start + bar_heght + 2 * ((int)index)) - 1; i++) {
1403+
oledDrawPixel(OLED_WIDTH - 1, i);
1404+
oledDrawPixel(OLED_WIDTH - 2, i);
1405+
}
1406+
} else {
1407+
for (i = bar_start + 2 * 12; i < (bar_start + bar_heght + 2 * (12 - 1)) - 1;
1408+
i++) {
1409+
oledDrawPixel(OLED_WIDTH - 1, i);
1410+
oledDrawPixel(OLED_WIDTH - 2, i);
1411+
}
1412+
}
1413+
}
1414+
13921415
#define QR_MAX_VERSION 9
13931416

13941417
uint8_t layoutAddress(const char *address, const char *address_type,
@@ -5168,6 +5191,9 @@ bool layoutSignMessage(const char *chain_name, bool verify, const char *signer,
51685191
resp.has_code = true;
51695192
resp.code = ButtonRequestType_ButtonRequest_ProtectCall;
51705193
msg_write(MessageType_MessageType_ButtonRequest, &resp);
5194+
#if !EMULATOR
5195+
enableLongPress(true);
5196+
#endif
51715197

51725198
refresh_menu:
51735199
layoutSwipe();
@@ -5193,6 +5219,7 @@ bool layoutSignMessage(const char *chain_name, bool verify, const char *signer,
51935219
}
51945220
delay_ms(10);
51955221
}
5222+
is_unsafe = false;
51965223
}
51975224
if (0 == index) {
51985225
oledDrawStringAdapter(0, y, _("Signed by:"), FONT_STANDARD);

legacy/firmware/protect.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,12 @@ uint8_t protectWaitKey(uint32_t time_out, uint8_t mode) {
820820
}
821821
#if !EMULATOR
822822
if (isLongPress(KEY_UP_OR_DOWN) && getLongPressStatus()) {
823+
if (isLongPress(KEY_UP)) {
824+
key = KEY_UP;
825+
} else if (isLongPress(KEY_DOWN)) {
826+
key = KEY_DOWN;
827+
}
828+
delay_ms(50);
823829
break;
824830
}
825831
#endif

0 commit comments

Comments
 (0)