Skip to content

Commit

Permalink
Fix amount conversion logic (#31)
Browse files Browse the repository at this point in the history
🐛 Fix amount conversion logic
  • Loading branch information
nagdahimanshu authored Jun 11, 2024
1 parent 570d902 commit d6b8602
Show file tree
Hide file tree
Showing 50 changed files with 22 additions and 10 deletions.
24 changes: 18 additions & 6 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ static bool set_amount_ui_uint8(ethQueryContractUI_t *msg,
return amountToString(amount, INT256_LENGTH, decimals, ticker, msg->msg, msg->msgLength);
}

// Set UI with custom title for amount (Lisk L1) screen with uint8 data.
static bool set_amount_l1_ui_uint8(ethQueryContractUI_t *msg,
const uint8_t *amount,
const char *title) {
strlcpy(msg->title, title, msg->titleLength);

uint8_t decimals = 8; // 1 LSK = 10**8 Beddows on Lisk L1 (legacy)
const char *ticker = "LSK";

return amountToString(amount, INT256_LENGTH, decimals, ticker, msg->msg, msg->msgLength);
}

// Set UI with custom title for amount screen with uint8 data.
static bool set_amount_ui_arr(ethQueryContractUI_t *msg,
const arr_uint8_t *amount,
Expand Down Expand Up @@ -125,9 +137,9 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) {
case CLAIM_REGULAR_ACCOUNT:
switch (msg->screenIndex) {
case 0:
ret = set_amount_ui_uint8(msg,
context->lisk.body.claim.claim_amount,
"Claim LSK");
ret = set_amount_l1_ui_uint8(msg,
context->lisk.body.claim.claim_amount,
"Claim LSK");
break;
case 1:
ret = set_sender_public_key_ui(msg, context);
Expand All @@ -144,9 +156,9 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) {
case CLAIM_MULTI_SIGNATURE_ACCOUNT:
switch (msg->screenIndex) {
case 0:
ret = set_amount_ui_uint8(msg,
context->lisk.body.claim.claim_amount,
"Claim LSK");
ret = set_amount_l1_ui_uint8(msg,
context->lisk.body.claim.claim_amount,
"Claim LSK");
break;
case 1:
ret = set_lisk_address_ui(msg, context);
Expand Down
Binary file modified tests/snapshots/flex/test_claim_airdrop/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/snapshots/flex/test_claim_multisig_account/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/snapshots/flex/test_claim_regular_account/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/snapshots/flex/test_create_position/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/snapshots/nanos/test_claim_airdrop/00005.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/snapshots/nanos/test_claim_airdrop/00006.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/snapshots/nanos/test_claim_airdrop/00007.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/snapshots/nanos/test_claim_airdrop/00008.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/snapshots/nanos/test_claim_multisig_account/00002.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/snapshots/nanos/test_claim_multisig_account/00003.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/snapshots/nanos/test_claim_multisig_account/00004.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/snapshots/nanos/test_claim_multisig_account/00005.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/snapshots/nanos/test_claim_multisig_account/00006.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/snapshots/nanos/test_claim_multisig_account/00007.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/snapshots/nanos/test_claim_multisig_account/00008.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/snapshots/nanos/test_claim_multisig_account/00009.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/snapshots/nanos/test_claim_multisig_account/00010.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/snapshots/nanos/test_claim_multisig_account/00011.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/snapshots/nanos/test_claim_regular_account/00002.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/snapshots/nanos/test_claim_regular_account/00003.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/snapshots/nanos/test_claim_regular_account/00004.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/snapshots/nanos/test_claim_regular_account/00005.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/snapshots/nanos/test_claim_regular_account/00006.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/snapshots/nanos/test_claim_regular_account/00007.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/snapshots/nanos/test_claim_regular_account/00008.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/snapshots/nanos/test_claim_regular_account/00009.png
Binary file modified tests/snapshots/nanos/test_claim_regular_account/00010.png
Binary file modified tests/snapshots/nanos/test_claim_regular_account/00011.png
Binary file modified tests/snapshots/nanos/test_claim_regular_account/00012.png
Binary file modified tests/snapshots/nanos/test_create_position/00002.png
Binary file modified tests/snapshots/nanos/test_create_position/00003.png
Binary file modified tests/snapshots/nanos/test_create_position/00004.png
Binary file modified tests/snapshots/nanos/test_create_position/00005.png
Binary file modified tests/snapshots/nanos/test_create_position/00006.png
Binary file modified tests/snapshots/nanosp/test_claim_airdrop/00003.png
Binary file modified tests/snapshots/nanosp/test_claim_multisig_account/00002.png
Binary file modified tests/snapshots/nanosp/test_claim_regular_account/00002.png
Binary file modified tests/snapshots/nanosp/test_create_position/00002.png
Binary file modified tests/snapshots/nanox/test_claim_airdrop/00003.png
Binary file modified tests/snapshots/nanox/test_claim_multisig_account/00002.png
Binary file modified tests/snapshots/nanox/test_claim_regular_account/00002.png
Binary file modified tests/snapshots/nanox/test_create_position/00002.png
Binary file modified tests/snapshots/stax/test_claim_airdrop/00001.png
Binary file modified tests/snapshots/stax/test_claim_multisig_account/00001.png
Binary file modified tests/snapshots/stax/test_claim_regular_account/00001.png
Binary file modified tests/snapshots/stax/test_create_position/00001.png
2 changes: 1 addition & 1 deletion tests/test_airdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def test_claim_airdrop(backend, firmware, navigator, test_name, wallet_addr):
data = contract.encodeABI("claimAirdrop", [
bytes.fromhex("77abc2dd8ca5021dbb8e91e63f574b1e440764d2"),
4915507196,
20000000000000000000,
[
bytes.fromhex("9ca797d905e78f38685b61f62521632ef486bc6ce3e707d2af41b7fe146303c1"),
]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_claim_regular_account(backend, firmware, navigator, test_name, wallet_a
bytes.fromhex("6f3f752b8381917128bc5145128af0d83e3d7547c83a2d28b20bb04b8952f4a6")
],
bytes.fromhex("f83c23fb2532ad248e107ebd5312f1f78f742488fdec815c94d6b63aa7682eb6"),
86511774,
1000000000, # 10 LSK to be claimed
bytes.fromhex("00bb7b59073f45177edf430090d5aa3c44aa7f23"),
(
bytes.fromhex("664272cc25b0d20adf551b7a015795b9ad4ab23a4a19a509642bc042c00e5256"),
Expand All @@ -37,7 +37,7 @@ def test_claim_multisig_account(backend, firmware, navigator, test_name, wallet_
bytes.fromhex("629779421eb7409cb867a7d8ee45aadc89a8b86f24423b737e1430832a78f026")
],
bytes.fromhex("77abc2dd8ca5021dbb8e91e63f574b1e440764d2"),
4915507196,
1000000000, # 10 LSK to be claimed
(
[
],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def test_create_position(backend, firmware, navigator, test_name, wallet_addr):
data = contract.encodeABI("createPosition", [
86511774,
200000000000000000,
100
])

Expand Down

0 comments on commit d6b8602

Please sign in to comment.