Skip to content

Commit

Permalink
Merge pull request #25 from blooo-io/fix/duplication-code
Browse files Browse the repository at this point in the history
fix(Donjon): implemented the donjon review
  • Loading branch information
GuilaneDen authored Mar 31, 2023
2 parents b01fca3 + 4bb41b2 commit 18c024b
Show file tree
Hide file tree
Showing 363 changed files with 45 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ jobs:
- name: Install node
uses: actions/setup-node@v3
with:
node-version: "14.18.1"
node-version: "16.19.0"
- name: Install yarn
run: |
npm install -g yarn
Expand All @@ -297,4 +297,4 @@ jobs:
cd tests && yarn install
- name: Run zemu tests
run: |
cd tests && docker pull zondax/builder-zemu@sha256:8d7b06cedf2d018b9464f4af4b7a8357c3fbb180f3ab153f8cb8f138defb22a4 && yarn test
cd tests && yarn test
2 changes: 1 addition & 1 deletion src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void handle_swap_exact_amount(ethPluginProvideParameter_t *msg,

case TOKEN_PATH_LENGTH:
if (!U2BE_from_parameter(msg->parameter, &(context->tmp_len)) &&
context->tmp_len * 2 != context->array_len) {
context->tmp_len != context->array_len * 2) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
Expand Down
37 changes: 21 additions & 16 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "apwine_plugin.h"

// Set UI for retrieving the ticker.
// The ticker is calculated based on the pair_path_first and the token_path_sent.
// The pair 0 == (PT,Underlying) and 1 == (PT, FYT)
// If the token path is 0, the ticker is the PT ticker, and if the token path is 1,
// the ticker is the Underlying or FYT ticker.
static void set_send_ticker_ui(ethQueryContractUI_t *msg, apwine_parameters_t *context) {
switch (context->selectorIndex) {
case SWAP_EXACT_AMOUNT_IN:
Expand Down Expand Up @@ -68,6 +73,11 @@ static void set_send_ticker_ui(ethQueryContractUI_t *msg, apwine_parameters_t *c
}
}

// Set UI for retrieving the ticker.
// The ticker is calculated based on the pair_path_last and the token_path_received.
// The pair 0 == (PT,Underlying) and 1 == (PT, FYT)
// If the token path is 0, the ticker is the PT ticker, and if the token path is 1,
// the ticker is the Underlying or FYT ticker.
static void set_receive_ticker_ui(ethQueryContractUI_t *msg, apwine_parameters_t *context) {
switch (context->selectorIndex) {
case SWAP_EXACT_AMOUNT_IN:
Expand Down Expand Up @@ -184,6 +194,7 @@ static void set_receive_ticker_ui(ethQueryContractUI_t *msg, apwine_parameters_t
}
}

// Set UI for retrieving the underlying ticker.
static void set_send_underlying_ui(ethQueryContractUI_t *msg, apwine_parameters_t *context) {
switch (context->selectorIndex) {
case ZAPINTOPT:
Expand Down Expand Up @@ -215,6 +226,7 @@ static void set_send_underlying_ui(ethQueryContractUI_t *msg, apwine_parameters_
}
}

// Set UI for retrieving the PT ticker.
static void set_receive_pt_ui(ethQueryContractUI_t *msg, apwine_parameters_t *context) {
switch (context->selectorIndex) {
case ZAPINTOPT:
Expand Down Expand Up @@ -246,6 +258,7 @@ static void set_receive_pt_ui(ethQueryContractUI_t *msg, apwine_parameters_t *co
}
}

// Set UI for retrieving the ticker used in deposit function.
static void set_future_vault_token_deposit_ui(ethQueryContractUI_t *msg,
apwine_parameters_t *context) {
switch (context->selectorIndex) {
Expand Down Expand Up @@ -275,11 +288,12 @@ static void set_future_vault_token_deposit_ui(ethQueryContractUI_t *msg,
}
}

// Set UI for retrieving the ticker used in withdraw function.
static void set_future_vault_token_withdraw_ui(ethQueryContractUI_t *msg,
apwine_parameters_t *context) {
switch (context->selectorIndex) {
case WITHDRAW:
strlcpy(msg->title, "Token Send", msg->titleLength);
strlcpy(msg->title, "Token Receive", msg->titleLength);
break;
default:
PRINTF("Unhandled selector Index: %d\n", context->selectorIndex);
Expand Down Expand Up @@ -312,10 +326,10 @@ static void set_send_amount_ui(ethQueryContractUI_t *msg, apwine_parameters_t *c
strlcpy(msg->title, "Amount In", msg->titleLength);
break;
case ADD_LIQUIDITY:
strlcpy(msg->title, "Amount In 1", msg->titleLength);
strlcpy(msg->title, "First Amount In", msg->titleLength);
break;
case REMOVE_LIQUIDITY:
strlcpy(msg->title, "Amount Out 1", msg->titleLength);
strlcpy(msg->title, "First Amount Out", msg->titleLength);
break;
case DEPOSIT:
case WITHDRAW:
Expand Down Expand Up @@ -364,10 +378,10 @@ static void set_receive_amount_ui(ethQueryContractUI_t *msg, apwine_parameters_t
strlcpy(msg->title, "Amount Out", msg->titleLength);
break;
case ADD_LIQUIDITY:
strlcpy(msg->title, "Amount In 2", msg->titleLength);
strlcpy(msg->title, "2nd Amount In", msg->titleLength);
break;
case REMOVE_LIQUIDITY:
strlcpy(msg->title, "Amount Out 2", msg->titleLength);
strlcpy(msg->title, "2nd Amount Out", msg->titleLength);
break;
case ZAPINTOPT:
strlcpy(msg->title, "Receive Min", msg->titleLength);
Expand Down Expand Up @@ -483,7 +497,7 @@ uint8_t default_screen(uint8_t index, apwine_parameters_t *context) {
}
case 2:
if (both_tokens_found) {
return BENEFICIARY_SCREEN;
return ERROR;
} else if (both_tokens_not_found) {
return WARN_SCREEN;
} else {
Expand All @@ -494,23 +508,14 @@ uint8_t default_screen(uint8_t index, apwine_parameters_t *context) {
return ERROR;
} else if (both_tokens_not_found) {
return RECEIVE_SCREEN;
} else {
return BENEFICIARY_SCREEN;
}
case 4:
if (both_tokens_not_found) {
return BENEFICIARY_SCREEN;
} else {
return ERROR;
}
default:
return ERROR;
}
}

// Helper function that returns the enum corresponding to the screen that should be displayed.
static screens_t get_screen(ethQueryContractUI_t *msg,
apwine_parameters_t *context __attribute__((unused))) {
static screens_t get_screen(ethQueryContractUI_t *msg, apwine_parameters_t *context) {
uint8_t index = msg->screenIndex;
switch (context->selectorIndex) {
case REDEEM_YIELD:
Expand Down
2 changes: 1 addition & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@ledgerhq/hw-app-eth": "^6.27.1",
"@ledgerhq/hw-transport-http": "^6.27.1",
"@ledgerhq/logs": "^6.2.0",
"@zondax/zemu": "^0.35.1",
"@zondax/zemu": "^0.37.0",
"core-js": "^3.16.3",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.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.
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/snapshots/ethereum_nanos_withdraw/00002.png
Binary file modified tests/snapshots/ethereum_nanosp_withdraw/00002.png
Binary file modified tests/snapshots/ethereum_nanox_withdraw/00002.png
Loading

0 comments on commit 18c024b

Please sign in to comment.