From d8c29959183dfd994c73ab2322ba9ff4f21519f0 Mon Sep 17 00:00:00 2001 From: GuilaneDen <83951892+GuilaneDen@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:24:05 +0200 Subject: [PATCH 1/4] fix(comments): Added comments for each functions, removed unused variables --- src/contract.c | 6 ------ src/handle_finalize.c | 6 ++++++ src/handle_provide_parameter.c | 26 +++++++++++++++++++++++ src/handle_query_contract_id.c | 1 + src/handle_query_contract_ui.c | 39 ++++++++++++++++++++++------------ src/stakekit_plugin.h | 2 -- 6 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/contract.c b/src/contract.c index 7847bc0..6234969 100644 --- a/src/contract.c +++ b/src/contract.c @@ -142,12 +142,6 @@ const uint8_t *const STAKEKIT_SELECTORS[NUM_STAKEKIT_SELECTORS] = { STAKEKIT_YEARN_VAULT_WITHDRAW_3_SELECTOR, }; -// Indicate the Ethereum chain ID -const uint8_t ETH_CHAIN_ID[CHAIN_ID_LENGTH] = {0x01}; - -// Indicate the BSC chain ID -const uint8_t BSC_CHAIN_ID[CHAIN_ID_LENGTH] = {0x38}; - // Null address const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/handle_finalize.c b/src/handle_finalize.c index bdeab7d..a0a1825 100644 --- a/src/handle_finalize.c +++ b/src/handle_finalize.c @@ -1,6 +1,9 @@ #include "stakekit_plugin.h" // Sets the deposit ticker as the token symbol +// Look into the STAKEKIT_SUPPORTED_YEARN_VAULT array to find the corresponding token symbol. +// If found, set the ticker and decimals. Then return true. +// If not found, return false. static bool set_ticker_deposit_for_mapped_token(plugin_parameters_t *context, ethPluginFinalize_t *msg) { for (size_t i = 0; i < NUM_SUPPORTED_SMART_CONTRACT; i++) { @@ -21,6 +24,9 @@ static bool set_ticker_deposit_for_mapped_token(plugin_parameters_t *context, return false; } // Sets the withdraw ticker as the token symbol +// Look into the STAKEKIT_SUPPORTED_YEARN_VAULT array to find the corresponding token symbol. +// If found, set the ticker and decimals. Then return true. +// If not found, return false. static bool set_ticker_withdraw_for_mapped_token(plugin_parameters_t *context, ethPluginFinalize_t *msg) { for (size_t i = 0; i < NUM_SUPPORTED_SMART_CONTRACT; i++) { diff --git a/src/handle_provide_parameter.c b/src/handle_provide_parameter.c index 8250be2..e7610a3 100644 --- a/src/handle_provide_parameter.c +++ b/src/handle_provide_parameter.c @@ -1,6 +1,8 @@ #include "stakekit_plugin.h" // Save two amounts in the context. +// The first amount is the amount received saved in amount_received. +// The second amount is the amount sent saved in amount_sent. static void handle_swap_from(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { case AMOUNT_RECEIVED: @@ -18,6 +20,8 @@ static void handle_swap_from(ethPluginProvideParameter_t *msg, plugin_parameters } // Save 1 amount and 1 recipient in the context. +// The amount is the amount sent saved in amount_sent. +// The second param is the recipient saved in recipient. static void handle_amount_recipient(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { @@ -36,6 +40,8 @@ static void handle_amount_recipient(ethPluginProvideParameter_t *msg, } // Save 1 amount and 1 recipient in the context. +// The first param is the recipient saved in recipient. +// The second param is the amount sent saved in amount_sent. static void handle_recipient_amount_sent(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { @@ -54,6 +60,9 @@ static void handle_recipient_amount_sent(ethPluginProvideParameter_t *msg, } // Save 1 amount and 1 recipient and 1 token address in the context. +// The first param is the token address which help to fetch the token info later. +// The second param is the recipient saved in recipient. +// The third param is the amount sent saved in amount_sent. static void handle_morpho_supply_1_3(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { @@ -80,6 +89,8 @@ static void handle_morpho_supply_1_3(ethPluginProvideParameter_t *msg, } // Save 1 amount and 1 token address in the context. +// The first param is the token address which help to fetch the token info later. +// The second param is the amount sent saved in amount_sent. static void handle_morpho_supply_2(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { case TOKEN_SENT: @@ -98,6 +109,8 @@ static void handle_morpho_supply_2(ethPluginProvideParameter_t *msg, plugin_para } // Save 1 amount and 1 token address in the context. +// The first param is the token address which help to fetch the token info later. +// The second param is the amount received saved in amount_received. static void handle_morpho_withdraw_1(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { @@ -120,6 +133,9 @@ static void handle_morpho_withdraw_1(ethPluginProvideParameter_t *msg, } // Save 1 amount and 1 recipient and 1 token address in the context. +// The first param is the token address which help to fetch the token info later. +// The second param is the amount received saved in amount_received. +// The third param is the recipient saved in recipient. static void handle_morpho_withdraw_2(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { @@ -146,6 +162,9 @@ static void handle_morpho_withdraw_2(ethPluginProvideParameter_t *msg, } // Save 2 recipients in the context. +// The first param is the recipient as we have 2 recipient and the storage has a limitation, +// we need to save it in another variable which is contract_address. +// The second param is the second recipient saved in recipient. static void handle_comet_claim(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { case RECIPIENT: // Put the Comet protocol address in contract_address @@ -166,6 +185,10 @@ static void handle_comet_claim(ethPluginProvideParameter_t *msg, plugin_paramete } // Save 1 amount and 3 recipients in the context. +// The first param is the second recipient saved in recipient. +// The second param is the amount sent saved in amount_sent. +// The third and fourth param are the recipients as we have 3 recipient and the storage has a limitation, +// we need to save it in other variables which are contract_address and amount_received. static void handle_vote_revoke(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { case RECIPIENT: @@ -200,6 +223,9 @@ static void handle_vote_revoke(ethPluginProvideParameter_t *msg, plugin_paramete } // Save 1 amount and 1 recipient and 1 token address in the context. +// The first param is the token address which help to fetch the token info later. +// The second param is the amount sent saved in amount_sent. +// The third param is the recipient saved in recipient. static void handle_aave_supply(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { case TOKEN_SENT: diff --git a/src/handle_query_contract_id.c b/src/handle_query_contract_id.c index 2e043e7..db542f0 100644 --- a/src/handle_query_contract_id.c +++ b/src/handle_query_contract_id.c @@ -1,5 +1,6 @@ #include "stakekit_plugin.h" +// Function to display the method name on the device. void handle_query_contract_id(void *parameters) { ethQueryContractID_t *msg = (ethQueryContractID_t *) parameters; plugin_parameters_t *context = (plugin_parameters_t *) msg->pluginContext; diff --git a/src/handle_query_contract_ui.c b/src/handle_query_contract_ui.c index a38379b..e48d8d6 100644 --- a/src/handle_query_contract_ui.c +++ b/src/handle_query_contract_ui.c @@ -1,6 +1,7 @@ #include "stakekit_plugin.h" // Set UI for the "Send" screen. +// Each methods sets the title and the message to be displayed on the screen. static void set_send_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) { switch (context->selectorIndex) { case DEPOSIT_SELF_APECOIN: @@ -59,7 +60,7 @@ static void set_send_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) PRINTF("AMOUNT SENT: %s\n", msg->msg); } -// Same as the "set_send_ui" function. Howerver the value is extracted from the pluginSharedRO. +// Same as the "set_send_ui" function. However the value is extracted from the pluginSharedRO. static void set_send_value_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) { switch (context->selectorIndex) { case STAKE: @@ -82,6 +83,7 @@ static void set_send_value_ui(ethQueryContractUI_t *msg, plugin_parameters_t *co } // Set UI for "Receive" screen. +// Each methods sets the title and the message to be displayed on the screen. static void set_receive_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) { switch (context->selectorIndex) { case WITHDRAW_SELF_APECOIN: @@ -128,6 +130,7 @@ static void print_address(ethQueryContractUI_t *msg, uint8_t *address) { } // Set UI for "Recipient" screen. +// Each methods sets the title and the message to be displayed on the screen. static void set_recipient_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) { switch (context->selectorIndex) { case SUBMIT_MATIC_LIDO: @@ -173,6 +176,7 @@ static void set_recipient_ui(ethQueryContractUI_t *msg, plugin_parameters_t *con // Set UI for "Recipient 2" screen. When having more than one recipient. // The recipient address is saved in the contract_address +// Each methods sets the title and the message to be displayed on the screen. static void set_recipient_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) { switch (context->selectorIndex) { case COMET_CLAIM: @@ -193,6 +197,7 @@ static void set_recipient_2_ui(ethQueryContractUI_t *msg, plugin_parameters_t *c // Set UI for "Recipient 2" screen. When having more than two recipients. // The recipient address is saved in the amount_received +// Each methods sets the title and the message to be displayed on the screen. static void set_recipient_3_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) { switch (context->selectorIndex) { case VOTE: @@ -209,6 +214,7 @@ static void set_recipient_3_ui(ethQueryContractUI_t *msg, plugin_parameters_t *c } // Set UI for smart contract address screen. +// Each methods sets the title and the message to be displayed on the screen. static void set_smart_contract_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) { switch (context->selectorIndex) { case CLAIM_SELF_APECOIN: @@ -232,6 +238,7 @@ static void set_smart_contract_ui(ethQueryContractUI_t *msg, plugin_parameters_t } // Set UI for unbound nonce boolean screen. +// Each methods sets the title and the message to be displayed on the screen. static void set_unbound_nonce_ui(ethQueryContractUI_t *msg, plugin_parameters_t *context) { switch (context->selectorIndex) { case UNSTAKE_CLAIM_TOKENS_NEW: @@ -256,6 +263,7 @@ static void set_warning_ui(ethQueryContractUI_t *msg, strlcpy(msg->msg, "Unknown token", msg->msgLength); } +// Set UI for the methods needing a send screen. static screens_t get_screen_amount_sent(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { switch (msg->screenIndex) { @@ -266,6 +274,7 @@ static screens_t get_screen_amount_sent(ethQueryContractUI_t *msg, } } +// Set UI for the methods needing a receive screen. static screens_t get_screen_receive(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { switch (msg->screenIndex) { @@ -276,16 +285,7 @@ static screens_t get_screen_receive(ethQueryContractUI_t *msg, } } -static screens_t get_screen_submit_eth_lido(ethQueryContractUI_t *msg, - plugin_parameters_t *context __attribute__((unused))) { - switch (msg->screenIndex) { - case 0: - return RECIPIENT_SCREEN; - default: - return ERROR; - } -} - +// Set UI for the methods needing a send and recipient screens. static screens_t get_screen_amount_sent_recipient(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { @@ -299,6 +299,8 @@ static screens_t get_screen_amount_sent_recipient(ethQueryContractUI_t *msg, } } +// Set UI for the methods needing a send and recipient screens. +// If the token is not found, we need an additional screen to display a warning message. static screens_t get_screen_supply(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { bool token_sent_found = context->tokens_found & TOKEN_SENT_FOUND; @@ -327,6 +329,8 @@ static screens_t get_screen_supply(ethQueryContractUI_t *msg, } } +// Set UI for the methods needing a receive and recipient screens. +// If the token is not found, we need an additional screen to display a warning message. static screens_t get_screen_morpho_withdraw(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { bool token_received_found = context->tokens_found & TOKEN_RECEIVED_FOUND; @@ -355,6 +359,7 @@ static screens_t get_screen_morpho_withdraw(ethQueryContractUI_t *msg, } } +// Set UI for the methods needing 2 recipients screens. static screens_t get_screen_comet_claim(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { switch (msg->screenIndex) { @@ -367,6 +372,7 @@ static screens_t get_screen_comet_claim(ethQueryContractUI_t *msg, } } +// Set UI for the methods needing a send and receive screens. static screens_t get_screen_amount_sent_receive(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { @@ -380,6 +386,7 @@ static screens_t get_screen_amount_sent_receive(ethQueryContractUI_t *msg, } } +// Set UI for the methods needing a send Value screen. static screens_t get_screen_value_sent(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { switch (msg->screenIndex) { @@ -390,6 +397,7 @@ static screens_t get_screen_value_sent(ethQueryContractUI_t *msg, } } +// Set UI for the methods needing a recipient screen. static screens_t get_screen_recipient(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { switch (msg->screenIndex) { @@ -400,6 +408,7 @@ static screens_t get_screen_recipient(ethQueryContractUI_t *msg, } } +// Set UI for the methods needing a smart contract screen. static screens_t get_screen_smart_contract_address(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { @@ -411,6 +420,8 @@ static screens_t get_screen_smart_contract_address(ethQueryContractUI_t *msg, } } +// Set UI for the Vote and Revoke methods. +// These methods need 4 screens. static screens_t get_screen_vote_revoke(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { switch (msg->screenIndex) { @@ -427,6 +438,8 @@ static screens_t get_screen_vote_revoke(ethQueryContractUI_t *msg, } } +// Set UI for the UnstakeClaim method. +// This method needs to display the unbound nonce boolean. static screens_t get_screen_unstake_claim(ethQueryContractUI_t *msg, plugin_parameters_t *context __attribute__((unused))) { switch (msg->screenIndex) { @@ -458,9 +471,8 @@ static screens_t get_screen(ethQueryContractUI_t *msg, return get_screen_receive(msg, context); case GRT_UNDELEGATE: case GRT_WITHDRAW_DELEGATED: - return get_screen_recipient(msg, context); case SUBMIT_ETH_LIDO: - return get_screen_submit_eth_lido(msg, context); + return get_screen_recipient(msg, context); case SUBMIT_MATIC_LIDO: case REQUEST_WITHDRAW: case PARASPACE_DEPOSIT: @@ -508,6 +520,7 @@ static screens_t get_screen(ethQueryContractUI_t *msg, return ERROR; } +// Set the UI according to the screen that needs to be displayed. void handle_query_contract_ui(void *parameters) { ethQueryContractUI_t *msg = (ethQueryContractUI_t *) parameters; plugin_parameters_t *context = (plugin_parameters_t *) msg->pluginContext; diff --git a/src/stakekit_plugin.h b/src/stakekit_plugin.h index 123f7b2..33331cc 100644 --- a/src/stakekit_plugin.h +++ b/src/stakekit_plugin.h @@ -25,8 +25,6 @@ extern const tokenSymbolAndDecimals_t STAKEKIT_SUPPORTED_YEARN_VAULT[NUM_SUPPORT #define CHAIN_ID_LENGTH 1 extern const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH]; -extern const uint8_t ETH_CHAIN_ID[CHAIN_ID_LENGTH]; -extern const uint8_t BSC_CHAIN_ID[CHAIN_ID_LENGTH]; // Returns 1 if corresponding address is the address for the chain token (ETH, BNB, MATIC,...) #define ADDRESS_IS_NETWORK_TOKEN(_addr) !memcmp(_addr, NULL_ETH_ADDRESS, ADDRESS_LENGTH) From eaeb9e8623e8c001ecf770584826e2d93237d994 Mon Sep 17 00:00:00 2001 From: GuilaneDen <83951892+GuilaneDen@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:33:15 +0200 Subject: [PATCH 2/4] fix(lint): Fixed lint error --- src/handle_provide_parameter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/handle_provide_parameter.c b/src/handle_provide_parameter.c index e7610a3..c8480cf 100644 --- a/src/handle_provide_parameter.c +++ b/src/handle_provide_parameter.c @@ -162,8 +162,8 @@ static void handle_morpho_withdraw_2(ethPluginProvideParameter_t *msg, } // Save 2 recipients in the context. -// The first param is the recipient as we have 2 recipient and the storage has a limitation, -// we need to save it in another variable which is contract_address. +// The first param is the recipient as we have 2 recipient and the storage has a +// limitation, we need to save it in another variable which is contract_address. // The second param is the second recipient saved in recipient. static void handle_comet_claim(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { From a4ca4dc4bb019a414409bb314000161c8d548589 Mon Sep 17 00:00:00 2001 From: GuilaneDen <83951892+GuilaneDen@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:36:46 +0200 Subject: [PATCH 3/4] fix(lint): Fixed lint error --- src/handle_provide_parameter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/handle_provide_parameter.c b/src/handle_provide_parameter.c index c8480cf..08b05d6 100644 --- a/src/handle_provide_parameter.c +++ b/src/handle_provide_parameter.c @@ -187,8 +187,8 @@ static void handle_comet_claim(ethPluginProvideParameter_t *msg, plugin_paramete // Save 1 amount and 3 recipients in the context. // The first param is the second recipient saved in recipient. // The second param is the amount sent saved in amount_sent. -// The third and fourth param are the recipients as we have 3 recipient and the storage has a limitation, -// we need to save it in other variables which are contract_address and amount_received. +// The third and fourth param are the recipients as we have 3 recipient and the storage has a +// limitation, we need to save it in other variables which are contract_address and amount_received. static void handle_vote_revoke(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { case RECIPIENT: From d827b95caa35ed68fba73bdb486a6ee26c6c19b4 Mon Sep 17 00:00:00 2001 From: GuilaneDen <83951892+GuilaneDen@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:38:18 +0200 Subject: [PATCH 4/4] fix(lint): Fixed lint error --- src/handle_provide_parameter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handle_provide_parameter.c b/src/handle_provide_parameter.c index 08b05d6..ed73d8b 100644 --- a/src/handle_provide_parameter.c +++ b/src/handle_provide_parameter.c @@ -188,7 +188,7 @@ static void handle_comet_claim(ethPluginProvideParameter_t *msg, plugin_paramete // The first param is the second recipient saved in recipient. // The second param is the amount sent saved in amount_sent. // The third and fourth param are the recipients as we have 3 recipient and the storage has a -// limitation, we need to save it in other variables which are contract_address and amount_received. +// limitation, we need to save it in other variables which are contract_address and amount_received. static void handle_vote_revoke(ethPluginProvideParameter_t *msg, plugin_parameters_t *context) { switch (context->next_param) { case RECIPIENT: