Skip to content

Commit

Permalink
fix: Add THOR.RUNE default denom + raw amount fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Z4karia committed Oct 1, 2024
1 parent a07a1b5 commit 482d8b3
Show file tree
Hide file tree
Showing 43 changed files with 52 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef enum {

#define COIN_DEFAULT_DENOM_BASE "rune"
#define COIN_DEFAULT_DENOM_REPR "RUNE"
#define COIN_DEFAULT_DENOM_REPR_2 "THOR.RUNE"
#define COIN_DEFAULT_DENOM_FACTOR 8u
#define COIN_DEFAULT_DENOM_TRIMMING 0u

Expand Down
34 changes: 20 additions & 14 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ __Z_INLINE parser_error_t is_default_denom_base(const char *denom, uint8_t denom
return parser_ok;
}

if (strlen(COIN_DEFAULT_DENOM_BASE) != denom_len) {
if (strlen(COIN_DEFAULT_DENOM_BASE) != denom_len && strlen(COIN_DEFAULT_DENOM_REPR_2) != denom_len) {
*is_default = false;
return parser_ok;
}

if (memcmp(denom, COIN_DEFAULT_DENOM_BASE, denom_len) == 0) {
if (memcmp(denom, COIN_DEFAULT_DENOM_BASE, denom_len) == 0 || memcmp(denom, COIN_DEFAULT_DENOM_REPR_2, denom_len) == 0) {
*is_default = true;
return parser_ok;
}
Expand All @@ -125,7 +125,7 @@ __Z_INLINE parser_error_t is_default_denom_base(const char *denom, uint8_t denom

__Z_INLINE parser_error_t parser_formatAmountItem(uint16_t amountToken,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {
uint8_t pageIdx, uint8_t *pageCount, bool *is_default) {
*pageCount = 0;

uint16_t numElements;
Expand Down Expand Up @@ -187,9 +187,9 @@ __Z_INLINE parser_error_t parser_formatAmountItem(uint16_t amountToken,

snprintf(bufferUI, sizeof(bufferUI), "%s ", tmpAmount);
// If denomination has been recognized format and replace
bool is_default =false;
CHECK_PARSER_ERR(is_default_denom_base(denomPtr, denomLen, &is_default))
if (is_default) {
*is_default = false;
CHECK_PARSER_ERR(is_default_denom_base(denomPtr, denomLen, is_default))
if (*is_default) {
if (fpstr_to_str(bufferUI, sizeof(bufferUI), tmpAmount, COIN_DEFAULT_DENOM_FACTOR) != 0) {
return parser_unexpected_error;
}
Expand All @@ -205,12 +205,12 @@ __Z_INLINE parser_error_t parser_formatAmountItem(uint16_t amountToken,

__Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {
ZEMU_LOGF(200, "[formatAmount] ------- pageidx %d", pageIdx)
uint8_t pageIdx, uint8_t *pageCount, bool *is_default) {
ZEMU_LOGF(200, "[formatAmount] ------- pageidx %d\n", pageIdx)

*pageCount = 0;
if (parser_tx_obj.tx_json.json.tokens[amountToken].type != JSMN_ARRAY) {
return parser_formatAmountItem(amountToken, outVal, outValLen, pageIdx, pageCount);
return parser_formatAmountItem(amountToken, outVal, outValLen, pageIdx, pageCount, is_default);
}

uint8_t totalPages = 0;
Expand All @@ -227,7 +227,7 @@ __Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken,
uint8_t subpagesCount;

CHECK_PARSER_ERR(array_get_nth_element(&parser_tx_obj.tx_json.json, amountToken, i, &itemTokenIdx));
CHECK_PARSER_ERR(parser_formatAmountItem(itemTokenIdx, outVal, outValLen, 0, &subpagesCount));
CHECK_PARSER_ERR(parser_formatAmountItem(itemTokenIdx, outVal, outValLen, 0, &subpagesCount, is_default));
totalPages += subpagesCount;

ZEMU_LOGF(200, "[formatAmount] [%d] TokenIdx: %d - PageIdx: %d - Pages: %d - Total %d", i, itemTokenIdx,
Expand Down Expand Up @@ -256,7 +256,7 @@ __Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken,
}

uint8_t dummy;
return parser_formatAmountItem(showItemTokenIdx, outVal, outValLen, showPageIdx, &dummy);
return parser_formatAmountItem(showItemTokenIdx, outVal, outValLen, showPageIdx, &dummy, is_default);
}

__Z_INLINE parser_error_t parser_getJsonItem(uint8_t displayIdx,
Expand Down Expand Up @@ -287,10 +287,12 @@ __Z_INLINE parser_error_t parser_getJsonItem(uint8_t displayIdx,
CHECK_APP_CANARY()
snprintf(outKey, outKeyLen, "%s", tmpKey);

bool is_default = false;

if (parser_isAmount(tmpKey)) {
CHECK_PARSER_ERR(parser_formatAmount(ret_value_token_index,
outVal, outValLen,
pageIdx, pageCount))
pageIdx, pageCount, &is_default))
} else {
CHECK_PARSER_ERR(tx_getToken(ret_value_token_index,
outVal, outValLen,
Expand All @@ -300,8 +302,12 @@ __Z_INLINE parser_error_t parser_getJsonItem(uint8_t displayIdx,

CHECK_PARSER_ERR(tx_display_make_friendly())
CHECK_APP_CANARY()

snprintf(outKey, outKeyLen, "%s", tmpKey);
// Display "Raw Amount" for non-default tokens
if(memcmp(tmpKey, "Amount", 6) == 0 && is_default == false){
snprintf(outKey, outKeyLen, "Raw %s", tmpKey);
} else {
snprintf(outKey, outKeyLen, "%s", tmpKey);
}
CHECK_APP_CANARY()

return parser_ok;
Expand Down
Binary file modified tests_zemu/snapshots/fl-sign_msgDeposit/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-sign_msgDeposit/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-sign_msgDeposit/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/st-sign_msgDeposit/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-sign_msgDeposit/00002.png
26 changes: 26 additions & 0 deletions tests_zemu/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,30 @@ export const example_tx_str_MsgDeposit = {
}
],
"sequence": "6"
};

export const example_tx_str_MsgDeposit_token_2 = {
"account_number": "588",
"chain_id": "thorchain",
"fee": {
"amount": [],
"gas": "10000000"
},
"memo": "",
"msgs": [
{
"type": "thorchain/MsgDeposit",
"value": {
"coins": [
{
"amount": "330000000",
"asset": "ETH.ETH"
}
],
"memo": "SWAP:BNB.BNB:tbnb1qk2m905ypazwfau9cn0qnr4c4yxz63v9u9md20:",
"signer": "tthor1c648xgpter9xffhmcqvs7lzd7hxh0prgv5t5gp"
}
}
],
"sequence": "6"
};
5 changes: 5 additions & 0 deletions tests_zemu/tests/thor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
AMINO_JSON_TX,
example_tx_str_MsgSend,
example_tx_str_MsgDeposit,
example_tx_str_MsgDeposit_token_2
} from './common'

// @ts-ignore
Expand Down Expand Up @@ -98,4 +99,8 @@ describe('Thor', function () {
await signAndVerifyTransaction(m, 'sign_msgDeposit', example_tx_str_MsgDeposit);
});

test.concurrent.each(DEVICE_MODELS)('sign msgDeposit token 2', async function (m) {
await signAndVerifyTransaction(m, 'sign_msgDeposit_token_2', example_tx_str_MsgDeposit_token_2);
});

})

0 comments on commit 482d8b3

Please sign in to comment.