Skip to content

Commit

Permalink
porting on Flex device
Browse files Browse the repository at this point in the history
  • Loading branch information
tdejoigny-ledger committed May 21, 2024
1 parent 231a712 commit 28e18f4
Show file tree
Hide file tree
Showing 415 changed files with 144 additions and 116 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ examples/protocol

# Temporary test snapshots
tests/snapshots-tmp

# Virtual env for sideload (macOS and Windows)
ledger/

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ ICON_NANOS = icons/nanos_app_tron.gif
ICON_NANOX = icons/nanox_app_tron.gif
ICON_NANOSP = icons/nanox_app_tron.gif
ICON_STAX = icons/stax_app_tron.gif
ICON_FLEX = icons/flex_app_tron.gif

ENABLE_BLUETOOTH = 1
ENABLE_SWAP = 1
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.0
0.6.0
File renamed without changes
Binary file added icons/flex_app_tron.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ledger_app.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[app]
build_directory = "./"
sdk = "C"
devices = ["nanos", "nanox", "nanos+", "stax"]
devices = ["nanos", "nanox", "nanos+", "stax", "flex"]

[tests]
pytest_directory = "./tests/"
101 changes: 48 additions & 53 deletions src/ui/ui_idle_menu_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,82 +31,77 @@ enum {

#define NB_INFO_FIELDS 3
static const char* const infoTypes[] = {"Version", "Developer", "Copyright"};
static const char* const infoContents[] = {APPVERSION, "Klever", "(c) 2023 Ledger"};
static const char* const infoContents[] = {APPVERSION, "Klever", "(c) 2024 Ledger"};

#define NB_SETTINGS_SWITCHES 3
#define SETTING_IDX(token) (token - SWITCH_ALLOW_TX_DATA_TOKEN)
static uint8_t settings[NB_SETTINGS_SWITCHES] = {S_DATA_ALLOWED, S_CUSTOM_CONTRACT, S_SIGN_BY_HASH};
static nbgl_layoutSwitch_t switches[NB_SETTINGS_SWITCHES];

static void displaySettingsMenu(void);
static void settingsControlsCallback(int token, uint8_t index);
static bool settingsNavCallback(uint8_t page, nbgl_pageContent_t* content);
static nbgl_layoutSwitch_t switches[NB_SETTINGS_SWITCHES] = {0};

void onQuitCallback(void) {
os_sched_exit(-1);
}

static bool settingsNavCallback(uint8_t page, nbgl_pageContent_t* content) {
if (page == 0) {
content->type = INFOS_LIST;
content->infosList.nbInfos = NB_INFO_FIELDS;
content->infosList.infoTypes = infoTypes;
content->infosList.infoContents = infoContents;
} else if (page == 1) {
switches[0].text = "Transactions data";
switches[0].subText = "Allow extra data in\ntransactions";
switches[0].token = SWITCH_ALLOW_TX_DATA_TOKEN;
switches[0].tuneId = TUNE_TAP_CASUAL;
switches[0].initState = (HAS_SETTING(S_DATA_ALLOWED)) ? ON_STATE : OFF_STATE;
switches[1].text = "Custom contracts";
switches[1].subText = "Allow unverified contracts";
switches[1].token = SWITCH_ALLOW_CSTM_CONTRACTS_TOKEN;
switches[1].tuneId = TUNE_TAP_CASUAL;
switches[1].initState = (HAS_SETTING(S_CUSTOM_CONTRACT)) ? ON_STATE : OFF_STATE;
switches[2].text = "Blind signing";
switches[2].subText = "Allow transaction blind signing";
switches[2].token = SWITCH_ALLOW_HASH_TX_TOKEN;
switches[2].tuneId = TUNE_TAP_CASUAL;
switches[2].initState = (HAS_SETTING(S_SIGN_BY_HASH)) ? ON_STATE : OFF_STATE;
content->type = SWITCHES_LIST;
content->switchesList.nbSwitches = NB_SETTINGS_SWITCHES;
content->switchesList.switches = (nbgl_layoutSwitch_t*) switches;
} else {
return false;
}
return true;
}

static void settingsControlsCallback(int token, uint8_t index) {
static void settingsControlsCallback(int token, uint8_t index, int page) {
UNUSED(index);
UNUSED(page);
switch (token) {
case SWITCH_ALLOW_TX_DATA_TOKEN:
case SWITCH_ALLOW_CSTM_CONTRACTS_TOKEN:
case SWITCH_ALLOW_HASH_TX_TOKEN:
SETTING_TOGGLE(settings[SETTING_IDX(token)]);
switches[0].initState = (HAS_SETTING(S_DATA_ALLOWED)) ? ON_STATE : OFF_STATE;
switches[1].initState = (HAS_SETTING(S_CUSTOM_CONTRACT)) ? ON_STATE : OFF_STATE;
switches[2].initState = (HAS_SETTING(S_SIGN_BY_HASH)) ? ON_STATE : OFF_STATE;
break;
default:
PRINTF("Should not happen !");
break;
}
}

static void displaySettingsMenu(void) {
nbgl_useCaseSettings("Tron settings",
0,
2,
false,
ui_idle,
settingsNavCallback,
settingsControlsCallback);
}
// info menu definition
static const nbgl_contentInfoList_t infoList = {
.nbInfos = NB_INFO_FIELDS,
.infoTypes = infoTypes,
.infoContents = infoContents,
};

// settings menu definition
#define SETTING_CONTENTS_NB 1
static const nbgl_content_t contents[SETTING_CONTENTS_NB] = {
{.type = SWITCHES_LIST,
.content.switchesList.nbSwitches = NB_SETTINGS_SWITCHES,
.content.switchesList.switches = switches,
.contentActionCallback = settingsControlsCallback}};

static const nbgl_genericContents_t settingContents = {.callbackCallNeeded = false,
.contentsList = contents,
.nbContents = SETTING_CONTENTS_NB};
void ui_idle(void) {
nbgl_useCaseHome("Tron",
&C_stax_app_tron_64px,
NULL,
true,
displaySettingsMenu,
onQuitCallback);
switches[0].text = "Transactions data";
switches[0].subText = "Allow extra data in\ntransactions";
switches[0].token = SWITCH_ALLOW_TX_DATA_TOKEN;
switches[0].tuneId = TUNE_TAP_CASUAL;
switches[0].initState = (HAS_SETTING(S_DATA_ALLOWED)) ? ON_STATE : OFF_STATE;
switches[1].text = "Custom contracts";
switches[1].subText = "Allow unverified contracts";
switches[1].token = SWITCH_ALLOW_CSTM_CONTRACTS_TOKEN;
switches[1].tuneId = TUNE_TAP_CASUAL;
switches[1].initState = (HAS_SETTING(S_CUSTOM_CONTRACT)) ? ON_STATE : OFF_STATE;
switches[2].text = "Blind signing";
switches[2].subText = "Allow transaction blind signing";
switches[2].token = SWITCH_ALLOW_HASH_TX_TOKEN;
switches[2].tuneId = TUNE_TAP_CASUAL;
switches[2].initState = (HAS_SETTING(S_SIGN_BY_HASH)) ? ON_STATE : OFF_STATE;

nbgl_useCaseHomeAndSettings(APPNAME,
&C_app_tron_64px,
NULL,
INIT_HOME_PAGE,
&settingContents,
&infoList,
NULL,
onQuitCallback);
}
#endif // HAVE_NBGL
63 changes: 28 additions & 35 deletions src/ui/ui_review_menu_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void dataWarningChoice(bool accept) {
}
} else {
ui_callback_tx_cancel(false);
nbgl_useCaseStatus("Transaction rejected", false, ui_idle);
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_idle);
}
}

Expand All @@ -87,12 +87,12 @@ static void customContractWarningChoice(bool accept) {
displayTransaction();
} else {
ui_callback_tx_cancel(false);
nbgl_useCaseStatus("Transaction rejected", false, ui_idle);
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_idle);
}
}

static void displayDataWarning(void) {
nbgl_useCaseChoice(&C_round_warning_64px,
nbgl_useCaseChoice(&C_Important_Circle_64px,
"WARNING\nThis transaction\ncontains\nextra data",
"Reject if you're not sure",
"Continue",
Expand All @@ -101,7 +101,7 @@ static void displayDataWarning(void) {
}

static void displayCustomContractWarning(void) {
nbgl_useCaseChoice(&C_round_warning_64px,
nbgl_useCaseChoice(&C_Important_Circle_64px,
"WARNING\nCustom Contract\nProceed with care",
"Reject if you're not sure",
"Continue",
Expand All @@ -110,22 +110,24 @@ static void displayCustomContractWarning(void) {
}

static void displayTransaction(void) {
nbgl_useCaseStaticReview(&pairList, &infoLongPress, "Reject transaction", reviewChoice);
// Start review
nbgl_useCaseReview(TYPE_TRANSACTION,
&pairList,
&C_app_tron_64px,
txInfos.flowTitle,
txInfos.flowSubtitle,
infoLongPress.text,
reviewChoice);
}

static void reviewStart() {
nbgl_callback_t displayFunction = displayTransaction;
if (txInfos.warnings[DATA_WARNING] == true) {
displayFunction = displayDataWarning;
displayDataWarning();
} else if (txInfos.warnings[CUSTOM_CONTRACT_WARNING] == true) {
displayFunction = displayCustomContractWarning;
displayCustomContractWarning();
} else {
displayTransaction();
}
nbgl_useCaseReviewStart(&C_stax_app_tron_64px,
txInfos.flowTitle,
txInfos.flowSubtitle,
"Reject transaction",
displayFunction,
rejectChoice);
}

static void reviewChoice(bool confirm) {
Expand All @@ -141,7 +143,7 @@ static void reviewChoice(bool confirm) {
}

if (ret) {
nbgl_useCaseStatus("TRANSACTION\nSIGNED", true, ui_idle);
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_SIGNED, ui_idle);
} else {
nbgl_useCaseStatus("Transaction failure", false, ui_idle);
}
Expand All @@ -152,7 +154,7 @@ static void reviewChoice(bool confirm) {

static void rejectConfirmation(void) {
ui_callback_tx_cancel(false);
nbgl_useCaseStatus("Transaction rejected", false, ui_idle);
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_idle);
}

static void rejectChoice(void) {
Expand All @@ -173,7 +175,7 @@ static void prepareTxInfos(ui_approval_state_t state, bool data_warning) {

infoLongPress.text = "Sign transaction";
infoLongPress.longPressText = "Hold to sign";
infoLongPress.icon = &C_stax_app_tron_64px;
infoLongPress.icon = &C_app_tron_64px;

pairList.pairs = (nbgl_layoutTagValue_t *) txInfos.fields;

Expand Down Expand Up @@ -397,33 +399,24 @@ static void prepareTxInfos(ui_approval_state_t state, bool data_warning) {
}
}

static void address_verification_cancelled(void) {
ui_callback_tx_cancel(false);
nbgl_useCaseStatus("Address verification\ncancelled", false, ui_idle);
}

static void display_address_callback(bool confirm) {
if (confirm) {
ui_callback_address_ok(false);
nbgl_useCaseStatus("ADDRESS\nVERIFIED", true, ui_idle);
nbgl_useCaseReviewStatus(STATUS_TYPE_ADDRESS_VERIFIED, ui_idle);
} else {
address_verification_cancelled();
ui_callback_tx_cancel(false);
nbgl_useCaseReviewStatus(STATUS_TYPE_ADDRESS_REJECTED, ui_idle);
}
}

// called when tapping on review start page to actually display address
static void display_addr(void) {
nbgl_useCaseAddressConfirmation(toAddress, &display_address_callback);
}

void ux_flow_display(ui_approval_state_t state, bool data_warning) {
if (state == APPROVAL_VERIFY_ADDRESS) {
nbgl_useCaseReviewStart(&C_stax_app_tron_64px,
"Verify Tron\naddress",
NULL,
"Cancel",
display_addr,
address_verification_cancelled);
nbgl_useCaseAddressReview(toAddress,
NULL,
&C_app_tron_64px,
"Verify Tron\naddress",
NULL,
display_address_callback);
} else {
// Prepare transaction infos to be displayed (field values etc.)
prepareTxInfos(state, data_warning);
Expand Down
15 changes: 14 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@
@pytest.fixture(scope="class")
def configuration(backend: BackendInterface, navigator, firmware):
if type(backend) is SpeculosBackend:
if firmware.device == "stax":
if firmware.device == "flex":
instructions = [
# Go to settings menu.
NavIns(NavInsID.USE_CASE_HOME_SETTINGS),
# Allow data in TXs
NavIns(NavInsID.TOUCH, (200, 150)),
# Allow custom contracts
NavIns(NavInsID.TOUCH, (200, 300)),
NavIns(NavInsID.USE_CASE_SETTINGS_NEXT),
# Allow sign by hash
NavIns(NavInsID.TOUCH, (200, 150)),
# Go back to main menu.
NavIns(NavInsID.USE_CASE_SETTINGS_MULTI_PAGE_EXIT),
]
elif firmware.device == "stax":
instructions = [
# Go to settings menu.
NavIns(NavInsID.USE_CASE_HOME_SETTINGS),
# Allow data in TXs
NavIns(NavInsID.TOUCH, (200, 150)),
# Allow custom contracts
Expand Down
3 changes: 0 additions & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
pytest
grpcio==1.44.0
grpcio-tools==1.44.0
base58==1.0.3
crypto==1.4.1
cryptography==2.8
eth-keys==0.3.1
ledgerblue==0.1.45
ragger[speculos]>=1.7.1
Expand Down
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.
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.
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 added tests/snapshots/flex/test_trx_ecdh_key/00000.png
Binary file added tests/snapshots/flex/test_trx_ecdh_key/00001.png
Binary file added tests/snapshots/flex/test_trx_ecdh_key/00002.png
Binary file added tests/snapshots/flex/test_trx_ecdh_key/00003.png
Binary file added tests/snapshots/flex/test_trx_send/00000.png
Binary file added tests/snapshots/flex/test_trx_send/00001.png
Binary file added tests/snapshots/flex/test_trx_send/00002.png
Binary file added tests/snapshots/flex/test_trx_send/00003.png
Binary file added tests/snapshots/flex/test_trx_send/00004.png
Binary file added tests/snapshots/flex/test_trx_send/00005.png
Binary file added tests/snapshots/flex/test_trx_sign_hash/00000.png
Binary file added tests/snapshots/flex/test_trx_sign_hash/00001.png
Binary file added tests/snapshots/flex/test_trx_sign_hash/00002.png
Binary file added tests/snapshots/flex/test_trx_sign_hash/00003.png
Binary file modified tests/snapshots/stax/test_get_public_key_confirm_accepted/00001.png
Binary file modified tests/snapshots/stax/test_get_public_key_confirm_accepted/00003.png
Binary file modified tests/snapshots/stax/test_trx_account_update/00000.png
Binary file modified tests/snapshots/stax/test_trx_account_update/00001.png
Binary file modified tests/snapshots/stax/test_trx_account_update/00002.png
Binary file modified tests/snapshots/stax/test_trx_account_update/00003.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file modified tests/snapshots/stax/test_trx_delegate_resource/00000.png
Binary file modified tests/snapshots/stax/test_trx_delegate_resource/00001.png
Binary file modified tests/snapshots/stax/test_trx_delegate_resource/00002.png
Binary file modified tests/snapshots/stax/test_trx_delegate_resource/00003.png
Binary file modified tests/snapshots/stax/test_trx_delegate_resource/00004.png
Binary file modified tests/snapshots/stax/test_trx_ecdh_key/00000.png
Binary file modified tests/snapshots/stax/test_trx_ecdh_key/00001.png
Binary file modified tests/snapshots/stax/test_trx_ecdh_key/00002.png
Binary file modified tests/snapshots/stax/test_trx_ecdh_key/00003.png
Binary file modified tests/snapshots/stax/test_trx_exchange_create/00000.png
Binary file modified tests/snapshots/stax/test_trx_exchange_create/00001.png
Binary file modified tests/snapshots/stax/test_trx_exchange_create/00002.png
Binary file modified tests/snapshots/stax/test_trx_exchange_create/00003.png
Binary file modified tests/snapshots/stax/test_trx_exchange_create/00004.png
Binary file modified tests/snapshots/stax/test_trx_exchange_inject/00000.png
Binary file modified tests/snapshots/stax/test_trx_exchange_inject/00001.png
Binary file modified tests/snapshots/stax/test_trx_exchange_inject/00002.png
Binary file modified tests/snapshots/stax/test_trx_exchange_inject/00003.png
Binary file modified tests/snapshots/stax/test_trx_exchange_inject/00004.png
Binary file modified tests/snapshots/stax/test_trx_exchange_transaction/00000.png
Binary file modified tests/snapshots/stax/test_trx_exchange_transaction/00001.png
Binary file modified tests/snapshots/stax/test_trx_exchange_transaction/00002.png
Binary file modified tests/snapshots/stax/test_trx_exchange_transaction/00003.png
Binary file modified tests/snapshots/stax/test_trx_exchange_transaction/00004.png
Binary file modified tests/snapshots/stax/test_trx_exchange_withdraw/00000.png
Binary file modified tests/snapshots/stax/test_trx_exchange_withdraw/00001.png
Binary file modified tests/snapshots/stax/test_trx_exchange_withdraw/00002.png
Binary file modified tests/snapshots/stax/test_trx_exchange_withdraw/00003.png
Binary file modified tests/snapshots/stax/test_trx_exchange_withdraw/00004.png
Binary file modified tests/snapshots/stax/test_trx_freezeV2_balance/00000.png
Binary file modified tests/snapshots/stax/test_trx_freezeV2_balance/00001.png
Binary file modified tests/snapshots/stax/test_trx_freezeV2_balance/00002.png
Binary file modified tests/snapshots/stax/test_trx_freezeV2_balance/00003.png
Binary file modified tests/snapshots/stax/test_trx_freezeV2_balance/00004.png
Binary file modified tests/snapshots/stax/test_trx_freeze_balance_bw/00000.png
Binary file modified tests/snapshots/stax/test_trx_freeze_balance_bw/00001.png
Binary file modified tests/snapshots/stax/test_trx_freeze_balance_bw/00002.png
Binary file modified tests/snapshots/stax/test_trx_freeze_balance_bw/00003.png
Binary file modified tests/snapshots/stax/test_trx_freeze_balance_bw/00004.png
Binary file modified tests/snapshots/stax/test_trx_freeze_balance_energy/00000.png
Binary file modified tests/snapshots/stax/test_trx_freeze_balance_energy/00001.png
Binary file modified tests/snapshots/stax/test_trx_freeze_balance_energy/00002.png
Binary file modified tests/snapshots/stax/test_trx_freeze_balance_energy/00003.png
Binary file modified tests/snapshots/stax/test_trx_freeze_balance_energy/00004.png
Loading

0 comments on commit 28e18f4

Please sign in to comment.