Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chunkifying the receiving address #3237

Merged
merged 15 commits into from
Sep 15, 2023
Merged

Chunkifying the receiving address #3237

merged 15 commits into from
Sep 15, 2023

Conversation

grdddj
Copy link
Contributor

@grdddj grdddj commented Aug 25, 2023

Fixes #3210:

  • allowing for showing the address in chunks of 4 characters

image

image

@grdddj grdddj self-assigned this Aug 25, 2023
@grdddj
Copy link
Contributor Author

grdddj commented Aug 25, 2023

Interesting edge-case in TT and Cardano - when there are more pages, the text area is smaller because of the scrollbar, and the last character does not fit. Might be possible to decrease the x_offset in case there are more pages

image

@grdddj grdddj marked this pull request as ready for review August 25, 2023 14:47
@grdddj grdddj requested review from Hannsek and removed request for prusnak August 25, 2023 14:47
@prusnak
Copy link
Member

prusnak commented Aug 25, 2023

Interesting edge-case in TT

Do we still want to show the dots representing the pages even after adding the new hints? Especially since you can't go back anyway ...

common/protob/messages-bitcoin.proto Outdated Show resolved Hide resolved
@Hannsek
Copy link
Contributor

Hannsek commented Aug 27, 2023

Interesting edge-case in TT

Do we still want to show the dots representing the pages even after adding the new hints? Especially since you can't go back anyway ...

The thing you cannot go back is a bug. Should be solved by #2888 (#2902).
We are thinking about removing the pagination when there are only 2 pages. But don't have a resolution now.

@grdddj We should display max 16 chunks per page, not more. See the image below.
image
image

What is the vertical space between rows/chunks? Is it currently variable?

Also, can we align the "next page" arrow to fit the last chunk (or block of text)?

@grdddj
Copy link
Contributor Author

grdddj commented Aug 28, 2023

@grdddj We should display max 16 chunks per page, not more. See the image below.

Is it worth doing this complexity, when the only addresses longer than 16 chunks are Cardano? Others are fine even without this limit

What is the vertical space between rows/chunks? Is it currently variable?

Vertical space between coherent text (inside one paragraph) is constant, as in all other text

Also, can we align the "next page" arrow to fit the last chunk (or block of text)?

Yes, we can somehow, but same as above, it is only valid for Cardano, others do not need it

@Hannsek
Copy link
Contributor

Hannsek commented Sep 4, 2023

Is it worth doing this complexity, when the only addresses longer than 16 chunks are Cardano? Others are fine even without this limit?

Hmm, probably not. And we can set the cardano address to appear as a standard string.
However, we should do it for (multisig) xpubs as well in the future.

Vertical space between coherent text (inside one paragraph) is constant, as in all other text

We should make it larger in both, TT and TR.

@grdddj
Copy link
Contributor Author

grdddj commented Sep 5, 2023

Vertical space between coherent text (inside one paragraph) is constant, as in all other text

We should make it larger in both, TT and TR.

Do you want to increase the vertical margin in this special case of chunked address, or in all the screens in general?

@Hannsek
Copy link
Contributor

Hannsek commented Sep 5, 2023

Only in this special case of chunked address.

@Hannsek
Copy link
Contributor

Hannsek commented Sep 5, 2023

Also please increase the horizontal space between chunks on TT by 1 px.

@grdddj grdddj force-pushed the grdddj/chunked_address branch from 1d8d08f to 798a2d2 Compare September 5, 2023 09:22
@grdddj
Copy link
Contributor Author

grdddj commented Sep 5, 2023

Force-pushed after rebase on master.

It includes increase in vertical spacing, as well as increase in TT's horizontal space

@grdddj grdddj requested a review from onvej-sl as a code owner September 6, 2023 10:41
@grdddj grdddj force-pushed the grdddj/chunked_address branch from 048d592 to 141024f Compare September 11, 2023 13:15
@grdddj
Copy link
Contributor Author

grdddj commented Sep 11, 2023

Last commit introduces chunkifying also for the address in sign flow. In TR, there is one edge-case where the word CoinJoin (as an address_label) is also shown at that screen, and it is chunkified as well. It would be quite complicated to render the label without chunks and the address with chunks.

@Hannsek Please consider if this looks good enough - and please look at all the other changed screens in signing flow.

image

@Hannsek
Copy link
Contributor

Hannsek commented Sep 11, 2023

We should render the label not chunked.

@grdddj
Copy link
Contributor Author

grdddj commented Sep 11, 2023

Did also the account addition, and some of the labels do not fit properly:
image

@mmilata
Copy link
Member

mmilata commented Sep 11, 2023

Not sure if it's an improvement on model T:
0d60046844f9f4e9dd1713962f13dd7acfc30830f97531ff0246f5c12b4c595a

@mmilata
Copy link
Member

mmilata commented Sep 11, 2023

Is the font really fixed width? Sometimes the alignment looks very wrong:
9edaffd47cb893106d4586c603663c85c90fb1cbb24fcf0e071cdf4f0e5c094b

@grdddj
Copy link
Contributor Author

grdddj commented Sep 12, 2023

Is the font really fixed width? Sometimes the alignment looks very wrong: 9edaffd47cb893106d4586c603663c85c90fb1cbb24fcf0e071cdf4f0e5c094b

Right, the font is an almost-mono. Some letters like m, M, w or W are one pixel wider than others (8 vs 7 pixels - including margin) - can be seen in https://github.com/trezor/trezor-firmware/blob/master/core/embed/lib/fonts/font_pixeloperatormono_regular_8.c

Seems there are no easy fixes, as the font is so small (narrow) that these four letters just cannot be made as narrow as other characters.

Possible measures:

  • manually increasing the width of all the letters from 7 to 8 pixels ... at the cost of making the majority of the text wastefully wider
  • accounting for it in the rendering, remembering the number or "extra pixels" in the chunk and decreasing the x-offset - this way at least the chunks would be starting at the same vertical line (however, not applicable when there are no chunks)

Do you see some other possibilities?

@Hannsek
Copy link
Contributor

Hannsek commented Sep 12, 2023

Please delete "account" in receive flow.
We need to figure out the wording in send on TT. So probably keep the "account" only for send flow on T2B1.

accounting for it in the rendering, remembering the number or "extra pixels" in the chunk and decreasing the x-offset - this way at least the chunks would be starting at the same vertical line (however, not applicable when there are no chunks)

Please try it

@grdddj grdddj force-pushed the grdddj/chunked_address branch from d8baa5b to fa24f7f Compare September 12, 2023 09:04
@Hannsek
Copy link
Contributor

Hannsek commented Sep 12, 2023

Now it looks good, but there is some trouble regarding long addresses (cardano) but I believe it is ok to leave it like this.
image

It should look like this:
image

@Hannsek
Copy link
Contributor

Hannsek commented Sep 12, 2023

The bigger problem is this, wrong positioning of the left arrow.
image

@grdddj grdddj requested a review from mmilata September 13, 2023 09:36
@grdddj grdddj force-pushed the grdddj/chunked_address branch from c2d03d1 to dd38f2a Compare September 14, 2023 12:15
Copy link
Contributor

@matejcik matejcik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-Rust part LGTM, just some superfluous default arguments

@@ -12,11 +12,12 @@ async def transfer(
common: NEMTransactionCommon,
transfer: NEMTransfer,
node: bip32.HDNode,
chunkify: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argument here and in layout.ask_transfer does not need a default value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7e03759

@@ -143,6 +145,7 @@ async def _require_confirm_output(
dst: MoneroTransactionDestinationEntry,
network_type: MoneroNetworkType,
payment_id: bytes | None,
chunkify: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove default value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7e03759

@@ -210,6 +210,7 @@ async def confirm_sending(
to: str,
output_type: Literal["address", "change", "collateral-return"],
network_id: int,
chunkify: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove default value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7e03759

@@ -62,6 +62,7 @@ async def confirm_output(
coin: CoinInfo,
amount_unit: AmountUnit,
output_index: int,
chunkify: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove default value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7e03759



async def _confirm_transfer(inputs_outputs: Sequence[tuple[str, str, str]]) -> None:
async def _confirm_transfer(
inputs_outputs: Sequence[tuple[str, str, str]], chunkify: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove default value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7e03759

Copy link
Member

@mmilata mmilata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screens look good now. Commented some nits, also not super happy about the renderer changes but don't really see how we can come up with something better in short time.

core/src/apps/bitcoin/keychain.py Outdated Show resolved Hide resolved
@@ -110,6 +110,7 @@ message GetAddress {
optional MultisigRedeemScriptType multisig = 4; // filled if we are showing a multisig address
optional InputScriptType script_type = 5 [default=SPENDADDRESS]; // used to distinguish between various address formats (non-segwit, segwit, etc.)
optional bool ignore_xpub_magic = 6; // ignore SLIP-0132 XPUB magic, use xpub/tpub prefix for all account types
optional bool chunkify = 7; // display the address in chunks of 4 characters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: thinking if we can come up with a more descriptive name, perhaps indicate that it is related to show_display. show_chunks? show_segmented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can change it to anything, if we agree. What is your preference? @matejcik

show_chunks sounds good to me

core/embed/rust/src/ui/component/text/layout.rs Outdated Show resolved Hide resolved
core/embed/rust/src/ui/component/text/op.rs Outdated Show resolved Hide resolved
/// How big will be the space between chunks (in pixels).
pub x_offset: i16,
/// Optional characters that are wider and should be accounted for
pub wider_chars: Option<&'static str>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda hate this tbh (as well as the whole idea of trying to render variable-width font as a fixed-width font). Trying to think how to make this more general. Can we instead remember the width of a normal (or smallest) character and keep track of the actual chunk size when processing chunk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nor am I happy with this, but this "almost-mono-font" can hardly be fixed to be "completely-mono", because of its small width, as I am describing here

Not sure I follow your suggestion - can you prototype some code for it?

Merging this does not need to be final, we can improve it in the future

line.advance.y = 0;
// Decreasing the offset for each wider character in the chunk
line.advance.x += chunkify_config.x_offset - chunks_wider_chars;
return line;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this can't break line-counting somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests seem to be alright, it works even with longer addresses that paginate (Cardano ones)

Comment on lines 93 to 98
Op::Chunkify(chunk) => {
if let Some((chunk_config, extra_y_offset)) = chunk {
self.layout.style.chunks = Some(chunk_config);
self.layout.style.extra_y_line_advance = Some(extra_y_offset);
} else {
self.layout.style.chunks = None;
self.layout.style.extra_y_line_advance = None;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Op::Chunkify(chunk) => {
if let Some((chunk_config, extra_y_offset)) = chunk {
self.layout.style.chunks = Some(chunk_config);
self.layout.style.extra_y_line_advance = Some(extra_y_offset);
} else {
self.layout.style.chunks = None;
self.layout.style.extra_y_line_advance = None;
}
}
Op::Chunkify(Some((chunk_config, extra_y_offset))) => {
self.layout.style.chunks = Some(chunk_config);
self.layout.style.extra_y_line_advance = Some(extra_y_offset);
}
Op::Chunkify(None) => {
self.layout.style.chunks = None;
self.layout.style.extra_y_line_advance = None;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have simplified it in eb3cab9 by separating to two Op enums

Copy link
Member

@mmilata mmilata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with merging this, rename the parameter to show_chunks if you want.

@grdddj grdddj force-pushed the grdddj/chunked_address branch from ddef752 to 7019b1a Compare September 14, 2023 18:03
@grdddj
Copy link
Contributor Author

grdddj commented Sep 14, 2023

@prusnak please review the change request, it is blocking the merge.

@grdddj grdddj requested a review from prusnak September 14, 2023 18:08
Copy link
Member

@prusnak prusnak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed only protobuf def changes

@grdddj grdddj merged commit 8c98015 into master Sep 15, 2023
@grdddj grdddj deleted the grdddj/chunked_address branch September 15, 2023 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

"Account" in address_label Chunked addresses
5 participants