Add network display (#152)

* Add network name display instead of chainID

* Add display of correct ticker along with network

* Add FTM

* Clang-format

* Add comment in python script

* Rename SIZE_MAX to MAX_SIZE

* Change %u to %d in printf

* Remove needless PIC

* Update comment about get_chain_id()

* Update example script to follow EIP155

* Remove unused PIC calls

* Add whitespace between ticker and amount when using EIP155

* Remove decimal config per network, set back 18 everywhere

* Adapt u32_from_BE to swith cases

* Remove chainid from signTx.py

* Switch to switch in stead of if in get_chain_id

* Revert "Remove chainid from signTx.py"

This reverts commit 454e09f280ec3e3ec1c7d7cc0027247ef4390088.

* Change Ethereum chainid to 1

* Rename chainid_step to network_step

* Adapt finalizeParsing to new chainid for Ethereum

* Update snapshots

* clang-format

* Fix network display logic for clones

* Fix tests

* Add clone tests

Co-authored-by: TamtamHero <10632523+TamtamHero@users.noreply.github.com>
This commit is contained in:
pscott
2021-07-02 18:46:23 +02:00
committed by GitHub
parent ea87a0a646
commit a2d9a8068a
42 changed files with 559 additions and 80 deletions

View File

@@ -2,3 +2,5 @@
customStatus_e customProcessor(txContext_t *context);
void finalizeParsing(bool direct);
void ux_approve_tx(bool dataPresent);

View File

@@ -6,6 +6,7 @@
#include "stark_utils.h"
#endif
#include "eth_plugin_handler.h"
#include "network.h"
#define ERR_SILENT_MODE_CHECK_FAILED 0x6001
@@ -195,7 +196,7 @@ void reportFinalizeError(bool direct) {
void computeFees(char *displayBuffer, uint32_t displayBufferSize) {
uint256_t gasPrice, startGas, uint256;
uint8_t *feeTicker = (uint8_t *) PIC(chainConfig->coinName);
char *feeTicker = get_network_ticker();
uint8_t tickerOffset = 0;
uint32_t i;
@@ -240,25 +241,14 @@ void computeFees(char *displayBuffer, uint32_t displayBufferSize) {
void finalizeParsing(bool direct) {
char displayBuffer[50];
uint8_t decimals = WEI_TO_ETHER;
uint8_t *ticker = (uint8_t *) PIC(chainConfig->coinName);
char *ticker = get_network_ticker();
ethPluginFinalize_t pluginFinalize;
tokenDefinition_t *token1 = NULL, *token2 = NULL;
bool genericUI = true;
// Verify the chain
if (chainConfig->chainId != 0) {
uint32_t id = 0;
if (txContext.txType == LEGACY) {
id = u32_from_BE(txContext.content->v, txContext.content->vLength, true);
} else if (txContext.txType == EIP2930) {
id = u32_from_BE(txContext.content->chainID.value,
txContext.content->chainID.length,
false);
} else {
PRINTF("TxType `%u` not supported while checking for chainID\n", txContext.txType);
return;
}
if (chainConfig->chainId != ETHEREUM_MAINNET_CHAINID) {
uint32_t id = get_chain_id();
if (chainConfig->chainId != id) {
PRINTF("Invalid chainID %u expected %u\n", id, chainConfig->chainId);
@@ -342,7 +332,7 @@ void finalizeParsing(bool direct) {
tmpContent.txContent.destinationLength = 20;
if (token1 != NULL) {
decimals = token1->decimals;
ticker = token1->ticker;
ticker = (char *) token1->ticker;
}
break;
default:
@@ -404,26 +394,22 @@ void finalizeParsing(bool direct) {
// Prepare chainID field
if (genericUI) {
if (txContext.txType == LEGACY) {
uint32_t id = u32_from_BE(txContext.content->v, txContext.content->vLength, true);
PRINTF("Chain ID: %u\n", id);
uint8_t res =
snprintf(strings.common.chainID, sizeof(strings.common.chainID), "%d", id);
if (res >= sizeof(strings.common.chainID)) {
char *name = get_network_name();
if (name == NULL) {
// No network name found so simply copy the chain ID as the network name.
uint32_t chain_id = get_chain_id();
uint8_t res = snprintf(strings.common.network_name,
sizeof(strings.common.network_name),
"%d",
chain_id);
if (res >= sizeof(strings.common.network_name)) {
// If the return value is higher or equal to the size passed in as parameter, then
// the output was truncated. Return the appropriate error code.
THROW(0x6502);
}
} else if (txContext.txType == EIP2930) {
uint256_t chainID;
convertUint256BE(tmpContent.txContent.chainID.value,
tmpContent.txContent.chainID.length,
&chainID);
tostring256(&chainID, 10, displayBuffer, sizeof(displayBuffer));
strncpy(strings.common.chainID, displayBuffer, sizeof(strings.common.chainID));
} else {
PRINTF("Txtype `%u` not supported while generating chainID\n", txContext.txType);
return;
// Network name found, simply copy it.
strncpy(strings.common.network_name, name, sizeof(strings.common.network_name));
}
}

View File

@@ -2,6 +2,8 @@
#include "ui_callbacks.h"
#include "chainConfig.h"
#include "utils.h"
#include "feature_signTx.h"
#include "network.h"
// clang-format off
UX_STEP_NOCB(
@@ -116,11 +118,11 @@ UX_STEP_NOCB(
.text = strings.common.maxFee,
});
UX_STEP_NOCB(
ux_approval_chainid_step,
ux_approval_network_step,
bnnn_paging,
{
.title = "Chain ID",
.text = strings.common.chainID,
.title = "Network",
.text = strings.common.network_name,
});
UX_STEP_CB(
ux_approval_accept_step,
@@ -171,18 +173,9 @@ void ux_approve_tx(bool dataPresent) {
ux_approval_tx_flow_[step++] = &ux_approval_nonce_step;
}
uint32_t id;
if (txContext.txType == LEGACY) {
id = u32_from_BE(txContext.content->v, txContext.content->vLength, true);
} else if (txContext.txType == EIP2930) {
id =
u32_from_BE(txContext.content->chainID.value, txContext.content->chainID.length, false);
} else {
PRINTF("TxType `%u` not supported while preparing to approve tx\n", txContext.txType);
THROW(0x6501);
}
if (id != ETHEREUM_MAINNET_CHAINID) {
ux_approval_tx_flow_[step++] = &ux_approval_chainid_step;
uint32_t chain_id = get_chain_id();
if (chainConfig->chainId == ETHEREUM_MAINNET_CHAINID && chain_id != chainConfig->chainId) {
ux_approval_tx_flow_[step++] = &ux_approval_network_step;
}
ux_approval_tx_flow_[step++] = &ux_approval_fees_step;
ux_approval_tx_flow_[step++] = &ux_approval_accept_step;