Skip to content

Commit

Permalink
Merge pull request #50 from blooo-io/feat/LDG-620--nano-app-implement…
Browse files Browse the repository at this point in the history
…-configurebaker-stax-and-flex

Feat/ldg 620  nano app implement configurebaker stax and flex
  • Loading branch information
n4l5u0r authored Dec 12, 2024
2 parents a2c06ac + 8fe29eb commit dfa3aad
Show file tree
Hide file tree
Showing 83 changed files with 217 additions and 8 deletions.
208 changes: 204 additions & 4 deletions src/common/ui/display_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,216 @@ void uiExportPrivateKey(volatile unsigned int *flags) {
}

void startConfigureBakerCommissionDisplay(void) {
// TODO: Implement this
// Get context from global state
signConfigureBaker_t *ctx = &global.signConfigureBaker;
// Create tag-value pairs for the content
uint8_t pairIndex = 0;

if (ctx->firstDisplay) {
// Add sender address
pairs[pairIndex].item = "Sender";
pairs[pairIndex].value = (char *) global_account_sender.sender;
pairIndex++;
ctx->firstDisplay = false;
}

if (ctx->hasTransactionFeeCommission || ctx->hasBakingRewardCommission ||
ctx->hasFinalizationRewardCommission) {
pairs[pairIndex].item = "Commission";
pairs[pairIndex].value = "rates";
pairIndex++;
}

if (ctx->hasTransactionFeeCommission) {
pairs[pairIndex].item = "Transaction fee";
pairs[pairIndex].value =
(char *) global.signConfigureBaker.commissionRates.transactionFeeCommissionRate;
pairIndex++;
}

if (ctx->hasBakingRewardCommission) {
pairs[pairIndex].item = "Baking reward";
pairs[pairIndex].value =
(char *) global.signConfigureBaker.commissionRates.bakingRewardCommissionRate;
pairIndex++;
}

if (ctx->hasFinalizationRewardCommission) {
pairs[pairIndex].item = "Finalization reward";
pairs[pairIndex].value =
(char *) global.signConfigureBaker.commissionRates.finalizationRewardCommissionRate;
pairIndex++;
}

// Create the page content
nbgl_contentTagValueList_t content;
content.nbPairs = pairIndex;
content.pairs = pairs;
content.smallCaseForValue = false;
content.nbMaxLinesForValue = 0;
content.startIndex = 0;

// Setup the review screen
nbgl_useCaseReview(TYPE_TRANSACTION,
&content,
&C_app_concordium_64px,
"Review Transaction",
NULL, // No subtitle
"Sign Transaction",
review_choice_sign);
}

void startConfigureBakerDisplay(void) {
// TODO: Implement this
// Get context from global state
signConfigureBaker_t *ctx = &global.signConfigureBaker;

// Create tag-value pairs for the content
uint8_t pairIndex = 0;
// Add sender address
pairs[pairIndex].item = "Sender";
pairs[pairIndex].value = (char *) global_account_sender.sender;
pairIndex++;

ctx->firstDisplay = false;

if (ctx->hasCapital) {
if (ctx->capitalRestakeDelegation.stopBaking) {
pairs[pairIndex].item = "Stop";
pairs[pairIndex].value = "Baking";
} else {
pairs[pairIndex].item = "Amount to stake";
pairs[pairIndex].value =
(char *) global.signConfigureBaker.capitalRestakeDelegation.displayCapital;
}
pairIndex++;
}

if (ctx->hasRestakeEarnings) {
pairs[pairIndex].item = "Restake earnings";
pairs[pairIndex].value =
(char *) global.signConfigureBaker.capitalRestakeDelegation.displayRestake;
pairIndex++;
}

if (ctx->hasOpenForDelegation) {
pairs[pairIndex].item = "Pool status";
pairs[pairIndex].value =
(char *) global.signConfigureBaker.capitalRestakeDelegation.displayOpenForDelegation;
pairIndex++;
}

if (ctx->hasKeys) {
pairs[pairIndex].item = "Update baker";
pairs[pairIndex].value = "keys";
pairIndex++;
}

PRINTF("GUI: pairIndex: %d\n", pairIndex);
// If there are additional steps, then show continue screen. If this is the last step,
// then show signing screens.
if (ctx->hasMetadataUrl || hasCommissionRate()) {
// Create the page content
nbgl_contentTagValueList_t content;
content.nbPairs = pairIndex;
content.pairs = pairs;
content.smallCaseForValue = false;
content.nbMaxLinesForValue = 0;
content.startIndex = 0;
// Setup the review screen
nbgl_useCaseReviewLight(TYPE_OPERATION,
&content,
&C_app_concordium_64px,
"Review Transaction",
NULL, // No subtitle
"Continue with transaction",
sendSuccessNoIdle);
} else {
// Create the page content
PRINTF("GUI: Sign transaction:");
nbgl_contentTagValueList_t content;
content.nbPairs = pairIndex;
content.pairs = pairs;
content.smallCaseForValue = false;
content.nbMaxLinesForValue = 0;
content.startIndex = 0;

// Setup the review screen
nbgl_useCaseReview(TYPE_TRANSACTION,
&content,
&C_app_concordium_64px,
"Review Transaction",
NULL, // No subtitle
"Sign transaction",
review_choice_sign);
}
}

void startConfigureBakerUrlDisplay(bool lastUrlPage) {
lastUrlPage = false;
// TODO: Implement this
// Get context from global state
signConfigureBaker_t *ctx = &global.signConfigureBaker;

// Create tag-value pairs for the content
uint8_t pairIndex = 0;

if (ctx->firstDisplay) {
// Add sender address
pairs[pairIndex].item = "Sender";
pairs[pairIndex].value = (char *) global_account_sender.sender;
pairIndex++;
ctx->firstDisplay = false;
}

if (!lastUrlPage) {
pairs[pairIndex].item = "URL";
pairs[pairIndex].value = (char *) global.signConfigureBaker.url.urlDisplay;
pairIndex++;
} else {
if (ctx->url.urlLength == 0) {
pairs[pairIndex].item = "Empty URL";
pairs[pairIndex].value = "";
} else {
pairs[pairIndex].item = "URL";
pairs[pairIndex].value = (char *) global.signConfigureBaker.url.urlDisplay;
}
pairIndex++;
}

// If there are additional steps show the continue screen, otherwise go
// to signing screens.
if (hasCommissionRate()) {
// Create the page content
nbgl_contentTagValueList_t content;
content.nbPairs = pairIndex;
content.pairs = pairs;
content.smallCaseForValue = false;
content.nbMaxLinesForValue = 0;
content.startIndex = 0;
// Setup the review screen
nbgl_useCaseReviewLight(TYPE_OPERATION,
&content,
&C_app_concordium_64px,
"Review Transaction",
NULL, // No subtitle
"Continue with transaction",
sendSuccessNoIdle);
} else {
// Create the page content
nbgl_contentTagValueList_t content;
content.nbPairs = pairIndex;
content.pairs = pairs;
content.smallCaseForValue = false;
content.nbMaxLinesForValue = 0;
content.startIndex = 0;

// Setup the review screen
nbgl_useCaseReview(TYPE_TRANSACTION,
&content,
&C_app_concordium_64px,
"Review Transaction",
NULL, // No subtitle
"Sign transaction",
review_choice_sign);
}
}

// TODO: To fix
Expand Down
5 changes: 2 additions & 3 deletions tests/application_client/boilerplate_command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,13 @@ def sign_configure_baker(

if aggregation_key:
# Second exchange - using with to wait for completion
with self.backend.exchange_async(
self.backend.exchange(
cla=CLA,
ins=InsType.CONFIGURE_BAKER,
p1=0x01,
p2=P2.P2_NONE,
data=transaction,
):
pass
)

# Final exchange with response yielded to caller
with self.backend.exchange_async(
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.
9 changes: 9 additions & 0 deletions tests/test_configure_baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def test_sign_configure_baker_all_parameters(
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK,
]

client = BoilerplateCommandSender(backend)

# Create the transaction with all keys
Expand All @@ -286,6 +287,10 @@ def test_sign_configure_baker_all_parameters(
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=False,
)
else:
navigate_until_text_and_compare(
firmware, navigator, "Continue", default_screenshot_path, test_name + "_1", True, False, NavInsID.USE_CASE_CHOICE_CONFIRM
)
with client.sign_configure_baker_url(
url=url_bytes, bitmap=bitmap, is_called_first=False
):
Expand All @@ -297,6 +302,10 @@ def test_sign_configure_baker_all_parameters(
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=False,
)
else:
navigate_until_text_and_compare(
firmware, navigator, "Continue", default_screenshot_path, test_name + "_2", True, False, NavInsID.USE_CASE_CHOICE_CONFIRM
)
with client.sign_configure_baker_commission_rate(
bitmap=bitmap,
transaction_fee=True,
Expand Down
3 changes: 2 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def navigate_until_text_and_compare(
test_name: str,
screen_change_before_first_instruction: bool = True,
screen_change_after_last_instruction: bool = True,
nav_ins_confirm_instruction: NavInsID = NavInsID.USE_CASE_REVIEW_CONFIRM,
):
"""Navigate through device screens until specified text is found and compare screenshots.
Expand Down Expand Up @@ -77,7 +78,7 @@ def navigate_until_text_and_compare(
"""
if firmware.device.startswith(("stax", "flex")):
go_right_instruction = NavInsID.SWIPE_CENTER_TO_LEFT
confirm_instructions = [NavInsID.USE_CASE_REVIEW_CONFIRM]
confirm_instructions = [nav_ins_confirm_instruction]
else:
go_right_instruction = NavInsID.RIGHT_CLICK
confirm_instructions = [NavInsID.BOTH_CLICK]
Expand Down

0 comments on commit dfa3aad

Please sign in to comment.